1
ningshuxia
2023-04-13 df27c5419af98c9bd179cb3d1fe42251458db107
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Linq;
using System.Data;
 
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Collections.Generic;
using IStation.ViewModel;
using AutoMapper;
using System.IO;
 
namespace IStation.WebApi.Controllers.OpenApi 
{
    internal class DispatchAnaCalcHelper
    {
 
        internal static IStation.Dto.SHYS.AnaScheme Station长兴岛(IStation.Dto.SHYS.DispatchStationEx dispatch)
        {
            if (dispatch == null)
                return new Dto.SHYS.AnaScheme();
 
            var url_sg = @"http://192.168.60.228:8821/Api/wsmp/v1/Chengtou/factoryCalc";
 
            var responseText = EmployeePosition(url_sg, JsonHelper.Object2Json((IStation.Dto.SHYS.DispatchStation)dispatch));
 
            //var responseText = System.IO.File.ReadAllText(@"D:\result.txt");
            var result_sg = JsonHelper.Json2Object<IStation.Dto.SHYS.FactoryResult>(responseText);
            if (result_sg == null)
                return default;
            //LogHelper.Info(responseText);
 
 
 
            var requestParas = new IStation.Model.Calc.DispatchAna.RequestParas();
            requestParas.CorpID = 4;
            requestParas.StationID = 2;
 
            var PipeQ1 = result_sg.result.Find(x => x.key == "stationCX_1#_flow").value;
            var PipeQ2 = result_sg.result.Find(x => x.key == "stationCX_2#_flow").value;
 
 
 
            requestParas.FlowPara = new List<Model.Calc.DispatchAna.TargetFlowPara>();
            requestParas.FlowPara.Add(new Model.Calc.DispatchAna.TargetFlowPara() { Name = "一号管", TargetFlow = PipeQ1 });
            requestParas.FlowPara.Add(new Model.Calc.DispatchAna.TargetFlowPara() { Name = "二号管", TargetFlow = PipeQ2 });
 
 
            var PipePr1 = result_sg.result.Find(x => x.key == "stationCX_1#_pressure").value;
            var PipePr2 = result_sg.result.Find(x => x.key == "stationCX_2#_pressure").value;
            requestParas.PressPara = new List<Model.Calc.DispatchAna.TargetPressPara>();
            requestParas.PressPara.Add(new Model.Calc.DispatchAna.TargetPressPara() { Name = "一号管", TargetPress = PipePr1 });
            requestParas.PressPara.Add(new Model.Calc.DispatchAna.TargetPressPara() { Name = "二号管", TargetPress = PipePr2 });
 
            int middleValveStatus = 1;
            requestParas.ValvePara = new List<Model.Calc.DispatchAna.ValvePara>();
            requestParas.ValvePara.Add(new Model.Calc.DispatchAna.ValvePara() { Name = "中间阀门", OpenStatus = middleValveStatus });
 
 
 
            var monitor_point_list = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID(4, IStation.ObjectType.Station_泵站, 2);
            double water_level = 0;
            foreach (var sg_item in result_sg.scada)
            {
                var monitor_item = monitor_point_list.Find(x => !string.IsNullOrEmpty(x.TerminalId) && x.TerminalId.Contains(sg_item.tagname.Remove(0, 1)));
                if (monitor_item == null)
                    continue;
                if (monitor_item.TagName == "0402010404030103001青草沙水库吸水井液位")
                {
                    water_level = sg_item.value;
                }
            }
            requestParas.WaterLevelPara = new List<Model.Calc.DispatchAna.WaterLevelPara>();
            requestParas.WaterLevelPara.Add(new Model.Calc.DispatchAna.WaterLevelPara() { Name = "吸水井液位", Value = water_level });
 
 
            #region 开停机状态
            List<long> open_machine_ids = new List<long>();
            List<long> machine_id_array = new List<long> { 19, 22, 25, 28 };
 
            if (1 == (int)result_sg.scada.Find(x => x.tagname == "_0402010403010101003").value)
            {
                open_machine_ids.Add(machine_id_array[0]);
            }
            if (1 == (int)result_sg.scada.Find(x => x.tagname == "_0402010403010201003").value)
            {
                open_machine_ids.Add(machine_id_array[1]);
            }
            if (1 == (int)result_sg.scada.Find(x => x.tagname == "_0402010403010301003").value)
            {
                open_machine_ids.Add(machine_id_array[2]);
            }
            if (1 == (int)result_sg.scada.Find(x => x.tagname == "_0402010403010401003").value)
            {
                open_machine_ids.Add(machine_id_array[3]);
            }
 
 
            #endregion
 
 
            var calc_helper = new IStation.Calculation.SHYS.Station.DispatchAnalyCalculator4长兴岛输水泵房();
            string error_info;
            var anaScheme = calc_helper.CalcKeepStatus(requestParas, open_machine_ids, out error_info);
            if (anaScheme == null  )
            {
                LogHelper.Info("没有结果");
                return default;
            }
 
 
            var result = new IStation.Dto.SHYS.AnaScheme();
            result.flowId = dispatch.flowId;
            result.Q = anaScheme.TotalWrkQ;
            result.H = anaScheme.TotalWrkH;
            result.E = anaScheme.TotalWrkE;
            result.P = anaScheme.TotalWrkP;
            result.WP = anaScheme.WP;
            result.UWP = anaScheme.UWP;
            result.Pumps = new List<IStation.Dto.SHYS.AnaSchemeItem>();
            foreach (var item in anaScheme.Items)
            {
                var pump_item = new IStation.Dto.SHYS.AnaSchemeItem();
                pump_item.Id = item.MachineID.ToString();
                pump_item.Index = machine_id_array .FindIndex(x => x == item.MachineID);
                pump_item.Name = item.MachineName;
                pump_item.IsFrequency = item.IsFrequecePump;
                pump_item.IsCurveExtend = item.IsExtendCurve;
                pump_item.Q = item.WorkPointQ;
                pump_item.H = item.WorkPointH;
                pump_item.E = item.WorkPointE;
                pump_item.P = item.WorkPointP;
                pump_item.Frequency = item.Frequence;
                pump_item.Speed = item.Speed;
                result.Pumps.Add(pump_item);
 
                if (item.MachineID == machine_id_array[0])
                    pump_item.Name = "长兴泵房1号机泵";
                else if (item.MachineID == machine_id_array[1])
                    pump_item.Name = "长兴泵房2号机泵";
                else if (item.MachineID == machine_id_array[2])
                    pump_item.Name = "长兴泵房3号机泵";
                else if (item.MachineID == machine_id_array[3])
                    pump_item.Name = "长兴泵房4号机泵";
            }
 
            return result;
        }
 
        private static string EmployeePosition(string url, string EmployeePositionData)
        {
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "EmployeePosition";
            request.ContentType = "application/json";
            request.KeepAlive = false;
            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(EmployeePositionData);
                streamWriter.Flush();
            }
            var response = (HttpWebResponse)request.GetResponse();
            var responseText = string.Empty;
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                responseText = reader.ReadToEnd();
            }
 
            return responseText;
        }
        //转换
        private double MPaToM(double Press)
        {
            return Press * 102;
        }
    }
}