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;
|
}
|
}
|
}
|