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>
|
/// MonitorGeneralYearRecord
|
/// </summary>
|
[Route("Run/MonitorGeneralYearRecord/Mgr")]
|
[ApiDescriptionSettings("Run", Name = "监测常规年记录(管理)", Order = 930)]
|
public class MonitorGeneralYearRecord_MgrController : IDynamicApiController
|
{
|
|
/// <summary>
|
/// 重新分析某个年份份区间(仅针对一个常规年分析测点的分析,会删除已有记录)
|
/// </summary>
|
[Route("AnalyAgainOfYearRange@V1.0")]
|
[HttpPost]
|
public AnalyAgainMonitorGeneralYearRecordOfYearRangeResultDto AnalyAgainOfYearRange
|
([Required] AnalyAgainMonitorGeneralYearRecordOfYearRangeInput input)
|
{
|
var corpId = input.CorpID;
|
var monitorId = input.MonitorPointID;
|
var startYear=input.StartYear;
|
var endYear=input.EndYear;
|
var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(corpId, monitorId);
|
if (monitor == null)
|
{
|
throw Oops.Oh(ErrorCodes.D001, $"测点:{monitorId}");
|
}
|
if (monitor.CronType != Model.Monitor.eCronType.EachYear)
|
{
|
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 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.MonitorYearRecord().GetBySignalIDOfYear(corpId, x, y, startYear-1);
|
});
|
var getRecordList = new Func<long, long,Model.Monitor.eCronType, DateTime,DateTime, List<Model.MonitorBasicRecord>>((x, y,cy, st,et) => {
|
switch (cy)
|
{
|
case Model.Monitor.eCronType.Real:
|
{
|
return new Service.MonitorRealRecord()
|
.GetFixedBySignalIDOfTimeRange(corpId,x,y,10000,st,et)?.Select(x=>x as Model.MonitorBasicRecord).ToList();
|
}
|
case Model.Monitor.eCronType.EachDay:
|
{
|
return new Service.MonitorDayRecord().GetBySignalIDOfDayRange
|
(monitor.CorpID, x, y,st.Date,et.Date.AddDays(-1))?.Select(x=>x as Model.MonitorBasicRecord).ToList();
|
}
|
case Model.Monitor.eCronType.EachMonth:
|
{
|
return new Service.MonitorMonthRecord().GetBySignalIDOfMonthRange
|
(monitor.CorpID, x, y, st.Year, st.Month, et.AddDays(-1).Year, et.AddDays(-1).Month)?.Select(x => x as Model.MonitorBasicRecord).ToList();
|
}
|
default:return default;
|
}
|
});
|
|
List<Model.MonitorYearRecordPure> recordList = null;
|
string msg = string.Empty;
|
switch (analyModel.FormulaType)
|
{
|
case Model.Monitor.FormulaType.Statistics_Max://最大值统计
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.StatisticalYearMaxValue
|
(startYear,endYear, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Statistics_Min://最小值统计
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.StatisticalYearMinValue
|
(startYear, endYear, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Statistics_Avg://平均值统计
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.StatisticalYearAvgValue
|
(startYear, endYear, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Statistics_Diff://差值统计
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.StatisticalYearDiffValue
|
(startYear, endYear, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
case Model.Monitor.FormulaType.Statistics_Sum://和值统计
|
{
|
recordList = MonitorFormulaHistoryCalcuHelper.StatisticalYearSumValue
|
(startYear, endYear, monitor, analyModel.FormulaParas, getMonitorPoint, getRecordList, getLastRecord, out msg);
|
}
|
break;
|
default: msg = $"不支持的公式类型:{analyModel.FormulaType}"; break;
|
}
|
|
if (recordList == null || recordList.Count < 1)
|
{
|
return new AnalyAgainMonitorGeneralYearRecordOfYearRangeResultDto(false, msg);
|
}
|
var bol = new Service.MonitorYearRecord().InsertsAgain(recordList);
|
return new AnalyAgainMonitorGeneralYearRecordOfYearRangeResultDto(bol, msg);
|
}
|
|
|
|
}
|
}
|