From 31a8e93cf1cc708b68456b88aa5b0031a41eb47a Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期二, 10 十二月 2024 16:36:45 +0800
Subject: [PATCH] 能耗分析

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs | 2032 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 1,597 insertions(+), 435 deletions(-)

diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
index 5672274..a0c4aa8 100644
--- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
+++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/00-core/AssetsMatchingHelper.cs
@@ -11,76 +11,198 @@
         private const double _headTolerance = 5;
         private const double _powerTolerance = 0.05;
 
+        private const double _valveLift = 10;//闃�闂ㄥ紑搴﹁寖鍥�
+        private const int _angle = 1;//瑙掑害鑼冨洿
+
         //璧勪骇鑷姩鍖归厤
-        public static async Task<bool> Matching(AssetsMatchingViewModel assetsAutoMatchingView)
+        public static bool Matching(HydroMatchingViewModel assetsAutoMatchingView, out string Error)
         {
+            Error = string.Empty;
             bool IsMaching = false;
-            var pumpMain = new BLL.PumpMain();
-            var adaptingManage = new BLL.AdaptingManage();
-            var pipeLineManage = new BLL.PipeLineManage();
-            var valveMain = new BLL.ValveMain();
-            var allPump = await pumpMain.GetAll();
-            var allAdapting = await adaptingManage.GetAll();
-            var allPipeLine = await pipeLineManage.GetAll();
-            var allValve = await valveMain.GetAll();
-            //娉靛尮閰�
-            foreach (var item in assetsAutoMatchingView.PumpMatchingList)
+            var AssetsPumpMain = new BLL.AssetsPumpMain();
+            var AdaptingManage = new BLL.AdaptingManage();
+            var pipeLineManage = new BLL.AssetsPipeMain();
+            var AssetsValveMain = new BLL.AssetsValveMain();
+            var AssetsElbowMain = new BLL.AssetsElbowMain();
+            var AssetsThreelinkMain = new BLL.AssetsThreelinkMain();
+            var AssetsFourlinkMain = new BLL.AssetsFourlinkMain();
+            var AssetsSprinkler = new BLL.AssetsSprinklerMain();
+            var AssetsExchanger = new BLL.AssetsExchangerMain();
+            var AssetsCompressorMain = new BLL.AssetsCompressorMain();
+            var AssetsBluntheadMain = new BLL.AssetsBluntheadMain();
+            var AssetsTankMain = new BLL.AssetsTankMain();
+            var AssetsMeterMain = new BLL.AssetsMeterMain();
+            var AssetsFlowmeterMain = new BLL.AssetsFlowmeterMain();
+            var AssetsHydrantMain = new BLL.AssetsHydrantMain();
+            var AssetsPressmeterMain = new BLL.AssetsPressmeterMain();
+            var AssetsTranslationMain = new BLL.AssetsTranslationMain();
+            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;
+                var allSprinkler = Task.Run(async () => await AssetsSprinkler.GetAll()).Result;
+                var allExchanger = Task.Run(async () => await AssetsExchanger.GetAll()).Result;
+                var allCompressorMain = Task.Run(async () => await AssetsCompressorMain.GetAll()).Result;
+                var allBluntheadMain = Task.Run(async () => await AssetsBluntheadMain.GetAll()).Result;
+                var allTankMain = Task.Run(async () => await AssetsTankMain.GetAll()).Result;
+                var allMeterMain = Task.Run(async () => await AssetsMeterMain.GetAll()).Result;
+                var allFlowmeterMain = Task.Run(async () => await AssetsFlowmeterMain.GetAll()).Result;
+                var allHydrantMain = Task.Run(async () => await AssetsHydrantMain.GetAll()).Result;
+                var allPressmeterMain = Task.Run(async () => await AssetsPressmeterMain.GetAll()).Result;
+                var allTranslationMain = Task.Run(async () => await AssetsTranslationMain.GetAll()).Result;
+                //娉靛尮閰�
+                foreach (var item in assetsAutoMatchingView.Pumps)
                 {
-                    IsMaching = true;
+                    if (MatchingPumps(item, allPump))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //涓夐�氬尮閰�
+                foreach (var item in assetsAutoMatchingView.Threelinks)
+                {
+                    if (MatchingThreelink(item, allThreeLink))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //鍥涢�氬尮閰�
+                foreach (var item in assetsAutoMatchingView.Fourlinks)
+                {
+                    if (MatchingFourlink(item, allFourLink))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //绠¢亾鍖归厤
+                foreach (var item in assetsAutoMatchingView.Pipes)
+                {
+                    if (MatchingPipe(item, allPipeLine))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //闃�闂ㄥ尮閰�
+                foreach (var item in assetsAutoMatchingView.Valves)
+                {
+                    if (MatchingValve(item, allValve))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //寮ご鍖归厤
+                foreach (var item in assetsAutoMatchingView.Elbows)
+                {
+                    if (MatchingElbow(item, allElbow))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //鍠峰ご鍖归厤
+                foreach (var item in assetsAutoMatchingView.Nozzles)
+                {
+                    if (MatchingSprinkler(item, allSprinkler))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //闂峰ご鍖归厤
+                foreach (var item in assetsAutoMatchingView.Bluntheads)
+                {
+                    if (MatchingBlunthead(item, allBluntheadMain))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //鎹㈢儹鍣ㄥ尮閰�
+                foreach (var item in assetsAutoMatchingView.Exchangers)
+                {
+                    if (MatchingExchanger(item, allExchanger))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //鍘嬬缉鏈哄尮閰�
+                foreach (var item in assetsAutoMatchingView.Compressors)
+                {
+                    if (MatchingCompressor(item, allCompressorMain))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //姘存睜鍖归厤
+                foreach (var item in assetsAutoMatchingView.Tanks)
+                {
+                    if (MatchingTank(item, allTankMain))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //姘磋〃鍖归厤
+                foreach (var item in assetsAutoMatchingView.Meters)
+                {
+                    if (MatchingMeter(item, allMeterMain))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //娴侀噺璁″尮閰�
+                foreach (var item in assetsAutoMatchingView.Flowmeters)
+                {
+                    if (MatchingFlowmeter(item, allFlowmeterMain))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //娑堢伀鏍撳尮閰�
+                foreach (var item in assetsAutoMatchingView.Hydrants)
+                {
+                    if (MatchingHydrant(item, allHydrantMain))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //鍘嬪姏琛ㄥ尮閰�
+                foreach (var item in assetsAutoMatchingView.Pressmeters)
+                {
+                    if (MatchingPressmeter(item, allPressmeterMain))
+                    {
+                        IsMaching = true;
+                    }
+                }
+                //杩囨浮浠跺尮閰�
+                foreach (var item in assetsAutoMatchingView.Translations)
+                {
+                    if (MatchingTranslation(item, allTranslationMain))
+                    {
+                        IsMaching = true;
+                    }
                 }
             }
-            //涓夐�氬尮閰�
-            foreach (var item in assetsAutoMatchingView.ThreelinkMatchingList)
+            catch (Exception ex)
             {
-                if (MatchingThreelink(item, allAdapting))
-                {
-                    IsMaching = true;
-                }
-            }
-            //鍥涢�氬尮閰�
-            foreach (var item in assetsAutoMatchingView.FourlinkMatchingList)
-            {
-                if (MatchingFourlink(item, allAdapting))
-                {
-                    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.ElbowsMatchingList)
-            {
-                if (MatchingElbow(item, allAdapting))
-                {
-                    IsMaching = true;
-                }
+                Error = ex.Message;
+                return false;
             }
             return IsMaching;
         }
 
         //娉靛尮閰�
-        public static async Task<bool> MatchingPumps(PumpMatchingViewModel InputModel, List<Vmo.PumpMainVmo> pumpMainVmos)
+        public static bool MatchingPumps(HydroPumpMatchingViewModel InputModel, List<Vmo.AssetsPumpMainVmo> AssetsPumpMainVmos)
         {
-            Vmo.PumpMainVmo vmo = null;
+            if (AssetsPumpMainVmos == null)
+            {
+                return true;
+            }
+            Vmo.AssetsPumpMainVmo vmo = null;
             int startCount = 0;
             // 灏濊瘯缁濆鍖归厤
-            var absoluteMatch = pumpMainVmos.Where(item =>
+            var absoluteMatch = AssetsPumpMainVmos.Where(item =>
             (InputModel.RatedN == null || InputModel.RatedN == item.RatedSpeed) &&
             (InputModel.RatedQ == null || InputModel.RatedQ == item.RatedFlow) &&
             (InputModel.RatedH == null || InputModel.RatedH == item.RatedHead) &&
@@ -100,7 +222,7 @@
             else
             {
                 // 灏濊瘯鍖洪棿鍖归厤
-                var rangeMatch = pumpMainVmos.Where(item =>
+                var rangeMatch = AssetsPumpMainVmos.Where(item =>
                    (InputModel.RatedN.HasValue ? Math.Abs(InputModel.RatedN.Value - item.RatedSpeed) <= _speedTolerance : true) &&
                    (InputModel.RatedQ.HasValue ? Math.Abs(InputModel.RatedQ.Value - item.RatedFlow) <= _flowTolerance : true) &&
                    (InputModel.RatedH.HasValue ? Math.Abs(InputModel.RatedH.Value - item.RatedHead) <= _headTolerance : true) &&
@@ -121,7 +243,7 @@
             //
             if (vmo == null)
             {
-                foreach (var item in pumpMainVmos)
+                foreach (var item in AssetsPumpMainVmos)
                 {
                     int commonCount = GetIntersect(InputModel.ModelType, item.Name);
                     if (commonCount > startCount)
@@ -139,38 +261,39 @@
                 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 graph_qh = list.First().Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
-                    var graph_qe = list.First().Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
-                    var graph_qp = list.First().Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
+                    var maxImportanceItem = list.OrderByDescending(x => x.Importance).First();
+                    InputModel.MatchingCurveDbId = maxImportanceItem.ID.ToString();
+                    var graph_qh = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
+                    var graph_qe = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
+                    var graph_qp = maxImportanceItem.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
                     if (graph_qh != null)
                     {
                         var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 100, null);
-                        InputModel.MatchingCurveQH = new List<CurvePointMatchingViewModel>();
+                        InputModel.MatchingCurveQH = new List<HydroCurvePointViewModel>();
                         foreach (var item in points_qh)
                         {
-                            InputModel.MatchingCurveQH.Add(new CurvePointMatchingViewModel(item.X, item.Y));
+                            InputModel.MatchingCurveQH.Add(new HydroCurvePointViewModel(item.X, item.Y));
                         }
                     }
                     if (graph_qe != null)
                     {
                         var points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 100, null);
-                        InputModel.MatchingCurveQE = new List<CurvePointMatchingViewModel>();
+                        InputModel.MatchingCurveQE = new List<HydroCurvePointViewModel>();
                         foreach (var item in points_qe)
                         {
-                            InputModel.MatchingCurveQE.Add(new CurvePointMatchingViewModel(item.X, item.Y));
+                            InputModel.MatchingCurveQE.Add(new HydroCurvePointViewModel(item.X, item.Y));
                         }
                     }
                     if (graph_qp != null)
                     {
                         var points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 100, null);
-                        InputModel.MatchingCurveQP = new List<CurvePointMatchingViewModel>();
+                        InputModel.MatchingCurveQP = new List<HydroCurvePointViewModel>();
                         foreach (var item in points_qp)
                         {
-                            InputModel.MatchingCurveQP.Add(new CurvePointMatchingViewModel(item.X, item.Y));
+                            InputModel.MatchingCurveQP.Add(new HydroCurvePointViewModel(item.X, item.Y));
                         }
                     }
                 }
@@ -180,520 +303,1559 @@
         }
 
         //闃�闂ㄥ尮閰�
-        public static bool MatchingValve(ValveMatchingViewModel input, List<Vmo.ValveMainVmo> adaptingManageVmos)
+        public static bool MatchingValve(HydroValveMatchingViewModel input, List<Vmo.AssetsValveMainVmo> valveMainVmos)
         {
-            HStation.Vmo.ValveMainVmo vmo = null;
-            int firstCount = 0;
+            bool isNotarize = false; //鏄惁纭畾
+            if (valveMainVmos == null)
+            {
+                return true;
+            }
+            HStation.Vmo.AssetsValveMainVmo vmo = null;
             //鍙e緞鏈�灏忓樊鍊�
             // 缁濆鍖归厤
-            var absoluteMatch = adaptingManageVmos.Where(i =>
-              ((i.Caliber == null) || i.Caliber == input.Diameter) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
+            valveMainVmos = valveMainVmos.Where(x => (int)x.ValveType == (int)input.ValveType).ToList();
+
+            var nameMatching = valveMainVmos.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();//浣跨敤鍨嬪彿鍚嶆垨鑰呭叧閿瓧鎵惧嚭鐩稿悓瀛楃鍦�1浠ヤ笂骞朵笖杩涜鎺掑簭
+
+            if (nameMatching.Count > 0)
             {
-                foreach (var range in absoluteMatch)
+                var absoluteMatching = nameMatching.Where(i =>
+              ((i.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - input.Diameter) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+               i.Material == input.Material  //鏉愭枡绾︽潫
+                 ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > firstCount)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        vmo = range;
-                        firstCount = commonCount;
+                        vmo = defaultList.First();
+                    }
+                    else if (defaultList.Count <= 0)
+                    {
+                        vmo = valveMainVmos.First();
                     }
                 }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = valveMainVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
             }
             else
             {
-                //鍖洪棿鍖归厤
-                var rangeMatch = adaptingManageVmos.Where(item =>
+                var absoluteMatching = valveMainVmos.Where(i =>
+          ((i.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - input.Diameter) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+           i.Material == input.Material   //鏉愭枡绾︽潫
+             ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    if (item.Caliber.HasValue)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Diameter)) <= _caliberTolerance;
+                        vmo = defaultList.First();
                     }
-                    else
+                    else if (defaultList.Count <= 0)
                     {
-                        if (item.Caliber == null)
-                        {
-                            return true;
-                        }
-                    }
-                    return false;
-                })
-             .ToList();
-                if (rangeMatch != null && rangeMatch.Count > 0)
-                {
-                    var materialList = new List<Vmo.ValveMainVmo>();
-                    foreach (var range in rangeMatch)
-                    {
-                        //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        if (range.Material == "榛樿")
-                        {
-                            materialList.Add(range);
-                        }
-                        else
-                        {
-                            int commonCount = GetIntersect(input.Material, range.Material);
-                            if (commonCount > firstCount)
-                            {
-                                materialList.Add(range);
-                                firstCount = commonCount;
-                            }
-                        }
-                    }
-                    //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢��
-                    firstCount = 0;
-                    foreach (var material in materialList)
-                    {
-                        int commonCount = GetIntersect(input.ModelType, material.Name);
-                        if (commonCount > firstCount)
-                        {
-                            vmo = material;
-                            firstCount = commonCount;
-                        }
+                        vmo = valveMainVmos.First();
                     }
                 }
-            }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
-            firstCount = 0;
-            if (vmo == null)
-            {
-                foreach (var item in adaptingManageVmos)
+                else if (absoluteMatching.Count == 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > firstCount)
-                    {
-                        vmo = item;
-                        firstCount = commonCount;
-                    }
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
                 }
+                else
+                    vmo = valveMainVmos.First();
             }
             if (vmo != null)
             {
-                input.MatchingMinorLoss = vmo.Coefficient;
-                input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingDiameter = vmo.Caliber;
-                input.MatchingMaterial = vmo.Material;
-                input.MatchingModelType = vmo.Name;
-                //  input.MatchingValveSetting =
-                input.MatchingValveType = vmo.Type.ToString();
+                if (!isNotarize)
+                {
+                    if (input.CurveDbId == null)
+                    {
+                        if ((int)input.ValveType == (int)HStation.Assets.eValveType.GPV)
+                        {
+                            var curveList = Task.Run(async () => await new BLL.AssetsValveCoefficient().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 if ((int)vmo.ValveType == (int)HStation.Assets.eValveType.TCV)
+                        {
+                            var curveList = Task.Run(async () => await new BLL.AssetsValveCoefficient().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().OpenLossCurve);
+                                input.MatchingCurveOL = pt_list;
+                            }
+                        }
+                    }
+                    if (input.MinorLoss < 0)
+                    {
+                        input.MatchingMinorLoss = vmo.MinorLoss;
+                    }
+                    if (!input.MatchingDiameter.HasValue)
+                        input.MatchingDiameter = vmo.Caliber;
+                    if (input.ValveSetting == null)
+                        input.MatchingValveSetting = vmo.ValveSetting;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingDiameter = vmo.Caliber;
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                    input.MatchingValveSetting = vmo.ValveSetting;
+                    input.MatchingValveType = (eValveType?)(int)vmo.ValveType;
+                    if (vmo.ValveType == HStation.Assets.eValveType.GPV)
+                    {
+                        var curveList = Task.Run(async () => await new BLL.AssetsValveCoefficient().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 if (vmo.ValveType == HStation.Assets.eValveType.TCV)
+                    {
+                        var curveList = Task.Run(async () => await new BLL.AssetsValveCoefficient().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().OpenLossCurve);
+                            input.MatchingCurveOL = pt_list;
+                        }
+                    }
+                }
                 return true;
             }
             return false;
         }
 
         //绠¢亾鍖归厤
-        public static bool MatchingPipe(PipeMatchingViewModel input, List<Vmo.PipeLineManageVmo> pipeLineManageVmos)
+        public static bool MatchingPipe(HydroPipeMatchingViewModel input, List<Vmo.AssetsPipeMainVmo> pipeLineMainVmos)
         {
-            Vmo.PipeLineManageVmo vmo = null;
-            int StartCount = 0;
-            //鍙e緞鏈�灏忓樊鍊�
-            // 缁濆鍖归厤
-            var absoluteMatch = pipeLineManageVmos.Where(i =>
-            ((i.Caliber == null) || i.Caliber == input.Diameter) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
+            bool isNotarize = false; //鏄惁纭畾
+            if (pipeLineMainVmos == null)
             {
-                foreach (var range in absoluteMatch)
+                return true;
+            }
+            Vmo.AssetsPipeMainVmo vmo = null;
+
+            var nameMatching = pipeLineMainVmos.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.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - input.Diameter) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+               i.Material == input.Material  //鏉愭枡绾︽潫
+                 ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > StartCount)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        vmo = range;
-                        StartCount = commonCount;
+                        vmo = defaultList.First();
+                    }
+                    else if (defaultList.Count <= 0)
+                    {
+                        vmo = pipeLineMainVmos.First();
                     }
                 }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = pipeLineMainVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
             }
             else
             {
-                //鍖洪棿鍖归厤
-                var rangeMatch = pipeLineManageVmos.Where(item =>
+                var absoluteMatching = pipeLineMainVmos.Where(i =>
+          ((i.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - input.Diameter) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+           i.Material == input.Material   //鏉愭枡绾︽潫
+             ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    if (item.Caliber != null)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Diameter)) <= _caliberTolerance;
+                        vmo = defaultList.First();
                     }
-                    return false;
-                })
-             .ToList();
-                if (rangeMatch != null)
-                {
-                    foreach (var range in rangeMatch)
+                    else if (defaultList.Count <= 0)
                     {
-                        //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        int commonCount = GetIntersect(input.Material, range.Material);
-                        if (commonCount > StartCount)
-                        {
-                            vmo = range;
-                            StartCount = commonCount;
-                        }
+                        vmo = pipeLineMainVmos.First();
                     }
                 }
-            }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
-            if (vmo == null)
-            {
-                foreach (var item in pipeLineManageVmos)
+                else if (absoluteMatching.Count == 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > StartCount)
-                    {
-                        vmo = item;
-                        StartCount = commonCount;
-                    }
+                    isNotarize = true;
+                    vmo = absoluteMatching.First();
                 }
+                else
+                    vmo = pipeLineMainVmos.First();
             }
             if (vmo != null)
             {
-                switch (input.eAlgorithmType)
+                if (!isNotarize)
                 {
-                    case HStation.Assets.eAlgorithmType.Hazen:
-                        input.MatchingRoughness = vmo.Hazen;
-                        break;
+                    if (input.DbId == null)
+                        input.MatchingDbId = vmo.ID.ToString();
+                    if (input.Material == null)
+                        input.MatchingMaterial = vmo.Material;
+                    if (input.MinorLoss < 0)
+                        input.MatchingMinorLoss = vmo.MinorLoss;
+                    switch (input.eAlgorithmType)
+                    {
+                        case eAlgorithmType.Hazen:
+                            input.MatchingRoughness = vmo.Hazen;
+                            break;
 
-                    case HStation.Assets.eAlgorithmType.Manning:
-                        input.MatchingRoughness = vmo.Manning;
-                        break;
+                        case eAlgorithmType.Manning:
+                            input.MatchingRoughness = vmo.Manning;
+                            break;
 
-                    case HStation.Assets.eAlgorithmType.Darcy:
-                        input.MatchingRoughness = vmo.Darcy;
-                        break;
+                        case eAlgorithmType.Darcy:
+                            input.MatchingRoughness = vmo.Darcy;
+                            break;
 
-                    default:
-                        input.MatchingRoughness = vmo.Hazen;
-                        break;
+                        default:
+                            input.MatchingRoughness = vmo.Hazen;
+                            break;
+                    }
+                 }
+                else
+                {
+                    switch (input.eAlgorithmType)
+                    {
+                        case eAlgorithmType.Hazen:
+                            input.MatchingRoughness = vmo.Hazen;
+                            break;
+
+                        case eAlgorithmType.Manning:
+                            input.MatchingRoughness = vmo.Manning;
+                            break;
+
+                        case eAlgorithmType.Darcy:
+                            input.MatchingRoughness = vmo.Darcy;
+                            break;
+
+                        default:
+                            input.MatchingRoughness = vmo.Hazen;
+                            break;
+                    }
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                    input.MatchingMinorLoss = vmo.MinorLoss;
                 }
-                input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.Material;
-                input.MatchingModelType = vmo.Name;
-                input.MatchingMinorLoss = vmo.Coefficient;
                 return true;
             }
             return false;
         }
 
         //寮ご鍖归厤
-        public static bool MatchingElbow(ElbowsMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos)
+        public static bool MatchingElbow(HydroElbowMatchingViewModel input, List<Vmo.AssetsElbowMainVmo> elbowMainVmos)
         {
-            Vmo.AdaptingManageVmo vmo = null;
-            int firstCount = 0;
-            //鍙e緞鏈�灏忓樊鍊�
-            // 缁濆鍖归厤
-            var absoluteMatch = adaptingManageVmos.Where(i =>
-              ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
+            bool isNotarize = false; //鏄惁纭畾
+            if (elbowMainVmos == null || input == null || elbowMainVmos.Count == 0)
             {
-                foreach (var range in absoluteMatch)
+                return true;
+            }
+            Vmo.AssetsElbowMainVmo vmo = null;
+            var nameMatching = elbowMainVmos.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.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+               i.Material == input.Material  //鏉愭枡绾︽潫
+                 ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > firstCount)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        vmo = range;
-                        firstCount = commonCount;
+                        vmo = defaultList.First();
+                    }
+                    else if (defaultList.Count <= 0)
+                    {
+                        vmo = elbowMainVmos.First();
                     }
                 }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = elbowMainVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+                vmo = nameMatching.First();
             }
             else
             {
-                //鍖洪棿鍖归厤
-                var rangeMatch = adaptingManageVmos.Where(item =>
+                var absoluteMatching = elbowMainVmos.Where(i =>
+          ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+           i.Material == input.Material   //鏉愭枡绾︽潫
+             ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    if (item.Caliber != null && input.Caliber != null)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance;
+                        vmo = defaultList.First();
                     }
-                    else
+                    else if (defaultList.Count <= 0)
                     {
-                        if (item.Caliber == null)
-                        {
-                            return true;
-                        }
-                    }
-                    return false;
-                })
-             .ToList();
-                if (rangeMatch != null && rangeMatch.Count > 0)
-                {
-                    var materialList = new List<Vmo.AdaptingManageVmo>();
-                    foreach (var range in rangeMatch)
-                    {
-                        //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        if (range.Material == "榛樿")
-                        {
-                            materialList.Add(range);
-                        }
-                        else
-                        {
-                            int commonCount = GetIntersect(input.Material, range.Material);
-                            if (commonCount > firstCount)
-                            {
-                                materialList.Add(range);
-                                firstCount = commonCount;
-                            }
-                        }
-                    }
-                    //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢��
-                    firstCount = 0;
-                    foreach (var material in materialList)
-                    {
-                        int commonCount = GetIntersect(input.ModelType, material.Name);
-                        if (commonCount > firstCount)
-                        {
-                            vmo = material;
-                            firstCount = commonCount;
-                        }
+                        vmo = elbowMainVmos.First();
                     }
                 }
-            }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
-            firstCount = 0;
-            if (vmo == null)
-            {
-                foreach (var item in adaptingManageVmos)
+                else if (absoluteMatching.Count == 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > firstCount)
-                    {
-                        vmo = item;
-                        firstCount = commonCount;
-                    }
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
                 }
+                else
+                    vmo = elbowMainVmos.First();
             }
             if (vmo != null)
             {
-                input.MatchingMinorLoss = vmo.Coefficient;
-                input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.Material;
-                input.MatchingModelType = vmo.Name;
+                if (!isNotarize)
+                {
+                    if (!input.MinorLoss.HasValue)
+                    {
+                        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.Material;
+                    }
+                    if (!input.ElbowType.HasValue)
+                    {
+                        input.MatchingElbowType = (eElbowType?)(int)vmo.ElbowType;
+                    }
+                    if (!input.BendingAngle.HasValue)
+                    {
+                        input.MatchingBendingAngle = vmo.Angle;
+                    }
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                    input.MatchingElbowType = (eElbowType?)(int)vmo.ElbowType;
+                    input.MatchingBendingAngle = vmo.Angle;
+                }
                 return true;
             }
             return false;
         }
 
         //涓夐�氬尮閰�
-        public static bool MatchingThreelink(ThreelinkMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos)
+        public static bool MatchingThreelink(HydroThreelinkMatchingViewModel input, List<Vmo.AssetsThreelinkMainVmo> threelinkVmos)
         {
-            Vmo.AdaptingManageVmo vmo = null;
-            int firstCount = 0;
-            //鍙e緞鏈�灏忓樊鍊�
-            // 缁濆鍖归厤
-            var absoluteMatch = adaptingManageVmos.Where(i =>
-              ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
+            bool isNotarize = false; //鏄惁纭畾
+            Vmo.AssetsThreelinkMainVmo vmo = null;
+            if (threelinkVmos == null || input == null || threelinkVmos.Count == 0)
             {
-                foreach (var range in absoluteMatch)
+                return true;
+            }
+            var nameMatching = threelinkVmos.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.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+               i.Material == input.Material  //鏉愭枡绾︽潫
+                 ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > firstCount)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        vmo = range;
-                        firstCount = commonCount;
+                        vmo = defaultList.First();
+                    }
+                    else if (defaultList.Count <= 0)
+                    {
+                        vmo = threelinkVmos.First();
                     }
                 }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = threelinkVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
             }
             else
             {
-                //鍖洪棿鍖归厤
-                var rangeMatch = adaptingManageVmos.Where(item =>
+                var absoluteMatching = threelinkVmos.Where(i =>
+          ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+           i.Material == input.Material   //鏉愭枡绾︽潫
+             ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    if (item.Caliber != null && input.Caliber != null)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance;
+                        vmo = defaultList.First();
                     }
-                    else
+                    else if (defaultList.Count <= 0)
                     {
-                        if (item.Caliber == null)
-                        {
-                            return true;
-                        }
-                    }
-                    return false;
-                })
-             .ToList();
-                if (rangeMatch != null && rangeMatch.Count > 0)
-                {
-                    var materialList = new List<Vmo.AdaptingManageVmo>();
-                    foreach (var range in rangeMatch)
-                    {
-                        //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        if (range.Material == "榛樿")
-                        {
-                            materialList.Add(range);
-                        }
-                        else
-                        {
-                            int commonCount = GetIntersect(input.Material, range.Material);
-                            if (commonCount > firstCount)
-                            {
-                                materialList.Add(range);
-                                firstCount = commonCount;
-                            }
-                        }
-                    }
-                    //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢��
-                    firstCount = 0;
-                    foreach (var material in materialList)
-                    {
-                        int commonCount = GetIntersect(input.ModelType, material.Name);
-                        if (commonCount > firstCount)
-                        {
-                            vmo = material;
-                            firstCount = commonCount;
-                        }
+                        vmo = threelinkVmos.First();
                     }
                 }
-            }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
-            firstCount = 0;
-            if (vmo == null)
-            {
-                foreach (var item in adaptingManageVmos)
+                else if (absoluteMatching.Count == 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > firstCount)
-                    {
-                        vmo = item;
-                        firstCount = commonCount;
-                    }
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
                 }
+                else
+                    vmo = threelinkVmos.First();
             }
             if (vmo != null)
             {
-                input.MatchingMinorLoss = vmo.Coefficient;
-                input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.Material;
-                input.MatchingModelType = vmo.Name;
+                if (!isNotarize)
+                {
+                    if (!input.MinorLoss.HasValue)
+                        input.MatchingMinorLoss = vmo.MinorLoss;
+                    if (input.DbId == null)
+                        input.MatchingDbId = vmo.ID.ToString();
+                    if (!input.RunningThroughLoss.HasValue)
+                        input.MatchingRunningThroughLoss = vmo.RunThroughMinorLoss;
+                    if (!input.MatchingBranchThroughLoss.HasValue)
+                        input.MatchingRunningThroughLoss = vmo.BranchThroughMinorLoss;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                    input.MatchingRunningThroughLoss = vmo.RunThroughMinorLoss;
+                    input.MatchingBranchThroughLoss = vmo.BranchThroughMinorLoss;
+                }
                 return true;
             }
             return false;
         }
 
         //鍥涢�氬尮閰�
-        public static bool MatchingFourlink(FourlinkMatchingViewModel input, List<Vmo.AdaptingManageVmo> adaptingManageVmos)
+        public static bool MatchingFourlink(HydroFourlinkMatchingViewModel input, List<Vmo.AssetsFourlinkMainVmo> fourLinkVmos)
         {
-            Vmo.AdaptingManageVmo vmo = null;
-            int firstCount = 0;
-            //鍙e緞鏈�灏忓樊鍊�
-            // 缁濆鍖归厤
-            var absoluteMatch = adaptingManageVmos.Where(i =>
-              ((input.Caliber == null && i.Caliber == null) || i.Caliber == input.Caliber) &&
-               ((input.Material == null && i.Material == "榛樿") || i.Material == input.Material)).ToList();
-            if (absoluteMatch.Any())
+            bool isNotarize = false; //鏄惁纭畾
+            if (fourLinkVmos == null || input == null || fourLinkVmos.Count == 0)
             {
-                foreach (var range in absoluteMatch)
+                return true;
+            }
+            Vmo.AssetsFourlinkMainVmo vmo = null;
+            var nameMatching = fourLinkVmos.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.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+               i.Material == input.Material  //鏉愭枡绾︽潫
+                 ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, range.Name);
-                    if (commonCount > firstCount)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        vmo = range;
-                        firstCount = commonCount;
+                        vmo = defaultList.First();
+                    }
+                    else if (defaultList.Count <= 0)
+                    {
+                        vmo = fourLinkVmos.First();
                     }
                 }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = fourLinkVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
             }
             else
             {
-                //鍖洪棿鍖归厤
-                var rangeMatch = adaptingManageVmos.Where(item =>
+                var absoluteMatching = fourLinkVmos.Where(i =>
+          ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+           i.Material == input.Material   //鏉愭枡绾︽潫
+             ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    if (item.Caliber != null && input.Caliber != null)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        return Math.Abs(Convert.ToInt64(item.Caliber - input.Caliber)) <= _caliberTolerance;
+                        vmo = defaultList.First();
                     }
-                    else
+                    else if (defaultList.Count <= 0)
                     {
-                        if (item.Caliber == null)
-                        {
-                            return true;
-                        }
-                    }
-                    return false;
-                })
-             .ToList();
-                if (rangeMatch != null && rangeMatch.Count > 0)
-                {
-                    var materialList = new List<Vmo.AdaptingManageVmo>();
-                    foreach (var range in rangeMatch)
-                    {
-                        //浠ユ潗鏂欎负鏉′欢寮�濮嬪尮閰�
-                        if (range.Material == "榛樿")
-                        {
-                            materialList.Add(range);
-                        }
-                        else
-                        {
-                            int commonCount = GetIntersect(input.Material, range.Material);
-                            if (commonCount > firstCount)
-                            {
-                                materialList.Add(range);
-                                firstCount = commonCount;
-                            }
-                        }
-                    }
-                    //鐢ㄥ凡缁忕瓫閫夊畬鎴愮殑鍒楄〃涓互鍚嶇О绛涢��
-                    firstCount = 0;
-                    foreach (var material in materialList)
-                    {
-                        int commonCount = GetIntersect(input.ModelType, material.Name);
-                        if (commonCount > firstCount)
-                        {
-                            vmo = material;
-                            firstCount = commonCount;
-                        }
+                        vmo = fourLinkVmos.First();
                     }
                 }
-            }
-            //鍙e緞鍜屾潗鏂欓兘娌℃湁鍖归厤涓�,灏辩敤鍨嬪彿鍚嶅尮閰�
-            firstCount = 0;
-            if (vmo == null)
-            {
-                foreach (var item in adaptingManageVmos)
+                else if (absoluteMatching.Count == 1)
                 {
-                    int commonCount = GetIntersect(input.ModelType, item.Name);
-                    if (commonCount > firstCount)
-                    {
-                        vmo = item;
-                        firstCount = commonCount;
-                    }
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
                 }
+                else
+                    vmo = fourLinkVmos.First();
             }
             if (vmo != null)
             {
-                input.MatchingMinorLoss = vmo.Coefficient;
-                input.MatchingDbId = vmo.ID.ToString();
-                input.MatchingMaterial = vmo.Material;
-                input.MatchingModelType = vmo.Name;
+                if (!isNotarize)
+                {
+                    if (!input.MinorLoss.HasValue)
+                        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;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                }
                 return true;
             }
             return false;
         }
 
-        /*
-                //杩斿洖涓や釜瀛楃涓蹭箣闂寸浉鍚岀殑瀛楃涓暟
-                private static int GetIntersect(string baseString, string compareString)
+        //鍠峰ご鍖归厤
+        public static bool MatchingSprinkler(HydroNozzleMatchingViewModel input, List<Vmo.AssetsSprinklerMainVmo> sprinklerVmos)
+        {
+            bool isNotarize = false; //鏄惁纭畾
+            if (sprinklerVmos == null || input == null || sprinklerVmos.Count == 0)
+            {
+                return true;
+            }
+            Vmo.AssetsSprinklerMainVmo vmo = null;
+            var nameMatching = sprinklerVmos.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.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+               i.Material == input.Material  //鏉愭枡绾︽潫
+                 ).ToList();
+                if (absoluteMatching.Count > 1)
                 {
-                    // 灏嗗瓧绗︿覆杞崲涓哄瓧绗﹂泦鍚�
-                    if (baseString == string.Empty || baseString == null || compareString == string.Empty || compareString == null)
+                    var defaultList = absoluteMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                    //鍙栭粯璁�
+                    if (defaultList.Count > 0)
                     {
-                        return 0;
+                        vmo = defaultList.First();
                     }
-                    HashSet<char> baseChars = new HashSet<char>(baseString);
-                    HashSet<char> comparisonChars = new HashSet<char>(compareString);
-                    // 璁$畻涓や釜闆嗗悎鐨勪氦闆�
-                    int commonCount = baseChars.Intersect(comparisonChars).Count();
-                    return commonCount;
-                }*/
+                    else if (defaultList.Count <= 0)
+                    {
+                        vmo = sprinklerVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = sprinklerVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
+            }
+            else
+            {
+                var absoluteMatching = sprinklerVmos.Where(i =>
+          ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+           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 = sprinklerVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = sprinklerVmos.First();
+            }
+            if (vmo != null)
+            {
+                if (!isNotarize)
+                {
+                    if (!input.MinorLoss.HasValue)
+                        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;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                }
+                return true;
+            }
+            return false;
+        }
+
+        //鎹㈢儹鍣ㄥ尮閰�
+        public static bool MatchingExchanger(HydroExchangerMatchingViewModel input, List<Vmo.AssetsExchangerMainVmo> exchangerVmos)
+        {
+            bool isNotarize = false; //鏄惁纭畾
+
+            if (exchangerVmos == null || input == null || exchangerVmos.Count == 0)
+            {
+                return true;
+            }
+            Vmo.AssetsExchangerMainVmo vmo = null;
+            var nameMatching = exchangerVmos.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 = exchangerVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = exchangerVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
+            }
+            else
+            {
+                var absoluteMatching = exchangerVmos.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 = exchangerVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = exchangerVmos.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.AssetsExchangerCoefficient().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.AssetsExchangerCoefficient().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;
+        }
+
+        //绌哄帇鏈哄尮閰�
+        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();
+
+            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 = 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;
+            }
+            return false;
+        }
+
+        //闂峰ご鍖归厤
+        public static bool MatchingBlunthead(HydroBluntheadMatchingViewModel input, List<Vmo.AssetsBluntheadMainVmo> bluntheadVmos)
+        {
+            bool isNotarize = false; //鏄惁纭畾
+            if (bluntheadVmos == null || input == null || bluntheadVmos.Count == 0)
+            {
+                return true;
+            }
+            Vmo.AssetsBluntheadMainVmo vmo = null;
+            var nameMatching = bluntheadVmos.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.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+               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 = bluntheadVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = bluntheadVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
+            }
+            else
+            {
+                var absoluteMatching = bluntheadVmos.Where(i =>
+              ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+               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 = bluntheadVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = bluntheadVmos.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;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                }
+                return true;
+            }
+            return false;
+        }
+
+        //姘存睜鍖归厤
+        public static bool MatchingTank(HydroTankMatchingViewModel input, List<Vmo.AssetsTankMainVmo> tankVmos)
+        {
+            bool isNotarize = false; //鏄惁纭畾
+            if (tankVmos == null || input == null || tankVmos.Count == 0)
+            {
+                return true;
+            }
+            Vmo.AssetsTankMainVmo vmo = null;
+            var nameMatching = tankVmos.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 defaultList = nameMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                //鍙栭粯璁�
+                if (defaultList.Count > 0)
+                {
+                    vmo = tankVmos.First();
+                }
+                else if (defaultList.Count <= 0)
+                {
+                    vmo = tankVmos.First();
+                }
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
+            }
+            else
+                vmo = tankVmos.First();
+            if (vmo != null)
+            {
+                if (!isNotarize)
+                {
+                    if (input.DbId == null)
+                        input.MatchingDbId = vmo.ID.ToString();
+                    if (input.ModelType == null)
+                        input.MatchingModelType = vmo.Name;
+                    if (input.DN < 0)
+                        input.MatchingDN = vmo.DN;
+                    if (input.MinLevel < 0)
+                        input.MatchingMinLevel = vmo.MinLevel;
+                    if (input.CurveDbId == null)
+                    {
+                        var curveList = Task.Run(async () => await new BLL.AssetsTankCoefficient().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().VolCurve);
+                            input.MatchingVolCurve = pt_list;
+                        }
+                    }
+                }
+                else
+                {
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingModelType = vmo.Name;
+                    input.MatchingDN = vmo.DN;
+                    input.MatchingMinLevel = vmo.MinLevel;
+                    input.MatchingOverFlow = vmo.OverFlow;
+                    var curveList = Task.Run(async () => await new BLL.AssetsTankCoefficient().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().VolCurve);
+                        input.MatchingVolCurve = pt_list;
+                    }
+                }
+                return true;
+            }
+            return false;
+        }
+
+        //姘磋〃鍖归厤
+        public static bool MatchingMeter(HydroMeterMatchingViewModel input, List<Vmo.AssetsMeterMainVmo> MeterMainVmos)
+        {
+            bool isNotarize = false; //鏄惁纭畾
+            Vmo.AssetsMeterMainVmo vmo = null;
+            if (MeterMainVmos == null || input == null || MeterMainVmos.Count == 0)
+            {
+                return true;
+            }
+            var nameMatching = MeterMainVmos.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 defaultList = nameMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                //鍙栭粯璁�
+                if (defaultList.Count > 0)
+                {
+                    vmo = defaultList.First();
+                }
+                else if (defaultList.Count <= 0)
+                {
+                    vmo = MeterMainVmos.First();
+                }
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
+            }
+            else
+                vmo = MeterMainVmos.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.ModelType == null)
+                        input.MatchingModelType = vmo.Name;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingModelType = vmo.Name;
+                }
+                return true;
+            }
+            return false;
+        }
+
+        //娴侀噺璁″尮閰�
+        public static bool MatchingFlowmeter(HydroFlowmeterMatchingViewModel input, List<Vmo.AssetsFlowmeterMainVmo> FlowmeterMainVmos)
+        {
+            bool isNotarize = false; //鏄惁纭畾
+            if (FlowmeterMainVmos == null || input == null || FlowmeterMainVmos.Count == 0)
+            {
+                return true;
+            }
+            Vmo.AssetsFlowmeterMainVmo vmo = null;
+            var nameMatching = FlowmeterMainVmos.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 defaultList = nameMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                //鍙栭粯璁�
+                if (defaultList.Count > 0)
+                {
+                    vmo = defaultList.First();
+                }
+                else if (defaultList.Count <= 0)
+                {
+                    vmo = FlowmeterMainVmos.First();
+                }
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
+            }
+            else
+            {
+                vmo = FlowmeterMainVmos.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.ModelType == null)
+                        input.MatchingModelType = vmo.Name;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingModelType = vmo.Name;
+                }
+                return true;
+            }
+            return false;
+        }
+
+        //娑堢伀鏍撳尮閰�
+        public static bool MatchingHydrant(HydroHydrantMatchingViewModel input, List<Vmo.AssetsHydrantMainVmo> hydrantVmos)
+        {
+            bool isNotarize = false; //鏄惁纭畾
+            if (hydrantVmos == null || input == null || hydrantVmos.Count == 0)
+            {
+                return true;
+            }
+            Vmo.AssetsHydrantMainVmo vmo = null;
+            var nameMatching = hydrantVmos.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.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+               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 = hydrantVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = hydrantVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                vmo = nameMatching.First();
+            }
+            else
+            {
+                var absoluteMatching = hydrantVmos.Where(i =>
+          ((i.Caliber == null || input.Caliber == null) || Math.Abs(Convert.ToInt64(i.Caliber) - Convert.ToInt64(input.Caliber)) <= _caliberTolerance) &&  //鐩村緞绾︽潫
+           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 = hydrantVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = hydrantVmos.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.ModelType == null)
+                        input.MatchingModelType = vmo.Name;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                }
+                return true;
+            }
+            return false;
+        }
+
+        //鍘嬪姏琛ㄥ尮閰�
+        public static bool MatchingPressmeter(HydroPressmeterMatchingViewModel input, List<Vmo.AssetsPressmeterMainVmo> pressmeterVmos)
+        {
+            bool isNotarize = false; //鏄惁纭畾
+            if (pressmeterVmos == null || input == null || pressmeterVmos.Count == 0)
+            {
+                return true;
+            }
+            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)
+            {
+                var defaultList = nameMatching.Where(x => x.Flags.Contains("榛樿鍊�")).ToList();
+                //鍙栭粯璁�
+                if (defaultList.Count > 0)
+                {
+                    vmo = pressmeterVmos.First();
+                }
+                else if (defaultList.Count <= 0)
+                {
+                    vmo = pressmeterVmos.First();
+                }
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
+            }
+            else
+            {
+                vmo = pressmeterVmos.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.ModelType == null)
+                        input.MatchingModelType = vmo.Name;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingModelType = vmo.Name;
+                }
+                return true;
+            }
+            return false;
+        }
+
+        //杩囨浮浠跺尮閰�
+        public static bool MatchingTranslation(HydroTranslationMatchingViewModel input, List<Vmo.AssetsTranslationMainVmo> translationVmos)
+        {
+            bool isNotarize = false; //鏄惁纭畾
+
+            if (translationVmos == null || input == null || translationVmos.Count == 0)
+            {
+                return true;
+            }
+            Vmo.AssetsTranslationMainVmo vmo = null;
+            var nameMatching = translationVmos.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 = translationVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = translationVmos.First();
+            }
+            else if (nameMatching.Count == 1)
+            {
+                isNotarize = true;
+
+                vmo = nameMatching.First();
+            }
+            else
+            {
+                var absoluteMatching = translationVmos.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 = translationVmos.First();
+                    }
+                }
+                else if (absoluteMatching.Count == 1)
+                {
+                    isNotarize = true;
+
+                    vmo = absoluteMatching.First();
+                }
+                else
+                    vmo = translationVmos.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.ModelType == null)
+                        input.MatchingModelType = vmo.Name;
+                    if (input.Roughness < 0)
+                        input.MatchingRoughness = vmo.Roughness;
+                    if (input.EndDiameter < 0)
+                        input.MatchingEndDiameter = vmo.EndDiameter;
+                    if (input.StartDiameter < 0)
+                        input.MatchingStartDiameter = vmo.StartDiameter;
+                    if (input.Diameter < 0)
+                        input.MatchingDiameter = vmo.Diameter;
+                }
+                else
+                {
+                    input.MatchingMinorLoss = vmo.MinorLoss;
+                    input.MatchingDbId = vmo.ID.ToString();
+                    input.MatchingMaterial = vmo.Material;
+                    input.MatchingModelType = vmo.Name;
+                    input.MatchingDiameter = vmo.Diameter;
+                    input.MatchingEndDiameter = vmo.EndDiameter;
+                    input.MatchingStartDiameter = vmo.StartDiameter;
+                    input.MatchingRoughness = vmo.Roughness;
+                }
+                return true;
+            }
+            return false;
+        }
 
         /// <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;
-
             return string.Join("", str1.Intersect(str2)).Count();
         }
     }

--
Gitblit v1.9.3