| | |
| | | using HStation.Vmo; |
| | | using HStation.WinFrmUI.PhartRelation; |
| | | using System.Windows.Input; |
| | | |
| | | namespace HStation.WinFrmUI |
| | | { |
| | |
| | | private const double _powerTolerance = 0.05; |
| | | |
| | | //资产自动匹配 |
| | | public static async Task<bool> Matching(AssetsMatchingViewModel assetsAutoMatchingView) |
| | | public static bool Matching(AssetsMatchingViewModel assetsAutoMatchingView, out string Error) |
| | | { |
| | | Error = string.Empty; |
| | | bool IsMaching = false; |
| | | var AssetsPumpMain = new BLL.AssetsPumpMain(); |
| | | var adaptingManage = new BLL.AdaptingManage(); |
| | |
| | | var AssetsElbowMain = new BLL.AssetsElbowMain(); |
| | | var AssetsThreelinkMain = new BLL.AssetsThreelinkMain(); |
| | | var AssetsFourlinkMain = new BLL.AssetsFourlinkMain(); |
| | | |
| | | var allPump = await AssetsPumpMain.GetAll(); |
| | | var allAdapting = await adaptingManage.GetAll(); |
| | | var allPipeLine = await pipeLineManage.GetAll(); |
| | | var allValve = await AssetsValveMain.GetAll(); |
| | | var allElbow = await AssetsElbowMain.GetAll(); |
| | | var allThreeLink = await AssetsThreelinkMain.GetAll(); |
| | | var allFourLink = await AssetsFourlinkMain.GetAll(); |
| | | //泵匹配 |
| | | foreach (var item in assetsAutoMatchingView.PumpMatchingList) |
| | | try |
| | | { |
| | | if (await MatchingPumps(item, allPump)) |
| | | 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; |
| | | //泵匹配 |
| | | foreach (var item in assetsAutoMatchingView.PumpMatchingList) |
| | | { |
| | | IsMaching = true; |
| | | if (MatchingPumps(item, allPump)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | //三通匹配 |
| | | foreach (var item in assetsAutoMatchingView.ThreelinkMatchingList) |
| | | { |
| | | if (MatchingThreelink(item, allThreeLink)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | //四通匹配 |
| | | foreach (var item in assetsAutoMatchingView.FourlinkMatchingList) |
| | | { |
| | | if (MatchingFourlink(item, allFourLink)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | //管道匹配 |
| | | foreach (var item in assetsAutoMatchingView.PipeMatchingList) |
| | | { |
| | | if (MatchingPipe(item, allPipeLine)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | //阀门匹配 |
| | | foreach (var item in assetsAutoMatchingView.ValveMatchingList) |
| | | { |
| | | if (MatchingValve(item, allValve)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | //弯头匹配 |
| | | foreach (var item in assetsAutoMatchingView.ElbowMatchingList) |
| | | { |
| | | if (MatchingElbow(item, allElbow)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | } |
| | | //三通匹配 |
| | | foreach (var item in assetsAutoMatchingView.ThreelinkMatchingList) |
| | | catch (Exception ex) |
| | | { |
| | | if (MatchingThreelink(item, allThreeLink)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | //四通匹配 |
| | | foreach (var item in assetsAutoMatchingView.FourlinkMatchingList) |
| | | { |
| | | if (MatchingFourlink(item, allFourLink)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | //管道匹配 |
| | | foreach (var item in assetsAutoMatchingView.PipeMatchingList) |
| | | { |
| | | if (MatchingPipe(item, allPipeLine)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | //阀门匹配 |
| | | foreach (var item in assetsAutoMatchingView.ValveMatchingList) |
| | | { |
| | | if (MatchingValve(item, allValve)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | } |
| | | //弯头匹配 |
| | | foreach (var item in assetsAutoMatchingView.ElbowMatchingList) |
| | | { |
| | | if (MatchingElbow(item, allElbow)) |
| | | { |
| | | IsMaching = true; |
| | | } |
| | | Error = ex.Message; |
| | | return false; |
| | | } |
| | | return IsMaching; |
| | | } |
| | | |
| | | //泵匹配 |
| | | public static async Task<bool> MatchingPumps(PumpMatchingViewModel InputModel, List<Vmo.AssetsPumpMainVmo> AssetsPumpMainVmos) |
| | | public static bool MatchingPumps(PumpMatchingViewModel InputModel, List<Vmo.AssetsPumpMainVmo> AssetsPumpMainVmos) |
| | | { |
| | | if (AssetsPumpMainVmos == null) |
| | | { |
| | |
| | | InputModel.MatchingRatedP = vmo.RatedPower; |
| | | InputModel.MatchingDbId = vmo.ID.ToString(); |
| | | InputModel.MatchingModelType = vmo.Name; |
| | | var list = await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(vmo.ID); |
| | | var list = Task.Run(async () => await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(vmo.ID)).Result; |
| | | if (list != null && list.Count > 0) |
| | | { |
| | | InputModel.MatchingCurveDbId = list.First().ID.ToString(); |
| | |
| | | var absoluteMatch = adaptingManageVmos.Where(i => |
| | | ((i.Caliber == null) || i.Caliber == input.Diameter) && |
| | | ((input.Material == null) || i.MaterialName == input.Material)).ToList(); |
| | | if (absoluteMatch.Any()) |
| | | if (absoluteMatch.Count > 1) |
| | | { |
| | | foreach (var range in absoluteMatch) |
| | | var allMatchingList = absoluteMatch |
| | | .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2) |
| | | .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType)) |
| | | .ToList();//找出相同字符在2以上并且进行排序 |
| | | if (allMatchingList.Count < 1) |
| | | return false;//通过型号名没有找到,则视为没有匹配到 |
| | | foreach (var item in allMatchingList) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, range.KeyWord); |
| | | if (commonCount > firstCount) |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = range; |
| | | firstCount = commonCount; |
| | | vmo = item; |
| | | } |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | else if (absoluteMatch.Count == 1) |
| | | { |
| | | vmo = absoluteMatch.First(); |
| | | } |
| | | else |
| | | { |
| | | //区间匹配 |
| | | var rangeMatch = adaptingManageVmos.Where(item => |
| | | { |
| | | if (item.Caliber.HasValue) |
| | | { |
| | | return Math.Abs(Convert.ToInt64(item.Caliber - input.Diameter)) <= _caliberTolerance; |
| | | } |
| | | else |
| | | { |
| | | if (item.Caliber == null) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | }) |
| | | .ToList(); |
| | | var rangeMatch = adaptingManageVmos |
| | | .Where(item => |
| | | item.Caliber == null || |
| | | Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Diameter)) <= _caliberTolerance) |
| | | .ToList(); |
| | | if (rangeMatch != null && rangeMatch.Count > 0) |
| | | { |
| | | var materialList = new List<Vmo.AssetsValveMainVmo>(); |
| | |
| | | } |
| | | //用已经筛选完成的列表中以名称筛选 |
| | | firstCount = 0; |
| | | foreach (var material in materialList) |
| | | if (materialList.Count < 1) |
| | | return false; |
| | | var allMatchingList = materialList |
| | | .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2) |
| | | .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType)) |
| | | .ToList();//找出相同字符在2以上并且进行排序 |
| | | if (allMatchingList.Count < 1) |
| | | return false;//通过型号名没有找到,则视为没有匹配到 |
| | | foreach (var item in allMatchingList) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, material.KeyWord); |
| | | if (commonCount > firstCount) |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = material; |
| | | firstCount = commonCount; |
| | | vmo = item; |
| | | } |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | } |
| | | //口径和材料都没有匹配上,就用型号名匹配 |
| | | 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; |
| | |
| | | return true; |
| | | } |
| | | Vmo.AssetsPipeMainVmo vmo = null; |
| | | int StartCount = 0; |
| | | int firstCount = 0; |
| | | //口径最小差值 |
| | | // 绝对匹配 |
| | | var absoluteMatch = pipeLineManageVmos.Where(i => |
| | | ((i.Caliber == null) || i.Caliber == input.Diameter) && |
| | | ((input.Material == null) || i.MaterialName == input.Material)).ToList(); |
| | | if (absoluteMatch.Any()) |
| | | if (absoluteMatch.Count > 1) |
| | | { |
| | | foreach (var range in absoluteMatch) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, range.KeyWord); |
| | | if (commonCount > StartCount) |
| | | { |
| | | vmo = range; |
| | | StartCount = commonCount; |
| | | } |
| | | } |
| | | } |
| | | else if (absoluteMatch.Count == 1) |
| | | { |
| | | vmo = absoluteMatch.First(); |
| | | } |
| | | else |
| | | { |
| | | //区间匹配 |
| | | var rangeMatch = pipeLineManageVmos.Where(item => |
| | | { |
| | | if (item.Caliber != null) |
| | | { |
| | | return Math.Abs(Convert.ToInt64(item.Caliber - input.Diameter)) <= _caliberTolerance; |
| | | } |
| | | return false; |
| | | }) |
| | | .ToList(); |
| | | var rangeMatch = pipeLineManageVmos |
| | | .Where(item => |
| | | item.Caliber == null || |
| | | Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Diameter)) <= _caliberTolerance) |
| | | .ToList(); |
| | | if (rangeMatch != null) |
| | | { |
| | | var materialList = new List<Vmo.AssetsPipeMainVmo>(); |
| | | foreach (var range in rangeMatch) |
| | | { |
| | | //以材料为条件开始匹配 |
| | | int commonCount = GetIntersect(input.Material, range.MaterialName); |
| | | if (commonCount > StartCount) |
| | | if (range.MaterialName == null) |
| | | { |
| | | vmo = range; |
| | | StartCount = commonCount; |
| | | materialList.Add(range); |
| | | } |
| | | else |
| | | { |
| | | int commonCount = GetIntersect(input.Material, range.MaterialName); |
| | | if (commonCount > firstCount) |
| | | { |
| | | materialList.Add(range); |
| | | firstCount = commonCount; |
| | | } |
| | | } |
| | | } |
| | | firstCount = 0; |
| | | if (materialList.Count < 1) |
| | | return false; |
| | | var allMatchingList = materialList |
| | | .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2) |
| | | .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType)) |
| | | .ToList();//找出相同字符在2以上并且进行排序 |
| | | if (allMatchingList.Count < 1) |
| | | return false;//通过型号名没有找到,则视为没有匹配到 |
| | | foreach (var item in allMatchingList) |
| | | { |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = item; |
| | | } |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | } |
| | | //口径和材料都没有匹配上,就用型号名匹配 |
| | | if (vmo == null) |
| | | { |
| | | foreach (var item in pipeLineManageVmos) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, item.KeyWord); |
| | | if (commonCount > StartCount) |
| | | { |
| | | vmo = item; |
| | | StartCount = commonCount; |
| | | } |
| | | } |
| | | } |
| | | if (vmo != null) |
| | | { |
| | | switch (input.eAlgorithmType) |
| | |
| | | } |
| | | Vmo.AssetsElbowMainVmo vmo = null; |
| | | int firstCount = 0; |
| | | //口径最小差值 |
| | | // 绝对匹配 |
| | | var absoluteMatch = adaptingManageVmos.Where(i => |
| | | ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) && |
| | | ((input.Material == null) || i.MaterialName == input.Material)).ToList(); |
| | | if (absoluteMatch.Any()) |
| | | if (absoluteMatch.Count > 1) |
| | | { |
| | | foreach (var range in absoluteMatch) |
| | | var allMatchingList = absoluteMatch |
| | | .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2) |
| | | .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType)) |
| | | .ToList();//找出相同字符在2以上并且进行排序 |
| | | if (allMatchingList.Count < 1) |
| | | return false;//通过型号名没有找到,则视为没有匹配到 |
| | | foreach (var item in allMatchingList) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, range.KeyWord); |
| | | if (commonCount > firstCount) |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = range; |
| | | firstCount = commonCount; |
| | | vmo = item; |
| | | } |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | else if (absoluteMatch.Count == 1) |
| | | { |
| | | vmo = absoluteMatch.First(); |
| | | } |
| | | 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(); |
| | | var rangeMatch = adaptingManageVmos |
| | | .Where(item => |
| | | input.Caliber == null || |
| | | item.Caliber == null || |
| | | Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) |
| | | .ToList(); |
| | | if (rangeMatch != null && rangeMatch.Count > 0) |
| | | { |
| | | var materialList = new List<Vmo.AssetsElbowMainVmo>(); |
| | |
| | | } |
| | | //用已经筛选完成的列表中以名称筛选 |
| | | firstCount = 0; |
| | | foreach (var material in materialList) |
| | | if (materialList.Count < 1) |
| | | return false; |
| | | var allMatchingList = materialList |
| | | .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2) |
| | | .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType)) |
| | | .ToList();//找出相同字符在2以上并且进行排序 |
| | | if (allMatchingList.Count < 1) |
| | | return false;//通过型号名没有找到,则视为没有匹配到 |
| | | foreach (var item in allMatchingList) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, material.KeyWord); |
| | | if (commonCount > firstCount) |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = material; |
| | | firstCount = commonCount; |
| | | vmo = item; |
| | | } |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | } |
| | | //口径和材料都没有匹配上,就用型号名匹配 |
| | | //精确匹配和粗糙匹配都没有匹配到就返回错误 |
| | | 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; |
| | |
| | | } |
| | | Vmo.AssetsThreelinkMainVmo vmo = null; |
| | | int firstCount = 0; |
| | | //口径最小差值 |
| | | // 绝对匹配 |
| | | var absoluteMatch = adaptingManageVmos.Where(i => |
| | | ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) && |
| | | ((input.Material == null) || i.MaterialName == input.Material)).ToList(); |
| | | if (absoluteMatch.Any()) |
| | | if (absoluteMatch.Count > 1) |
| | | { |
| | | foreach (var range in absoluteMatch) |
| | | var allMatchingList = absoluteMatch |
| | | .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2) |
| | | .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType)) |
| | | .ToList();//找出相同字符在2以上并且进行排序 |
| | | if (allMatchingList.Count < 1) |
| | | return false;//通过型号名没有找到,则视为没有匹配到 |
| | | foreach (var item in allMatchingList) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, range.Name); |
| | | if (commonCount > firstCount) |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = range; |
| | | firstCount = commonCount; |
| | | vmo = item; |
| | | } |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | else if (absoluteMatch.Count == 1) |
| | | { |
| | | vmo = absoluteMatch.First(); |
| | | } |
| | | 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(); |
| | | var rangeMatch = adaptingManageVmos |
| | | .Where(item => |
| | | input.Caliber == null || |
| | | item.Caliber == null || |
| | | Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) |
| | | .ToList(); |
| | | if (rangeMatch != null && rangeMatch.Count > 0) |
| | | { |
| | | var materialList = new List<Vmo.AssetsThreelinkMainVmo>(); |
| | |
| | | } |
| | | //用已经筛选完成的列表中以名称筛选 |
| | | firstCount = 0; |
| | | foreach (var material in materialList) |
| | | if (materialList.Count < 1) |
| | | return false; |
| | | var allMatchingList = materialList |
| | | .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2) |
| | | .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType)) |
| | | .ToList();//找出相同字符在2以上并且进行排序 |
| | | if (allMatchingList.Count < 1) |
| | | return false;//通过型号名没有找到,则视为没有匹配到 |
| | | foreach (var item in allMatchingList) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, material.Name); |
| | | if (commonCount > firstCount) |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = material; |
| | | firstCount = commonCount; |
| | | vmo = item; |
| | | } |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | } |
| | | //口径和材料都没有匹配上,就用型号名匹配 |
| | | //精确匹配和粗糙匹配都没有匹配到就返回错误 |
| | | 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; |
| | |
| | | } |
| | | Vmo.AssetsFourlinkMainVmo vmo = null; |
| | | int firstCount = 0; |
| | | //口径最小差值 |
| | | // 绝对匹配 |
| | | var absoluteMatch = adaptingManageVmos.Where(i => |
| | | ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) && |
| | | ((input.Material == null) || i.MaterialName == input.Material)).ToList(); |
| | | if (absoluteMatch.Any()) |
| | | if (absoluteMatch.Count > 1) |
| | | { |
| | | foreach (var range in absoluteMatch) |
| | | var allMatchingList = absoluteMatch |
| | | .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2) |
| | | .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType)) |
| | | .ToList();//找出相同字符在2以上并且进行排序 |
| | | if (allMatchingList.Count < 1) |
| | | return false;//通过型号名没有找到,则视为没有匹配到 |
| | | foreach (var item in allMatchingList) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, range.Name); |
| | | if (commonCount > firstCount) |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = range; |
| | | firstCount = commonCount; |
| | | vmo = item; |
| | | } |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | else if (absoluteMatch.Count == 1) |
| | | { |
| | | vmo = absoluteMatch.First(); |
| | | } |
| | | 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(); |
| | | var rangeMatch = adaptingManageVmos |
| | | .Where(item => |
| | | input.Caliber == null || |
| | | item.Caliber == null || |
| | | Math.Abs(Convert.ToInt64(item.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) |
| | | .ToList(); |
| | | if (rangeMatch != null && rangeMatch.Count > 0) |
| | | { |
| | | var materialList = new List<Vmo.AssetsFourlinkMainVmo>(); |
| | |
| | | } |
| | | //用已经筛选完成的列表中以名称筛选 |
| | | firstCount = 0; |
| | | foreach (var material in materialList) |
| | | if (materialList.Count < 1) |
| | | return false; |
| | | var allMatchingList = materialList |
| | | .Where(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType) >= 2) |
| | | .OrderByDescending(x => GetIntersect(x.KeyWord == string.Empty ? x.Name : x.KeyWord, input.ModelType)) |
| | | .ToList();//找出相同字符在2以上并且进行排序 |
| | | if (allMatchingList.Count < 1) |
| | | return false;//通过型号名没有找到,则视为没有匹配到 |
| | | foreach (var item in allMatchingList) |
| | | { |
| | | int commonCount = GetIntersect(input.ModelType, material.Name); |
| | | if (commonCount > firstCount) |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = material; |
| | | firstCount = commonCount; |
| | | vmo = item; |
| | | } |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | } |
| | | //口径和材料都没有匹配上,就用型号名匹配 |
| | | //精确匹配和粗糙匹配都没有匹配到就返回错误 |
| | | 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; |
| | |
| | | /// <summary> |
| | | /// 获取两个字符串的所有交集 |
| | | /// </summary> |
| | | /// <param name="str1"></param> |
| | | /// <param name="str2"></param> |
| | | /// <returns></returns> |
| | | public static int GetIntersect(string str1, string str2) |
| | | { |
| | | if (str1 == null || str2 == null) return 0; |