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 Mapster;
|
using IStation.Calculation;
|
using IStation.Model;
|
using Microsoft.AspNetCore.Authorization;
|
using Furion.FriendlyException;
|
|
namespace IStation.Application
|
{
|
/// <summary>
|
/// MonitorGeneralRealRecord
|
/// </summary>
|
[Route("Run/MonitorGeneralRealRecord/Mgr")]
|
[ApiDescriptionSettings("Run", Name = "监测常规实时记录(管理)", Order = 930)]
|
public class MonitorGeneralRealRecord_MgrController : IDynamicApiController
|
{
|
/// <summary>
|
/// 重新分析某天(仅针对一个常规实时分析测点一天的分析,会删除已有记录)
|
/// </summary>
|
[Route("AnalyAgainOfDay@V1.0")]
|
[HttpPost]
|
public AnalyAgainMonitorGeneralRealRecordOfDayResultDto AnalyAgainOfDay([Required] AnalyAgainMonitorGeneralRealRecordOfDayInput input)
|
{
|
var corpId = input.CorpID;
|
var monitorId = input.MonitorPointID;
|
var day = input.Day;
|
var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(corpId,monitorId);
|
if (monitor == null)
|
{
|
throw Oops.Oh(ErrorCodes.D001, $"测点:{monitorId}");
|
}
|
if (monitor.CronType != Model.Monitor.eCronType.Real)
|
{
|
throw Oops.Oh(ErrorCodes.D002, $"测点:{monitorId}","不是实时测点");
|
}
|
if (monitor.SourceType != Model.Monitor.eSourceType.Analyse)
|
{
|
throw Oops.Oh(ErrorCodes.D002, $"测点:{monitorId}", "不是分析测点");
|
}
|
if (string.IsNullOrEmpty(monitor.SourceParas))
|
{
|
throw Oops.Oh(ErrorCodes.D002, $"测点:{monitorId}", "未配置分析参数");
|
}
|
var analyModel = Model.Monitor.AnalyseParameters.ToModel(monitor.SourceParas);
|
if (analyModel == null)
|
{
|
throw Oops.Oh(ErrorCodes.D002, $"测点:{monitorId}", "分析参数配置错误");
|
}
|
if (string.IsNullOrEmpty(analyModel.FormulaType))
|
{
|
throw Oops.Oh(ErrorCodes.D002, $"测点:{monitorId}", "未配置公式类型");
|
}
|
if (string.IsNullOrEmpty(analyModel.FormulaParas))
|
{
|
throw Oops.Oh(ErrorCodes.D002, $"测点:{monitorId}", "未配置公式参数");
|
}
|
|
var startTime = day.Date;//开始时间
|
var endTime = day.AddDays(1).Date.AddSeconds(-1);//结束时间
|
var getMonitorPoint = new Func<long, Model.MonitorPoint_Signal_SignalType>(x => {
|
return new Service.MonitorPoint().GetExSignalWithSignalTypeByID(corpId, x);
|
});
|
var getLastRecord = new Func<long,long, Model.MonitorBasicRecord>((x,y) => {
|
return new Service.MonitorRealRecord().GetLastBySignalIDOfDay(corpId, x, y, day.AddDays(-1));
|
});
|
var getRecordList = new Func<long, long, List<Model.MonitorBasicRecord>>((x, y) => {
|
return new Service.MonitorRealRecord().GetBySignalIDOfDay(corpId, x, y, day)?.Select(t=>t as Model.MonitorBasicRecord).ToList();
|
});
|
|
List<Model.MonitorRealRecordPure> recordList = null;
|
string msg = string.Empty;
|
switch (analyModel.FormulaType)
|
{
|
case Model.Monitor.FormulaType.Calculation_SingleMapping://单一映射转换
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuSingleMapping
|
(startTime,endTime,monitor,analyModel.FormulaParas,getMonitorPoint,getRecordList,getLastRecord,out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_CompareMapping://比较映射转换
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuCompareMapping
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_RangeMapping://区间映射转换
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuRangeMapping
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_OnceRatio://一元系数换算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuOnceRatio
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_TwiceRatio://二元系数换算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuTwiceRatio
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_RunStatus://运行状态计算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuRunStatus
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_Sum://和值计算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuSum
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_Diff://差值计算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuDiff
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_NumericAccumulate://数值累积计算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuNumberAccumulate
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_EnumAccumulate://枚举累积计算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuEnumAccumulate
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_E://效率计算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuE
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_WP://千吨能耗计算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuWP
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Calculation_UWP://单位能耗计算
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.CalcuUWP
|
(startTime, endTime, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
default:msg = $"不支持的公式类型:{analyModel.FormulaType}";break;
|
}
|
|
if (recordList == null || recordList.Count < 1)
|
{
|
return new AnalyAgainMonitorGeneralRealRecordOfDayResultDto(false, msg);
|
}
|
var bol = new Service.MonitorRealRecord().InsertsAgain(recordList);
|
return new AnalyAgainMonitorGeneralRealRecordOfDayResultDto(bol, msg);
|
}
|
|
|
|
}
|
}
|