From dd4fa076e58b00f46118928bbdaf38f7593544b4 Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期六, 12 十月 2024 13:59:11 +0800 Subject: [PATCH] 状态显示调整 --- WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs | 846 ++++++++++++++++++++++++++++++------------------------- 1 files changed, 461 insertions(+), 385 deletions(-) diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs index c8231cc..34281f8 100644 --- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs +++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs @@ -1,4 +1,7 @@ -锘縩amespace HStation.WinFrmUI +锘縰sing HStation.Vmo; +using HStation.WinFrmUI.PhartRelation; + +namespace HStation.WinFrmUI { public class AssetsMatchingHelper { @@ -10,365 +13,203 @@ private const double _powerTolerance = 0.05; //璧勪骇鑷姩鍖归厤 - public static async Task<AssetsMatchingViewModel> Matching(AssetsMatchingViewModel assetsAutoMatchingView) + public static async Task<bool> Matching(AssetsMatchingViewModel assetsAutoMatchingView) { + bool IsMaching = false; var pumpMain = new BLL.PumpMain(); var adaptingManage = new BLL.AdaptingManage(); - var pipeLineManage = new BLL.PipeLineManage(); + var pipeLineManage = new BLL.PipeMain(); var valveMain = new BLL.ValveMain(); + var elbowMain = new BLL.ElbowMain(); + var threeLinkMain = new BLL.ThreeLinkMain(); + var fourLinkMain = new BLL.FourLinkMain(); + var allPump = await pumpMain.GetAll(); var allAdapting = await adaptingManage.GetAll(); var allPipeLine = await pipeLineManage.GetAll(); var allValve = await valveMain.GetAll(); - var assetsAutoMatching = new AssetsMatchingViewModel(); - var pumpMatchingList = new List<PumpMatchingViewModel>(); - var threeLinkMatchingList = new List<ThreelinkMatchingViewModel>(); - var fourLinkMatchingList = new List<FourlinkMatchingViewModel>(); - var pipeLineMatchingList = new List<PipeMatchingViewModel>(); - var valveMatchingList = new List<ValveMatchingViewModel>(); - var elbowsMatchingList = new List<ElbowsMatchingViewModel>(); + var allElbow = await elbowMain.GetAll(); + var allThreeLink = await threeLinkMain.GetAll(); + var allFourLink = await fourLinkMain.GetAll(); //娉靛尮閰� foreach (var item in assetsAutoMatchingView.PumpMatchingList) { - pumpMatchingList.Add(await MatchingPumps(item, allPump)); + if (await MatchingPumps(item, allPump)) + { + IsMaching = true; + } } //涓夐�氬尮閰� foreach (var item in assetsAutoMatchingView.ThreelinkMatchingList) { - threeLinkMatchingList.Add(MatchingThreeLink(item, allAdapting)); + if (MatchingThreelink(item, allThreeLink)) + { + IsMaching = true; + } } //鍥涢�氬尮閰� foreach (var item in assetsAutoMatchingView.FourlinkMatchingList) { - fourLinkMatchingList.Add(MatchingFourLink(item, allAdapting)); + if (MatchingFourlink(item, allFourLink)) + { + IsMaching = true; + } } //绠¢亾鍖归厤 foreach (var item in assetsAutoMatchingView.PipeMatchingList) { - pipeLineMatchingList.Add(MatchingPipes(item, allPipeLine)); + if (MatchingPipe(item, allPipeLine)) + { + IsMaching = true; + } } //闃�闂ㄥ尮閰� foreach (var item in assetsAutoMatchingView.ValveMatchingList) { - valveMatchingList.Add(MatchingValves(item, allValve)); + if (MatchingValve(item, allValve)) + { + IsMaching = true; + } } //寮ご鍖归厤 - foreach (var item in assetsAutoMatchingView.ElbowsMatchingList) + foreach (var item in assetsAutoMatchingView.ElbowMatchingList) { - elbowsMatchingList.Add(MatchingElbows(item, allAdapting)); + if (MatchingElbow(item, allElbow)) + { + IsMaching = true; + } } - assetsAutoMatching.PumpMatchingList = pumpMatchingList; - assetsAutoMatching.ThreelinkMatchingList = threeLinkMatchingList; - assetsAutoMatching.FourlinkMatchingList = fourLinkMatchingList; - assetsAutoMatching.ElbowsMatchingList = elbowsMatchingList; - assetsAutoMatching.PipeMatchingList = pipeLineMatchingList; - assetsAutoMatching.ValveMatchingList = valveMatchingList; - return assetsAutoMatching; + return IsMaching; } - //寮ご鍖归厤 - public static ElbowsMatchingViewModel MatchingElbows(ElbowsMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos) + //娉靛尮閰� + public static async Task<bool> MatchingPumps(PumpMatchingViewModel InputModel, List<Vmo.PumpMainVmo> pumpMainVmos) { - Vmo.AdaptingManageVmo 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()) + if (pumpMainVmos == null) { - foreach (var range in absoluteMatch) + return true; + } + Vmo.PumpMainVmo vmo = null; + int startCount = 0; + // 灏濊瘯缁濆鍖归厤 + var absoluteMatch = pumpMainVmos.Where(item => + (InputModel.RatedN == null || InputModel.RatedN == item.RatedSpeed) && + (InputModel.RatedQ == null || InputModel.RatedQ == item.RatedFlow) && + (InputModel.RatedH == null || InputModel.RatedH == item.RatedHead) && + (InputModel.RatedP == item.RatedPower)).ToList(); + if (absoluteMatch != null && absoluteMatch.Count != 0) + { + foreach (var item in absoluteMatch) { - int commonCount = CountCommonCharacters(input.ModelType, range.Name); - if (commonCount > firstCount) + int commonCount = GetIntersect(InputModel.ModelType, item.Name); + if (commonCount > startCount) { - vmo = range; - firstCount = commonCount; + vmo = item; + startCount = commonCount; } } } else { - //鍖洪棿鍖归厤 - var rangeMatch = adaptingManageVmos.Where(item => + // 灏濊瘯鍖洪棿鍖归厤 + var rangeMatch = pumpMainVmos.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) && + (Math.Abs(InputModel.RatedP - item.RatedPower) <= _powerTolerance)).ToList(); + if (rangeMatch != null && rangeMatch.Count != 0) { - if (item.Caliber != null && input.Caliber != null) + foreach (var item in rangeMatch) { - return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance; - } - else - { - if (item.Caliber == null) + int commonCount = GetIntersect(InputModel.ModelType, item.Name); + if (commonCount > startCount) { - return true; - } - } - return false; - }) - .ToList(); - if (rangeMatch != null && rangeMatch.Count > 0) - { - var materialList = new List<Vmo.AdaptingManageVmo>(); - foreach (var range in rangeMatch) - { - //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰� - if (range.Material == "榛樿") - { - materialList.Add(range); - } - else - { - int commonCount = CountCommonCharacters(input.Material, range.Material); - if (commonCount > firstCount) - { - materialList.Add(range); - firstCount = commonCount; - } - } - } - //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢�� - firstCount = 0; - foreach (var material in materialList) - { - int commonCount = CountCommonCharacters(input.ModelType, material.Name); - if (commonCount > firstCount) - { - vmo = material; - firstCount = commonCount; + vmo = item; + startCount = commonCount; } } } } - //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰� - firstCount = 0; + // if (vmo == null) { - foreach (var item in adaptingManageVmos) + foreach (var item in pumpMainVmos) { - int commonCount = CountCommonCharacters(input.ModelType, item.Name); - if (commonCount > firstCount) + int commonCount = GetIntersect(InputModel.ModelType, item.Name); + if (commonCount > startCount) { vmo = item; - firstCount = commonCount; + startCount = commonCount; } } } if (vmo != null) { - input.MatchingMinorLoss = vmo.Coefficient; - return input; - } - return input; - } - - //鍥涢�氬尮閰� - public static FourlinkMatchingViewModel MatchingFourLink(FourlinkMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos) - { - Vmo.AdaptingManageVmo 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()) - { - foreach (var range in absoluteMatch) + InputModel.MatchingRatedH = vmo.RatedHead; + InputModel.MatchingRatedN = vmo.RatedSpeed; + InputModel.MatchingRatedQ = vmo.RatedFlow; + InputModel.MatchingRatedP = vmo.RatedPower; + InputModel.MatchingDbId = vmo.ID.ToString(); + InputModel.MatchingModelType = vmo.Name; + var list = await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(vmo.ID); + if (list != null && list.Count > 0) { - int commonCount = CountCommonCharacters(input.ModelType, range.Name); - if (commonCount > firstCount) + 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); + if (graph_qh != null) { - vmo = range; - firstCount = commonCount; - } - } - } - 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) + var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 100, null); + InputModel.MatchingCurveQH = new List<CurvePointMatchingViewModel>(); + foreach (var item in points_qh) { - return true; + InputModel.MatchingCurveQH.Add(new CurvePointMatchingViewModel(item.X, item.Y)); } } - return false; - }) - .ToList(); - if (rangeMatch != null && rangeMatch.Count > 0) - { - var materialList = new List<Vmo.AdaptingManageVmo>(); - foreach (var range in rangeMatch) + if (graph_qe != null) { - //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰� - if (range.Material == "榛樿") + var points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 100, null); + InputModel.MatchingCurveQE = new List<CurvePointMatchingViewModel>(); + foreach (var item in points_qe) { - materialList.Add(range); - } - else - { - int commonCount = CountCommonCharacters(input.Material, range.Material); - if (commonCount > firstCount) - { - materialList.Add(range); - firstCount = commonCount; - } + InputModel.MatchingCurveQE.Add(new CurvePointMatchingViewModel(item.X, item.Y)); } } - //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢�� - firstCount = 0; - foreach (var material in materialList) + if (graph_qp != null) { - int commonCount = CountCommonCharacters(input.ModelType, material.Name); - if (commonCount > firstCount) + var points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 100, null); + InputModel.MatchingCurveQP = new List<CurvePointMatchingViewModel>(); + foreach (var item in points_qp) { - vmo = material; - firstCount = commonCount; + InputModel.MatchingCurveQP.Add(new CurvePointMatchingViewModel(item.X, item.Y)); } } } + return true; } - //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰� - firstCount = 0; - if (vmo == null) - { - foreach (var item in adaptingManageVmos) - { - int commonCount = CountCommonCharacters(input.ModelType, item.Name); - if (commonCount > firstCount) - { - vmo = item; - firstCount = commonCount; - } - } - } - if (vmo != null) - { - input.MatchingMinorLoss = vmo.Coefficient; - return input; - } - return input; - } - - //涓夐�氬尮閰� - public static ThreelinkMatchingViewModel MatchingThreeLink(ThreelinkMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos) - { - Vmo.AdaptingManageVmo 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()) - { - foreach (var range in absoluteMatch) - { - int commonCount = CountCommonCharacters(input.ModelType, range.Name); - if (commonCount > firstCount) - { - vmo = range; - firstCount = commonCount; - } - } - } - 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(); - if (rangeMatch != null && rangeMatch.Count > 0) - { - var materialList = new List<Vmo.AdaptingManageVmo>(); - foreach (var range in rangeMatch) - { - //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰� - if (range.Material == "榛樿") - { - materialList.Add(range); - } - else - { - int commonCount = CountCommonCharacters(input.Material, range.Material); - if (commonCount > firstCount) - { - materialList.Add(range); - firstCount = commonCount; - } - } - } - //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢�� - firstCount = 0; - foreach (var material in materialList) - { - int commonCount = CountCommonCharacters(input.ModelType, material.Name); - if (commonCount > firstCount) - { - vmo = material; - firstCount = commonCount; - } - } - } - } - //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰� - firstCount = 0; - if (vmo == null) - { - foreach (var item in adaptingManageVmos) - { - int commonCount = CountCommonCharacters(input.ModelType, item.Name); - if (commonCount > firstCount) - { - vmo = item; - firstCount = commonCount; - } - } - } - if (vmo != null) - { - input.MatchingMinorLoss = vmo.Coefficient; - return input; - } - return input; + return false; } //闃�闂ㄥ尮閰� - public static ValveMatchingViewModel MatchingValves(ValveMatchingViewModel input, List<Vmo.ValveMainVmo> adaptingManageVmos) + public static bool MatchingValve(ValveMatchingViewModel input, List<Vmo.ValveMainVmo> adaptingManageVmos) { + if (adaptingManageVmos == null) + { + return true; + } HStation.Vmo.ValveMainVmo vmo = null; int firstCount = 0; //鍙e緞鏈�灏忓樊鍊� // 缁濆鍖归厤 var absoluteMatch = adaptingManageVmos.Where(i => - ((input.Diameter == null && i.Caliber == null) || i.Caliber == input.Diameter) && - ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList(); + ((i.Caliber == null) || i.Caliber == input.Diameter) && + ((input.Material == null) || i.MaterialName == input.Material)).ToList(); if (absoluteMatch.Any()) { foreach (var range in absoluteMatch) { - int commonCount = CountCommonCharacters(input.ModelType, range.Name); + int commonCount = GetIntersect(input.ModelType, range.KeyWord); if (commonCount > firstCount) { vmo = range; @@ -381,7 +222,7 @@ //鍖洪棿鍖归厤 var rangeMatch = adaptingManageVmos.Where(item => { - if (item.Caliber != null && input.Diameter != null) + if (item.Caliber.HasValue) { return Math.Abs(Convert.ToInt64(item.Caliber - input.Diameter)) <= _caliberTolerance; } @@ -401,13 +242,13 @@ foreach (var range in rangeMatch) { //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰� - if (range.Material == "榛樿") + if (range.MaterialName == null) { materialList.Add(range); } else { - int commonCount = CountCommonCharacters(input.Material, range.Material); + int commonCount = GetIntersect(input.Material, range.MaterialName); if (commonCount > firstCount) { materialList.Add(range); @@ -419,7 +260,7 @@ firstCount = 0; foreach (var material in materialList) { - int commonCount = CountCommonCharacters(input.ModelType, material.Name); + int commonCount = GetIntersect(input.ModelType, material.KeyWord); if (commonCount > firstCount) { vmo = material; @@ -434,7 +275,7 @@ { foreach (var item in adaptingManageVmos) { - int commonCount = CountCommonCharacters(input.ModelType, item.Name); + int commonCount = GetIntersect(input.ModelType, item.KeyWord); if (commonCount > firstCount) { vmo = item; @@ -445,99 +286,36 @@ if (vmo != null) { input.MatchingMinorLoss = vmo.Coefficient; - return input; + input.MatchingDbId = vmo.ID.ToString(); + input.MatchingDiameter = vmo.Caliber; + input.MatchingMaterial = vmo.MaterialName; + input.MatchingModelType = vmo.Name; + // input.MatchingValveSetting = + input.MatchingValveType = vmo.SeriesType.ToString(); + return true; } - return input; - } - - //娉靛尮閰� - public static async Task<PumpMatchingViewModel> MatchingPumps(PumpMatchingViewModel viewModel, List<Vmo.PumpMainVmo> pumpMainVmos) - { - Vmo.PumpMainVmo vmo = null; - int startCount = 0; - // 灏濊瘯缁濆鍖归厤 - var absoluteMatch = pumpMainVmos.Where(item => - (viewModel.RatedN == null || viewModel.RatedN == item.RatedSpeed) && - (viewModel.RatedQ == null || viewModel.RatedQ == item.RatedFlow) && - (viewModel.RatedH == null || viewModel.RatedH == item.RatedHead) && - (viewModel.RatedP == item.RatedPower)).ToList(); - if (absoluteMatch != null && absoluteMatch.Count != 0) - { - foreach (var item in absoluteMatch) - { - int commonCount = CountCommonCharacters(viewModel.ModelType, item.Name); - if (commonCount > startCount) - { - vmo = item; - startCount = commonCount; - } - } - } - else - { - // 灏濊瘯鍖洪棿鍖归厤 - var rangeMatch = pumpMainVmos.Where(item => - (viewModel.RatedN.HasValue ? Math.Abs(viewModel.RatedN.Value - item.RatedSpeed) <= _speedTolerance : true) && - (viewModel.RatedQ.HasValue ? Math.Abs(viewModel.RatedQ.Value - item.RatedFlow) <= _flowTolerance : true) && - (viewModel.RatedH.HasValue ? Math.Abs(viewModel.RatedH.Value - item.RatedHead) <= _headTolerance : true) && - (Math.Abs(viewModel.RatedP - item.RatedPower) <= _powerTolerance)).ToList(); - if (rangeMatch != null && rangeMatch.Count != 0) - { - foreach (var item in rangeMatch) - { - int commonCount = CountCommonCharacters(viewModel.ModelType, item.Name); - if (commonCount > startCount) - { - vmo = item; - startCount = commonCount; - } - } - } - } - // - if (vmo == null) - { - foreach (var item in pumpMainVmos) - { - int commonCount = CountCommonCharacters(viewModel.ModelType, item.Name); - if (commonCount > startCount) - { - vmo = item; - startCount = commonCount; - } - } - } - if (vmo != null) - { - viewModel.MatchingRatedH = vmo.RatedHead; - viewModel.MatchingRatedN = vmo.RatedSpeed; - viewModel.MatchingRatedQ = vmo.RatedFlow; - viewModel.MatchingRatedP = vmo.RatedPower; - viewModel.MatchingDbId = vmo.ID.ToString(); - var list = await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(vmo.ID); - if (list != null && list.Count > 0) - { - viewModel.MatchingCurveDbId = list.First().ID; - } - } - return null; + return false; } //绠¢亾鍖归厤 - public static PipeMatchingViewModel MatchingPipes(PipeMatchingViewModel input, List<Vmo.PipeLineManageVmo> pipeLineManageVmos) + public static bool MatchingPipe(PipeMatchingViewModel input, List<Vmo.PipeMainVmo> pipeLineManageVmos) { - Vmo.PipeLineManageVmo vmo = null; + if (pipeLineManageVmos == null) + { + return true; + } + Vmo.PipeMainVmo vmo = null; int StartCount = 0; //鍙e緞鏈�灏忓樊鍊� // 缁濆鍖归厤 var absoluteMatch = pipeLineManageVmos.Where(i => - ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) && - ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList(); + ((i.Caliber == null) || i.Caliber == input.Diameter) && + ((input.Material == null) || i.MaterialName == input.Material)).ToList(); if (absoluteMatch.Any()) { foreach (var range in absoluteMatch) { - int commonCount = CountCommonCharacters(input.ModelType, range.Name); + int commonCount = GetIntersect(input.ModelType, range.KeyWord); if (commonCount > StartCount) { vmo = range; @@ -550,9 +328,9 @@ //鍖洪棿鍖归厤 var rangeMatch = pipeLineManageVmos.Where(item => { - if (item.Caliber != null && input.Caliber != null) + if (item.Caliber != null) { - return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance; + return Math.Abs(Convert.ToInt64(item.Caliber - input.Diameter)) <= _caliberTolerance; } return false; }) @@ -562,7 +340,7 @@ foreach (var range in rangeMatch) { //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰� - int commonCount = CountCommonCharacters(input.Material, range.Material); + int commonCount = GetIntersect(input.Material, range.MaterialName); if (commonCount > StartCount) { vmo = range; @@ -576,7 +354,7 @@ { foreach (var item in pipeLineManageVmos) { - int commonCount = CountCommonCharacters(input.ModelType, item.Name); + int commonCount = GetIntersect(input.ModelType, item.KeyWord); if (commonCount > StartCount) { vmo = item; @@ -589,38 +367,337 @@ switch (input.eAlgorithmType) { case HStation.Assets.eAlgorithmType.Hazen: - input.MatchingMinorLoss = vmo.Hazen; - return input; + input.MatchingRoughness = vmo.Hazen; + break; case HStation.Assets.eAlgorithmType.Manning: - input.MatchingMinorLoss = vmo.Manning; - return input; + input.MatchingRoughness = vmo.Manning; + break; case HStation.Assets.eAlgorithmType.Darcy: - input.MatchingMinorLoss = vmo.Darcy; - return input; + input.MatchingRoughness = vmo.Darcy; + break; default: - input.MatchingMinorLoss = vmo.Hazen; - return input; + input.MatchingRoughness = vmo.Hazen; + break; } + input.MatchingDbId = vmo.ID.ToString(); + input.MatchingMaterial = vmo.MaterialName; + input.MatchingModelType = vmo.Name; + input.MatchingMinorLoss = vmo.Coefficient; + return true; } - return input; + return false; } - //杩斿洖涓や釜瀛楃涓蹭箣闂寸浉鍚岀殑瀛楃涓暟 - private static int CountCommonCharacters(string baseString, string compareString) + //寮ご鍖归厤 + public static bool MatchingElbow(ElbowMatchingViewModel input, List<Vmo.ElbowMainVmo> adaptingManageVmos) { - // 灏嗗瓧绗︿覆杞崲涓哄瓧绗﹂泦鍚� - if (baseString == string.Empty || baseString == null || compareString == string.Empty || compareString == null) + if (adaptingManageVmos == null) { - return 0; + return true; } - HashSet<char> baseChars = new HashSet<char>(baseString); - HashSet<char> comparisonChars = new HashSet<char>(compareString); - // 璁$畻涓や釜闆嗗悎鐨勪氦闆� - int commonCount = baseChars.Intersect(comparisonChars).Count(); - return commonCount; + Vmo.ElbowMainVmo 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.MaterialName == input.Material)).ToList(); + if (absoluteMatch.Any()) + { + foreach (var range in absoluteMatch) + { + int commonCount = GetIntersect(input.ModelType, range.KeyWord); + if (commonCount > firstCount) + { + vmo = range; + firstCount = commonCount; + } + } + } + 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(); + if (rangeMatch != null && rangeMatch.Count > 0) + { + var materialList = new List<Vmo.ElbowMainVmo>(); + 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; + foreach (var material in materialList) + { + int commonCount = GetIntersect(input.ModelType, material.KeyWord); + if (commonCount > firstCount) + { + vmo = material; + firstCount = commonCount; + } + } + } + } + //鍙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.MaterialName; + input.MatchingModelType = vmo.Name; + return true; + } + return false; + } + + //涓夐�氬尮閰� + public static bool MatchingThreelink(ThreelinkMatchingViewModel input, List<Vmo.ThreeLinkMainVmo> adaptingManageVmos) + { + if (adaptingManageVmos == null) + { + return true; + } + Vmo.ThreeLinkMainVmo 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.MaterialName == input.Material)).ToList(); + if (absoluteMatch.Any()) + { + foreach (var range in absoluteMatch) + { + int commonCount = GetIntersect(input.ModelType, range.Name); + if (commonCount > firstCount) + { + vmo = range; + firstCount = commonCount; + } + } + } + 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(); + if (rangeMatch != null && rangeMatch.Count > 0) + { + var materialList = new List<Vmo.ThreeLinkMainVmo>(); + 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; + foreach (var material in materialList) + { + int commonCount = GetIntersect(input.ModelType, material.Name); + if (commonCount > firstCount) + { + vmo = material; + firstCount = commonCount; + } + } + } + } + //鍙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.MaterialName; + input.MatchingModelType = vmo.Name; + return true; + } + return false; + } + + //鍥涢�氬尮閰� + public static bool MatchingFourlink(FourlinkMatchingViewModel input, List<Vmo.FourLinkMainVmo> adaptingManageVmos) + { + if (adaptingManageVmos == null) + { + return true; + } + Vmo.FourLinkMainVmo 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.MaterialName == input.Material)).ToList(); + if (absoluteMatch.Any()) + { + foreach (var range in absoluteMatch) + { + int commonCount = GetIntersect(input.ModelType, range.Name); + if (commonCount > firstCount) + { + vmo = range; + firstCount = commonCount; + } + } + } + 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(); + if (rangeMatch != null && rangeMatch.Count > 0) + { + var materialList = new List<Vmo.FourLinkMainVmo>(); + 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; + foreach (var material in materialList) + { + int commonCount = GetIntersect(input.ModelType, material.Name); + if (commonCount > firstCount) + { + vmo = material; + firstCount = commonCount; + } + } + } + } + //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰� + firstCount = 0; + if (vmo == null) + { + foreach (var item in adaptingManageVmos) + { + int commonCount = GetIntersect(input.ModelType, item.KeyWord); + if (commonCount > firstCount) + { + vmo = item; + firstCount = commonCount; + } + } + } + if (vmo != null) + { + input.MatchingMinorLoss = vmo.Coefficient; + input.MatchingDbId = vmo.ID.ToString(); + input.MatchingMaterial = vmo.MaterialName; + input.MatchingModelType = vmo.Name; + return true; + } + return false; } /// <summary> @@ -629,12 +706,11 @@ /// <param name="str1"></param> /// <param name="str2"></param> /// <returns></returns> - public static string GetIntersect(string str1, string str2) + public static int GetIntersect(string str1, string str2) { - if (str1 == null || str2 == null) return null; + if (str1 == null || str2 == null) return 0; - return string.Join("", str1.Intersect(str2)); + return string.Join("", str1.Intersect(str2)).Count(); } - } } \ No newline at end of file -- Gitblit v1.9.3