lixiaojun
2024-09-27 ddea52cb5c957705b1ed4e004de65e1a3f5ad129
WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingParasHelper.cs
@@ -1,11 +1,4 @@
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HStation.WinFrmUI
namespace HStation.WinFrmUI
{
    /// <summary>
    /// 资产匹配参数辅助类
@@ -13,102 +6,212 @@
    public class AssetsMatchingParasHelper
    {
        //创建资产自动匹配ViewModel
        #region 创建
        /// <summary>
        /// 创建资产自动匹配ViewModel
        /// </summary>
        public static AssetsMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            var input = new AssetsMatchingViewModel();
            //水泵
            input.PumpMatchingList = hydroInfo.Pumps?.Select(x => new PumpMatchingViewModel()
            {
                ID = x.ID,
                Code = x.Code,
                Name = x.Name,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                DbId = x.DbId,
                CurveDbId = hydroInfo.Curves?.Find(t => t.Code == x.CurveQH)?.DbId,
                RatedP = x.RatedP,
                RatedH = x.RatedH,
                RatedN = x.RatedN,
                RatedQ = x.RatedQ,
            }).ToList();
            input.PumpMatchingList = hydroInfo.Pumps?.Select(x => Create(hydroInfo, x)).ToList();
            //阀门
            input.ValveMatchingList = hydroInfo.Valves?.Select(x => new ValveMatchingViewModel()
            {
                ID = x.ID,
                Code = x.Code,
                Name = x.Name,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                DbId = x.DbId,
                Diameter = x.Diameter,
                Material = x.Material,
                MinorLoss = x.MinorLoss,
                ValveType = x.ValveType
            }).ToList();
            input.ValveMatchingList = hydroInfo.Valves?.Select(x => Create(hydroInfo, x)).ToList();
            //管道
            input.PipeMatchingList = hydroInfo.Pipes?.Select(x => new PipeMatchingViewModel()
            {
                ID = x.ID,
                Code = x.Code,
                Name = x.Name,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                DbId = x.DbId,
                Diameter = x.Diameter,
                Material = x.Material,
                Roughness = x.Roughness,
                MinorLoss = x.MinorLoss,
                eAlgorithmType = HStation.Assets.eAlgorithmType.Hazen
            }).ToList();
            input.PipeMatchingList = hydroInfo.Pipes?.Select(x => Create(hydroInfo, x)).ToList();
            //弯头
            input.ElbowsMatchingList = hydroInfo.Elbows?.Select(x => new ElbowsMatchingViewModel()
            {
                ID = x.ID,
                Code = x.Code,
                Name = x.Name,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                DbId = x.DbId,
                Caliber = x.Caliber,
                Material = x.Material,
                MinorLoss = x.MinorLoss
            }).ToList();
            input.ElbowMatchingList = hydroInfo.Elbows?.Select(x => Create(hydroInfo, x)).ToList();
            //三通
            input.ThreelinkMatchingList = hydroInfo.Threelinks?.Select(x => new ThreelinkMatchingViewModel()
            {
                ID = x.ID,
                Name = x.Name,
                Code = x.Code,
                DbId = x.DbId,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                Caliber = x.Caliber,
                Material = x.Material
            }).ToList();
            input.ThreelinkMatchingList = hydroInfo.Threelinks?.Select(x => Create(hydroInfo, x)).ToList();
            //四通
            input.FourlinkMatchingList = hydroInfo.Fourlinks?.Select(x => new FourlinkMatchingViewModel()
            {
                ID = x.ID,
                Name = x.Name,
                Code = x.Code,
                DbId = x.DbId,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                Caliber = x.Caliber,
                Material = x.Material
            }).ToList();
            input.FourlinkMatchingList = hydroInfo.Fourlinks?.Select(x => Create(hydroInfo, x)).ToList();
            return input;
        }
        //应用资产自动匹配ViewModel
        /// <summary>
        /// 创建泵自动匹配ViewModel
        /// </summary>
        public static PumpMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroPumpInfo pumpInfo)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            if (pumpInfo == null)
            {
                return default;
            }
            return new PumpMatchingViewModel()
            {
                ID = pumpInfo.ID,
                Code = pumpInfo.Code,
                Name = pumpInfo.Name,
                DbLocked = pumpInfo.DbLocked,
                ModelType = pumpInfo.ModelType,
                DbId = pumpInfo.DbId,
                CurveDbId = hydroInfo.Curves?.Find(t => t.Code == pumpInfo.CurveQH)?.DbId,
                RatedP = pumpInfo.RatedP,
                RatedH = pumpInfo.RatedH,
                RatedN = pumpInfo.RatedN,
                RatedQ = pumpInfo.RatedQ,
            };
        }
        /// <summary>
        /// 创建阀门自动匹配ViewModel
        /// </summary>
        public static ValveMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroValveInfo valveInfo)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            if (valveInfo == null)
            {
                return default;
            }
            return new ValveMatchingViewModel()
            {
                ID = valveInfo.ID,
                Code = valveInfo.Code,
                Name = valveInfo.Name,
                DbLocked = valveInfo.DbLocked,
                ModelType = valveInfo.ModelType,
                DbId = valveInfo.DbId,
                Diameter = valveInfo.Diameter,
                Material = valveInfo.Material,
                MinorLoss = valveInfo.MinorLoss,
                ValveType = valveInfo.ValveType
            };
        }
        /// <summary>
        /// 创建管道自动匹配ViewModel
        /// </summary>
        public static PipeMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroPipeInfo pipeInfo)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            if (pipeInfo == null)
            {
                return default;
            }
            return new PipeMatchingViewModel()
            {
                ID = pipeInfo.ID,
                Code = pipeInfo.Code,
                Name = pipeInfo.Name,
                DbLocked = pipeInfo.DbLocked,
                ModelType = pipeInfo.ModelType,
                DbId = pipeInfo.DbId,
                Diameter = pipeInfo.Diameter,
                Material = pipeInfo.Material,
                Roughness = pipeInfo.Roughness,
                MinorLoss = pipeInfo.MinorLoss,
                eAlgorithmType = HStation.Assets.eAlgorithmType.Hazen
            };
        }
        /// <summary>
        /// 创建弯头自动匹配ViewModel
        /// </summary>
        public static ElbowMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroElbowInfo elbowInfo)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            if (elbowInfo == null)
            {
                return default;
            }
            return new ElbowMatchingViewModel()
            {
                ID = elbowInfo.ID,
                Code = elbowInfo.Code,
                Name = elbowInfo.Name,
                DbLocked = elbowInfo.DbLocked,
                ModelType = elbowInfo.ModelType,
                DbId = elbowInfo.DbId,
                Caliber = elbowInfo.Caliber,
                Material = elbowInfo.Material,
                MinorLoss = elbowInfo.MinorLoss
            };
        }
        /// <summary>
        /// 创建三通自动匹配ViewModel
        /// </summary>
        public static ThreelinkMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroThreelinkInfo threelinkInfo)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            if (threelinkInfo == null)
            {
                return default;
            }
            return new ThreelinkMatchingViewModel()
            {
                ID = threelinkInfo.ID,
                Code = threelinkInfo.Code,
                Name = threelinkInfo.Name,
                DbLocked = threelinkInfo.DbLocked,
                ModelType = threelinkInfo.ModelType,
                DbId = threelinkInfo.DbId,
                Caliber = threelinkInfo.Caliber,
                Material = threelinkInfo.Material,
                MinorLoss = threelinkInfo.MinorLoss
            };
        }
        /// <summary>
        /// 创建四通自动匹配ViewModel
        /// </summary>
        public static FourlinkMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroFourlinkInfo fourlinkInfo)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            if (fourlinkInfo == null)
            {
                return default;
            }
            return new FourlinkMatchingViewModel()
            {
                ID = fourlinkInfo.ID,
                Code = fourlinkInfo.Code,
                Name = fourlinkInfo.Name,
                DbLocked = fourlinkInfo.DbLocked,
                ModelType = fourlinkInfo.ModelType,
                DbId = fourlinkInfo.DbId,
                Caliber = fourlinkInfo.Caliber,
                Material = fourlinkInfo.Material,
                MinorLoss = fourlinkInfo.MinorLoss
            };
        }
        #endregion
        /// <summary>
        /// 应用资产自动匹配ViewModel
        /// </summary>
        public static bool Apply(Yw.Model.HydroModelInfo hydroInfo, AssetsMatchingViewModel output)
        {
            if (hydroInfo == null)
@@ -186,6 +289,7 @@
                                            hydroInfo.Curves = new List<Yw.Model.HydroCurveInfo>();
                                        }
                                        hydroInfo.Curves.Add(curveqh);
                                        pump.CurveQH = curveqh.Code;
                                    }
                                    else
                                    {
@@ -214,6 +318,7 @@
                                            hydroInfo.Curves = new List<Yw.Model.HydroCurveInfo>();
                                        }
                                        hydroInfo.Curves.Add(curveqp);
                                        pump.CurveQP = curveqp.Code;
                                    }
                                    else
                                    {
@@ -242,6 +347,7 @@
                                            hydroInfo.Curves = new List<Yw.Model.HydroCurveInfo>();
                                        }
                                        hydroInfo.Curves.Add(curveqe);
                                        pump.CurveQE = curveqe.Code;
                                    }
                                    else
                                    {
@@ -253,6 +359,7 @@
                                    }
                                }
                                result = true;
                            }
                        }
                    }
@@ -366,11 +473,11 @@
            }
            //弯头
            if (output.ElbowsMatchingList != null && output.ElbowsMatchingList.Count > 0)
            if (output.ElbowMatchingList != null && output.ElbowMatchingList.Count > 0)
            {
                if (hydroInfo.Elbows != null && hydroInfo.Elbows.Count > 0)
                {
                    foreach (var elbowsMatching in output.ElbowsMatchingList)
                    foreach (var elbowsMatching in output.ElbowMatchingList)
                    {
                        var elbows = hydroInfo.Elbows.Find(x => x.Code == elbowsMatching.Code);
                        if (elbows != null)
@@ -506,6 +613,156 @@
            return result;
        }
        /// <summary>
        /// 应用泵自动匹配ViewModel
        /// </summary>
        public static bool ApplyPump(Yw.Model.HydroModelInfo hydroInfo, PumpMatchingViewModel pumpMatching)
        {
            if (hydroInfo == null)
            {
                return false;
            }
            if (pumpMatching == null)
            {
                return false;
            }
            bool result = false;
            var pump = hydroInfo.Pumps?.Find(x => x.Code == pumpMatching.Code);
            if (pump != null)
            {
                pump.DbLocked = pumpMatching.DbLocked;
                pump.ModelType = pumpMatching.ModelType;
                pump.RatedP = pumpMatching.RatedP;
                pump.RatedQ = pumpMatching.RatedQ;
                pump.RatedH = pumpMatching.RatedH;
                pump.RatedN = pumpMatching.RatedN;
                if (!pump.DbLocked)
                {
                    if (!string.IsNullOrEmpty(pumpMatching.MatchingModelType))
                    {
                        pump.ModelType = pumpMatching.MatchingModelType;
                    }
                    if (!string.IsNullOrEmpty(pumpMatching.MatchingDbId))
                    {
                        pump.DbId = pumpMatching.MatchingDbId;
                    }
                    if (pumpMatching.MatchingRatedP.HasValue)
                    {
                        pump.RatedP = pumpMatching.MatchingRatedP.Value;
                    }
                    if (pumpMatching.MatchingRatedQ.HasValue)
                    {
                        pump.RatedQ = pumpMatching.MatchingRatedQ.Value;
                    }
                    if (pumpMatching.MatchingRatedH.HasValue)
                    {
                        pump.RatedH = pumpMatching.MatchingRatedH.Value;
                    }
                    if (pumpMatching.MatchingRatedN.HasValue)
                    {
                        pump.RatedN = pumpMatching.MatchingRatedN.Value;
                    }
                    if (!string.IsNullOrEmpty(pumpMatching.MatchingCurveDbId))
                    {
                        //流量扬程曲线
                        var curveqh = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQH);
                        if (curveqh == null)
                        {
                            curveqh = new Yw.Model.HydroCurveInfo();
                            curveqh.Catalog = Yw.Hydro.ParterCatalog.Curve;
                            curveqh.Code = Yw.Untity.UniqueHelper.CreateFromFirst("curve", GetAllCodeList(hydroInfo));
                            curveqh.Name = "匹配";
                            curveqh.ModelType = string.Empty;
                            curveqh.DbLocked = false;
                            curveqh.DbId = pumpMatching.MatchingCurveDbId;
                            curveqh.CurveType = Yw.WinFrmUI.HydroCurve.PumpQH;
                            curveqh.CurveData = pumpMatching.MatchingCurveQH?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList();
                            if (hydroInfo.Curves == null)
                            {
                                hydroInfo.Curves = new List<Yw.Model.HydroCurveInfo>();
                            }
                            hydroInfo.Curves.Add(curveqh);
                            pump.CurveQH = curveqh.Code;
                        }
                        else
                        {
                            if (!curveqh.DbLocked)
                            {
                                curveqh.DbId = pumpMatching.MatchingDbId;
                                curveqh.CurveData = pumpMatching.MatchingCurveQH?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList();
                            }
                        }
                        //流量功率曲线
                        var curveqp = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQP);
                        if (curveqp == null)
                        {
                            curveqp = new Yw.Model.HydroCurveInfo();
                            curveqp.Catalog = Yw.Hydro.ParterCatalog.Curve;
                            curveqp.Code = Yw.Untity.UniqueHelper.CreateFromFirst("curve", GetAllCodeList(hydroInfo));
                            curveqp.Name = "匹配";
                            curveqp.ModelType = string.Empty;
                            curveqp.DbLocked = false;
                            curveqp.DbId = pumpMatching.MatchingCurveDbId;
                            curveqp.CurveType = Yw.WinFrmUI.HydroCurve.PumpQP;
                            curveqp.CurveData = pumpMatching.MatchingCurveQP?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList();
                            if (hydroInfo.Curves == null)
                            {
                                hydroInfo.Curves = new List<Yw.Model.HydroCurveInfo>();
                            }
                            hydroInfo.Curves.Add(curveqp);
                            pump.CurveQP = curveqp.Code;
                        }
                        else
                        {
                            if (!curveqp.DbLocked)
                            {
                                curveqp.DbId = pumpMatching.MatchingDbId;
                                curveqp.CurveData = pumpMatching.MatchingCurveQP?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList();
                            }
                        }
                        //流量效率曲线
                        var curveqe = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQE);
                        if (curveqe == null)
                        {
                            curveqe = new Yw.Model.HydroCurveInfo();
                            curveqe.Catalog = Yw.Hydro.ParterCatalog.Curve;
                            curveqe.Code = Yw.Untity.UniqueHelper.CreateFromFirst("curve", GetAllCodeList(hydroInfo));
                            curveqe.Name = "匹配";
                            curveqe.ModelType = string.Empty;
                            curveqe.DbLocked = false;
                            curveqe.DbId = pumpMatching.MatchingCurveDbId;
                            curveqe.CurveType = Yw.WinFrmUI.HydroCurve.PumpQE;
                            curveqe.CurveData = pumpMatching.MatchingCurveQE?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList();
                            if (hydroInfo.Curves == null)
                            {
                                hydroInfo.Curves = new List<Yw.Model.HydroCurveInfo>();
                            }
                            hydroInfo.Curves.Add(curveqe);
                            pump.CurveQE = curveqe.Code;
                        }
                        else
                        {
                            if (!curveqe.DbLocked)
                            {
                                curveqe.DbId = pumpMatching.MatchingDbId;
                                curveqe.CurveData = pumpMatching.MatchingCurveQE?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList();
                            }
                        }
                    }
                    result = true;
                }
            }
            return result;
        }
        //获取所有编码列表
        private static List<string> GetAllCodeList(Yw.Model.HydroModelInfo hydroInfo)
        {