From 7c9869ecbc4380c17c1158b096dbb5b0a92ad439 Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期二, 05 十一月 2024 18:01:19 +0800
Subject: [PATCH] 继续优化阀门管理界面

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs |  765 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 410 insertions(+), 355 deletions(-)

diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
index f95086b..f5d9380 100644
--- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
+++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
@@ -1,4 +1,6 @@
-锘縰sing HStation.WinFrmUI.PhartRelation;
+锘縰sing HStation.Vmo;
+using HStation.WinFrmUI.PhartRelation;
+using System.Windows.Input;
 
 namespace HStation.WinFrmUI
 {
@@ -11,76 +13,98 @@
         private const double _headTolerance = 5;
         private const double _powerTolerance = 0.05;
 
+        private const double _valveLift = 10;//闃�闂ㄥ紑搴﹁寖鍥�
+        private const int _angle = 1;//瑙掑害鑼冨洿
+
         //璧勪骇鑷姩鍖归厤
-        public static async Task<bool> Matching(AssetsMatchingViewModel assetsAutoMatchingView)
+        public static bool Matching(AssetsMatchingViewModel assetsAutoMatchingView, out string Error)
         {
+            Error = string.Empty;
             bool IsMaching = false;
-            var pumpMain = new BLL.PumpMain();
+            var AssetsPumpMain = new BLL.AssetsPumpMain();
             var adaptingManage = new BLL.AdaptingManage();
-            var pipeLineManage = new BLL.PipeLineManage();
-            var valveMain = new BLL.ValveMain();
-            var allPump = await pumpMain.GetAll();
-            var allAdapting = await adaptingManage.GetAll();
-            var allPipeLine = await pipeLineManage.GetAll();
-            var allValve = await valveMain.GetAll();
-            //娉靛尮閰�
-            foreach (var item in assetsAutoMatchingView.PumpMatchingList)
+            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();
+            try
             {
-                if (await MatchingPumps(item, allPump))
+                var allPump = Task.Run(async () => await AssetsPumpMain.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;
+                //娉靛尮閰�
+                foreach (var item in assetsAutoMatchingView.PumpMatchingList)
                 {
-                    IsMaching = true;
+                    if (MatchingPumps(item, allPump))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //涓夐�氬尮閰�
+                foreach (var item in assetsAutoMatchingView.ThreelinkMatchingList)
+                {
+                    if (MatchingThreelink(item, allThreeLink))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //鍥涢�氬尮閰�
+                foreach (var item in assetsAutoMatchingView.FourlinkMatchingList)
+                {
+                    if (MatchingFourlink(item, allFourLink))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //绠¢亾鍖归厤
+                foreach (var item in assetsAutoMatchingView.PipeMatchingList)
+                {
+                    if (MatchingPipe(item, allPipeLine))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //闃�闂ㄥ尮閰�
+                foreach (var item in assetsAutoMatchingView.ValveMatchingList)
+                {
+                    if (MatchingValve(item, allValve))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //寮ご鍖归厤
+                foreach (var item in assetsAutoMatchingView.ElbowMatchingList)
+                {
+                    if (MatchingElbow(item, allElbow))
+                    {
+                        IsMaching = true;
+                    }
                 }
             }
-            //涓夐�氬尮閰�
-            foreach (var item in assetsAutoMatchingView.ThreelinkMatchingList)
+            catch (Exception ex)
             {
-                if (MatchingThreelink(item, allAdapting))
-                {
-                    IsMaching = true;
-                }
-            }
-            //鍥涢�氬尮閰�
-            foreach (var item in assetsAutoMatchingView.FourlinkMatchingList)
-            {
-                if (MatchingFourlink(item, allAdapting))
-                {
-                    IsMaching = true;
-                }
-            }
-            //绠¢亾鍖归厤
-            foreach (var item in assetsAutoMatchingView.PipeMatchingList)
-            {
-                if (MatchingPipe(item, allPipeLine))
-                {
-                    IsMaching = true;
-                }
-            }
-            //闃�闂ㄥ尮閰�
-            foreach (var item in assetsAutoMatchingView.ValveMatchingList)
-            {
-                if (MatchingValve(item, allValve))
-                {
-                    IsMaching = true;
-                }
-            }
-            //寮ご鍖归厤
-            foreach (var item in assetsAutoMatchingView.ElbowMatchingList)
-            {
-                if (MatchingElbow(item, allAdapting))
-                {
-                    IsMaching = true;
-                }
+                Error = ex.Message;
+                return false;
             }
             return IsMaching;
         }
 
         //娉靛尮閰�
-        public static async Task<bool> MatchingPumps(PumpMatchingViewModel InputModel, List<Vmo.PumpMainVmo> pumpMainVmos)
+        public static bool MatchingPumps(PumpMatchingViewModel InputModel, List<Vmo.AssetsPumpMainVmo> AssetsPumpMainVmos)
         {
-            Vmo.PumpMainVmo vmo = null;
+            if (AssetsPumpMainVmos == null)
+            {
+                return true;
+            }
+            Vmo.AssetsPumpMainVmo vmo = null;
             int startCount = 0;
             // 灏濊瘯缁濆鍖归厤
-            var absoluteMatch = pumpMainVmos.Where(item =>
+            var absoluteMatch = AssetsPumpMainVmos.Where(item =>
             (InputModel.RatedN == null || InputModel.RatedN == item.RatedSpeed) &&
             (InputModel.RatedQ == null || InputModel.RatedQ == item.RatedFlow) &&
             (InputModel.RatedH == null || InputModel.RatedH == item.RatedHead) &&
@@ -100,7 +124,7 @@
             else
             {
                 // 灏濊瘯鍖洪棿鍖归厤
-                var rangeMatch = pumpMainVmos.Where(item =>
+                var rangeMatch = AssetsPumpMainVmos.Where(item =>
                    (InputModel.RatedN.HasValue ? Math.Abs(InputModel.RatedN.Value - item.RatedSpeed) <= _speedTolerance : true) &&
                    (InputModel.RatedQ.HasValue ? Math.Abs(InputModel.RatedQ.Value - item.RatedFlow) <= _flowTolerance : true) &&
                    (InputModel.RatedH.HasValue ? Math.Abs(InputModel.RatedH.Value - item.RatedHead) <= _headTolerance : true) &&
@@ -121,7 +145,7 @@
             //
             if (vmo == null)
             {
-                foreach (var item in pumpMainVmos)
+                foreach (var item in AssetsPumpMainVmos)
                 {
                     int commonCount = GetIntersect(InputModel.ModelType, item.Name);
                     if (commonCount > startCount)
@@ -139,13 +163,14 @@
                 InputModel.MatchingRatedP = vmo.RatedPower;
                 InputModel.MatchingDbId = vmo.ID.ToString();
                 InputModel.MatchingModelType = vmo.Name;
-                var list = await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(vmo.ID);
+                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);
@@ -180,59 +205,192 @@
         }
 
         //闃�闂ㄥ尮閰�
-        public static bool MatchingValve(ValveMatchingViewModel input, List<Vmo.ValveMainVmo> adaptingManageVmos)
+        public static bool MatchingValve(ValveMatchingViewModel input, List<Vmo.AssetsValveMainVmo> adaptingManageVmos)
         {
-            HStation.Vmo.ValveMainVmo vmo = null;
+            if (adaptingManageVmos == null)
+            {
+                return true;
+            }
+            /*       HStation.Vmo.AssetsValveMainVmo vmo = null;
+                   //鍙e緞鏈�灏忓樊鍊�
+                   // 缁濆鍖归厤
+                   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浠ヤ笂骞朵笖杩涜鎺掑簭
+
+                   if (nameMatching.Count > 0)
+                   {
+                       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 (nameMatching.Count == 1)
+                   {
+                       vmo = nameMatching.First();
+                   }
+                   else
+                   {
+                       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)
+                       {
+                           return false;
+                       }
+                       else if (absoluteMatching.Count == 1)
+                       {
+                           vmo = absoluteMatching.First();
+                       }
+                       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();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
+                       }
+                   }
+                   //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
+                   firstCount = 0;*//*
+                   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.ToString();
+                       return true;
+                   }*/
+            return false;
+        }
+
+        //绠¢亾鍖归厤
+        public static bool MatchingPipe(PipeMatchingViewModel input, List<Vmo.AssetsPipeMainVmo> pipeLineManageVmos)
+        {
+            if (pipeLineManageVmos == null)
+            {
+                return true;
+            }
+            Vmo.AssetsPipeMainVmo vmo = null;
             int firstCount = 0;
             //鍙e緞鏈�灏忓樊鍊�
             // 缁濆鍖归厤
-            var absoluteMatch = adaptingManageVmos.Where(i =>
-              ((i.Caliber == null) || i.Caliber == input.Diameter) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
+            var absoluteMatch = pipeLineManageVmos.Where(i =>
+            ((i.Caliber == null) || i.Caliber == input.Diameter) &&
+               ((input.Material == null) || i.MaterialName == input.Material)).ToList();
+            if (absoluteMatch.Count > 1)
             {
-                foreach (var range in absoluteMatch)
-                {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > firstCount)
-                    {
-                        vmo = range;
-                        firstCount = commonCount;
-                    }
-                }
+            }
+            else if (absoluteMatch.Count == 1)
+            {
+                vmo = absoluteMatch.First();
             }
             else
             {
                 //鍖洪棿鍖归厤
-                var rangeMatch = adaptingManageVmos.Where(item =>
+                var rangeMatch = pipeLineManageVmos
+               .Where(item =>
+               item.Caliber == null ||
+               Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Diameter)) <= _caliberTolerance)
+         .ToList();
+                if (rangeMatch != null)
                 {
-                    if (item.Caliber.HasValue)
-                    {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Diameter)) <= _caliberTolerance;
-                    }
-                    else
-                    {
-                        if (item.Caliber == null)
-                        {
-                            return true;
-                        }
-                    }
-                    return false;
-                })
-             .ToList();
-                if (rangeMatch != null && rangeMatch.Count > 0)
-                {
-                    var materialList = new List<Vmo.ValveMainVmo>();
+                    var materialList = new List<Vmo.AssetsPipeMainVmo>();
                     foreach (var range in rangeMatch)
                     {
                         //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        if (range.Material == "榛樿")
+                        if (range.MaterialName == null)
                         {
                             materialList.Add(range);
                         }
                         else
                         {
-                            int commonCount = GetIntersect(input.Material, range.Material);
+                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                             if (commonCount > firstCount)
                             {
                                 materialList.Add(range);
@@ -240,108 +398,26 @@
                             }
                         }
                     }
-                    //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢��
                     firstCount = 0;
-                    foreach (var material in materialList)
+                    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)
                     {
-                        int commonCount = GetIntersect(input.ModelType, material.Name);
-                        if (commonCount > firstCount)
+                        if (item.IsDefault)
                         {
-                            vmo = material;
-                            firstCount = commonCount;
+                            vmo = item;
                         }
                     }
+                    vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
                 }
             }
             //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
-            firstCount = 0;
-            if (vmo == null)
-            {
-                foreach (var item in adaptingManageVmos)
-                {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > firstCount)
-                    {
-                        vmo = item;
-                        firstCount = commonCount;
-                    }
-                }
-            }
-            if (vmo != null)
-            {
-                input.MatchingMinorLoss = vmo.Coefficient;
-                input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingDiameter = vmo.Caliber;
-                input.MatchingMaterial = vmo.Material;
-                input.MatchingModelType = vmo.Name;
-                //  input.MatchingValveSetting =
-                input.MatchingValveType = vmo.Type.ToString();
-                return true;
-            }
-            return false;
-        }
-
-        //绠¢亾鍖归厤
-        public static bool MatchingPipe(PipeMatchingViewModel input, List<Vmo.PipeLineManageVmo> pipeLineManageVmos)
-        {
-            Vmo.PipeLineManageVmo vmo = null;
-            int StartCount = 0;
-            //鍙e緞鏈�灏忓樊鍊�
-            // 缁濆鍖归厤
-            var absoluteMatch = pipeLineManageVmos.Where(i =>
-            ((i.Caliber == null) || i.Caliber == input.Diameter) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
-            {
-                foreach (var range in absoluteMatch)
-                {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > StartCount)
-                    {
-                        vmo = range;
-                        StartCount = commonCount;
-                    }
-                }
-            }
-            else
-            {
-                //鍖洪棿鍖归厤
-                var rangeMatch = pipeLineManageVmos.Where(item =>
-                {
-                    if (item.Caliber != null)
-                    {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Diameter)) <= _caliberTolerance;
-                    }
-                    return false;
-                })
-             .ToList();
-                if (rangeMatch != null)
-                {
-                    foreach (var range in rangeMatch)
-                    {
-                        //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        int commonCount = GetIntersect(input.Material, range.Material);
-                        if (commonCount > StartCount)
-                        {
-                            vmo = range;
-                            StartCount = commonCount;
-                        }
-                    }
-                }
-            }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
-            if (vmo == null)
-            {
-                foreach (var item in pipeLineManageVmos)
-                {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > StartCount)
-                    {
-                        vmo = item;
-                        StartCount = commonCount;
-                    }
-                }
-            }
             if (vmo != null)
             {
                 switch (input.eAlgorithmType)
@@ -363,7 +439,7 @@
                         break;
                 }
                 input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.Material;
+                input.MatchingMaterial = vmo.MaterialName;
                 input.MatchingModelType = vmo.Name;
                 input.MatchingMinorLoss = vmo.Coefficient;
                 return true;
@@ -372,59 +448,64 @@
         }
 
         //寮ご鍖归厤
-        public static bool MatchingElbow(ElbowMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos)
+        public static bool MatchingElbow(ElbowMatchingViewModel input, List<Vmo.AssetsElbowMainVmo> adaptingManageVmos)
         {
-            Vmo.AdaptingManageVmo vmo = null;
+            if (adaptingManageVmos == null)
+            {
+                return true;
+            }
+            Vmo.AssetsElbowMainVmo vmo = null;
             int firstCount = 0;
-            //鍙e緞鏈�灏忓樊鍊�
             // 缁濆鍖归厤
             var absoluteMatch = adaptingManageVmos.Where(i =>
               ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
+               ((input.Material == null) || i.MaterialName == input.Material)).ToList();
+            if (absoluteMatch.Count > 1)
             {
-                foreach (var range in absoluteMatch)
+                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)
                 {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > firstCount)
+                    if (item.IsDefault)
                     {
-                        vmo = range;
-                        firstCount = commonCount;
+                        vmo = item;
                     }
                 }
+                vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
+            }
+            else if (absoluteMatch.Count == 1)
+            {
+                vmo = absoluteMatch.First();
             }
             else
             {
                 //鍖洪棿鍖归厤
-                var rangeMatch = adaptingManageVmos.Where(item =>
-                {
-                    if (item.Caliber != null && input.Caliber != null)
-                    {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance;
-                    }
-                    else
-                    {
-                        if (item.Caliber == null)
-                        {
-                            return true;
-                        }
-                    }
-                    return false;
-                })
-             .ToList();
+                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.AdaptingManageVmo>();
+                    var materialList = new List<Vmo.AssetsElbowMainVmo>();
                     foreach (var range in rangeMatch)
                     {
                         //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        if (range.Material == "榛樿")
+                        if (range.MaterialName == null)
                         {
                             materialList.Add(range);
                         }
                         else
                         {
-                            int commonCount = GetIntersect(input.Material, range.Material);
+                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                             if (commonCount > firstCount)
                             {
                                 materialList.Add(range);
@@ -434,96 +515,95 @@
                     }
                     //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢��
                     firstCount = 0;
-                    foreach (var material in materialList)
+                    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)
                     {
-                        int commonCount = GetIntersect(input.ModelType, material.Name);
-                        if (commonCount > firstCount)
+                        if (item.IsDefault)
                         {
-                            vmo = material;
-                            firstCount = commonCount;
+                            vmo = item;
                         }
                     }
+                    vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
                 }
             }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
+            //绮剧‘鍖归厤鍜岀矖绯欏尮閰嶉兘娌℃湁鍖归厤鍒板氨杩斿洖閿欒
             firstCount = 0;
-            if (vmo == null)
-            {
-                foreach (var item in adaptingManageVmos)
-                {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > firstCount)
-                    {
-                        vmo = item;
-                        firstCount = commonCount;
-                    }
-                }
-            }
             if (vmo != null)
             {
                 input.MatchingMinorLoss = vmo.Coefficient;
                 input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.Material;
+                input.MatchingMaterial = vmo.MaterialName;
                 input.MatchingModelType = vmo.Name;
+                input.MatchingConnectionLength = vmo.ConnectionLength;
+                input.MatchingAngle = vmo.Angle;
                 return true;
             }
             return false;
         }
 
         //涓夐�氬尮閰�
-        public static bool MatchingThreelink(ThreelinkMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos)
+        public static bool MatchingThreelink(ThreelinkMatchingViewModel input, List<Vmo.AssetsThreelinkMainVmo> adaptingManageVmos)
         {
-            Vmo.AdaptingManageVmo vmo = null;
+            if (adaptingManageVmos == null)
+            {
+                return true;
+            }
+            Vmo.AssetsThreelinkMainVmo vmo = null;
             int firstCount = 0;
-            //鍙e緞鏈�灏忓樊鍊�
             // 缁濆鍖归厤
             var absoluteMatch = adaptingManageVmos.Where(i =>
               ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
+               ((input.Material == null) || i.MaterialName == input.Material)).ToList();
+            if (absoluteMatch.Count > 1)
             {
-                foreach (var range in absoluteMatch)
+                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)
                 {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > firstCount)
+                    if (item.IsDefault)
                     {
-                        vmo = range;
-                        firstCount = commonCount;
+                        vmo = item;
                     }
                 }
+                vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
+            }
+            else if (absoluteMatch.Count == 1)
+            {
+                vmo = absoluteMatch.First();
             }
             else
             {
                 //鍖洪棿鍖归厤
-                var rangeMatch = adaptingManageVmos.Where(item =>
-                {
-                    if (item.Caliber != null && input.Caliber != null)
-                    {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance;
-                    }
-                    else
-                    {
-                        if (item.Caliber == null)
-                        {
-                            return true;
-                        }
-                    }
-                    return false;
-                })
-             .ToList();
+                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.AdaptingManageVmo>();
+                    var materialList = new List<Vmo.AssetsThreelinkMainVmo>();
                     foreach (var range in rangeMatch)
                     {
                         //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        if (range.Material == "榛樿")
+                        if (range.MaterialName == null)
                         {
                             materialList.Add(range);
                         }
                         else
                         {
-                            int commonCount = GetIntersect(input.Material, range.Material);
+                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                             if (commonCount > firstCount)
                             {
                                 materialList.Add(range);
@@ -533,96 +613,95 @@
                     }
                     //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢��
                     firstCount = 0;
-                    foreach (var material in materialList)
+                    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)
                     {
-                        int commonCount = GetIntersect(input.ModelType, material.Name);
-                        if (commonCount > firstCount)
+                        if (item.IsDefault)
                         {
-                            vmo = material;
-                            firstCount = commonCount;
+                            vmo = item;
                         }
                     }
+                    vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
                 }
             }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
+            //绮剧‘鍖归厤鍜岀矖绯欏尮閰嶉兘娌℃湁鍖归厤鍒板氨杩斿洖閿欒
             firstCount = 0;
-            if (vmo == null)
-            {
-                foreach (var item in adaptingManageVmos)
-                {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > firstCount)
-                    {
-                        vmo = item;
-                        firstCount = commonCount;
-                    }
-                }
-            }
             if (vmo != null)
             {
                 input.MatchingMinorLoss = vmo.Coefficient;
                 input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.Material;
+                input.MatchingMaterial = vmo.MaterialName;
                 input.MatchingModelType = vmo.Name;
+                input.MatchingRunThroughCoefficient = vmo.RunThroughCoefficient;
+                input.MatchingBranchThroughCoefficient = vmo.BranchThroughCoefficient;
                 return true;
             }
             return false;
         }
 
         //鍥涢�氬尮閰�
-        public static bool MatchingFourlink(FourlinkMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos)
+        public static bool MatchingFourlink(FourlinkMatchingViewModel input, List<Vmo.AssetsFourlinkMainVmo> adaptingManageVmos)
         {
-            Vmo.AdaptingManageVmo vmo = null;
+            if (adaptingManageVmos == null)
+            {
+                return true;
+            }
+            Vmo.AssetsFourlinkMainVmo vmo = null;
             int firstCount = 0;
-            //鍙e緞鏈�灏忓樊鍊�
             // 缁濆鍖归厤
             var absoluteMatch = adaptingManageVmos.Where(i =>
               ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
+               ((input.Material == null) || i.MaterialName == input.Material)).ToList();
+            if (absoluteMatch.Count > 1)
             {
-                foreach (var range in absoluteMatch)
+                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)
                 {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > firstCount)
+                    if (item.IsDefault)
                     {
-                        vmo = range;
-                        firstCount = commonCount;
+                        vmo = item;
                     }
                 }
+                vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
+            }
+            else if (absoluteMatch.Count == 1)
+            {
+                vmo = absoluteMatch.First();
             }
             else
             {
                 //鍖洪棿鍖归厤
-                var rangeMatch = adaptingManageVmos.Where(item =>
-                {
-                    if (item.Caliber != null && input.Caliber != null)
-                    {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance;
-                    }
-                    else
-                    {
-                        if (item.Caliber == null)
-                        {
-                            return true;
-                        }
-                    }
-                    return false;
-                })
-             .ToList();
+                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.AdaptingManageVmo>();
+                    var materialList = new List<Vmo.AssetsFourlinkMainVmo>();
                     foreach (var range in rangeMatch)
                     {
                         //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        if (range.Material == "榛樿")
+                        if (range.MaterialName == null)
                         {
                             materialList.Add(range);
                         }
                         else
                         {
-                            int commonCount = GetIntersect(input.Material, range.Material);
+                            int commonCount = GetIntersect(input.Material, range.MaterialName);
                             if (commonCount > firstCount)
                             {
                                 materialList.Add(range);
@@ -632,68 +711,44 @@
                     }
                     //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢��
                     firstCount = 0;
-                    foreach (var material in materialList)
+                    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)
                     {
-                        int commonCount = GetIntersect(input.ModelType, material.Name);
-                        if (commonCount > firstCount)
+                        if (item.IsDefault)
                         {
-                            vmo = material;
-                            firstCount = commonCount;
+                            vmo = item;
                         }
                     }
+                    vmo = allMatchingList.First();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹�
                 }
             }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
+            //绮剧‘鍖归厤鍜岀矖绯欏尮閰嶉兘娌℃湁鍖归厤鍒板氨杩斿洖閿欒
             firstCount = 0;
-            if (vmo == null)
-            {
-                foreach (var item in adaptingManageVmos)
-                {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > firstCount)
-                    {
-                        vmo = item;
-                        firstCount = commonCount;
-                    }
-                }
-            }
             if (vmo != null)
             {
                 input.MatchingMinorLoss = vmo.Coefficient;
                 input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.Material;
+                input.MatchingMaterial = vmo.MaterialName;
                 input.MatchingModelType = vmo.Name;
                 return true;
             }
             return false;
         }
 
-        /*
-                //杩斿洖涓や釜瀛楃涓蹭箣闂寸浉鍚岀殑瀛楃涓暟
-                private static int GetIntersect(string baseString, string compareString)
-                {
-                    // 灏嗗瓧绗︿覆杞崲涓哄瓧绗﹂泦鍚�
-                    if (baseString == string.Empty || baseString == null || compareString == string.Empty || compareString == null)
-                    {
-                        return 0;
-                    }
-                    HashSet<char> baseChars = new HashSet<char>(baseString);
-                    HashSet<char> comparisonChars = new HashSet<char>(compareString);
-                    // 璁$畻涓や釜闆嗗悎鐨勪氦闆�
-                    int commonCount = baseChars.Intersect(comparisonChars).Count();
-                    return commonCount;
-                }*/
-
         /// <summary>
         /// 鑾峰彇涓や釜瀛楃涓茬殑鎵�鏈変氦闆�
         /// </summary>
-        /// <param name="str1"></param>
-        /// <param name="str2"></param>
-        /// <returns></returns>
         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();
         }
     }

--
Gitblit v1.9.3