using HStation.WinFrmUI.PhartRelation; using Swashbuckle.AspNetCore.SwaggerGen; using System.Linq; using Yw.WinFrmUI.Q3d; namespace HStation.WinFrmUI { public class AssetsMatchingHelper { private readonly Lazy _bll_ex = new(); private const double _caliberTolerance = 10.0; private const double _speedTolerance = 100; private const double _flowTolerance = 10; private const double _headTolerance = 5; private const double _powerTolerance = 0.05; private const double _valveLift = 10;//阀门开度范围 private const int _angle = 1;//角度范围 //资产自动匹配 public static bool Matching(HydroMatchingViewModel assetsAutoMatchingView, out string Error) { Error = string.Empty; bool IsMaching = false; var AssetsPumpMain = new BLL.AssetsPumpMain(); var AdaptingManage = new BLL.AdaptingManage(); 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(); var AssetsSprinkler = new BLL.AssetsSprinklerMain(); var AssetsExchanger = new BLL.AssetsExchangerMain(); var AssetsCompressorMain = new BLL.AssetsCompressorMain(); var AssetsBluntheadMain = new BLL.AssetsBluntheadMain(); var AssetsTankMain = new BLL.AssetsTankMain(); var AssetsMeterMain = new BLL.AssetsMeterMain(); var AssetsFlowmeterMain = new BLL.AssetsFlowmeterMain(); var AssetsHydrantMain = new BLL.AssetsHydrantMain(); var AssetsPressmeterMain = new BLL.AssetsPressmeterMain(); var AssetsTranslationMain = new BLL.AssetsTranslationMain(); try { 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; var allSprinkler = Task.Run(async () => await AssetsSprinkler.GetAll()).Result; var allExchanger = Task.Run(async () => await AssetsExchanger.GetAll()).Result; var allCompressorMain = Task.Run(async () => await AssetsCompressorMain.GetAll()).Result; var allBluntheadMain = Task.Run(async () => await AssetsBluntheadMain.GetAll()).Result; var allTankMain = Task.Run(async () => await AssetsTankMain.GetAll()).Result; var allMeterMain = Task.Run(async () => await AssetsMeterMain.GetAll()).Result; var allFlowmeterMain = Task.Run(async () => await AssetsFlowmeterMain.GetAll()).Result; var allHydrantMain = Task.Run(async () => await AssetsHydrantMain.GetAll()).Result; var allPressmeterMain = Task.Run(async () => await AssetsPressmeterMain.GetAll()).Result; var allTranslationMain = Task.Run(async () => await AssetsTranslationMain.GetAll()).Result; //泵匹配 foreach (var item in assetsAutoMatchingView.Pumps) { if (MatchingPumps(item, allPump)) { IsMaching = true; } } //三通匹配 foreach (var item in assetsAutoMatchingView.Threelinks) { if (MatchingThreelink(item, allThreeLink)) { IsMaching = true; } } //四通匹配 foreach (var item in assetsAutoMatchingView.Fourlinks) { if (MatchingFourlink(item, allFourLink)) { IsMaching = true; } } //管道匹配 foreach (var item in assetsAutoMatchingView.Pipes) { if (MatchingPipe(item, allPipeLine)) { IsMaching = true; } } //阀门匹配 foreach (var item in assetsAutoMatchingView.Valves) { if (MatchingValve(item, allValve)) { IsMaching = true; } } //弯头匹配 foreach (var item in assetsAutoMatchingView.Elbows) { if (MatchingElbow(item, allElbow)) { IsMaching = true; } } //喷头匹配 foreach (var item in assetsAutoMatchingView.Nozzles) { if (MatchingSprinkler(item, allSprinkler)) { IsMaching = true; } } //闷头匹配 foreach (var item in assetsAutoMatchingView.Bluntheads) { if (MatchingBlunthead(item, allBluntheadMain)) { IsMaching = true; } } //换热器匹配 foreach (var item in assetsAutoMatchingView.Exchangers) { if (MatchingExchanger(item, allExchanger)) { IsMaching = true; } } //压缩机匹配 foreach (var item in assetsAutoMatchingView.Compressors) { if (MatchingCompressor(item, allCompressorMain)) { IsMaching = true; } } //水池匹配 foreach (var item in assetsAutoMatchingView.Tanks) { if (MatchingTank(item, allTankMain)) { IsMaching = true; } } //水表匹配 foreach (var item in assetsAutoMatchingView.Meters) { if (Matching(item, allMeterMain)) { IsMaching = true; } } //流量计匹配 foreach (var item in assetsAutoMatchingView.Flowmeters) { if (Matching(item, allFlowmeterMain)) { IsMaching = true; } } //消火栓匹配 foreach (var item in assetsAutoMatchingView.Hydrants) { if (MatchingHydrant(item, allHydrantMain)) { IsMaching = true; } } //压力表匹配 foreach (var item in assetsAutoMatchingView.Pressmeters) { if (MatchingPressmeter(item, allPressmeterMain)) { IsMaching = true; } } //过渡件匹配 foreach (var item in assetsAutoMatchingView.Translations) { if (MatchingTranslation(item, allTranslationMain)) { IsMaching = true; } } } catch (Exception ex) { Error = ex.Message; return false; } return IsMaching; } //泵匹配 public static bool MatchingPumps(HydroPumpMatchingViewModel InputModel, List AssetsPumpMainVmos) { if (AssetsPumpMainVmos == null) { return true; } Vmo.AssetsPumpMainVmo vmo = null; int startCount = 0; // 尝试绝对匹配 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) && (InputModel.RatedP == item.RatedPower)).ToList(); if (absoluteMatch != null && absoluteMatch.Count != 0) { foreach (var item in absoluteMatch) { int commonCount = GetIntersect(InputModel.ModelType, item.Name); if (commonCount > startCount) { vmo = item; startCount = commonCount; } } } else { // 尝试区间匹配 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) && (Math.Abs(InputModel.RatedP - item.RatedPower) <= _powerTolerance)).ToList(); if (rangeMatch != null && rangeMatch.Count != 0) { foreach (var item in rangeMatch) { int commonCount = GetIntersect(InputModel.ModelType, item.Name); if (commonCount > startCount) { vmo = item; startCount = commonCount; } } } } // if (vmo == null) { foreach (var item in AssetsPumpMainVmos) { int commonCount = GetIntersect(InputModel.ModelType, item.Name); if (commonCount > startCount) { vmo = item; startCount = commonCount; } } } if (vmo != null) { 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 = Task.Run(async () => await new BLL.PhartDiagramRelation().GetExByObjectTypeAndObjectID(HStation.Assets.DataType.PumpMain, vmo.ID)).Result; /* if (list != null && list.Count > 0) { 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.QH); var graph_qe = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.QE); var graph_qp = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.QP); if (graph_qh != null) { var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 100, null); InputModel.MatchingCurveQH = new List(); foreach (var item in points_qh) { InputModel.MatchingCurveQH.Add(new HydroCurvePointViewModel(item.X, item.Y)); } } if (graph_qe != null) { var points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 100, null); InputModel.MatchingCurveQE = new List(); foreach (var item in points_qe) { InputModel.MatchingCurveQE.Add(new HydroCurvePointViewModel(item.X, item.Y)); } } if (graph_qp != null) { var points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 100, null); InputModel.MatchingCurveQP = new List(); foreach (var item in points_qp) { InputModel.MatchingCurveQP.Add(new HydroCurvePointViewModel(item.X, item.Y)); } } }*/ return true; } return false; } //阀门匹配 public static bool MatchingValve(HydroValveMatchingViewModel input, List valveMainVmos) { bool isNotarize = false; //是否确定 if (valveMainVmos == null) { return true; } HStation.Vmo.AssetsValveMainVmo vmo = null; //口径最小差值 // 绝对匹配 valveMainVmos = valveMainVmos.Where(x => (int)x.ValveType == (int)input.ValveType).ToList(); var nameMatching = valveMainVmos.Where(x => (x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || (x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1 ) //先进行筛选,后进行从大到小排序 .OrderByDescending(x => (x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || (x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1) .ToList();//使用型号名或者关键字找出相同字符在1以上并且进行排序 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) { var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = valveMainVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = valveMainVmos.First(); } else if (nameMatching.Count == 1) { isNotarize = true; vmo = nameMatching.First(); } else { var absoluteMatching = valveMainVmos.Where(i => ((i.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - input.Diameter) <= _caliberTolerance) && //直径约束 i.Material == input.Material //材料约束 ).ToList(); if (absoluteMatching.Count > 1) { var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = valveMainVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = valveMainVmos.First(); } if (vmo != null) { if (!isNotarize) { if (input.CurveDbId == null) { if ((int)input.ValveType == (int)HStation.Assets.eValveType.GPV) { var curveList = Task.Run(async () => await new BLL.AssetsValveFactor().GetByMainID(vmo.ID)).Result; if (curveList != null && curveList.Count > 0) { input.MatchingCurveDbId = curveList.First().ID.ToString(); var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().MinorLossCurve); input.MatchingCurveQL = pt_list; } } else if ((int)vmo.ValveType == (int)HStation.Assets.eValveType.TCV) { var curveList = Task.Run(async () => await new BLL.AssetsValveFactor().GetByMainID(vmo.ID)).Result; if (curveList != null && curveList.Count > 0) { input.MatchingCurveDbId = curveList.First().ID.ToString(); var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().OpenLossCurve); input.MatchingCurveOL = pt_list; } } } if (input.MinorLoss < 0) { input.MatchingMinorLoss = vmo.MinorLoss; } if (!input.MatchingDiameter.HasValue) input.MatchingDiameter = vmo.Caliber; if (input.ValveSetting == null) input.MatchingValveSetting = vmo.ValveSetting; if (input.DbId == null) { input.MatchingDbId = vmo.ID.ToString(); } } else { 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 = (eValveType?)(int)vmo.ValveType; if (vmo.ValveType == HStation.Assets.eValveType.GPV) { var curveList = Task.Run(async () => await new BLL.AssetsValveFactor().GetByMainID(vmo.ID)).Result; if (curveList != null && curveList.Count > 0) { input.MatchingCurveDbId = curveList.First().ID.ToString(); var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().MinorLossCurve); input.MatchingCurveQL = pt_list; } } else if (vmo.ValveType == HStation.Assets.eValveType.TCV) { var curveList = Task.Run(async () => await new BLL.AssetsValveFactor().GetByMainID(vmo.ID)).Result; if (curveList != null && curveList.Count > 0) { input.MatchingCurveDbId = curveList.First().ID.ToString(); var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().OpenLossCurve); input.MatchingCurveOL = pt_list; } } } return true; } return false; } //管道匹配 public static bool MatchingPipe(HydroPipeMatchingViewModel input, List pipeLineMainVmos) { bool isNotarize = false; //是否确定 if (pipeLineMainVmos == null) { return true; } Vmo.AssetsPipeMainVmo vmo = null; 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(); 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) { var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = pipeLineMainVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = pipeLineMainVmos.First(); } else if (nameMatching.Count == 1) { isNotarize = true; 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) { var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = pipeLineMainVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = pipeLineMainVmos.First(); } if (vmo != null) { if (!isNotarize) { if (input.DbId == null) input.MatchingDbId = vmo.ID.ToString(); if (input.Material == null) input.MatchingMaterial = vmo.Material; if (input.MinorLoss < 0) input.MatchingMinorLoss = vmo.MinorLoss; switch (input.eAlgorithmType) { case eAlgorithmType.Hazen: input.MatchingRoughness = vmo.Hazen; break; case eAlgorithmType.Manning: input.MatchingRoughness = vmo.Manning; break; case eAlgorithmType.Darcy: input.MatchingRoughness = vmo.Darcy; break; default: input.MatchingRoughness = vmo.Hazen; break; } } else { switch (input.eAlgorithmType) { case eAlgorithmType.Hazen: input.MatchingRoughness = vmo.Hazen; break; case eAlgorithmType.Manning: input.MatchingRoughness = vmo.Manning; break; case 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(HydroElbowMatchingViewModel input, List elbowMainVmos) { bool isNotarize = false; //是否确定 if (elbowMainVmos == null || input == null || elbowMainVmos.Count == 0) { return true; } Vmo.AssetsElbowMainVmo vmo = null; 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 defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = elbowMainVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = elbowMainVmos.First(); } else if (nameMatching.Count == 1) { isNotarize = true; 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 defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = elbowMainVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = elbowMainVmos.First(); } if (vmo != null) { if (!isNotarize) { if (!input.MinorLoss.HasValue) { input.MatchingMinorLoss = vmo.MinorLoss; } if (input.DbId == null) { input.MatchingDbId = vmo.ID.ToString(); } if (input.Material == null) { input.MatchingMaterial = vmo.Material; } if (input.ModelType == null) { input.MatchingModelType = vmo.Material; } if (!input.ElbowType.HasValue) { input.MatchingElbowType = (eElbowType?)(int)vmo.ElbowType; } if (!input.BendingAngle.HasValue) { input.MatchingBendingAngle = vmo.Angle; } } else { input.MatchingMinorLoss = vmo.MinorLoss; input.MatchingDbId = vmo.ID.ToString(); input.MatchingMaterial = vmo.Material; input.MatchingModelType = vmo.Name; input.MatchingElbowType = (eElbowType?)(int)vmo.ElbowType; input.MatchingBendingAngle = vmo.Angle; } return true; } return false; } //三通匹配 public static bool MatchingThreelink(HydroThreelinkMatchingViewModel input, List threelinkVmos) { bool isNotarize = false; //是否确定 Vmo.AssetsThreelinkMainVmo vmo = null; if (threelinkVmos == null || input == null || threelinkVmos.Count == 0) { 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) { var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = threelinkVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = threelinkVmos.First(); } else if (nameMatching.Count == 1) { isNotarize = true; 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 defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = threelinkVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = threelinkVmos.First(); } if (vmo != null) { if (!isNotarize) { if (!input.MinorLoss.HasValue) input.MatchingMinorLoss = vmo.MinorLoss; if (input.DbId == null) input.MatchingDbId = vmo.ID.ToString(); if (!input.RunningThroughLoss.HasValue) input.MatchingRunningThroughLoss = vmo.RunThroughMinorLoss; if (!input.MatchingBranchThroughLoss.HasValue) input.MatchingRunningThroughLoss = vmo.BranchThroughMinorLoss; } else { input.MatchingMinorLoss = vmo.MinorLoss; input.MatchingDbId = vmo.ID.ToString(); input.MatchingMaterial = vmo.Material; input.MatchingModelType = vmo.Name; input.MatchingRunningThroughLoss = vmo.RunThroughMinorLoss; input.MatchingBranchThroughLoss = vmo.BranchThroughMinorLoss; } return true; } return false; } //四通匹配 public static bool MatchingFourlink(HydroFourlinkMatchingViewModel input, List fourLinkVmos) { bool isNotarize = false; //是否确定 if (fourLinkVmos == null || input == null || fourLinkVmos.Count == 0) { 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) { var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = fourLinkVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = fourLinkVmos.First(); } else if (nameMatching.Count == 1) { isNotarize = true; 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) { var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = fourLinkVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = fourLinkVmos.First(); } if (vmo != null) { if (!isNotarize) { if (!input.MinorLoss.HasValue) input.MatchingMinorLoss = vmo.MinorLoss; if (input.DbId == null) input.MatchingDbId = vmo.ID.ToString(); if (input.Material == null) input.MatchingMaterial = vmo.Material; if (input.ModelType == null) input.MatchingModelType = vmo.Name; } else { input.MatchingMinorLoss = vmo.MinorLoss; input.MatchingDbId = vmo.ID.ToString(); input.MatchingMaterial = vmo.Material; input.MatchingModelType = vmo.Name; } return true; } return false; } //喷头匹配 public static bool MatchingSprinkler(HydroNozzleMatchingViewModel input, List sprinklerVmos) { bool isNotarize = false; //是否确定 if (sprinklerVmos == null || input == null || sprinklerVmos.Count == 0) { return true; } Vmo.AssetsSprinklerMainVmo vmo = null; var nameMatching = sprinklerVmos.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 defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = sprinklerVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = sprinklerVmos.First(); } else if (nameMatching.Count == 1) { isNotarize = true; vmo = nameMatching.First(); } else { var absoluteMatching = sprinklerVmos.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 defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = sprinklerVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = sprinklerVmos.First(); } if (vmo != null) { if (!isNotarize) { if (!input.MinorLoss.HasValue) input.MatchingMinorLoss = vmo.MinorLoss; if (input.DbId == null) input.MatchingDbId = vmo.ID.ToString(); if (input.Material == null) input.MatchingMaterial = vmo.Material; if (input.ModelType == null) input.MatchingModelType = vmo.Name; } else { input.MatchingMinorLoss = vmo.MinorLoss; input.MatchingDbId = vmo.ID.ToString(); input.MatchingMaterial = vmo.Material; input.MatchingModelType = vmo.Name; } return true; } return false; } //换热器匹配 public static bool MatchingExchanger(HydroExchangerMatchingViewModel input, List exchangerVmos) { // bool isNotarize = false; //是否确定 // if (exchangerVmos == null || input == null || exchangerVmos.Count == 0) // { // return true; // } // Vmo.AssetsExchangerMainVmo vmo = null; // var nameMatching = exchangerVmos.Where(x => //(x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || //(x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1 //) //先进行筛选,后进行从大到小排序 //.OrderByDescending(x => // (x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || // (x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1).ToList(); // if (nameMatching.Count > 1) // { // var absoluteMatching = nameMatching.Where(i => // i.Material == input.Material //材料约束 // ).ToList(); // if (absoluteMatching.Count > 1) // { // var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); // //取默认 // if (defaultList.Count > 0) // { // vmo = defaultList.First(); // } // else if (defaultList.Count <= 0) // { // vmo = exchangerVmos.First(); // } // } // else if (absoluteMatching.Count == 1) // { // isNotarize = true; // vmo = absoluteMatching.First(); // } // else // vmo = exchangerVmos.First(); // } // else if (nameMatching.Count == 1) // { // isNotarize = true; // vmo = nameMatching.First(); // } // else // { // var absoluteMatching = exchangerVmos.Where(i => // i.Material == input.Material //材料约束 // ).ToList(); // if (absoluteMatching.Count > 1) // { // var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); // //取默认 // if (defaultList.Count > 0) // { // vmo = defaultList.First(); // } // else if (defaultList.Count <= 0) // { // vmo = exchangerVmos.First(); // } // } // else if (absoluteMatching.Count == 1) // { // isNotarize = true; // vmo = absoluteMatching.First(); // } // else // vmo = exchangerVmos.First(); // } // if (vmo != null) // { // if (!isNotarize) // { // if (input.MinorLoss < 0) // input.MatchingMinorLoss = vmo.MinorLoss; // if (input.DbId == null) // input.MatchingDbId = vmo.ID.ToString(); // if (input.Material == null) // input.MatchingMaterial = vmo.Material; // if (input.ModelType == null) // input.MatchingModelType = vmo.Name; // if (input.CurveDbId == null) // { // var curveList = Task.Run(async () => await new BLL.AssetsExchangerCoefficient().GetByMainID(vmo.ID)).Result; // if (curveList != null && curveList.Count > 0) // { // input.MatchingCurveDbId = curveList.First().ID.ToString(); // var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().MinorLossCurve); // input.MatchingCurveQL = pt_list; // } // } // } // else // { // input.MatchingMinorLoss = vmo.MinorLoss; // input.MatchingDbId = vmo.ID.ToString(); // input.MatchingMaterial = vmo.Material; // input.MatchingModelType = vmo.Name; // var curveList = Task.Run(async () => await new BLL.AssetsExchangerCoefficient().GetByMainID(vmo.ID)).Result; // if (curveList != null && curveList.Count > 0) // { // input.MatchingCurveDbId = curveList.First().ID.ToString(); // var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().MinorLossCurve); // input.MatchingCurveQL = pt_list; // } // } // return true; // } // return false; return true; } //空压机匹配 public static bool MatchingCompressor(HydroCompressorMatchingViewModel input, List compressorVmos) { // bool isNotarize = false; //是否确定 // if (compressorVmos == null || input == null || compressorVmos.Count == 0) // { // return true; // } // Vmo.AssetsCompressorMainVmo vmo = null; // var nameMatching = compressorVmos.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.Material == input.Material //材料约束 // ).ToList(); // if (absoluteMatching.Count > 1) // { // var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); // //取默认 // if (defaultList.Count > 0) // { // vmo = defaultList.First(); // } // else if (defaultList.Count <= 0) // { // vmo = compressorVmos.First(); // } // } // else if (absoluteMatching.Count == 1) // { // isNotarize = true; // vmo = absoluteMatching.First(); // } // else // vmo = compressorVmos.First(); // } // else if (nameMatching.Count == 1) // { // isNotarize = true; // vmo = nameMatching.First(); // } // else // { // var absoluteMatching = compressorVmos.Where(i => // i.Material == input.Material //材料约束 // ).ToList(); // if (absoluteMatching.Count > 1) // { // var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); // //取默认 // if (defaultList.Count > 0) // { // vmo = defaultList.First(); // } // else if (defaultList.Count <= 0) // { // vmo = compressorVmos.First(); // } // } // else if (absoluteMatching.Count == 1) // { // isNotarize = true; // vmo = absoluteMatching.First(); // } // else // vmo = compressorVmos.First(); // } // if (vmo != null) // { // if (!isNotarize) // { // if (input.MinorLoss < 0) // input.MatchingMinorLoss = vmo.MinorLoss; // if (input.DbId == null) // input.MatchingDbId = vmo.ID.ToString(); // if (input.Material == null) // input.MatchingMaterial = vmo.Material; // if (input.ModelType == null) // input.MatchingModelType = vmo.Name; // if (input.CurveDbId == null) // { // var curveList = Task.Run(async () => await new BLL.AssetsCompressorCoefficient().GetByMainID(vmo.ID)).Result; // if (curveList != null && curveList.Count > 0) // { // input.MatchingCurveDbId = curveList.First().ID.ToString(); // var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().MinorLossCurve); // input.MatchingCurveQL = pt_list; // } // } // } // else // { // input.MatchingMinorLoss = vmo.MinorLoss; // input.MatchingDbId = vmo.ID.ToString(); // input.MatchingMaterial = vmo.Material; // input.MatchingModelType = vmo.Name; // var curveList = Task.Run(async () => await new BLL.AssetsCompressorCoefficient().GetByMainID(vmo.ID)).Result; // if (curveList != null && curveList.Count > 0) // { // input.MatchingCurveDbId = curveList.First().ID.ToString(); // var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().MinorLossCurve); // input.MatchingCurveQL = pt_list; // } // } // return true; // } return false; } //闷头匹配 public static bool MatchingBlunthead(HydroBluntheadMatchingViewModel input, List bluntheadVmos) { bool isNotarize = false; //是否确定 if (bluntheadVmos == null || input == null || bluntheadVmos.Count == 0) { return true; } Vmo.AssetsBluntheadMainVmo vmo = null; var nameMatching = bluntheadVmos.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 defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = bluntheadVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = bluntheadVmos.First(); } else if (nameMatching.Count == 1) { isNotarize = true; vmo = nameMatching.First(); } else { var absoluteMatching = bluntheadVmos.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 defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = bluntheadVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = bluntheadVmos.First(); } if (vmo != null) { if (!isNotarize) { if (input.MinorLoss < 0) input.MatchingMinorLoss = vmo.MinorLoss; if (input.DbId == null) input.MatchingDbId = vmo.ID.ToString(); if (input.Material == null) input.MatchingMaterial = vmo.Material; if (input.ModelType == null) input.MatchingModelType = vmo.Name; } else { input.MatchingMinorLoss = vmo.MinorLoss; input.MatchingDbId = vmo.ID.ToString(); input.MatchingMaterial = vmo.Material; input.MatchingModelType = vmo.Name; } return true; } return false; } //水池匹配 public static bool MatchingTank(HydroTankMatchingViewModel input, List tankVmos) { bool isNotarize = false; //是否确定 if (tankVmos == null || input == null || tankVmos.Count == 0) { return true; } Vmo.AssetsTankMainVmo vmo = null; var nameMatching = tankVmos.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 defaultList = nameMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = tankVmos.First(); } else if (defaultList.Count <= 0) { vmo = tankVmos.First(); } } else if (nameMatching.Count == 1) { isNotarize = true; vmo = nameMatching.First(); } else vmo = tankVmos.First(); if (vmo != null) { if (!isNotarize) { if (input.DbId == null) input.MatchingDbId = vmo.ID.ToString(); if (input.ModelType == null) input.MatchingModelType = vmo.Name; if (input.DN < 0) input.MatchingDN = vmo.DN; if (input.MinLevel < 0) input.MatchingMinLevel = vmo.MinLevel; if (input.CurveDbId == null) { var curveList = Task.Run(async () => await new BLL.AssetsTankCoefficient().GetByMainID(vmo.ID)).Result; if (curveList != null && curveList.Count > 0) { input.MatchingCurveDbId = curveList.First().ID.ToString(); var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().VolCurve); input.MatchingVolCurve = pt_list; } } } else { input.MatchingDbId = vmo.ID.ToString(); input.MatchingModelType = vmo.Name; input.MatchingDN = vmo.DN; input.MatchingMinLevel = vmo.MinLevel; input.MatchingOverFlow = vmo.OverFlow; var curveList = Task.Run(async () => await new BLL.AssetsTankCoefficient().GetByMainID(vmo.ID)).Result; if (curveList != null && curveList.Count > 0) { input.MatchingCurveDbId = curveList.First().ID.ToString(); var pt_list = Yw.JsonHelper.Json2Object>(curveList.First().VolCurve); input.MatchingVolCurve = pt_list; } } return true; } return false; } //水表匹配 public static bool Matching(HydroMeterMatchingViewModel input, List allMeterList) { //输入参数验证 if (input == null) { return false; } //数据源没有数据则没有匹配成功 if (allMeterList == null || allMeterList.Count < 1) { return false; } //权重字典 var dict = new Dictionary(); foreach (var item in allMeterList) { dict.Add(item, 0); } //型号 int modelTypeWeight = 100; if (!string.IsNullOrEmpty(input.ModelType)) { foreach (var item in allMeterList) { if (!string.IsNullOrEmpty(item.Name)) { var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count(); dict[item] += count * modelTypeWeight; } } } // 关键字 int keywordWeight = 1; foreach (var item in allMeterList) { 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 allMeterList) { 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; } //流量计匹配 public static bool Matching(HydroFlowmeterMatchingViewModel input, List allFlowmeterList) { //输入参数验证 if (input == null) { return false; } //数据源没有数据则没有匹配成功 if (allFlowmeterList == null || allFlowmeterList.Count < 1) { return false; } //权重字典 var dict = new Dictionary(); foreach (var item in allFlowmeterList) { dict.Add(item, 0); } //型号 int modelTypeWeight = 100; if (!string.IsNullOrEmpty(input.ModelType)) { foreach (var item in allFlowmeterList) { if (!string.IsNullOrEmpty(item.Name)) { var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count(); dict[item] += count * modelTypeWeight; } } } // 关键字 int keywordWeight = 1; foreach (var item in allFlowmeterList) { 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 allFlowmeterList) { 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; } //消火栓匹配 public static bool MatchingHydrant(HydroHydrantMatchingViewModel input, List hydrantVmos) { bool isNotarize = false; //是否确定 if (hydrantVmos == null || input == null || hydrantVmos.Count == 0) { return true; } Vmo.AssetsHydrantMainVmo vmo = null; var nameMatching = hydrantVmos.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 defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = hydrantVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = hydrantVmos.First(); } else if (nameMatching.Count == 1) { vmo = nameMatching.First(); } else { var absoluteMatching = hydrantVmos.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 defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = hydrantVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = hydrantVmos.First(); } if (vmo != null) { if (!isNotarize) { 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; } else { input.MatchingMinorLoss = vmo.MinorLoss; input.MatchingDbId = vmo.ID.ToString(); input.MatchingMaterial = vmo.Material; input.MatchingModelType = vmo.Name; } return true; } return false; } //压力表匹配 public static bool MatchingPressmeter(HydroPressmeterMatchingViewModel input, List pressmeterVmos) { bool isNotarize = false; //是否确定 if (pressmeterVmos == null || input == null || pressmeterVmos.Count == 0) { return true; } Vmo.AssetsPressmeterMainVmo vmo = null; var nameMatching = pressmeterVmos.Where(x => (x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || (x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1 ) //先进行筛选,后进行从大到小排序 .OrderByDescending(x => (x.KeyWords != null && x.KeyWords.Any(keyword => GetIntersect(keyword, input.ModelType) >= 1)) || (x.KeyWords == null || !x.KeyWords.Any()) && GetIntersect(x.Name, input.ModelType) >= 1).ToList(); if (nameMatching.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(); } } else if (nameMatching.Count == 1) { isNotarize = true; vmo = nameMatching.First(); } else { vmo = pressmeterVmos.First(); } if (vmo != null) { if (!isNotarize) { 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; } else { input.MatchingMinorLoss = vmo.MinorLoss; input.MatchingDbId = vmo.ID.ToString(); input.MatchingModelType = vmo.Name; } return true; } return false; } //过渡件匹配 public static bool MatchingTranslation(HydroTranslationMatchingViewModel input, List translationVmos) { bool isNotarize = false; //是否确定 if (translationVmos == null || input == null || translationVmos.Count == 0) { return true; } Vmo.AssetsTranslationMainVmo vmo = null; var nameMatching = translationVmos.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.Material == input.Material //材料约束 ).ToList(); if (absoluteMatching.Count > 1) { var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = translationVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = translationVmos.First(); } else if (nameMatching.Count == 1) { isNotarize = true; vmo = nameMatching.First(); } else { var absoluteMatching = translationVmos.Where(i => i.Material == input.Material //材料约束 ).ToList(); if (absoluteMatching.Count > 1) { var defaultList = absoluteMatching.Where(x => x.Flags.Contains("默认值")).ToList(); //取默认 if (defaultList.Count > 0) { vmo = defaultList.First(); } else if (defaultList.Count <= 0) { vmo = translationVmos.First(); } } else if (absoluteMatching.Count == 1) { isNotarize = true; vmo = absoluteMatching.First(); } else vmo = translationVmos.First(); } if (vmo != null) { if (!isNotarize) { 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 (input.Roughness < 0) input.MatchingRoughness = vmo.Roughness; if (input.EndDiameter < 0) input.MatchingEndDiameter = vmo.EndDiameter; if (input.StartDiameter < 0) input.MatchingStartDiameter = vmo.StartDiameter; if (input.Diameter < 0) input.MatchingDiameter = vmo.Diameter; } else { input.MatchingMinorLoss = vmo.MinorLoss; input.MatchingDbId = vmo.ID.ToString(); input.MatchingMaterial = vmo.Material; input.MatchingModelType = vmo.Name; input.MatchingDiameter = vmo.Diameter; input.MatchingEndDiameter = vmo.EndDiameter; input.MatchingStartDiameter = vmo.StartDiameter; input.MatchingRoughness = vmo.Roughness; } return true; } return false; } //冷却器匹配 public static bool Matching(HydroCoolingMatchingViewModel input, List allCoolingList) { //输入参数验证 if (input == null) { return false; } //数据源没有数据则没有匹配成功 if (allCoolingList == null || allCoolingList.Count < 1) { return false; } //权重字典 var dict = new Dictionary(); foreach (var item in allCoolingList) { dict.Add(item, 0); } //型号 int modelTypeWeight = 10; if (!string.IsNullOrEmpty(input.ModelType)) { foreach (var item in allCoolingList) { if (!string.IsNullOrEmpty(item.Name)) { var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count(); dict[item] += count * modelTypeWeight; } } } //材质 int materialWeight = 5; if (!string.IsNullOrEmpty(input.Material)) { foreach (var item in allCoolingList) { if (!string.IsNullOrEmpty(item.Material)) { var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count(); dict[item] += count * materialWeight; } } } //口径 int caliberWeight = 1; if (input.Caliber.HasValue) { foreach (var item in allCoolingList) { if (item.Caliber.HasValue) { var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value); dict[item] += diff / input.Caliber.Value * 100 * caliberWeight; } } } // 关键字 int keywordWeight = 1; foreach (var item in allCoolingList) { 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; } if (!string.IsNullOrEmpty(input.Material)) { var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower())); dict[item] += count * keywordWeight; } } } //标签 int flagWeight = 1; foreach (var item in allCoolingList) { if (item.Flags != null && item.Flags.Count > 0) { if (item.Flags.Contains(HStation.Assets.Flags.默认)) { dict[item] += flagWeight; } } } var cooling = dict.OrderBy(x => x.Value).LastOrDefault().Key; input.MatchingDbId = cooling.ID.ToString(); if (string.IsNullOrEmpty(input.ModelType)) { input.MatchingModelType = cooling.Name; } if (string.IsNullOrEmpty(input.Material)) { input.MatchingMaterial = cooling.Material; } if (!input.Caliber.HasValue || input.Caliber.Value <= 0) { input.Caliber = cooling.Caliber; } if (input.Coefficient <= 1) { input.MatchingCoefficient = cooling.Coefficient; } if (input.LowerLimit <= 0) { input.MatchingLowerLimit = cooling.LowerLimit; } return true; } /// /// 获取两个字符串的所有交集 /// public static int GetIntersect(string str1, string str2) { if (str1 == null || str2 == null) return 0; return string.Join("", str1.Intersect(str2)).Count(); } } }