using Microsoft.AspNetCore.Mvc;
|
using System.Net;
|
using System.Net.Http.Headers;
|
using Microsoft.Extensions.Hosting.Internal;
|
using Microsoft.AspNetCore.Http.Extensions;
|
using IStation.Untity;
|
using Furion.DynamicApiController;
|
using System.ComponentModel.DataAnnotations;
|
using Microsoft.AspNetCore.Authorization;
|
using IStation.Calculation;
|
using IStation.Dto;
|
using System.Collections.Generic;
|
|
namespace IStation.Application
|
{
|
/// <summary>
|
/// ShysPlanAna
|
/// </summary>
|
[Route("OpenApi/PlanAna/SHYS")]
|
[ApiDescriptionSettings("OpenApi", Name = "上海原水计划分析", Order = 1000)]
|
public class PlanAna_ShysController : IDynamicApiController
|
{
|
private const long _corpId = 4;
|
|
/// <summary>
|
/// 计算
|
/// </summary>
|
[AllowAnonymous]
|
[NonUnify]
|
[Route("Calculate")]
|
[HttpPost]
|
public List<PlanAnaDto> Calculate([Required] List<PlanAnaInput> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
{
|
LogHelper.Error("上海原水能耗计划分析计算接口入参为空");
|
return default;
|
}
|
//debug
|
LogHelper.Debug(JsonHelper.Object2Json(inputList));
|
|
var url_sg = Settings.WebApi.OpenApi.SanGaoPlanUrl;
|
var responseText = HttpRequestHelper.Post(url_sg, JsonHelper.Object2Json(inputList));
|
//debug
|
LogHelper.Debug(responseText);
|
|
var planDataList = JsonHelper.Json2Object<List<PlanAnaData>>(responseText);
|
return CalculateCore(planDataList);
|
}
|
|
/// <summary>
|
/// 计算-调试
|
/// </summary>
|
[AllowAnonymous]
|
[NonUnify]
|
[Route("Calculate@Debug")]
|
[HttpGet]
|
public List<PlanAnaDto> Calculate_debug()
|
{
|
var path = @"D:\WorkData\IStation\result_1024b.json";
|
if (!System.IO.File.Exists(path))
|
return null;
|
|
var responseText = System.IO.File.ReadAllText(path);//(测试用的)
|
var planDataList = JsonHelper.Json2Object<List<PlanAnaData>>(responseText);
|
return CalculateCore(planDataList);
|
}
|
|
/// <summary>
|
/// 分析核心
|
/// </summary>
|
/// <param name="planDataList"></param>
|
/// <returns></returns>
|
private List<PlanAnaDto> CalculateCore(List<PlanAnaData> planDataList)
|
{
|
if (planDataList == null || planDataList.Count < 1)
|
{
|
LogHelper.Error("上海原水能耗计划分析计算三高返回接口出参为空");
|
return default;
|
}
|
if (planDataList.Exists(x => x.datas == null || x.datas.Count < 1))
|
{
|
LogHelper.Error("上海原水能耗计划分析计算三高返回接口出参格式错误");
|
return default;
|
}
|
|
var sg_factoryIds = planDataList.SelectMany(x => x.datas).Select(x => x.factory).Distinct().ToList();
|
var vmList = new List<PlanAnaDto>();
|
foreach (var sg_factoryId in sg_factoryIds)
|
{
|
var vmItem = Ana(planDataList, sg_factoryId);
|
if (vmItem != null)
|
vmList.Add(vmItem);
|
}
|
return vmList;
|
}
|
|
private PlanAnaDto Ana(List<PlanAnaData> planDataList, int sg_factoryId)
|
{
|
//找到相关泵站,并进行计算
|
var stationInfo = ShysPlanHelper.GetStationInfo(sg_factoryId);
|
if (stationInfo == null)
|
{
|
// LogHelper.Error("未找到id:{factoryId},对应的泵站");
|
return null;
|
}
|
|
var stationId = stationInfo.ID;
|
var station = new Service.Station().GetByID(_corpId, stationId);
|
if (station == null)
|
{
|
LogHelper.Error($"上海原水能耗计划分析计算中, 泵站id:{stationId}, 数据库中未找到此泵站");
|
return null;
|
}
|
var calculator = stationInfo.Calculator;
|
if (calculator == null)
|
{
|
LogHelper.Error($"上海原水能耗计划分析计算中, 泵站id:{stationId}, 未构建计算器");
|
return null;
|
}
|
calculator.SetStationID(4, stationInfo.ID);//设置ID
|
|
//构造计算入参
|
var sumRecordList = new List<MonthSumRecord>();
|
foreach (var planData in planDataList)
|
{
|
var sumRecord = new MonthSumRecord();
|
sumRecord.Month = planData.timeflag;
|
sumRecord.HourRecords = new List<HourSumRecord>();
|
var factoryData = planData.datas.Find(t => t.factory == sg_factoryId);
|
for (int i = 0; i <= 23; i++)
|
{
|
var hourSumRecord = new HourSumRecord();
|
hourSumRecord.Hour = i;
|
hourSumRecord.Records = new List<Dto.MonitorRecord4SG>();
|
if (factoryData.scada != null && factoryData.scada.Count > 0)
|
{
|
foreach (var scadaItem in factoryData.scada)
|
{
|
var scadaRecord = new Dto.MonitorRecord4SG();
|
scadaRecord.MonitorTag = scadaItem.tagname;
|
var ff = scadaItem.values.Find(t => t.GetHour() == i);
|
if (ff == null)
|
{
|
if (calculator.IsIgnoreAble(scadaItem.tagname))
|
{
|
scadaRecord.RecordValue = 0;
|
}
|
else if (calculator.Is液位Monitor(scadaItem.tagname))
|
{
|
scadaRecord.RecordValue = 0;
|
}
|
else
|
{
|
LogHelper.Error($"上海原水能耗计划分析计算中, 泵站id:{stationId}, {scadaItem.tagname} 时间点{i}, 未找到数据");
|
return null;
|
}
|
}
|
else
|
{
|
scadaRecord.RecordValue = ff.value;
|
}
|
|
hourSumRecord.Records.Add(scadaRecord);
|
}
|
}
|
sumRecord.HourRecords.Add(hourSumRecord);
|
}
|
sumRecordList.Add(sumRecord);
|
}
|
|
string error_info = "";
|
var resultList = calculator.Calc(station, sg_factoryId, sumRecordList, out error_info);
|
if (resultList == null || resultList.Count() < 1)
|
{
|
LogHelper.Error($"上海原水能耗计划分析计算中,泵站名称:{station.Name} 泵站id:{stationId},计算错误,原因是:{error_info}");
|
return null;
|
}
|
|
//生成返回结果
|
var vmItem = new PlanAnaDto();
|
vmItem.factory = sg_factoryId;
|
vmItem.name = station.Name;
|
vmItem.values = new List<List<double>>();
|
for (int i = 1; i <= 12; i++)
|
{
|
var result = resultList.Find(t => t.Month == i);
|
if (result == null)
|
{
|
vmItem.values.Add(new List<double>() { 0, 0, 0 });
|
}
|
else
|
{
|
vmItem.values.Add(new List<double>() { result.Qt, result.Dt, result.WP });
|
}
|
}
|
|
return vmItem;
|
}
|
|
|
|
|
|
|
|
|
}
|
}
|