| | |
| | | using HStation.Vmo; |
| | | using System.Windows.Media.Media3D; |
| | | using Yw.WinFrmUI.Q3d; |
| | | using Microsoft.CodeAnalysis.CSharp.Syntax; |
| | | |
| | | namespace HStation.WinFrmUI |
| | | { |
| | | public class AsstesAutoMatchingHelper |
| | | { |
| | | private readonly Lazy<BLL.XhsPumpMainPhartMappingExtensions> _bll_ex = new(); |
| | | const double _caliberTolerance = 10.0; |
| | | 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; |
| | | |
| | | //连接件匹配 |
| | | public static T AutoMatching<T>(T input, List<Vmo.AdaptingManageVmo> adaptingManageVmos) where T : AdaptingViewModel |
| | | //资产自动匹配 |
| | | public static async Task<AssetsAutoMatchingViewModel> AssetsAutoMatchingView(AssetsAutoMatchingViewModel assetsAutoMatchingView) |
| | | { |
| | | var pumpMain = new BLL.PumpMain(); |
| | | var adaptingManage = new BLL.AdaptingManage(); |
| | | var pipeLineManage = new BLL.PipeLineManage(); |
| | | var valveMain = new BLL.ValveMain(); |
| | | var allPump = await pumpMain.GetAll(); |
| | | var allAdapting = await adaptingManage.GetAll(); |
| | | var allPipeLine = await pipeLineManage.GetAll(); |
| | | var allValve = await valveMain.GetAll(); |
| | | var assetsAutoMatching = new AssetsAutoMatchingViewModel(); |
| | | var pumpMatchingList = new List<PumpMatchingViewModel>(); |
| | | var threeLinkMatchingList = new List<ThreeLinkMatchingViewModel>(); |
| | | var fourLinkMatchingList = new List<FourLinkMatchingViewModel>(); |
| | | var pipeLineMatchingList = new List<PipeLineMatchingViewModel>(); |
| | | var valveMatchingList = new List<ValveMatchingViewModel>(); |
| | | var elbowsMatchingList = new List<ElbowsMatchingViewModel>(); |
| | | //泵匹配 |
| | | foreach (var item in assetsAutoMatchingView.PumpMatchingModels) |
| | | { |
| | | pumpMatchingList.Add(await PumpMatching(item, allPump)); |
| | | } |
| | | //三通匹配 |
| | | foreach (var item in assetsAutoMatchingView.ThreeLinkMatchingModels) |
| | | { |
| | | threeLinkMatchingList.Add(ThreeLinkAutoMatching(item, allAdapting)); |
| | | } |
| | | //四通匹配 |
| | | foreach (var item in assetsAutoMatchingView.FourLinkMatchingModels) |
| | | { |
| | | fourLinkMatchingList.Add(FourLinkAutoMatching(item, allAdapting)); |
| | | } |
| | | //管道匹配 |
| | | foreach (var item in assetsAutoMatchingView.PipeLineMatchingModels) |
| | | { |
| | | pipeLineMatchingList.Add(PipeAutoMatching(item, allPipeLine)); |
| | | } |
| | | //阀门匹配 |
| | | foreach (var item in assetsAutoMatchingView.ValveMatchingModels) |
| | | { |
| | | valveMatchingList.Add(ValveMatching(item, allValve)); |
| | | } |
| | | //弯头匹配 |
| | | foreach (var item in assetsAutoMatchingView.ElbowsMatchingModels) |
| | | { |
| | | elbowsMatchingList.Add(ElbowsAutoMatching(item, allAdapting)); |
| | | } |
| | | assetsAutoMatching.PumpMatchingModels = pumpMatchingList; |
| | | assetsAutoMatching.ThreeLinkMatchingModels = threeLinkMatchingList; |
| | | assetsAutoMatching.FourLinkMatchingModels = fourLinkMatchingList; |
| | | assetsAutoMatching.ElbowsMatchingModels = elbowsMatchingList; |
| | | assetsAutoMatching.PipeLineMatchingModels = pipeLineMatchingList; |
| | | assetsAutoMatching.ValveMatchingModels = valveMatchingList; |
| | | return assetsAutoMatching; |
| | | } |
| | | |
| | | //弯头匹配 |
| | | public static ElbowsMatchingViewModel ElbowsAutoMatching(ElbowsMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos) |
| | | { |
| | | Vmo.AdaptingManageVmo vmo = null; |
| | | int firstCount = 0; |
| | | //口径最小差值 |
| | | // 绝对匹配 |
| | | var absoluteMatch = adaptingManageVmos.Where(i => |
| | | ((input.Caliber == null && i.Caliber == "默认") || i.Caliber == input.Caliber) && |
| | | ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) && |
| | | ((input.Material == null && i.Material == "默认") || i.Material == input.Material)).ToList(); |
| | | if (absoluteMatch.Any()) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | double inputCaliber; |
| | | if (!double.TryParse(input.Caliber, out inputCaliber)) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | //区间匹配 |
| | | var rangeMatch = adaptingManageVmos.Where(item => |
| | | { |
| | | double itemCaliber; |
| | | if (double.TryParse(item.Caliber, out itemCaliber)) |
| | | if (item.Caliber != null && input.Caliber != null) |
| | | { |
| | | return Math.Abs(itemCaliber - inputCaliber) <= _caliberTolerance; |
| | | return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance; |
| | | } |
| | | else |
| | | { |
| | | if (item.Caliber == "默认") |
| | | if (item.Caliber == null) |
| | | { |
| | | return true; |
| | | } |
| | |
| | | } |
| | | if (vmo != null) |
| | | { |
| | | input.AlterMinorLoss = vmo.Coefficient; |
| | | input.MatchingType = Xhs.eMatchingType.Success; |
| | | input.MatchingMinorLoss = vmo.Coefficient; |
| | | return input; |
| | | } |
| | | return null; |
| | | return input; |
| | | } |
| | | |
| | | //阀门匹配 |
| | | public static ValveMatchingViewModel ValveMatching(ValveMatchingViewModel input, List<Vmo.ValveMainVmo> adaptingManageVmos) |
| | | //四通匹配 |
| | | public static FourLinkMatchingViewModel FourLinkAutoMatching(FourLinkMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos) |
| | | { |
| | | HStation.Vmo.ValveMainVmo vmo = null; |
| | | Vmo.AdaptingManageVmo vmo = null; |
| | | int firstCount = 0; |
| | | //口径最小差值 |
| | | const double caliberTolerance = 10.0; |
| | | // 绝对匹配 |
| | | var absoluteMatch = adaptingManageVmos.Where(i => |
| | | ((input.Caliber == null && i.Caliber == "默认") || i.Caliber == input.Caliber) && |
| | | ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) && |
| | | ((input.Material == null && i.Material == "默认") || i.Material == input.Material)).ToList(); |
| | | if (absoluteMatch.Any()) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | double inputCaliber; |
| | | if (!double.TryParse(input.Caliber, out inputCaliber)) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | //区间匹配 |
| | | var rangeMatch = adaptingManageVmos.Where(item => |
| | | { |
| | | double itemCaliber; |
| | | if (double.TryParse(item.Caliber, out itemCaliber)) |
| | | if (item.Caliber != null && input.Caliber != null) |
| | | { |
| | | return Math.Abs(itemCaliber - inputCaliber) <= caliberTolerance; |
| | | return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance; |
| | | } |
| | | else |
| | | { |
| | | if (item.Caliber == "默认") |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //口径和材料都没有匹配上,就用型号名匹配 |
| | | 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 ThreeLinkAutoMatching(ThreeLinkMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos) |
| | | { |
| | | Vmo.AdaptingManageVmo 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 == "默认") || 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; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //口径和材料都没有匹配上,就用型号名匹配 |
| | | 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 ValveMatchingViewModel ValveMatching(ValveMatchingViewModel input, List<Vmo.ValveMainVmo> adaptingManageVmos) |
| | | { |
| | | HStation.Vmo.ValveMainVmo 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 == "默认") || 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; |
| | | } |
| | |
| | | } |
| | | if (vmo != null) |
| | | { |
| | | input.AlterMinorLoss = vmo.Coefficient; |
| | | input.MatchingType = Xhs.eMatchingType.Success; |
| | | input.MatchingMinorLoss = vmo.Coefficient; |
| | | return input; |
| | | } |
| | | return null; |
| | | return input; |
| | | } |
| | | |
| | | //泵匹配 |
| | | public static async Task<PumpMatchingViewModel> PumpMatching(PumpMatchingViewModel viewModel, List<Vmo.PumpMainVmo> pumpMainVmos) |
| | | { |
| | | const double speedTolerance = 100; |
| | | const double flowTolerance = 10; |
| | | const double headTolerance = 5; |
| | | const double powerTolerance = 0.05; |
| | | Vmo.PumpMainVmo vmo = null; |
| | | int startCount = 0; |
| | | // 尝试绝对匹配 |
| | |
| | | } |
| | | if (vmo != null) |
| | | { |
| | | viewModel.AlterRatedH = vmo.RatedHead; |
| | | viewModel.AlterRatedN = vmo.RatedSpeed; |
| | | viewModel.AlterRatedQ = vmo.RatedFlow; |
| | | viewModel.AlterRatedP = vmo.RatedPower; |
| | | viewModel.AlterDbID = vmo.ID.ToString(); |
| | | 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.AlterChartDbID = list.First().ID; |
| | | viewModel.MatchingChartDbID = list.First().ID; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | //管道匹配 |
| | | public static PipeLineMatchingViewModel PipeAutoMatching(PipeLineMatchingViewModel input, List<Vmo.PipeLineManageVmo> adaptingManageVmos) |
| | | public static PipeLineMatchingViewModel PipeAutoMatching(PipeLineMatchingViewModel input, List<Vmo.PipeLineManageVmo> pipeLineManageVmos) |
| | | { |
| | | Vmo.PipeLineManageVmo vmo = null; |
| | | int StartCount = 0; |
| | | //口径最小差值 |
| | | const double caliberTolerance = 10.0; |
| | | // 绝对匹配 |
| | | var absoluteMatch = adaptingManageVmos.Where(i => |
| | | ((input.Caliber == null && i.Caliber == "默认") || i.Caliber == input.Caliber) && |
| | | 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(); |
| | | if (absoluteMatch.Any()) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | double inputCaliber; |
| | | if (!double.TryParse(input.Caliber, out inputCaliber)) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | //区间匹配 |
| | | var rangeMatch = adaptingManageVmos.Where(item => |
| | | var rangeMatch = pipeLineManageVmos.Where(item => |
| | | { |
| | | double itemCaliber; |
| | | if (double.TryParse(item.Caliber, out itemCaliber)) |
| | | if (item.Caliber != null && input.Caliber != null) |
| | | { |
| | | return Math.Abs(itemCaliber - inputCaliber) <= caliberTolerance; |
| | | return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance; |
| | | } |
| | | return false; |
| | | }) |
| | |
| | | //口径和材料都没有匹配上,就用型号名匹配 |
| | | if (vmo == null) |
| | | { |
| | | foreach (var item in adaptingManageVmos) |
| | | foreach (var item in pipeLineManageVmos) |
| | | { |
| | | int commonCount = CountCommonCharacters(input.ModelType, item.Name); |
| | | if (commonCount > StartCount) |
| | |
| | | switch (input.eAlgorithmType) |
| | | { |
| | | case HStation.Assets.eAlgorithmType.Hazen: |
| | | input.AlterMinorLoss = vmo.Hazen; |
| | | input.MatchingMinorLoss = vmo.Hazen; |
| | | return input; |
| | | |
| | | case HStation.Assets.eAlgorithmType.Manning: |
| | | input.AlterMinorLoss = vmo.Manning; |
| | | input.MatchingMinorLoss = vmo.Manning; |
| | | return input; |
| | | |
| | | case HStation.Assets.eAlgorithmType.Darcy: |
| | | input.AlterMinorLoss = vmo.Darcy; |
| | | input.MatchingMinorLoss = vmo.Darcy; |
| | | return input; |
| | | |
| | | default: |
| | | input.AlterMinorLoss = vmo.Hazen; |
| | | input.MatchingMinorLoss = vmo.Hazen; |
| | | return input; |
| | | } |
| | | } |
| | | return null; |
| | | return input; |
| | | } |
| | | |
| | | //返回两个字符串之间相同的字符个数 |