tangxu
2023-04-10 dfdb157df49c99d5599688fa6209ec2dc9f1afbc
Application/IStation.Application.OpenApi/shys/dispatch/DispatchAna_ShysController.cs
@@ -8,6 +8,7 @@
using System.ComponentModel.DataAnnotations;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using SqlSugar;
namespace IStation.Application
{
@@ -176,8 +177,8 @@
                water_level = scada_water.value;
            }
      
            complex_request_paras.WaterLevelPara = new List<IStation.Calculation.DispatchAna.Model.WaterLevelPara>();
            complex_request_paras.WaterLevelPara.Add(new IStation.Calculation.DispatchAna.Model.WaterLevelPara() {
            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 });
@@ -290,11 +291,46 @@
            complex_request_paras.SchemeSortType = Calculation.DispatchAna.Model.eAnaSchemeSortType.功率;
            complex_request_paras.SchemeNumber = 1;
            //构造计算器
            var calulator = IStation.Calculation.DispatchAnalyCalculatorFactory.CreateKeepStatusCalculator(4, IStation.ObjectType.Station, 2,null);
            //构造计算器
            var calulator = IStation.Calculation.DispatchAnalyCalculatorFactory.CreateKeepStatusCalculator(4,
                IStation.ObjectType.Station, 2,null);
            calulator.IntialRequest(complex_request_paras,
                    null,
                    machine_run_status);
            #region 实时量
            double real_total_flow_pipe1 = 0;
            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;
            }
            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;
            }
            double real_total_flow_pipe2 = 0;
            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;
            }
            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)
            {//实时量,  stationCX_2#_flow" 三高给的目标量
                real_oulet_press_pipe2 = pipe2_val_press_real.value;
            }
            #endregion
            //出方案 
            var scheme = calulator.Calc(out error_info);
            if (scheme == null)
@@ -307,6 +343,48 @@
            result.P = scheme.TotalWrkP;
            result.WP = scheme.WP;
            result.UWP = scheme.UWP;
            result.Scheme = new DispatchAnaCurrentOutput();
            result.Scheme.MiddleValveStatus = middleValveStatus;
            result.Scheme.Pipes = new List<DispatchAnaCurrentOutput.PipeParaOutput>();
            result.Scheme.Pipes.Add(
                new DispatchAnaCurrentOutput.PipeParaOutput()
                {
                    Name = "1#管",
                    TargetFlow = pipe1.TargetFlow,
                    TargetPressure = pipe1.TargetPress,
                    CurrentFlow = real_total_flow_pipe1,
                    CurrentPressure = real_oulet_press_pipe1
                }
                );
            result.Scheme.Pipes.Add(
                new DispatchAnaCurrentOutput.PipeParaOutput()
                {
                    Name = "2#管",
                    TargetFlow = pipe2.TargetFlow,
                    TargetPressure = pipe2.TargetPress,
                    CurrentFlow = real_total_flow_pipe2,
                    CurrentPressure = real_oulet_press_pipe2
                }
            );
            List<string> machine_frq_hz_target_name = new List<string> {
                        "_0402010403010112007",
                        "_0402010403010212019",
                        "_0402010403010312007",
                        "_0402010403010412019" };
            List<string> machine_speed_target_name = new List<string> {
                        "_0402010403010112008",
                        "_0402010403010212020",
                        "_0402010403010312008",
                        "_0402010403010412020" };
            List<string> machine_names = new List<string> {
                        "长兴泵房1号机泵",
                        "长兴泵房2号机泵",
                        "长兴泵房3号机泵",
                        "长兴泵房4号机泵" };
            result.Pumps = new List<IStation.Application.DispatchAnaSchemeItemOutput>();
            foreach (IStation.Calculation.DispatchAna.Model.AnaSchemeItem item in scheme.Items)
            {
@@ -322,17 +400,100 @@
                pump_item.P = item.WorkPointP;
                pump_item.Frequency = item.Frequence;
                pump_item.Speed = item.Speed;
                result.Pumps.Add(pump_item);
                if (pump_item.Index == 0)
                    pump_item.Name = "长兴泵房1号机泵";
                else if (pump_item.Index == 1)
                    pump_item.Name = "长兴泵房2号机泵";
                else if (pump_item.Index == 2)
                    pump_item.Name = "长兴泵房3号机泵";
                else if (pump_item.Index == 3)
                    pump_item.Name = "长兴泵房4号机泵";
                if (pump_item.Index >= 0 && pump_item.Index < 4)
                {
                    //获取实时频率
                    var fr_hz_tag_name = machine_frq_hz_target_name[pump_item.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)
                    {
                        pump_item.CurrentFrequency = current_val_fr_hz.value;
                    }
                    //获取实时转速
                    var speed_tag_name = machine_speed_target_name[pump_item.Index];
                    var current_val_speed = result_sg.scada.Find(t => t.tagname == speed_tag_name);
                    if (current_val_speed != null && current_val_speed.value > 10)
                    {
                        pump_item.CurrentSpeed = current_val_speed.value;
                    }
                    //机泵名称
                    pump_item.Name = machine_names[pump_item.Index];
                }
                result.Pumps.Add(pump_item);
            }
            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)
                        {
                            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)
                        {
                            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
                    if (x.Frequency > 10)
                    {
                        if (x.Frequency < 49.5)
                        {
                            x.Speed = Math.Round
                                (x.Speed * (x.Frequency + 0.5) / (x.Frequency), 0);
                            x.Frequency = x.Frequency + 0.5;
                        }
                    }
                    if (x.Frequency > 50)
                        x.Frequency = 50;
                });
            }
            return result;
        }