lixiaojun
2024-12-20 357693611c60d93fb17189273d4c91dab364f0d4
WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
@@ -1160,119 +1160,119 @@
        //空压机匹配
        public static bool MatchingCompressor(HydroCompressorMatchingViewModel input, List<Vmo.AssetsCompressorMainVmo> 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();
            //        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;
            //        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 = 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 = 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<List<HydroCurvePointViewModel>>(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<List<HydroCurvePointViewModel>>(curveList.First().MinorLossCurve);
                        input.MatchingCurveQL = pt_list;
                    }
                }
                return 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<List<HydroCurvePointViewModel>>(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<List<HydroCurvePointViewModel>>(curveList.First().MinorLossCurve);
            //                    input.MatchingCurveQL = pt_list;
            //                }
            //            }
            //            return true;
            //        }
            return false;
        }