lixiaojun
2024-12-19 e37b6f2ca026097b83da3ec989cb0d454cceddad
WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
@@ -173,7 +173,7 @@
                //压力表匹配
                foreach (var item in assetsAutoMatchingView.Pressmeters)
                {
                    if (MatchingPressmeter(item, allPressmeterMain))
                    if (Matching(item, allPressmeterMain))
                    {
                        IsMaching = true;
                    }
@@ -1716,65 +1716,80 @@
        }
        //压力表匹配
        public static bool MatchingPressmeter(HydroPressmeterMatchingViewModel input, List<Vmo.AssetsPressmeterMainVmo> pressmeterVmos)
        public static bool Matching(HydroPressmeterMatchingViewModel input, List<Vmo.AssetsPressmeterMainVmo> allPressmeterList)
        {
            bool isNotarize = false; //是否确定
            if (pressmeterVmos == null || input == null || pressmeterVmos.Count == 0)
            //输入参数验证
            if (input == null)
            {
                return true;
                return false;
            }
            Vmo.AssetsPressmeterMainVmo vmo = null;
            var nameMatching = pressmeterVmos.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)
            //数据源没有数据则没有匹配成功
            if (allPressmeterList == null || allPressmeterList.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();
                }
                return false;
            }
            else if (nameMatching.Count == 1)
            {
                isNotarize = true;
                vmo = nameMatching.First();
            }
            else
            //权重字典
            var dict = new Dictionary<AssetsPressmeterMainVmo, double>();
            foreach (var item in allPressmeterList)
            {
                vmo = pressmeterVmos.First();
                dict.Add(item, 0);
            }
            if (vmo != null)
            //型号
            int modelTypeWeight = 100;
            if (!string.IsNullOrEmpty(input.ModelType))
            {
                if (!isNotarize)
                foreach (var item in allPressmeterList)
                {
                    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 (!string.IsNullOrEmpty(item.Name))
                    {
                        var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
                        dict[item] += count * modelTypeWeight;
                    }
                }
                else
                {
                    input.MatchingMinorLoss = vmo.MinorLoss;
                    input.MatchingDbId = vmo.ID.ToString();
                    input.MatchingModelType = vmo.Name;
                }
                return true;
            }
            return false;
            // 关键字
            int keywordWeight = 1;
            foreach (var item in allPressmeterList)
            {
                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 allPressmeterList)
            {
                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;
        }
        //过渡件匹配