From e37b6f2ca026097b83da3ec989cb0d454cceddad Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期四, 19 十二月 2024 14:13:22 +0800 Subject: [PATCH] 压力表整改 --- WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs | 109 +++++++++++++++++++++++++++++++----------------------- 1 files changed, 62 insertions(+), 47 deletions(-) diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs index 87bb6cb..acb74d3 100644 --- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs +++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs @@ -173,7 +173,7 @@ //鍘嬪姏琛ㄥ尮閰� foreach (var item in assetsAutoMatchingView.Pressmeters) { - if (MatchingPressmeter(item, allPressmeterMain)) + if (Matching(item, allPressmeterMain)) { IsMaching = true; } @@ -1716,65 +1716,80 @@ } //鍘嬪姏琛ㄥ尮閰� - public static bool MatchingPressmeter(HydroPressmeterMatchingViewModel input, List<Vmo.AssetsPressmeterMainVmo> pressmeterVmos) + public static bool Matching(HydroPressmeterMatchingViewModel input, List<Vmo.AssetsPressmeterMainVmo> allPressmeterList) { - bool isNotarize = false; //鏄惁纭畾 - if (pressmeterVmos == null || input == null || pressmeterVmos.Count == 0) + //杈撳叆鍙傛暟楠岃瘉 + if (input == null) { - return true; + return false; } - Vmo.AssetsPressmeterMainVmo vmo = null; - var nameMatching = pressmeterVmos.Where(x => - (x.KeyWord != null && x.KeyWord.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || - (x.KeyWord == null || !x.KeyWord.Any()) && GetIntersect(x.Name, input.ModelType) >= 1 - ) //鍏堣繘琛岀瓫閫�,鍚庤繘琛屼粠澶у埌灏忔帓搴� - .OrderByDescending(x => - (x.KeyWord != null && x.KeyWord.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || - (x.KeyWord == null || !x.KeyWord.Any()) && GetIntersect(x.Name, input.ModelType) >= 1).ToList(); - if (nameMatching.Count > 1) + //鏁版嵁婧愭病鏈夋暟鎹垯娌℃湁鍖归厤鎴愬姛 + if (allPressmeterList == null || allPressmeterList.Count < 1) { - var defaultList = nameMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList(); - //鍙栭粯璁� - if (defaultList.Count > 0) - { - vmo = pressmeterVmos.First(); - } - else if (defaultList.Count <= 0) - { - vmo = pressmeterVmos.First(); - } + return false; } - else if (nameMatching.Count == 1) - { - isNotarize = true; - vmo = nameMatching.First(); - } - else + //鏉冮噸瀛楀吀 + var dict = new Dictionary<AssetsPressmeterMainVmo, double>(); + foreach (var item in allPressmeterList) { - vmo = pressmeterVmos.First(); + dict.Add(item, 0); } - if (vmo != null) + + //鍨嬪彿 + int modelTypeWeight = 100; + if (!string.IsNullOrEmpty(input.ModelType)) { - if (!isNotarize) + foreach (var item in allPressmeterList) { - if (input.MinorLoss < 0) - input.MatchingMinorLoss = vmo.MinorLoss; - if (input.DbId == null) - input.MatchingDbId = vmo.ID.ToString(); - if (input.ModelType == null) - input.MatchingModelType = vmo.Name; + if (!string.IsNullOrEmpty(item.Name)) + { + var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count(); + dict[item] += count * modelTypeWeight; + } } - else - { - input.MatchingMinorLoss = vmo.MinorLoss; - input.MatchingDbId = vmo.ID.ToString(); - input.MatchingModelType = vmo.Name; - } - return true; } - return false; + + // 鍏抽敭瀛� + int keywordWeight = 1; + foreach (var item in allPressmeterList) + { + if (item.KeyWords != null && item.KeyWords.Count > 0) + { + if (!string.IsNullOrEmpty(input.ModelType)) + { + var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower())); + dict[item] += count * keywordWeight; + } + } + } + + //鏍囩 + int flagWeight = 10; + foreach (var item in allPressmeterList) + { + if (item.Flags != null && item.Flags.Count > 0) + { + if (item.Flags.Contains(HStation.Assets.Flags.榛樿)) + { + dict[item] += flagWeight; + } + } + } + + var flowmeter = dict.OrderBy(x => x.Value).LastOrDefault().Key; + input.MatchingDbId = flowmeter.ID.ToString(); + if (string.IsNullOrEmpty(input.ModelType)) + { + input.MatchingModelType = flowmeter.Name; + } + if (input.MinorLoss <= 0) + { + input.MatchingMinorLoss = flowmeter.MinorLoss; + } + + return true; } //杩囨浮浠跺尮閰� -- Gitblit v1.9.3