lixiaojun
2024-12-02 f54adb8f368def21b9aa01e466b09bed6cd8347c
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
{
@@ -205,20 +203,26 @@
        }
        //阀门匹配
        public static bool MatchingValve(ValveMatchingViewModel input, List<Vmo.AssetsValveMainVmo> adaptingManageVmos)
        public static bool MatchingValve(ValveMatchingViewModel 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();
            var nameMatching = adaptingManageVmos.Where(x => GetIntersect(x.KeyWord == string.Empty
    ? x.Name : x.KeyWord, input.ModelType) >= 1)
    .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType))
    .ToList();//使用型号名或者关键字找出相同字符在2以上并且进行排序
            valveMainVmos = valveMainVmos.Where(x => x.ValveType == input.ValveType).ToList();
            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
        ) //先进行筛选,后进行从大到小排序
       .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();//使用型号名或者关键字找出相同字符在1以上并且进行排序
            if (nameMatching.Count > 0)
            {
                var absoluteMatching = nameMatching.Where(i =>
@@ -242,7 +246,7 @@
            }
            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();
@@ -257,83 +261,6 @@
                else
                    return false;
            }
            /*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;
@@ -342,81 +269,107 @@
                input.MatchingMaterial = vmo.Material;
                input.MatchingModelType = vmo.Name;
                input.MatchingValveSetting = vmo.ValveSetting;
                input.MatchingValveType = vmo.ValveType.ToString();
                return true;
                input.MatchingValveType = 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<CurvePointMatchingViewModel>();
                            foreach (var item in points_qh)
                            {
                                input.MatchingCurveQL.Add(new CurvePointMatchingViewModel(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<CurvePointMatchingViewModel>();
                            foreach (var item in points_qh)
                            {
                                input.MatchingCurveOL.Add(new CurvePointMatchingViewModel(item.X, item.Y));
                            }
                        }
                    }
                    return true;
                }
            }
            return false;
        }
        //管道匹配
        public static bool MatchingPipe(PipeMatchingViewModel input, List<Vmo.AssetsPipeMainVmo> pipeLineManageVmos)
        public static bool MatchingPipe(PipeMatchingViewModel 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)
                {
                    return false;
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
            }
            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)
                    {
                        //以材料为条件开始匹配
                        if (range.MaterialName == null)
                        {
                            materialList.Add(range);
                        }
                        else
                        {
                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                            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();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                    return false;
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
            }
            //口径和材料都没有匹配上,就用型号名匹配
            if (vmo != null)
            {
                switch (input.eAlgorithmType)
@@ -438,109 +391,75 @@
                        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(ElbowMatchingViewModel 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)
                    {
                        vmo = item;
                    }
                    return false;
                }
                vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
            }
            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)
                    {
                        //以材料为条件开始匹配
                        if (range.MaterialName == null)
                        {
                            materialList.Add(range);
                        }
                        else
                        {
                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                            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();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                    return false;
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
            }
            //精确匹配和粗糙匹配都没有匹配到就返回错误
            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.MatchingConnectionLength = vmo.ElbowLengthType;
                input.MatchingAngle = vmo.Angle;
                return true;
            }
@@ -548,193 +467,131 @@
        }
        //三通匹配
        public static bool MatchingThreelink(ThreelinkMatchingViewModel input, List<Vmo.AssetsThreelinkMainVmo> adaptingManageVmos)
        public static bool MatchingThreelink(ThreelinkMatchingViewModel 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)
                    {
                        vmo = item;
                    }
                    return false;
                }
                vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
            }
            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)
                    {
                        //以材料为条件开始匹配
                        if (range.MaterialName == null)
                        {
                            materialList.Add(range);
                        }
                        else
                        {
                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                            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();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                    return false;
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
            }
            //精确匹配和粗糙匹配都没有匹配到就返回错误
            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.MatchingRunThroughCoefficient = vmo.RunThroughMinorLoss;
                input.MatchingBranchThroughCoefficient = vmo.BranchThroughMinorLoss;
                return true;
            }
            return false;
        }
        //四通匹配
        public static bool MatchingFourlink(FourlinkMatchingViewModel input, List<Vmo.AssetsFourlinkMainVmo> adaptingManageVmos)
        public static bool MatchingFourlink(FourlinkMatchingViewModel 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)
                    {
                        vmo = item;
                    }
                    return false;
                }
                vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
            }
            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)
                    {
                        //以材料为条件开始匹配
                        if (range.MaterialName == null)
                        {
                            materialList.Add(range);
                        }
                        else
                        {
                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                            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();//如果没有设置默认值,则默认返回匹配字符最多的一条数据
                    return false;
                }
                else if (absoluteMatching.Count == 1)
                {
                    vmo = absoluteMatching.First();
                }
                else
                    return false;
            }
            //精确匹配和粗糙匹配都没有匹配到就返回错误
            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;
            }
@@ -747,7 +604,6 @@
        public static int GetIntersect(string str1, string str2)
        {
            if (str1 == null || str2 == null) return 0;
            var a = string.Join("", str1.Intersect(str2)).Count();
            return string.Join("", str1.Intersect(str2)).Count();
        }
    }