From 7676398e188b4e6618ec9c7831534db1775c99cc Mon Sep 17 00:00:00 2001 From: Shuxia Ning <NingShuxia0927@outlook.com> Date: 星期一, 02 十二月 2024 15:23:03 +0800 Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/HStation/XHS.V1.0 --- WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs | 595 ++++++++++++++++++++++++----------------------------------- 1 files changed, 245 insertions(+), 350 deletions(-) diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs index 09d8b96..25e9e8e 100644 --- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs +++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs @@ -1,6 +1,4 @@ -锘縰sing HStation.Vmo; -using HStation.WinFrmUI.PhartRelation; -using System.Windows.Input; +锘縰sing HStation.WinFrmUI.PhartRelation; namespace HStation.WinFrmUI { @@ -205,18 +203,18 @@ } //闃�闂ㄥ尮閰� - 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; //鍙e緞鏈�灏忓樊鍊� // 缁濆鍖归厤 - adaptingManageVmos = adaptingManageVmos.Where(x => x.ValveType == input.ValveType).ToList(); + valveMainVmos = valveMainVmos.Where(x => x.ValveType == input.ValveType).ToList(); - var nameMatching = adaptingManageVmos.Where(x => + var nameMatching = valveMainVmos.Where(x => (x.KeyWord != null && x.KeyWord.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || (x.KeyWord == null || !x.KeyWord.Any()) && GetIntersect(x.Name, input.ModelType) >= 1 ) //鍏堣繘琛岀瓫閫�,鍚庤繘琛屼粠澶у埌灏忔帓搴� @@ -248,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(); @@ -318,388 +316,285 @@ } //绠¢亾鍖归厤 - public static bool MatchingPipe(PipeMatchingViewModel input, List<Vmo.AssetsPipeMainVmo> pipeLineManageVmos) + public static bool MatchingPipe(PipeMatchingViewModel input, List<Vmo.AssetsPipeMainVmo> pipeLineMainVmos) { - /* if (pipeLineManageVmos == null) - { - return true; - } - Vmo.AssetsPipeMainVmo vmo = null; - int firstCount = 0; - //鍙e緞鏈�灏忓樊鍊� - // 缁濆鍖归厤 - var absoluteMatch = pipeLineManageVmos.Where(i => - ((i.Caliber == null) || i.Caliber == input.Diameter) && - ((input.Material == null) || i.Material == input.Material)).ToList(); - if (absoluteMatch.Count > 1) - { - } - else if (absoluteMatch.Count == 1) - { - vmo = absoluteMatch.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 materialList = new List<Vmo.AssetsPipeMainVmo>(); - 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();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹� - } - } - //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰� - if (vmo != null) - { - switch (input.eAlgorithmType) - { - case HStation.Assets.eAlgorithmType.Hazen: - input.MatchingRoughness = vmo.Hazen; - break; + if (pipeLineMainVmos == null) + { + return true; + } + Vmo.AssetsPipeMainVmo vmo = null; - case HStation.Assets.eAlgorithmType.Manning: - input.MatchingRoughness = vmo.Manning; - break; + 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(); - case HStation.Assets.eAlgorithmType.Darcy: - input.MatchingRoughness = vmo.Darcy; - break; + 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 (nameMatching.Count == 1) + { + vmo = nameMatching.First(); + } + else + { + 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) + { + return false; + } + else if (absoluteMatching.Count == 1) + { + vmo = absoluteMatching.First(); + } + else + return false; + } + if (vmo != null) + { + switch (input.eAlgorithmType) + { + case HStation.Assets.eAlgorithmType.Hazen: + input.MatchingRoughness = vmo.Hazen; + break; - default: - input.MatchingRoughness = vmo.Hazen; - break; - } - input.MatchingDbId = vmo.ID.ToString(); - input.MatchingMaterial = vmo.Material; - input.MatchingModelType = vmo.Name; - input.MatchingMinorLoss = vmo.MinorLoss; - return true; - }*/ + case HStation.Assets.eAlgorithmType.Manning: + input.MatchingRoughness = vmo.Manning; + break; + + case HStation.Assets.eAlgorithmType.Darcy: + input.MatchingRoughness = vmo.Darcy; + break; + + default: + input.MatchingRoughness = vmo.Hazen; + break; + } + input.MatchingDbId = vmo.ID.ToString(); + input.MatchingMaterial = vmo.Material; + input.MatchingModelType = vmo.Name; + 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.Material == 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 absoluteMatching = nameMatching.Where(i => + ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) && //鐩村緞绾︽潫 + i.Material == input.Material //鏉愭枡绾︽潫 + ).ToList(); + if (absoluteMatching.Count > 1) { - var 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();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹� + return false; } - else if (absoluteMatch.Count == 1) + else if (absoluteMatching.Count == 1) { - vmo = absoluteMatch.First(); + vmo = absoluteMatching.First(); } else + return false; + } + else if (nameMatching.Count == 1) + { + vmo = nameMatching.First(); + } + else + { + var absoluteMatching = elbowMainVmos.Where(i => + ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) && //鐩村緞绾︽潫 + i.Material == input.Material //鏉愭枡绾︽潫 + ).ToList(); + if (absoluteMatching.Count > 1) { - //鍖洪棿鍖归厤 - var 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();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹� - } + return false; } - //绮剧‘鍖归厤鍜岀矖绯欏尮閰嶉兘娌℃湁鍖归厤鍒板氨杩斿洖閿欒 - firstCount = 0; - if (vmo != null) + else if (absoluteMatching.Count == 1) { - 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; - }*/ + vmo = absoluteMatching.First(); + } + else + return false; + } + 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; } //涓夐�氬尮閰� - 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; + } + 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 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) { - return true; + return false; } - 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.Material == input.Material)).ToList(); - if (absoluteMatch.Count > 1) + else if (absoluteMatching.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(); + vmo = absoluteMatching.First(); } else + return false; + } + else if (nameMatching.Count == 1) + { + vmo = nameMatching.First(); + } + else + { + 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 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.AssetsThreelinkMainVmo>(); - 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();//濡傛灉娌℃湁璁剧疆榛樿鍊�,鍒欓粯璁よ繑鍥炲尮閰嶅瓧绗︽渶澶氱殑涓�鏉℃暟鎹� - } + return false; } - //绮剧‘鍖归厤鍜岀矖绯欏尮閰嶉兘娌℃湁鍖归厤鍒板氨杩斿洖閿欒 - firstCount = 0; - if (vmo != null) + else if (absoluteMatching.Count == 1) { - input.MatchingMinorLoss = vmo.MinorLoss; - input.MatchingDbId = vmo.ID.ToString(); - input.MatchingMaterial = vmo.Material; - input.MatchingModelType = vmo.Name; - input.MatchingRunThroughCoefficient = vmo.RunThroughCoefficient; - input.MatchingBranchThroughCoefficient = vmo.BranchThroughCoefficient; - return true; + vmo = absoluteMatching.First(); } - return false;*/ + else + return false; + } + if (vmo != null) + { + input.MatchingMinorLoss = vmo.MinorLoss; + input.MatchingDbId = vmo.ID.ToString(); + input.MatchingMaterial = vmo.Material; + input.MatchingModelType = vmo.Name; + 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) - { - 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; - }*/ + if (fourLinkVmos == null) + { + return true; + } + Vmo.AssetsFourlinkMainVmo vmo = null; + var nameMatching = fourLinkVmos.Where(x => + (x.KeyWord != null && x.KeyWord.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || + (x.KeyWord == null || !x.KeyWord.Any()) && GetIntersect(x.Name, input.ModelType) >= 1 + ) //鍏堣繘琛岀瓫閫�,鍚庤繘琛屼粠澶у埌灏忔帓搴� +.OrderByDescending(x => + (x.KeyWord != null && x.KeyWord.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || + (x.KeyWord == null || !x.KeyWord.Any()) && GetIntersect(x.Name, input.ModelType) >= 1).ToList(); + + if (nameMatching.Count > 1) + { + var absoluteMatching = nameMatching.Where(i => + ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) && //鐩村緞绾︽潫 + i.Material == input.Material //鏉愭枡绾︽潫 + ).ToList(); + if (absoluteMatching.Count > 1) + { + return false; + } + else if (absoluteMatching.Count == 1) + { + vmo = absoluteMatching.First(); + } + else + return false; + } + else if (nameMatching.Count == 1) + { + vmo = nameMatching.First(); + } + else + { + 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) + { + 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.MatchingMaterial = vmo.Material; + input.MatchingModelType = vmo.Name; + return true; + } return false; } -- Gitblit v1.9.3