| | |
| | | //三通匹配 |
| | | public static bool MatchingThreelink(ThreelinkMatchingViewModel input, List<Vmo.AssetsThreelinkMainVmo> adaptingManageVmos) |
| | | { |
| | | if (adaptingManageVmos == null) |
| | | { |
| | | return true; |
| | | } |
| | | 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.Count > 1) |
| | | { |
| | | 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) |
| | | /* if (adaptingManageVmos == null) |
| | | { |
| | | if (item.IsDefault) |
| | | { |
| | | vmo = item; |
| | | } |
| | | return true; |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | else if (absoluteMatch.Count == 1) |
| | | { |
| | | vmo = absoluteMatch.First(); |
| | | } |
| | | else |
| | | { |
| | | //区间匹配 |
| | | 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) |
| | | 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.Material == input.Material)).ToList(); |
| | | if (absoluteMatch.Count > 1) |
| | | { |
| | | var materialList = new List<Vmo.AssetsThreelinkMainVmo>(); |
| | | 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; |
| | | 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以上并且进行排序 |
| | | 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) |
| | |
| | | } |
| | | vmo = allMatchingList.First();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | } |
| | | //精确匹配和粗糙匹配都没有匹配到就返回错误 |
| | | firstCount = 0; |
| | | if (vmo != null) |
| | | { |
| | | input.MatchingMinorLoss = vmo.Coefficient; |
| | | input.MatchingDbId = vmo.ID.ToString(); |
| | | input.MatchingMaterial = vmo.MaterialName; |
| | | input.MatchingModelType = vmo.Name; |
| | | input.MatchingRunThroughCoefficient = vmo.RunThroughCoefficient; |
| | | input.MatchingBranchThroughCoefficient = vmo.BranchThroughCoefficient; |
| | | return true; |
| | | } |
| | | else if (absoluteMatch.Count == 1) |
| | | { |
| | | vmo = absoluteMatch.First(); |
| | | } |
| | | else |
| | | { |
| | | //区间匹配 |
| | | 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>(); |
| | | foreach (var range in rangeMatch) |
| | | { |
| | | //以材料为条件开始匹配 |
| | | if (range.Material == null) |
| | | { |
| | | materialList.Add(range); |
| | | } |
| | | else |
| | | { |
| | | int commonCount = GetIntersect(input.Material, range.Material); |
| | | 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();//如果没有设置默认值,则默认返回匹配字符最多的一条数据 |
| | | } |
| | | } |
| | | //精确匹配和粗糙匹配都没有匹配到就返回错误 |
| | | firstCount = 0; |
| | | if (vmo != null) |
| | | { |
| | | input.MatchingMinorLoss = vmo.MinorLoss; |
| | | input.MatchingDbId = vmo.ID.ToString(); |
| | | input.MatchingMaterial = vmo.Material; |
| | | input.MatchingModelType = vmo.Name; |
| | | input.MatchingRunThroughCoefficient = vmo.RunThroughCoefficient; |
| | | input.MatchingBranchThroughCoefficient = vmo.BranchThroughCoefficient; |
| | | return true; |
| | | } |
| | | return false;*/ |
| | | return false; |
| | | } |
| | | |