duheng
2024-12-05 b26ae60e85d4a03a2426e6607e7afe89e1c10a5f
WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
@@ -1,6 +1,4 @@
using HStation.Vmo;
using HStation.WinFrmUI.PhartRelation;
using System.Windows.Input;
using HStation.WinFrmUI.PhartRelation;
namespace HStation.WinFrmUI
{
@@ -17,28 +15,48 @@
        private const int _angle = 1;//角度范围
        //资产自动匹配
        public static bool Matching(AssetsMatchingViewModel assetsAutoMatchingView, out string Error)
        public static bool Matching(HydroMatchingViewModel assetsAutoMatchingView, out string Error)
        {
            Error = string.Empty;
            bool IsMaching = false;
            var AssetsPumpMain = new BLL.AssetsPumpMain();
            var adaptingManage = new BLL.AdaptingManage();
            var AdaptingManage = new BLL.AdaptingManage();
            var pipeLineManage = new BLL.AssetsPipeMain();
            var AssetsValveMain = new BLL.AssetsValveMain();
            var AssetsElbowMain = new BLL.AssetsElbowMain();
            var AssetsThreelinkMain = new BLL.AssetsThreelinkMain();
            var AssetsFourlinkMain = new BLL.AssetsFourlinkMain();
            var AssetsSprinkler = new BLL.AssetsSprinklerMain();
            var AssetsExchanger = new BLL.AssetsExchangerMain();
            var AssetsCompressorMain = new BLL.AssetsCompressorMain();
            var AssetsBluntheadMain = new BLL.AssetsBluntheadMain();
            var AssetsTankMain = new BLL.AssetsTankMain();
            var AssetsMeterMain = new BLL.AssetsMeterMain();
            var AssetsFlowmeterMain = new BLL.AssetsFlowmeterMain();
            var AssetsHydrantMain = new BLL.AssetsHydrantMain();
            var AssetsPressmeterMain = new BLL.AssetsPressmeterMain();
            var AssetsTranslationMain = new BLL.AssetsTranslationMain();
            try
            {
                var allPump = Task.Run(async () => await AssetsPumpMain.GetAll()).Result;
                var allAdapting = Task.Run(async () => await adaptingManage.GetAll()).Result;
                //   var allAdapting = Task.Run(async () => await adaptingManage.GetAll()).Result;
                var allPipeLine = Task.Run(async () => await pipeLineManage.GetAll()).Result;
                var allValve = Task.Run(async () => await AssetsValveMain.GetAll()).Result;
                var allElbow = Task.Run(async () => await AssetsElbowMain.GetAll()).Result;
                var allThreeLink = Task.Run(async () => await AssetsThreelinkMain.GetAll()).Result;
                var allFourLink = Task.Run(async () => await AssetsFourlinkMain.GetAll()).Result;
                var allSprinkler = Task.Run(async () => await AssetsSprinkler.GetAll()).Result;
                var allExchanger = Task.Run(async () => await AssetsExchanger.GetAll()).Result;
                var allCompressorMain = Task.Run(async () => await AssetsCompressorMain.GetAll()).Result;
                var allBluntheadMain = Task.Run(async () => await AssetsBluntheadMain.GetAll()).Result;
                var allTankMain = Task.Run(async () => await AssetsTankMain.GetAll()).Result;
                var allMeterMain = Task.Run(async () => await AssetsMeterMain.GetAll()).Result;
                var allFlowmeterMain = Task.Run(async () => await AssetsFlowmeterMain.GetAll()).Result;
                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;
                //泵匹配
                foreach (var item in assetsAutoMatchingView.PumpMatchingList)
                foreach (var item in assetsAutoMatchingView.Pumps)
                {
                    if (MatchingPumps(item, allPump))
                    {
@@ -46,7 +64,7 @@
                    }
                }
                //三通匹配
                foreach (var item in assetsAutoMatchingView.ThreelinkMatchingList)
                foreach (var item in assetsAutoMatchingView.Threelinks)
                {
                    if (MatchingThreelink(item, allThreeLink))
                    {
@@ -54,7 +72,7 @@
                    }
                }
                //四通匹配
                foreach (var item in assetsAutoMatchingView.FourlinkMatchingList)
                foreach (var item in assetsAutoMatchingView.Fourlinks)
                {
                    if (MatchingFourlink(item, allFourLink))
                    {
@@ -62,7 +80,7 @@
                    }
                }
                //管道匹配
                foreach (var item in assetsAutoMatchingView.PipeMatchingList)
                foreach (var item in assetsAutoMatchingView.Pipes)
                {
                    if (MatchingPipe(item, allPipeLine))
                    {
@@ -70,7 +88,7 @@
                    }
                }
                //阀门匹配
                foreach (var item in assetsAutoMatchingView.ValveMatchingList)
                foreach (var item in assetsAutoMatchingView.Valves)
                {
                    if (MatchingValve(item, allValve))
                    {
@@ -78,9 +96,89 @@
                    }
                }
                //弯头匹配
                foreach (var item in assetsAutoMatchingView.ElbowMatchingList)
                foreach (var item in assetsAutoMatchingView.Elbows)
                {
                    if (MatchingElbow(item, allElbow))
                    {
                        IsMaching = true;
                    }
                }
                //喷头匹配
                foreach (var item in assetsAutoMatchingView.Nozzles)
                {
                    if (MatchingSprinkler(item, allSprinkler))
                    {
                        IsMaching = true;
                    }
                }
                //闷头匹配
                foreach (var item in assetsAutoMatchingView.Bluntheads)
                {
                    if (MatchingBlunthead(item, allBluntheadMain))
                    {
                        IsMaching = true;
                    }
                }
                //换热器匹配
                foreach (var item in assetsAutoMatchingView.Exchangers)
                {
                    if (MatchingExchanger(item, allExchanger))
                    {
                        IsMaching = true;
                    }
                }
                //压缩机匹配
                foreach (var item in assetsAutoMatchingView.Compressors)
                {
                    if (MatchingCompressor(item, allCompressorMain))
                    {
                        IsMaching = true;
                    }
                }
                //水池匹配
                foreach (var item in assetsAutoMatchingView.Tanks)
                {
                    if (MatchingTank(item, allTankMain))
                    {
                        IsMaching = true;
                    }
                }
                //水表匹配
                foreach (var item in assetsAutoMatchingView.Meters)
                {
                    if (MatchingMeter(item, allMeterMain))
                    {
                        IsMaching = true;
                    }
                }
                //流量计匹配
                foreach (var item in assetsAutoMatchingView.Flowmeters)
                {
                    if (MatchingFlowmeter(item, allFlowmeterMain))
                    {
                        IsMaching = true;
                    }
                }
                //消火栓匹配
                foreach (var item in assetsAutoMatchingView.Hydrants)
                {
                    if (MatchingHydrant(item, allHydrantMain))
                    {
                        IsMaching = true;
                    }
                }
                //压力表匹配
                foreach (var item in assetsAutoMatchingView.Pressmeters)
                {
                    if (MatchingPressmeter(item, allPressmeterMain))
                    {
                        IsMaching = true;
                    }
                }
                //过渡件匹配
                foreach (var item in assetsAutoMatchingView.Translations)
                {
                    if (MatchingTranslation(item, allTranslationMain))
                    {
                        IsMaching = true;
                    }
@@ -95,7 +193,7 @@
        }
        //泵匹配
        public static bool MatchingPumps(PumpMatchingViewModel InputModel, List<Vmo.AssetsPumpMainVmo> AssetsPumpMainVmos)
        public static bool MatchingPumps(HydroPumpMatchingViewModel InputModel, List<Vmo.AssetsPumpMainVmo> AssetsPumpMainVmos)
        {
            if (AssetsPumpMainVmos == null)
            {
@@ -174,28 +272,28 @@
                    if (graph_qh != null)
                    {
                        var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 100, null);
                        InputModel.MatchingCurveQH = new List<CurvePointMatchingViewModel>();
                        InputModel.MatchingCurveQH = new List<HydroCurvePointViewModel>();
                        foreach (var item in points_qh)
                        {
                            InputModel.MatchingCurveQH.Add(new CurvePointMatchingViewModel(item.X, item.Y));
                            InputModel.MatchingCurveQH.Add(new HydroCurvePointViewModel(item.X, item.Y));
                        }
                    }
                    if (graph_qe != null)
                    {
                        var points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 100, null);
                        InputModel.MatchingCurveQE = new List<CurvePointMatchingViewModel>();
                        InputModel.MatchingCurveQE = new List<HydroCurvePointViewModel>();
                        foreach (var item in points_qe)
                        {
                            InputModel.MatchingCurveQE.Add(new CurvePointMatchingViewModel(item.X, item.Y));
                            InputModel.MatchingCurveQE.Add(new HydroCurvePointViewModel(item.X, item.Y));
                        }
                    }
                    if (graph_qp != null)
                    {
                        var points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 100, null);
                        InputModel.MatchingCurveQP = new List<CurvePointMatchingViewModel>();
                        InputModel.MatchingCurveQP = new List<HydroCurvePointViewModel>();
                        foreach (var item in points_qp)
                        {
                            InputModel.MatchingCurveQP.Add(new CurvePointMatchingViewModel(item.X, item.Y));
                            InputModel.MatchingCurveQP.Add(new HydroCurvePointViewModel(item.X, item.Y));
                        }
                    }
                }
@@ -205,18 +303,18 @@
        }
        //阀门匹配
        public static bool MatchingValve(ValveMatchingViewModel input, List<Vmo.AssetsValveMainVmo> adaptingManageVmos)
        public static bool MatchingValve(HydroValveMatchingViewModel input, List<Vmo.AssetsValveMainVmo> valveMainVmos)
        {
            if (adaptingManageVmos == null)
            if (valveMainVmos == null)
            {
                return true;
            }
            HStation.Vmo.AssetsValveMainVmo vmo = null;
            //口径最小差值
            // 绝对匹配
            adaptingManageVmos = adaptingManageVmos.Where(x => x.ValveType.ToString() == input.ValveType).ToList();
            valveMainVmos = valveMainVmos.Where(x => (int)x.ValveType == (int)input.ValveType).ToList();
            var nameMatching = adaptingManageVmos.Where(x =>
            var nameMatching = valveMainVmos.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
        ) //先进行筛选,后进行从大到小排序
@@ -233,14 +331,23 @@
                 ).ToList();
                if (absoluteMatching.Count > 1)
                {
                    return false;
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        vmo = defaultList.First();
                    }
                    else if (defaultList.Count < 0)
                    {
                        vmo = valveMainVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
                    vmo = valveMainVmos.First();
            }
            else if (nameMatching.Count == 1)
            {
@@ -248,97 +355,30 @@
            }
            else
            {
                var absoluteMatching = adaptingManageVmos.Where(i =>
                var absoluteMatching = valveMainVmos.Where(i =>
          ((i.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - input.Diameter) <= _caliberTolerance) &&  //直径约束
           i.Material == input.Material   //材料约束
             ).ToList();
                if (absoluteMatching.Count > 1)
                {
                    return false;
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        vmo = defaultList.First();
                    }
                    else if (defaultList.Count < 0)
                    {
                        vmo = valveMainVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
                    vmo = valveMainVmos.First();
            }
            /*   var absoluteMatch = adaptingManageVmos.Where(i =>
                ((i.Caliber == null) || i.Caliber == input.Diameter) &&
                 ((input.Material == null && i.Materia == null) || i.Materia == input.Material)).ToList();
              if (absoluteMatch.Count > 1)
              {
                  var allMatchingList = absoluteMatch
      .Where(x => GetIntersect(x.KeyWord == string.Empty
      ? x.Name : x.KeyWord, input.ModelType) >= 2)
      .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
      .ToList();//找出相同字符在2以上并且进行排序
                  if (allMatchingList.Count < 1)
                      return false;//通过型号名没有找到,则视为没有匹配到
                  foreach (var item in allMatchingList)
                  {
                      if (item.IsDefault)
                      {
                          vmo = item;
                      }
                  }
                  vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
              }
              else if (absoluteMatch.Count == 1)
              {
                  vmo = absoluteMatch.First();
              }
              else
              {
                  //区间匹配
                  var rangeMatch = adaptingManageVmos
                 .Where(item =>
                      item.Caliber == null ||
                     Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Diameter)) <= _caliberTolerance
                     || Math.Abs(Convert.ToInt64(item.ValveLift) - Convert.ToInt64(input.ValveLift)) <= _valveLift)
                 .ToList();
                  if (rangeMatch != null && rangeMatch.Count > 0)
                  {
                      var materialList = new List<Vmo.AssetsValveMainVmo>();
                      foreach (var range in rangeMatch)
                      {
                          //以材料为条件开始匹配
                          if (range.Materia == null)
                          {
                              materialList.Add(range);
                          }
                          else
                          {
                              int commonCount = GetIntersect(input.Material, range.Materia);
                              if (commonCount > firstCount)
                              {
                                  materialList.Add(range);
                                  firstCount = commonCount;
                              }
                          }
                      }
                      //用已经筛选完成的列表中以名称筛选
                      firstCount = 0;
                      if (materialList.Count < 1)
                          return false;
                      var allMatchingList = materialList
    .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2)
    .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
    .ToList();//找出相同字符在2以上并且进行排序
                      if (allMatchingList.Count < 1)
                          return false;//通过型号名没有找到,则视为没有匹配到
                      foreach (var item in allMatchingList)
                      {
                          if (item.IsDefault)
                          {
                              vmo = item;
                          }
                      }
                      vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                  }
              }
              //口径和材料都没有匹配上,就用型号名匹配
              firstCount = 0;*/
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
@@ -347,94 +387,138 @@
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                input.MatchingValveSetting = vmo.ValveSetting;
                input.MatchingValveType = vmo.ValveType.ToString();
                return true;
                input.MatchingValveType = (eValveType?)(int)vmo.ValveType;
                if (vmo.ValveType == HStation.Assets.eValveType.GPV)
                {
                    var list = Task.Run(async () => await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(vmo.ID)).Result;
                    if (list != null && list.Count > 0)
                    {
                        var maxImportanceItem = list.OrderByDescending(x => x.Importance).First();
                        input.MatchingCurveDbId = maxImportanceItem.ID.ToString();
                        var graph_ql = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.ValveQL);
                        var graph_ol = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.ValveOL);
                        if (graph_ql != null)
                        {
                            var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_ql.GraphType, graph_ql.GeometryInfo, 100, null);
                            input.MatchingCurveQL = new List<HydroCurvePointViewModel>();
                            foreach (var item in points_qh)
                            {
                                input.MatchingCurveQL.Add(new HydroCurvePointViewModel(item.X, item.Y));
                            }
                        }
                    }
                    return true;
                }
                else if (vmo.ValveType == HStation.Assets.eValveType.TCV)
                {
                    var list = Task.Run(async () => await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(vmo.ID)).Result;
                    if (list != null && list.Count > 0)
                    {
                        var maxImportanceItem = list.OrderByDescending(x => x.Importance).First();
                        input.MatchingCurveDbId = maxImportanceItem.ID.ToString();
                        var graph_ol = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.ValveOL);
                        if (graph_ol != null)
                        {
                            var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_ol.GraphType, graph_ol.GeometryInfo, 100, null);
                            input.MatchingCurveOL = new List<HydroCurvePointViewModel>();
                            foreach (var item in points_qh)
                            {
                                input.MatchingCurveOL.Add(new HydroCurvePointViewModel(item.X, item.Y));
                            }
                        }
                    }
                    return true;
                }
            }
            return false;
        }
        //管道匹配
        public static bool MatchingPipe(PipeMatchingViewModel input, List<Vmo.AssetsPipeMainVmo> pipeLineManageVmos)
        public static bool MatchingPipe(HydroPipeMatchingViewModel input, List<Vmo.AssetsPipeMainVmo> pipeLineMainVmos)
        {
            if (pipeLineManageVmos == null)
            if (pipeLineMainVmos == null)
            {
                return true;
            }
            Vmo.AssetsPipeMainVmo vmo = null;
            int firstCount = 0;
            //口径最小差值
            // 绝对匹配
            var absoluteMatch = pipeLineManageVmos.Where(i =>
            ((i.Caliber == null) || i.Caliber == input.Diameter) &&
               ((input.Material == null) || i.MaterialName == input.Material)).ToList();
            if (absoluteMatch.Count > 1)
            var nameMatching = pipeLineMainVmos.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();
            if (nameMatching.Count > 1)
            {
                var absoluteMatching = nameMatching.Where(i =>
              ((i.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - input.Diameter) <= _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 = pipeLineMainVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = pipeLineMainVmos.First();
            }
            else if (absoluteMatch.Count == 1)
            else if (nameMatching.Count == 1)
            {
                vmo = absoluteMatch.First();
                vmo = nameMatching.First();
            }
            else
            {
                //区间匹配
                var rangeMatch = pipeLineManageVmos
               .Where(item =>
               item.Caliber == null ||
               Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Diameter)) <= _caliberTolerance)
         .ToList();
                if (rangeMatch != null)
                var absoluteMatching = pipeLineMainVmos.Where(i =>
          ((i.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - input.Diameter) <= _caliberTolerance) &&  //直径约束
           i.Material == input.Material   //材料约束
             ).ToList();
                if (absoluteMatching.Count > 1)
                {
                    var materialList = new List<Vmo.AssetsPipeMainVmo>();
                    foreach (var range in rangeMatch)
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        //以材料为条件开始匹配
                        if (range.MaterialName == null)
                        {
                            materialList.Add(range);
                        }
                        else
                        {
                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                            if (commonCount > firstCount)
                            {
                                materialList.Add(range);
                                firstCount = commonCount;
                            }
                        }
                        vmo = defaultList.First();
                    }
                    firstCount = 0;
                    if (materialList.Count < 1)
                        return false;
                    var allMatchingList = materialList
                     .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2)
                     .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
                     .ToList();//找出相同字符在2以上并且进行排序
                    if (allMatchingList.Count < 1)
                        return false;//通过型号名没有找到,则视为没有匹配到
                    foreach (var item in allMatchingList)
                    else if (defaultList.Count < 0)
                    {
                        if (item.IsDefault)
                        {
                            vmo = item;
                        }
                        vmo = pipeLineMainVmos.First();
                    }
                    vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = pipeLineMainVmos.First();
            }
            //口径和材料都没有匹配上,就用型号名匹配
            if (vmo != null)
            {
                switch (input.eAlgorithmType)
                {
                    case HStation.Assets.eAlgorithmType.Hazen:
                    case eAlgorithmType.Hazen:
                        input.MatchingRoughness = vmo.Hazen;
                        break;
                    case HStation.Assets.eAlgorithmType.Manning:
                    case eAlgorithmType.Manning:
                        input.MatchingRoughness = vmo.Manning;
                        break;
                    case HStation.Assets.eAlgorithmType.Darcy:
                    case eAlgorithmType.Darcy:
                        input.MatchingRoughness = vmo.Darcy;
                        break;
@@ -443,303 +527,937 @@
                        break;
                }
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.MaterialName;
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                input.MatchingMinorLoss = vmo.Coefficient;
                input.MatchingMinorLoss = vmo.MinorLoss;
                return true;
            }
            return false;
        }
        //弯头匹配
        public static bool MatchingElbow(ElbowMatchingViewModel input, List<Vmo.AssetsElbowMainVmo> adaptingManageVmos)
        public static bool MatchingElbow(HydroElbowMatchingViewModel input, List<Vmo.AssetsElbowMainVmo> elbowMainVmos)
        {
            if (adaptingManageVmos == null)
            if (elbowMainVmos == null)
            {
                return true;
            }
            Vmo.AssetsElbowMainVmo vmo = null;
            int firstCount = 0;
            // 绝对匹配
            var absoluteMatch = adaptingManageVmos.Where(i =>
              ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
               ((input.Material == null) || i.MaterialName == input.Material)).ToList();
            if (absoluteMatch.Count > 1)
            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();
            if (nameMatching.Count > 1)
            {
                var allMatchingList = absoluteMatch
    .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2)
    .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
    .ToList();//找出相同字符在2以上并且进行排序
                if (allMatchingList.Count < 1)
                    return false;//通过型号名没有找到,则视为没有匹配到
                foreach (var item in allMatchingList)
                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)
                {
                    if (item.IsDefault)
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        vmo = item;
                        vmo = defaultList.First();
                    }
                    else if (defaultList.Count < 0)
                    {
                        vmo = elbowMainVmos.First();
                    }
                }
                vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = elbowMainVmos.First();
            }
            else if (absoluteMatch.Count == 1)
            else if (nameMatching.Count == 1)
            {
                vmo = absoluteMatch.First();
                vmo = nameMatching.First();
            }
            else
            {
                //区间匹配
                var rangeMatch = adaptingManageVmos
   .Where(item =>
       (input.Caliber == null && input.Caliber == null)
       || (item.Caliber.HasValue && input.Caliber.HasValue) &&   //存在值,则进行下面差值判断
       Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance
       || item.ConnectionLength == input.ConnectionLength
       || (item.Angle.HasValue && input.Angle.HasValue) &&      //存在值,则进行下面差值判断
       Math.Abs(Convert.ToInt64(item.Angle) - Convert.ToInt64(input.Angle)) <= _angle)
    .ToList();
                if (rangeMatch != null && rangeMatch.Count > 0)
                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 materialList = new List<Vmo.AssetsElbowMainVmo>();
                    foreach (var range in rangeMatch)
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        //以材料为条件开始匹配
                        if (range.MaterialName == null)
                        {
                            materialList.Add(range);
                        }
                        else
                        {
                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                            if (commonCount > firstCount)
                            {
                                materialList.Add(range);
                                firstCount = commonCount;
                            }
                        }
                        vmo = defaultList.First();
                    }
                    //用已经筛选完成的列表中以名称筛选
                    firstCount = 0;
                    if (materialList.Count < 1)
                        return false;
                    var allMatchingList = materialList
  .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2)
  .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
  .ToList();//找出相同字符在2以上并且进行排序
                    if (allMatchingList.Count < 1)
                        return false;//通过型号名没有找到,则视为没有匹配到
                    foreach (var item in allMatchingList)
                    else if (defaultList.Count < 0)
                    {
                        if (item.IsDefault)
                        {
                            vmo = item;
                        }
                        vmo = elbowMainVmos.First();
                    }
                    vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = elbowMainVmos.First();
            }
            //精确匹配和粗糙匹配都没有匹配到就返回错误
            firstCount = 0;
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.Coefficient;
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.MaterialName;
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                input.MatchingConnectionLength = vmo.ConnectionLength;
                input.MatchingAngle = vmo.Angle;
                input.MatchingElbowType = (eElbowType?)(int)vmo.ElbowType;
                input.MatchingBendingAngle = vmo.Angle;
                return true;
            }
            return false;
        }
        //三通匹配
        public static bool MatchingThreelink(ThreelinkMatchingViewModel input, List<Vmo.AssetsThreelinkMainVmo> adaptingManageVmos)
        public static bool MatchingThreelink(HydroThreelinkMatchingViewModel input, List<Vmo.AssetsThreelinkMainVmo> threelinkVmos)
        {
            if (adaptingManageVmos == null)
            Vmo.AssetsThreelinkMainVmo vmo = null;
            if (threelinkVmos == null)
            {
                return true;
            }
            Vmo.AssetsThreelinkMainVmo vmo = null;
            int firstCount = 0;
            // 绝对匹配
            var absoluteMatch = adaptingManageVmos.Where(i =>
              ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
               ((input.Material == null) || i.MaterialName == input.Material)).ToList();
            if (absoluteMatch.Count > 1)
            var nameMatching = threelinkVmos.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();
            if (nameMatching.Count > 1)
            {
                var allMatchingList = absoluteMatch
    .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2)
    .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
    .ToList();//找出相同字符在2以上并且进行排序
                if (allMatchingList.Count < 1)
                    return false;//通过型号名没有找到,则视为没有匹配到
                foreach (var item in allMatchingList)
                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)
                {
                    if (item.IsDefault)
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        vmo = item;
                        vmo = defaultList.First();
                    }
                    else if (defaultList.Count < 0)
                    {
                        vmo = threelinkVmos.First();
                    }
                }
                vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = threelinkVmos.First();
            }
            else if (absoluteMatch.Count == 1)
            else if (nameMatching.Count == 1)
            {
                vmo = absoluteMatch.First();
                vmo = nameMatching.First();
            }
            else
            {
                //区间匹配
                var rangeMatch = adaptingManageVmos
   .Where(item =>
       input.Caliber == null ||
       item.Caliber == null ||
       Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance)
   .ToList();
                if (rangeMatch != null && rangeMatch.Count > 0)
                var absoluteMatching = threelinkVmos.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 materialList = new List<Vmo.AssetsThreelinkMainVmo>();
                    foreach (var range in rangeMatch)
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        //以材料为条件开始匹配
                        if (range.MaterialName == null)
                        {
                            materialList.Add(range);
                        }
                        else
                        {
                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                            if (commonCount > firstCount)
                            {
                                materialList.Add(range);
                                firstCount = commonCount;
                            }
                        }
                        vmo = defaultList.First();
                    }
                    //用已经筛选完成的列表中以名称筛选
                    firstCount = 0;
                    if (materialList.Count < 1)
                        return false;
                    var allMatchingList = materialList
  .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2)
  .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
  .ToList();//找出相同字符在2以上并且进行排序
                    if (allMatchingList.Count < 1)
                        return false;//通过型号名没有找到,则视为没有匹配到
                    foreach (var item in allMatchingList)
                    else if (defaultList.Count < 0)
                    {
                        if (item.IsDefault)
                        {
                            vmo = item;
                        }
                        vmo = threelinkVmos.First();
                    }
                    vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = threelinkVmos.First();
            }
            //精确匹配和粗糙匹配都没有匹配到就返回错误
            firstCount = 0;
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.Coefficient;
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.MaterialName;
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                input.MatchingRunThroughCoefficient = vmo.RunThroughCoefficient;
                input.MatchingBranchThroughCoefficient = vmo.BranchThroughCoefficient;
                input.MatchingRunningThroughLoss = vmo.RunThroughMinorLoss;
                input.MatchingBranchThroughLoss = vmo.BranchThroughMinorLoss;
                return true;
            }
            return false;
        }
        //四通匹配
        public static bool MatchingFourlink(FourlinkMatchingViewModel input, List<Vmo.AssetsFourlinkMainVmo> adaptingManageVmos)
        public static bool MatchingFourlink(HydroFourlinkMatchingViewModel input, List<Vmo.AssetsFourlinkMainVmo> fourLinkVmos)
        {
            if (adaptingManageVmos == null)
            if (fourLinkVmos == null)
            {
                return true;
            }
            Vmo.AssetsFourlinkMainVmo vmo = null;
            int firstCount = 0;
            // 绝对匹配
            var absoluteMatch = adaptingManageVmos.Where(i =>
              ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
               ((input.Material == null) || i.MaterialName == input.Material)).ToList();
            if (absoluteMatch.Count > 1)
            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
 ) //先进行筛选,后进行从大到小排序
.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();
            if (nameMatching.Count > 1)
            {
                var allMatchingList = absoluteMatch
    .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2)
    .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
    .ToList();//找出相同字符在2以上并且进行排序
                if (allMatchingList.Count < 1)
                    return false;//通过型号名没有找到,则视为没有匹配到
                foreach (var item in allMatchingList)
                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)
                {
                    if (item.IsDefault)
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        vmo = item;
                        vmo = defaultList.First();
                    }
                    else if (defaultList.Count < 0)
                    {
                        vmo = fourLinkVmos.First();
                    }
                }
                vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = fourLinkVmos.First();
            }
            else if (absoluteMatch.Count == 1)
            else if (nameMatching.Count == 1)
            {
                vmo = absoluteMatch.First();
                vmo = nameMatching.First();
            }
            else
            {
                //区间匹配
                var rangeMatch = adaptingManageVmos
   .Where(item =>
       input.Caliber == null ||
       item.Caliber == null ||
       Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance)
   .ToList();
                if (rangeMatch != null && rangeMatch.Count > 0)
                var absoluteMatching = fourLinkVmos.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 materialList = new List<Vmo.AssetsFourlinkMainVmo>();
                    foreach (var range in rangeMatch)
                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                    //取默认
                    if (defaultList.Count > 0)
                    {
                        //以材料为条件开始匹配
                        if (range.MaterialName == null)
                        {
                            materialList.Add(range);
                        }
                        else
                        {
                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                            if (commonCount > firstCount)
                            {
                                materialList.Add(range);
                                firstCount = commonCount;
                            }
                        }
                        vmo = defaultList.First();
                    }
                    //用已经筛选完成的列表中以名称筛选
                    firstCount = 0;
                    if (materialList.Count < 1)
                        return false;
                    var allMatchingList = materialList
  .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2)
  .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
  .ToList();//找出相同字符在2以上并且进行排序
                    if (allMatchingList.Count < 1)
                        return false;//通过型号名没有找到,则视为没有匹配到
                    foreach (var item in allMatchingList)
                    else if (defaultList.Count < 0)
                    {
                        if (item.IsDefault)
                        {
                            vmo = item;
                        }
                        vmo = fourLinkVmos.First();
                    }
                    vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = fourLinkVmos.First();
            }
            //精确匹配和粗糙匹配都没有匹配到就返回错误
            firstCount = 0;
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.Coefficient;
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.MaterialName;
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                return true;
            }
            return false;
        }
        //喷头匹配
        public static bool MatchingSprinkler(HydroNozzleMatchingViewModel input, List<Vmo.AssetsSprinklerMainVmo> sprinklerVmos)
        {
            if (sprinklerVmos == null)
            {
                return true;
            }
            Vmo.AssetsSprinklerMainVmo vmo = null;
            var nameMatching = sprinklerVmos.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();
            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 = sprinklerVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = sprinklerVmos.First();
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
            {
                var absoluteMatching = sprinklerVmos.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 = sprinklerVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = sprinklerVmos.First();
            }
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                return true;
            }
            return false;
        }
        //换热器匹配
        public static bool MatchingExchanger(HydroExchangerMatchingViewModel input, List<Vmo.AssetsExchangerMainVmo> exchangerVmos)
        {
            if (exchangerVmos == null)
            {
                return true;
            }
            Vmo.AssetsExchangerMainVmo vmo = null;
            var nameMatching = exchangerVmos.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();
            if (nameMatching.Count > 1)
            {
                var absoluteMatching = nameMatching.Where(i =>
                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 = exchangerVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = exchangerVmos.First();
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
            {
                var absoluteMatching = exchangerVmos.Where(i =>
            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 = exchangerVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = exchangerVmos.First();
            }
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                return true;
            }
            return false;
        }
        //空压机匹配
        public static bool MatchingCompressor(HydroCompressorMatchingViewModel input, List<Vmo.AssetsCompressorMainVmo> compressorVmos)
        {
            if (compressorVmos == null)
            {
                return true;
            }
            Vmo.AssetsCompressorMainVmo vmo = null;
            var nameMatching = compressorVmos.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();
            if (nameMatching.Count > 1)
            {
                var absoluteMatching = nameMatching.Where(i =>
                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 = compressorVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = compressorVmos.First();
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
            {
                var absoluteMatching = compressorVmos.Where(i =>
            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 = compressorVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = compressorVmos.First();
            }
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                return true;
            }
            return false;
        }
        //闷头匹配
        public static bool MatchingBlunthead(HydroBluntheadMatchingViewModel input, List<Vmo.AssetsBluntheadMainVmo> bluntheadVmos)
        {
            if (bluntheadVmos == null)
            {
                return true;
            }
            Vmo.AssetsBluntheadMainVmo vmo = null;
            var nameMatching = bluntheadVmos.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();
            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 = bluntheadVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = bluntheadVmos.First();
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
            {
                var absoluteMatching = bluntheadVmos.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 = bluntheadVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = bluntheadVmos.First();
            }
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                return true;
            }
            return false;
        }
        //水池匹配
        public static bool MatchingTank(HydroTankMatchingViewModel input, List<Vmo.AssetsTankMainVmo> tankVmos)
        {
            if (tankVmos == null)
            {
                return true;
            }
            Vmo.AssetsTankMainVmo vmo = null;
            var nameMatching = tankVmos.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();
            if (nameMatching.Count > 1)
            {
                var defaultList = nameMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                //取默认
                if (defaultList.Count > 0)
                {
                    vmo = tankVmos.First();
                }
                else if (defaultList.Count < 0)
                {
                    vmo = tankVmos.First();
                }
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
                vmo = tankVmos.First();
            if (vmo != null)
            {
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingModelType = vmo.Name;
                //    input.mat
                return true;
            }
            return false;
        }
        //水表匹配
        public static bool MatchingMeter(HydroMeterMatchingViewModel input, List<Vmo.AssetsMeterMainVmo> MeterMainVmos)
        {
            Vmo.AssetsMeterMainVmo vmo = null;
            if (MeterMainVmos == null)
            {
                return true;
            }
            var nameMatching = MeterMainVmos.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();
            if (nameMatching.Count > 1)
            {
                var defaultList = nameMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                //取默认
                if (defaultList.Count > 0)
                {
                    vmo = defaultList.First();
                }
                else if (defaultList.Count < 0)
                {
                    vmo = MeterMainVmos.First();
                }
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
                vmo = MeterMainVmos.First();
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingModelType = vmo.Name;
                return true;
            }
            return false;
        }
        //流量计匹配
        public static bool MatchingFlowmeter(HydroFlowmeterMatchingViewModel input, List<Vmo.AssetsFlowmeterMainVmo> FlowmeterMainVmos)
        {
            if (FlowmeterMainVmos == null)
            {
                return true;
            }
            Vmo.AssetsFlowmeterMainVmo vmo = null;
            var nameMatching = FlowmeterMainVmos.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();
            if (nameMatching.Count > 1)
            {
                var defaultList = nameMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                //取默认
                if (defaultList.Count > 0)
                {
                    vmo = defaultList.First();
                }
                else if (defaultList.Count < 0)
                {
                    vmo = FlowmeterMainVmos.First();
                }
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
            {
                vmo = FlowmeterMainVmos.First();
            }
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingModelType = vmo.Name;
                return true;
            }
            return false;
        }
        //消火栓匹配
        public static bool MatchingHydrant(HydroHydrantMatchingViewModel input, List<Vmo.AssetsHydrantMainVmo> hydrantVmos)
        {
            if (hydrantVmos == null)
            {
                return true;
            }
            Vmo.AssetsHydrantMainVmo vmo = null;
            var nameMatching = hydrantVmos.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();
            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 = hydrantVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = hydrantVmos.First();
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
            {
                var absoluteMatching = hydrantVmos.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 = hydrantVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = hydrantVmos.First();
            }
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                return true;
            }
            return false;
        }
        //压力表匹配
        public static bool MatchingPressmeter(HydroPressmeterMatchingViewModel input, List<Vmo.AssetsPressmeterMainVmo> pressmeterVmos)
        {
            if (pressmeterVmos == null)
            {
                return true;
            }
            Vmo.AssetsPressmeterMainVmo vmo = null;
            var nameMatching = pressmeterVmos.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();
            if (nameMatching.Count > 1)
            {
                var defaultList = nameMatching.Where(x => x.Flags.Contains("默认值")).ToList();
                //取默认
                if (defaultList.Count > 0)
                {
                    vmo = pressmeterVmos.First();
                }
                else if (defaultList.Count < 0)
                {
                    vmo = pressmeterVmos.First();
                }
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
            {
                vmo = pressmeterVmos.First();
            }
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingModelType = vmo.Name;
                return true;
            }
            return false;
        }
        //过渡件匹配
        public static bool MatchingTranslation(HydroTranslationMatchingViewModel input, List<Vmo.AssetsTranslationMainVmo> translationVmos)
        {
            if (translationVmos == null)
            {
                return true;
            }
            Vmo.AssetsTranslationMainVmo vmo = null;
            var nameMatching = translationVmos.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();
            if (nameMatching.Count > 1)
            {
                var absoluteMatching = nameMatching.Where(i =>
                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 = translationVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = translationVmos.First();
            }
            else if (nameMatching.Count == 1)
            {
                vmo = nameMatching.First();
            }
            else
            {
                var absoluteMatching = translationVmos.Where(i =>
            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 = translationVmos.First();
                    }
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    vmo = translationVmos.First();
            }
            if (vmo != null)
            {
                input.MatchingMinorLoss = vmo.MinorLoss;
                input.MatchingDbId = vmo.ID.ToString();
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                return true;
            }