From d5a533d045422407c1b7edfdde9fd19740e478d1 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期二, 27 六月 2023 09:34:58 +0800
Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/IStation/Service.V4.1

---
 Application/IStation.Application.OpenApi/shys/dispatch/DispatchAna_ShysController.cs |  215 +++++++++++++++++++++++++++++------------------------
 1 files changed, 117 insertions(+), 98 deletions(-)

diff --git a/Application/IStation.Application.OpenApi/shys/dispatch/DispatchAna_ShysController.cs b/Application/IStation.Application.OpenApi/shys/dispatch/DispatchAna_ShysController.cs
index daf4a3d..54eb99c 100644
--- a/Application/IStation.Application.OpenApi/shys/dispatch/DispatchAna_ShysController.cs
+++ b/Application/IStation.Application.OpenApi/shys/dispatch/DispatchAna_ShysController.cs
@@ -17,7 +17,7 @@
     /// </summary>
     [Route("OpenApi/DispatchAna/SHYS")]
     [ApiDescriptionSettings("OpenApi", Name = "涓婃捣鍘熸按璋冨害鍒嗘瀽", Order = 1000)]
-    public class DispatchAna_ShysController : IDynamicApiController 
+    public class DispatchAna_ShysController : IDynamicApiController
     {
         /// <summary>
         /// 璁$畻淇濇寔鐨勬柟妗�
@@ -30,10 +30,20 @@
         {
             if (input == null)
                 return default;
-            LogHelper.Debug(JsonHelper.Object2Json(input));
+            //浼楁瘏杩炵画涓ゆ璋冪敤瑙e喅鏂规
+            if (!string.IsNullOrEmpty(_lastFlowId))
+            {
+                if (_lastFlowId == input.flowId)
+                {
+                    LogHelper.Debug($"浼楁瘏閲嶅鍏ュ弬锛歿JsonHelper.Object2Json(input)}");
+                    return default;
+                }
+            }
+            _lastFlowId = input.flowId;
+            LogHelper.Debug($"浼楁瘏鍏ュ弬锛歿JsonHelper.Object2Json(input)}");
             var url_sg = Settings.WebApi.OpenApi.SanGaoDispatchUrl;
-            var responseText = HttpRequestHelper.Post(url_sg,JsonHelper.Object2Json(input));
-            LogHelper.Debug(responseText);
+            var responseText = HttpRequestHelper.Post(url_sg, JsonHelper.Object2Json(input));
+            LogHelper.Debug($"涓夐珮鍑哄弬锛歿responseText}");
             var result_sg = JsonHelper.Json2Object<DispatchFactoryDto>(responseText);
             if (result_sg == null)
                 return default;
@@ -42,13 +52,14 @@
             {
                 case 1://闀垮叴娉电珯
                     {
-                        var result= shys_cxd(input, result_sg,out error_info);
-                        //LogHelper.Debug(JsonHelper.Object2Json(result));
+                        var result = shys_cxd(input, result_sg, out error_info);
+                        LogHelper.Debug($"涔夌淮鍑哄弬锛歿JsonHelper.Object2Json(result)}");
                         return result;
                     }
-                default:return default;
+                default: return default;
             }
         }
+        private static string _lastFlowId = null;
 
         /// <summary>
         /// 璁$畻淇濇寔鐨勬柟妗�
@@ -117,16 +128,16 @@
             var input = new StationDispatchExInput();
             input.flowId = "娴嬭瘯";
             input.type = 1;
-            input.factory = new List<FactoryDispatchInput>() { new FactoryDispatchInput() { id=1,value=200} };
+            input.factory = new List<FactoryDispatchInput>() { new FactoryDispatchInput() { id = 1, value = 200 } };
 
             var result_sg = new DispatchFactoryDto();
             result_sg.result = new List<DispatchBranchDto>();
-            result_sg.result.Add(new DispatchBranchDto() { key= "stationCX_1#_flow",value= flow1 });
+            result_sg.result.Add(new DispatchBranchDto() { key = "stationCX_1#_flow", value = flow1 });
             result_sg.result.Add(new DispatchBranchDto() { key = "stationCX_1#_pressure", value = press1 });
             result_sg.result.Add(new DispatchBranchDto() { key = "stationCX_2#_flow", value = flow2 });
             result_sg.result.Add(new DispatchBranchDto() { key = "stationCX_2#_pressure", value = press2 });
             result_sg.scada = new List<DispatchScadaDto>();
-            result_sg.scada.Add(new DispatchScadaDto() {tagname= "_0402010404030103001",value=waterLevel });
+            result_sg.scada.Add(new DispatchScadaDto() { tagname = "_0402010404030103001", value = waterLevel });
             result_sg.scada.Add(new DispatchScadaDto() { tagname = "_0402010403150103003", value = middleValveStatus });
             result_sg.scada.Add(new DispatchScadaDto() { tagname = "_0402010403010101003", value = runStatus1 });
             result_sg.scada.Add(new DispatchScadaDto() { tagname = "_0402010403010201003", value = runStatus2 });
@@ -174,13 +185,15 @@
             }
             else
             {
-                water_level = scada_water.value;
+                water_level = Math.Round( scada_water.value,2);
             }
-      
+
             complex_request_paras.InletPipePara = new List<IStation.Calculation.DispatchAna.Model.InletPipePara>();
-            complex_request_paras.InletPipePara.Add(new IStation.Calculation.DispatchAna.Model.InletPipePara() {
-                Name = "鍚告按浜曟恫浣�", 
-                Value = water_level });
+            complex_request_paras.InletPipePara.Add(new IStation.Calculation.DispatchAna.Model.InletPipePara()
+            {
+                Name = "鍚告按浜曟恫浣�",
+                Value = water_level
+            });
 
 
 
@@ -191,7 +204,7 @@
                 middleValveStatus = (int)scada_middle_vavle.value;
             complex_request_paras.ValvePara = new List<IStation.Calculation.DispatchAna.Model.ValvePara>();
             complex_request_paras.ValvePara.Add(new IStation.Calculation.DispatchAna.Model.ValvePara() { Name = "涓棿闃�闂�", OpenStatus = middleValveStatus });
- 
+
 
             //鏈烘车 寮�鍋滄満鐘舵��
             List<long> machine_id_array = new List<long> { 19, 22, 25, 28 };
@@ -200,7 +213,7 @@
             var scada_runstatus1 = result_sg.scada.Find(t => t.tagname == "_0402010403010101003");
             if (scada_runstatus1 != null && (int)scada_runstatus1.value == 1)
                 machine_run_status.Add(machine_id_array[0]);
- 
+
             //2鍙锋车寮�鏈虹姸鎬�
             var scada_runstatus2 = result_sg.scada.Find(t => t.tagname == "_0402010403010201003");
             if (scada_runstatus2 != null && (int)scada_runstatus2.value == 1)
@@ -226,15 +239,15 @@
             IStation.Calculation.DispatchAna.Model.OutletPipePara pipe1 = new Calculation.DispatchAna.Model.OutletPipePara();
             pipe1.Name = "涓�鍙风";
             var flow1 = result_sg.result.Find(x => x.key == "stationCX_1#_flow");
-            if(flow1 == null)
+            if (flow1 == null)
             {
                 error_info = "涓�鍙风娴侀噺鏃犳硶鑾峰彇";
                 return null;
             }
             else
             {
-                pipe1.TargetFlow = flow1.value;
-            } 
+                pipe1.TargetFlow = Math.Round(flow1.value,0);
+            }
             var press1 = result_sg.result.Find(x => x.key == "stationCX_1#_pressure");
             if (press1 == null)
             {
@@ -243,15 +256,15 @@
             }
             else
             {
-                pipe1.TargetPress = press1.value;
-            }    
+                pipe1.TargetPress = Math.Round(press1.value,4);
+            }
             var pipe1_val = result_sg.scada.Find(t => t.tagname == "_0402010403150101003");
             if (pipe1_val != null)
             {
-                pipe1.ValveStatus =  (int)pipe1_val.value;
+                pipe1.ValveStatus = (int)pipe1_val.value;
             }
-             
-    
+
+
 
             //2鍙风
             IStation.Calculation.DispatchAna.Model.OutletPipePara pipe2 = new Calculation.DispatchAna.Model.OutletPipePara();
@@ -264,9 +277,9 @@
             }
             else
             {
-                pipe2.TargetFlow = flow2.value;
+                pipe2.TargetFlow = Math.Round(flow2.value,0);
             }
-           
+
             var press2 = result_sg.result.Find(x => x.key == "stationCX_2#_pressure");
             if (press2 == null)
             {
@@ -275,14 +288,14 @@
             }
             else
             {
-                pipe2.TargetPress = press2.value;
-            } 
+                pipe2.TargetPress = Math.Round(press2.value,4);
+            }
             var pipe2_val = result_sg.scada.Find(t => t.tagname == "_0402010403150102003");
             if (pipe2_val != null)
             {
                 pipe2.ValveStatus = (int)pipe2_val.value;
             }
-    
+
 
             complex_request_paras.OutletPipePara = new List<IStation.Calculation.DispatchAna.Model.OutletPipePara>(2);
             complex_request_paras.OutletPipePara.Add(pipe1);
@@ -293,7 +306,7 @@
 
             //鏋勯�犺绠楀櫒
             var calulator = IStation.Calculation.DispatchAnalyCalculatorFactory.CreateKeepStatusCalculator(4,
-                IStation.ObjectType.Station, 2,null);
+                IStation.ObjectType.Station, 2, null);
             calulator.IntialRequest(complex_request_paras,
                     null,
                     machine_run_status);
@@ -303,14 +316,14 @@
             var pipe1_val_flow_real = result_sg.scada.Find(t => t.tagname == "_0402010403030002001");
             if (pipe1_val_flow_real != null && pipe1_val_flow_real.value > 100)
             {//瀹炴椂閲�,  stationCX_2#_flow" 涓夐珮缁欑殑鐩爣閲�
-                real_total_flow_pipe1 = pipe1_val_flow_real.value;
+                real_total_flow_pipe1 = Math.Round( pipe1_val_flow_real.value,0);
             }
-            
+
             double real_oulet_press_pipe1 = 0;
             var pipe1_val_press_real = result_sg.scada.Find(t => t.tagname == "_0402010403030002005");
-            if (pipe1_val_press_real != null && pipe1_val_press_real.value > 100)
-            {//瀹炴椂閲�,  stationCX_2#_flow" 涓夐珮缁欑殑鐩爣閲�
-                real_oulet_press_pipe1 = pipe1_val_press_real.value;
+            if (pipe1_val_press_real != null)
+            {//瀹炴椂閲�,  "stationCX_2#_flow" 鏄� 涓夐珮缁欑殑鐩爣閲�
+                real_oulet_press_pipe1 = Math.Round(pipe1_val_press_real.value,5);
             }
 
 
@@ -318,19 +331,17 @@
             var pipe2_val_flow_real = result_sg.scada.Find(t => t.tagname == "_0402010403030002002");
             if (pipe2_val_flow_real != null && pipe2_val_flow_real.value > 100)
             {
-                real_total_flow_pipe2 = pipe2_val_flow_real.value;
+                real_total_flow_pipe2 = Math.Round(pipe2_val_flow_real.value,0);
             }
 
             double real_oulet_press_pipe2 = 0;
             var pipe2_val_press_real = result_sg.scada.Find(t => t.tagname == "_0402010403030002006");
-            if (pipe2_val_press_real != null && pipe2_val_press_real.value > 100)
+            if (pipe2_val_press_real != null)
             {//瀹炴椂閲�,  stationCX_2#_flow" 涓夐珮缁欑殑鐩爣閲�
-                real_oulet_press_pipe2 = pipe2_val_press_real.value;
+                real_oulet_press_pipe2 = Math.Round(pipe2_val_press_real.value,5);
             }
 
-            #endregion
-
-
+ 
             //鍑烘柟妗� 
             var scheme = calulator.Calc(out error_info);
             if (scheme == null)
@@ -423,59 +434,13 @@
                     pump_item.Name = machine_names[pump_item.Index];
                 }
 
-
                 result.Pumps.Add(pump_item);
-                
-
- 
             }
 
+            #endregion
 
-
-            
+            #region 淇
             if (machine_run_status.Count == 1)
-            {//淇濊瘉寮�涓�鍙版车鏃�, 娴侀噺澶� 棰戠巼涔熷ぇ, 娴侀噺灏� , 棰戠巼涔熷皬
-                if(pipe1.TargetFlow + pipe2.TargetFlow > 100)
-                {
-                    double current_total_flow = 0;
-                    if (pipe1.TargetFlow > 100)
-                        current_total_flow = pipe1.TargetFlow;
-                    else
-                        current_total_flow = pipe2.TargetFlow;
-
- 
-                    var open_pump = result.Pumps.First();
-                    var fr_hz_tag_name = machine_frq_hz_target_name[open_pump.Index];
-                    var current_val_fr_hz = result_sg.scada.Find(t => t.tagname == fr_hz_tag_name);
-                    if (current_val_fr_hz != null && current_val_fr_hz.value > 10)
-                    {
-                        if (current_total_flow < scheme.TotalWrkQ && current_val_fr_hz.value > open_pump.Frequency)
-                        {//淇濊瘉瓒嬪娍姝g‘
-                            open_pump.Frequency = Math.Round(current_val_fr_hz.value * scheme.TotalWrkQ / current_total_flow, 2);
-                        }
-                        else if (current_total_flow > scheme.TotalWrkQ && current_val_fr_hz.value < open_pump.Frequency)
-                        {//淇濊瘉瓒嬪娍姝g‘
-                            open_pump.Frequency = Math.Round(current_val_fr_hz.value * scheme.TotalWrkQ / current_total_flow, 2);
-                        }
-                        else
-                        {//鍘熸按鍙嶉 , 鐢ㄦ洸绾胯绠�, 棰戠巼鍋忎綆, 浜轰负澧炲姞0.5HZ
-                            if (open_pump.Frequency < 49.5)
-                            {
-                                open_pump.Speed = Math.Round
-                                    (open_pump.Speed * (open_pump.Frequency + 0.5) / (open_pump.Frequency),0);
-                                open_pump.Frequency = open_pump.Frequency + 0.5;
-                            }
-
-                            if (open_pump.Frequency > 50)
-                            {
-                                open_pump.Frequency = 50;                           
-                            }
-                                
-                        }
-                    }
-                }
-            }
-            else
             {
                 result.Pumps.ForEach(x =>
                 {//鍘熸按鍙嶉 , 鐢ㄦ洸绾胯绠�, 棰戠巼鍋忎綆, 浜轰负澧炲姞0.5HZ
@@ -483,21 +448,75 @@
                     {
                         if (x.Frequency < 49.5)
                         {
-                            x.Speed = Math.Round
-                                (x.Speed * (x.Frequency + 0.5) / (x.Frequency), 0);
+                            //x.Speed = Math.Round
+                            //    (x.Speed * (x.Frequency + 0.5) / (x.Frequency), 0);
                             x.Frequency = x.Frequency + 0.5;
-                        } 
+                            x.Speed = Math.Round(740 * x.Frequency / 50, 1);
+                        }
                     }
-                    if (x.Frequency > 50)
-                        x.Frequency = 50;
+                });
+
+                //if (pipe1.TargetFlow + pipe2.TargetFlow > 100)
+                //{
+                //    double current_total_flow = 0;
+                //    if (pipe1.TargetFlow > 100)
+                //        current_total_flow = pipe1.TargetFlow;
+                //    else
+                //        current_total_flow = pipe2.TargetFlow;
+                //    var open_pump = result.Pumps.First();
+                //    var fr_hz_tag_name = machine_frq_hz_target_name[open_pump.Index];
+                //    var current_val_fr_hz = result_sg.scada.Find(t => t.tagname == fr_hz_tag_name);
+                //    if (current_val_fr_hz != null && current_val_fr_hz.value > 10)
+                //    {
+                //        bool isCor = false;
+                //        if (current_total_flow < scheme.TotalWrkQ && current_val_fr_hz.value > open_pump.Frequency)
+                //        {//淇濊瘉瓒嬪娍姝g‘
+                //            isCor = true;
+                //            open_pump.Note = string.Format("ORI_{0}", open_pump.Frequency);
+                //            open_pump.Frequency = Math.Round(current_val_fr_hz.value * scheme.TotalWrkQ / current_total_flow, 1);
+                //        }
+                //        else if (current_total_flow > scheme.TotalWrkQ && current_val_fr_hz.value < open_pump.Frequency)
+                //        {//淇濊瘉瓒嬪娍姝g‘
+                //            isCor = true;
+                //            open_pump.Note = string.Format("ORI_{0}", open_pump.Frequency);
+                //            open_pump.Frequency = Math.Round(current_val_fr_hz.value * scheme.TotalWrkQ / current_total_flow, 1);
+                //        }
+
+                //    }
+                //}
+            }
+            else
+            {
+                result.Pumps.ForEach(x =>
+                {//鍘熸按鍙嶉 , 鐢ㄦ洸绾胯绠�, 棰戠巼鍋忎綆, 浜轰负澧炲姞0.3HZ
+                    if (x.Frequency > 10)
+                    {
+                        if (x.Frequency < 49.7)
+                        {
+                            x.Frequency = x.Frequency + 0.3;
+                            x.Speed = Math.Round(740 * x.Frequency / 50, 1);
+                        }
+                    }
                 });
             }
 
+            #endregion
+
+            result.Pumps.ForEach(x =>
+            {//鍐嶆鏌ヤ竴涓嬭浆閫�
+                if (x.Frequency > 10)
+                {
+                    x.Frequency = Math.Round(x.Frequency, 1);
+                    x.Speed = Math.Round(740 * x.Frequency / 50, 1);
+                }
+                if (x.Frequency >= 50)
+                {
+                    x.Frequency = 50;
+                    x.Speed = 740;
+                }
+            });
             return result;
         }
-
-
-
 
 
     }

--
Gitblit v1.9.3