duheng
2024-12-24 63834af1872ab37f22a5e67b5df20a082f7a052a
WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/07-matching/00-core/AssetsMatchingHelper.cs
@@ -40,6 +40,7 @@
            var AssetsHydrantMain = new BLL.AssetsHydrantMain();
            var AssetsPressmeterMain = new BLL.AssetsPressmeterMain();
            var AssetsTranslationMain = new BLL.AssetsTranslationMain();
            var AssetsCoolingMain = new BLL.AssetsCoolingMain();
            try
            {
                var allPump = Task.Run(async () => await AssetsPumpMain.GetAll()).Result;
@@ -59,6 +60,7 @@
                var allHydrantMain = Task.Run(async () => await AssetsHydrantMain.GetAll()).Result;
                var allPressmeterMain = Task.Run(async () => await AssetsPressmeterMain.GetAll()).Result;
                var allTranslationMain = Task.Run(async () => await AssetsTranslationMain.GetAll()).Result;
                var allCoolingMain = Task.Run(async () => await AssetsCoolingMain.GetAll()).Result;
                //泵匹配
                foreach (var item in assetsAutoMatchingView.Pumps)
                {
@@ -102,7 +104,7 @@
                //弯头匹配
                foreach (var item in assetsAutoMatchingView.Elbows)
                {
                    if (MatchingElbow(item, allElbow))
                    if (Matching(item, allElbow))
                    {
                        IsMaching = true;
                    }
@@ -111,6 +113,15 @@
                foreach (var item in assetsAutoMatchingView.Nozzles)
                {
                    if (MatchingSprinkler(item, allSprinkler))
                    {
                        IsMaching = true;
                    }
                }
                //喷头匹配
                foreach (var item in assetsAutoMatchingView.Coolings)
                {
                    if (Matching(item, allCoolingMain))
                    {
                        IsMaching = true;
                    }
@@ -290,6 +301,7 @@
                        InputModel.MatchingCurveQE.Add(new HydroCurvePointViewModel(item.X, item.Y));
                    }
                }
                return true;
            }
            return false;
@@ -598,125 +610,125 @@
            return false;
        }
        //弯头匹配
        public static bool MatchingElbow(HydroElbowMatchingViewModel input, List<Vmo.AssetsElbowMainVmo> elbowMainVmos)
        {
            bool isNotarize = false; //是否确定
            if (elbowMainVmos == null || input == null || elbowMainVmos.Count == 0)
            {
                return true;
            }
            Vmo.AssetsElbowMainVmo vmo = null;
            var nameMatching = elbowMainVmos.Where(x =>
        (x.KeyWord != null && x.KeyWord.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) ||
        (x.KeyWord == null || !x.KeyWord.Any()) && GetIntersect(x.Name, input.ModelType) >= 1
        ) //先进行筛选,后进行从大到小排序
       .OrderByDescending(x =>
        (x.KeyWord != null && x.KeyWord.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) ||
        (x.KeyWord == null || !x.KeyWord.Any()) && GetIntersect(x.Name, input.ModelType) >= 1).ToList();
        /*   //弯头匹配
           public static bool MatchingElbow(HydroElbowMatchingViewModel input, List<Vmo.AssetsElbowMainVmo> elbowMainVmos)
           {
               bool isNotarize = false; //是否确定
               if (elbowMainVmos == null || input == null || elbowMainVmos.Count == 0)
               {
                   return true;
               }
               Vmo.AssetsElbowMainVmo vmo = null;
               var nameMatching = elbowMainVmos.Where(x =>
           (x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) ||
           (x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1
           ) //先进行筛选,后进行从大到小排序
          .OrderByDescending(x =>
           (x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) ||
           (x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1).ToList();
            if (nameMatching.Count > 1)
            {
                var absoluteMatching = nameMatching.Where(i =>
              ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //直径约束
               i.Material == input.Material  //材料约束
                 ).ToList();
                if (absoluteMatching.Count > 1)
                {
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        vmo = defaultList.First();
                    }
                    else if (defaultList.Count <= 0)
                    {
                        vmo = elbowMainVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    isNotarize = true;
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = elbowMainVmos.First();
            }
            else if (nameMatching.Count == 1)
            {
                isNotarize = true;
                vmo = nameMatching.First();
            }
            else
            {
                var absoluteMatching = elbowMainVmos.Where(i =>
          ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //直径约束
           i.Material == input.Material   //材料约束
             ).ToList();
                if (absoluteMatching.Count > 1)
                {
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        vmo = defaultList.First();
                    }
                    else if (defaultList.Count <= 0)
                    {
                        vmo = elbowMainVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    isNotarize = true;
               if (nameMatching.Count > 1)
               {
                   var absoluteMatching = nameMatching.Where(i =>
                 ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //直径约束
                  i.Material == input.Material  //材料约束
                    ).ToList();
                   if (absoluteMatching.Count > 1)
                   {
                       var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                       //取默认
                       if (defaultList.Count > 0)
                       {
                           vmo = defaultList.First();
                       }
                       else if (defaultList.Count <= 0)
                       {
                           vmo = elbowMainVmos.First();
                       }
                   }
                   else if (absoluteMatching.Count == 1)
                   {
                       isNotarize = true;
                       vmo = absoluteMatching.First();
                   }
                   else
                       vmo = elbowMainVmos.First();
               }
               else if (nameMatching.Count == 1)
               {
                   isNotarize = true;
                   vmo = nameMatching.First();
               }
               else
               {
                   var absoluteMatching = elbowMainVmos.Where(i =>
             ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //直径约束
              i.Material == input.Material   //材料约束
                ).ToList();
                   if (absoluteMatching.Count > 1)
                   {
                       var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                       //取默认
                       if (defaultList.Count > 0)
                       {
                           vmo = defaultList.First();
                       }
                       else if (defaultList.Count <= 0)
                       {
                           vmo = elbowMainVmos.First();
                       }
                   }
                   else if (absoluteMatching.Count == 1)
                   {
                       isNotarize = true;
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = elbowMainVmos.First();
            }
            if (vmo != null)
            {
                if (!isNotarize)
                {
                    if (!input.MinorLoss.HasValue)
                    {
                        input.MatchingMinorLoss = vmo.MinorLoss;
                    }
                    if (input.DbId == null)
                    {
                        input.MatchingDbId = vmo.ID.ToString();
                    }
                    if (input.Material == null)
                    {
                        input.MatchingMaterial = vmo.Material;
                    }
                    if (input.ModelType == null)
                    {
                        input.MatchingModelType = vmo.Material;
                    }
                    if (!input.ElbowType.HasValue)
                    {
                        input.MatchingElbowType = (eElbowType?)(int)vmo.ElbowType;
                    }
                    if (!input.BendingAngle.HasValue)
                    {
                        input.MatchingBendingAngle = vmo.Angle;
                    }
                }
                else
                {
                    input.MatchingMinorLoss = vmo.MinorLoss;
                    input.MatchingDbId = vmo.ID.ToString();
                    input.MatchingMaterial = vmo.Material;
                    input.MatchingModelType = vmo.Name;
                    input.MatchingElbowType = (eElbowType?)(int)vmo.ElbowType;
                    input.MatchingBendingAngle = vmo.Angle;
                }
                return true;
            }
            return false;
        }
                       vmo = absoluteMatching.First();
                   }
                   else
                       vmo = elbowMainVmos.First();
               }
               if (vmo != null)
               {
                   if (!isNotarize)
                   {
                       if (!input.MinorLoss.HasValue)
                       {
                           input.MatchingMinorLoss = vmo.MinorLoss;
                       }
                       if (input.DbId == null)
                       {
                           input.MatchingDbId = vmo.ID.ToString();
                       }
                       if (input.Material == null)
                       {
                           input.MatchingMaterial = vmo.Material;
                       }
                       if (input.ModelType == null)
                       {
                           input.MatchingModelType = vmo.Material;
                       }
                       if (!input.ElbowType.HasValue)
                       {
                           input.MatchingElbowType = (eElbowType?)(int)vmo.ElbowType;
                       }
                       if (!input.BendingAngle.HasValue)
                       {
                           input.MatchingBendingAngle = vmo.Angle;
                       }
                   }
                   else
                   {
                       input.MatchingMinorLoss = vmo.MinorLoss;
                       input.MatchingDbId = vmo.ID.ToString();
                       input.MatchingMaterial = vmo.Material;
                       input.MatchingModelType = vmo.Name;
                       input.MatchingElbowType = (eElbowType?)(int)vmo.ElbowType;
                       input.MatchingBendingAngle = vmo.Angle;
                   }
                   return true;
               }
               return false;
           }*/
        //三通匹配
        public static bool MatchingThreelink(HydroThreelinkMatchingViewModel input, List<Vmo.AssetsThreelinkMainVmo> threelinkVmos)
@@ -834,12 +846,12 @@
            }
            Vmo.AssetsFourlinkMainVmo vmo = null;
            var nameMatching = fourLinkVmos.Where(x =>
    (x.KeyWord != null && x.KeyWord.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) ||
    (x.KeyWord == null || !x.KeyWord.Any()) && GetIntersect(x.Name, input.ModelType) >= 1
    (x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) ||
    (x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1
    ) //先进行筛选,后进行从大到小排序
    .OrderByDescending(x =>
     (x.KeyWord != null && x.KeyWord.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) ||
     (x.KeyWord == null || !x.KeyWord.Any()) && GetIntersect(x.Name, input.ModelType) >= 1).ToList();
     (x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) ||
     (x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1).ToList();
            if (nameMatching.Count > 1)
            {
@@ -1458,15 +1470,20 @@
                {
                    if (input.DbId == null)
                        input.MatchingDbId = vmo.ID.ToString();
                    if (input.ModelType == null)
                    if (input.ModelType == null && input.ModelType == string.Empty)
                        input.MatchingModelType = vmo.Name;
                    if (input.DN < 0)
                    if (input.DN <= 0)
                        input.MatchingDN = vmo.DN;
                    if (input.MinLevel < 0)
                    if (input.MinLevel <= 0)
                        input.MatchingMinLevel = vmo.MinLevel;
                    input.MatchingOverFlow = vmo.OverFlow;
                    if (input.MinVol <= 0)
                        input.MatchingMinVol = vmo.MinVol;
                    if (input.MaxLevel <= 0)
                        input.MatchingMaxLevel = vmo.MaxLevel;
                    if (input.CurveDbId == null)
                    {
                        var list = Task.Run(async () => await new BLL.PhartDiagramRelation().GetExByObjectTypeAndObjectID(HStation.Assets.DataType.ValveMain, vmo.ID)).Result;
                        var list = Task.Run(async () => await new BLL.PhartDiagramRelation().GetExByObjectTypeAndObjectID(HStation.Assets.DataType.TankMain, vmo.ID)).Result;
                        if (list != null && list.Count > 0)
                        {
                            var def = list.OrderByDescending(x => x.Importance).First();
@@ -1487,6 +1504,9 @@
                    input.MatchingDN = vmo.DN;
                    input.MatchingMinLevel = vmo.MinLevel;
                    input.MatchingOverFlow = vmo.OverFlow;
                    input.MatchingMinVol = vmo.MinVol;
                    input.MatchingMaxLevel = vmo.MaxLevel;
                    var list = Task.Run(async () => await new BLL.PhartDiagramRelation().GetExByObjectTypeAndObjectID(HStation.Assets.DataType.ValveMain, vmo.ID)).Result;
                    if (list != null && list.Count > 0)
                    {
@@ -1759,6 +1779,93 @@
            return false;
        }
        //弯头匹配
        public static bool Matching(HydroElbowMatchingViewModel input, List<Vmo.AssetsElbowMainVmo> allElbowList)
        {
            //输入参数验证
            if (input == null)
            {
                return false;
            }
            //数据源没有数据则没有匹配成功
            if (allElbowList == null || allElbowList.Count < 1)
            {
                return false;
            }
            //权重字典
            var dict = new Dictionary<AssetsElbowMainVmo, double>();
            foreach (var item in allElbowList)
            {
                dict.Add(item, 0);
            }
            //型号
            int modelTypeWeight = 100;
            if (!string.IsNullOrEmpty(input.ModelType))
            {
                foreach (var item in allElbowList)
                {
                    if (!string.IsNullOrEmpty(item.Name))
                    {
                        var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
                        dict[item] += count * modelTypeWeight;
                    }
                }
            }
            // 关键字
            int keywordWeight = 1;
            foreach (var item in allElbowList)
            {
                if (item.KeyWords != null && item.KeyWords.Count > 0)
                {
                    if (!string.IsNullOrEmpty(input.ModelType))
                    {
                        var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
                        dict[item] += count * keywordWeight;
                    }
                }
            }
            //标签
            int flagWeight = 10;
            foreach (var item in allElbowList)
            {
                if (item.Flags != null && item.Flags.Count > 0)
                {
                    if (item.Flags.Contains(HStation.Assets.Flags.默认))
                    {
                        dict[item] += flagWeight;
                    }
                }
            }
            var flowmeter = dict.OrderBy(x => x.Value).LastOrDefault().Key;
            input.MatchingDbId = flowmeter.ID.ToString();
            if (string.IsNullOrEmpty(input.ModelType))
            {
                input.MatchingModelType = flowmeter.Name;
            }
            if (input.MinorLoss <= 0)
            {
                input.MatchingMinorLoss = flowmeter.MinorLoss;
            }
            if (input.BendingAngle <= 0)
            {
                input.MatchingBendingAngle = flowmeter.Angle;
            }
            input.MatchingElbowType = (Yw.WinFrmUI.eElbowType)(int)flowmeter.ElbowType;
            if (input.Material == null || input.Material == string.Empty)
            {
                input.MatchingMaterial = flowmeter.Material;
            }
            if (!input.Caliber.HasValue)
                input.MatchingCaliber = flowmeter.Caliber;
            return true;
        }
        //压力表匹配
        public static bool MatchingPressmeter(HydroPressmeterMatchingViewModel input, List<Vmo.AssetsPressmeterMainVmo> pressmeterVmos)
        {