From c0a8df94a97281d7ed5a38550dd6fcf73e9cf0c8 Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期六, 09 十一月 2024 13:53:43 +0800
Subject: [PATCH] 核心修改

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs |  482 ++++++++++++++++++++++++++--------------------------
 1 files changed, 242 insertions(+), 240 deletions(-)

diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
index 94cad1b..8f99713 100644
--- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
+++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
@@ -166,10 +166,11 @@
                 var list = Task.Run(async () => await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(vmo.ID)).Result;
                 if (list != null && list.Count > 0)
                 {
-                    InputModel.MatchingCurveDbId = list.First().ID.ToString();
-                    var graph_qh = list.First().Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
-                    var graph_qe = list.First().Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
-                    var graph_qp = list.First().Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
+                    var maxImportanceItem = list.OrderByDescending(x => x.Importance).First();
+                    InputModel.MatchingCurveDbId = maxImportanceItem.ID.ToString();
+                    var graph_qh = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
+                    var graph_qe = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
+                    var graph_qp = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
                     if (graph_qh != null)
                     {
                         var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 100, null);
@@ -211,97 +212,107 @@
                 return true;
             }
             HStation.Vmo.AssetsValveMainVmo vmo = null;
-            int firstCount = 0;
             //鍙e緞鏈�灏忓樊鍊�
             // 缁濆鍖归厤
-            adaptingManageVmos = adaptingManageVmos.Where(x => x.Type.ToString() == input.ValveType).ToList();
-            var absoluteMatch = adaptingManageVmos.Where(i =>
-              ((i.Caliber == null) || i.Caliber == input.Diameter) &&
-               ((input.Material == null && i.MaterialName == null) || i.MaterialName == input.Material)).ToList();
-            if (absoluteMatch.Count > 1)
+            adaptingManageVmos = adaptingManageVmos.Where(x => x.ValveType == input.ValveType).ToList();
+
+            var nameMatching = adaptingManageVmos.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 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) || Math.Abs(Convert.ToInt64(i.Caliber) - input.Diameter) <= _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 =>
-                    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 absoluteMatching = adaptingManageVmos.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.AssetsValveMainVmo>();
-                    foreach (var range in rangeMatch)
+                    return false;
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    return false;
+            }
+            if (vmo != null)
+            {
+                input.MatchingMinorLoss = vmo.MinorLoss;
+                input.MatchingDbId = vmo.ID.ToString();
+                input.MatchingDiameter = vmo.Caliber;
+                input.MatchingMaterial = vmo.Material;
+                input.MatchingModelType = vmo.Name;
+                input.MatchingValveSetting = vmo.ValveSetting;
+                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)
                     {
-                        //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        if (range.MaterialName == null)
+                        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)
                         {
-                            materialList.Add(range);
-                        }
-                        else
-                        {
-                            int commonCount = GetIntersect(input.Material, range.MaterialName);
-                            if (commonCount > firstCount)
+                            var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_ql.GraphType, graph_ql.GeometryInfo, 100, null);
+                            input.MatchingCurveQL = new List<CurvePointMatchingViewModel>();
+                            foreach (var item in points_qh)
                             {
-                                materialList.Add(range);
-                                firstCount = commonCount;
+                                input.MatchingCurveQL.Add(new CurvePointMatchingViewModel(item.X, item.Y));
                             }
                         }
                     }
-                    //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢��
-                    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)
+                    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)
                     {
-                        if (item.IsDefault)
+                        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)
                         {
-                            vmo = item;
+                            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));
+                            }
                         }
                     }
-                    vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
+                    return true;
                 }
-            }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
-            firstCount = 0;
-            if (vmo != null)
-            {
-                input.MatchingMinorLoss = vmo.Coefficient;
-                input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingDiameter = vmo.Caliber;
-                input.MatchingMaterial = vmo.MaterialName;
-                input.MatchingModelType = vmo.Name;
-                //  input.MatchingValveSetting =
-                input.MatchingValveLift = vmo.ValveLift;
-                input.MatchingValveType = vmo.Type.ToString();
-                return true;
             }
             return false;
         }
@@ -414,70 +425,15 @@
             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 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 absoluteMatch = adaptingManageVmos.Where(i =>
+                  ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
+                   ((input.Material == null) || i.Material == input.Material)).ToList();
+                if (absoluteMatch.Count > 1)
                 {
-                    if (item.IsDefault)
-                    {
-                        vmo = item;
-                    }
-                }
-                vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
-            }
-            else if (absoluteMatch.Count == 1)
-            {
-                vmo = absoluteMatch.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 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浠ヤ笂骞朵笖杩涜鎺掑簭
+                    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)
@@ -489,19 +445,74 @@
                     }
                     vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
                 }
-            }
-            //绮剧‘鍖归厤鍜岀矖绯欏尮閰嶉兘娌℃湁鍖归厤鍒板氨杩斿洖閿欒
-            firstCount = 0;
-            if (vmo != null)
-            {
-                input.MatchingMinorLoss = vmo.Coefficient;
-                input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.MaterialName;
-                input.MatchingModelType = vmo.Name;
-                input.MatchingConnectionLength = vmo.ConnectionLength;
-                input.MatchingAngle = vmo.Angle;
-                return true;
-            }
+                else if (absoluteMatch.Count == 1)
+                {
+                    vmo = absoluteMatch.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.ElbowLengthType == input.ElbowLengthType
+           || (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 materialList = new List<Vmo.AssetsElbowMainVmo>();
+                        foreach (var range in rangeMatch)
+                        {
+                            //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
+                            if (range.Material == null)
+                            {
+                                materialList.Add(range);
+                            }
+                            else
+                            {
+                                int commonCount = GetIntersect(input.Material, range.Material);
+                                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;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                    input.MatchingConnectionLength = vmo.ElbowLengthType;
+                    input.MatchingAngle = vmo.Angle;
+                    return true;
+                }*/
             return false;
         }
 
@@ -606,96 +617,88 @@
         //鍥涢�氬尮閰�
         public static bool MatchingFourlink(FourlinkMatchingViewModel input, List<Vmo.AssetsFourlinkMainVmo> adaptingManageVmos)
         {
-            if (adaptingManageVmos == 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 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 =>
-       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 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();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
-                }
-            }
-            //绮剧‘鍖归厤鍜岀矖绯欏尮閰嶉兘娌℃湁鍖归厤鍒板氨杩斿洖閿欒
-            firstCount = 0;
-            if (vmo != null)
-            {
-                input.MatchingMinorLoss = vmo.Coefficient;
-                input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.MaterialName;
-                input.MatchingModelType = vmo.Name;
-                return true;
-            }
+            /*   if (adaptingManageVmos == 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.Material == 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)
+                   {
+                   }
+                   vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
+               }
+               else if (absoluteMatch.Count == 1)
+               {
+                   vmo = absoluteMatch.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 materialList = new List<Vmo.AssetsFourlinkMainVmo>();
+                       foreach (var range in rangeMatch)
+                       {
+                           //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
+                           if (range.Material == null)
+                           {
+                               materialList.Add(range);
+                           }
+                           else
+                           {
+                               int commonCount = GetIntersect(input.Material, range.Material);
+                               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)
+                       {
+                       }
+                       vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
+                   }
+               }
+               //绮剧‘鍖归厤鍜岀矖绯欏尮閰嶉兘娌℃湁鍖归厤鍒板氨杩斿洖閿欒
+               firstCount = 0;
+               if (vmo != null)
+               {
+                   input.MatchingMinorLoss = vmo.MinorLoss;
+                   input.MatchingDbId = vmo.ID.ToString();
+                   input.MatchingMaterial = vmo.Material;
+                   input.MatchingModelType = vmo.Name;
+                   return true;
+               }*/
             return false;
         }
 
@@ -705,7 +708,6 @@
         public static int GetIntersect(string str1, string str2)
         {
             if (str1 == null || str2 == null) return 0;
-
             return string.Join("", str1.Intersect(str2)).Count();
         }
     }

--
Gitblit v1.9.3