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;
|
|
namespace IStation.Application
|
{
|
/// <summary>
|
/// MonitorMonthRecord
|
/// </summary>
|
[Route("Run/MonitorMonthRecord")]
|
[ApiDescriptionSettings("Run", Name = "监测月记录", Order = 950)]
|
public class MonitorMonthRecord_Controller : IDynamicApiController
|
{
|
//服务
|
private readonly Service.MonitorMonthRecord _service = new Service.MonitorMonthRecord();
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取最近一条数据
|
/// </summary>
|
[Route("GetLastRecordByMonitorPointID@V1.0")]
|
[HttpGet]
|
public List<MonitorMonthRecordDto> GetLastRecordByMonitorPointID([FromQuery][Required] MonitorPointIDUnderCorpInput input)
|
{
|
var list = _service.GetLastRecord(input.CorpID, input.MonitorPointID);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorMonthRecordPure, MonitorMonthRecordDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointIds 获取最近一条数据
|
/// </summary>
|
[Route("GetLastRecordByMonitorPointIds@V1.0")]
|
[HttpGet]
|
public List<MonitorMonthRecordDto> GetLastRecordByMonitorPointIds([FromQuery][Required] MonitorPointIdsUnderCorpInput input)
|
{
|
var ids = LongListHelper.ToList(input.MonitorPointIds);
|
var list = _service.GetLastRecord(input.CorpID, ids);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorMonthRecordPure, MonitorMonthRecordDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 SignalID 获取最近一条数据
|
/// </summary>
|
[Route("GetLastRecordBySignalID@V1.0")]
|
[HttpGet]
|
public MonitorMonthRecordDto GetLastRecordBySignalID([FromQuery][Required] SignalIDUnderCorpInput input)
|
{
|
var model = _service.GetLastRecord(input.CorpID, input.MonitorPointID, input.SignalID);
|
return model?.Adapt<Model.MonitorMonthRecordPure, MonitorMonthRecordDto>();
|
}
|
|
/// <summary>
|
/// 通过 SignalIds 获取最近一条数据
|
/// </summary>
|
[Route("GetLastRecordBySignalIds@V1.0")]
|
[HttpGet]
|
public List<MonitorMonthRecordDto> GetLastRecordBySignalIds([FromQuery][Required] SignalIdsUnderCorpInput input)
|
{
|
var ids = LongListHelper.ToList(input.SignalIds);
|
var list = _service.GetLastRecord(input.CorpID, input.MonitorPointID, ids);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorMonthRecordPure, MonitorMonthRecordDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取某年的数据
|
/// </summary>
|
[Route("GetByMonitorPointIDOfYear@V1.0")]
|
[HttpGet]
|
public List<MonitorMonthRecordDto> GetByMonitorPointIDOfYear
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 必须大于0")]
|
long CorpID,
|
[Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
|
long MonitorPointID,
|
[Required]
|
int Year
|
)
|
{
|
var list = _service.GetByMonitorPointIDOfYear(CorpID, MonitorPointID, Year);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorMonthRecord, MonitorMonthRecordDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取某月的数据
|
/// </summary>
|
[Route("GetByMonitorPointIDOfMonth@V1.0")]
|
[HttpGet]
|
public List<MonitorMonthRecordDto> GetByMonitorPointIDOfMonth
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 必须大于0")]
|
long CorpID,
|
[Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
|
long MonitorPointID,
|
[Required]
|
int Year,
|
[Required, Range(1, 12, ErrorMessage = "Month 必须介于1-12之间")]
|
int Month
|
)
|
{
|
|
var list = _service.GetByMonitorPointIDOfMonth(CorpID, MonitorPointID, Year, Month);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorMonthRecord, MonitorMonthRecordDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取年区间内的数据
|
/// </summary>
|
[Route("GetByMonitorPointIDOfYearRange@V1.0")]
|
[HttpGet]
|
public List<MonitorMonthRecordDto> GetByMonitorPointIDOfYearRange
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 必须大于0")]
|
long CorpID,
|
[Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
|
long MonitorPointID,
|
[Required]
|
int StartYear,
|
[Required]
|
int EndYear
|
)
|
{
|
|
var list = _service.GetByMonitorPointIDOfYearRange(CorpID, MonitorPointID, StartYear, EndYear);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorMonthRecord, MonitorMonthRecordDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取月区间内的数据
|
/// </summary>
|
[Route("GetByMonitorPointIDOfMonthRange@V1.0")]
|
[HttpGet]
|
public List<MonitorMonthRecordDto> GetByMonitorPointIDOfMonthRange
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "CorpID 必须大于0")]
|
long CorpID,
|
[Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
|
long MonitorPointID,
|
[Required]
|
int StartYear,
|
[Required, Range(1, 12, ErrorMessage = "StartMonth 必须介于1-12之间")]
|
int StartMonth,
|
[Required]
|
int EndYear,
|
[Required, Range(1, 12, ErrorMessage = "EndMonth 必须介于1-12之间")]
|
int EndMonth
|
)
|
{
|
var list = _service.GetByMonitorPointIDOfMonthRange(CorpID, MonitorPointID, StartYear, StartMonth, EndYear, EndMonth);
|
var vm_list = list?.Select(x => x.Adapt<Model.MonitorMonthRecord, MonitorMonthRecordDto>()).ToList();
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 补录一条
|
/// </summary>
|
[Route("InsertSupplement@V1.0")]
|
[HttpPost]
|
public bool InsertSupplement([Required] SupplementMonitorMonthRecordInput input)
|
{
|
var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(input.CorpID, input.MonitorPointID);
|
if (monitor.CronType != Model.Monitor.eCronType.EachMonth)
|
{
|
return false;
|
}
|
var bol = false;
|
var dataTime = DateTime.Now;
|
switch (monitor.MonitorType)
|
{
|
case Model.eMonitorType.General:
|
{
|
var signal = monitor.SignalList?.FirstOrDefault();
|
if (signal != null)
|
{
|
var data_status = new List<string>();
|
var data_value = MonitorHandleHelper.Handle(monitor, signal, lastRecord: null, input.SrcTime, input.SrcValue, data_status);
|
if (!string.IsNullOrEmpty(data_value))
|
{
|
var record = new Model.MonitorMonthRecordPure();
|
record.CorpID = input.CorpID;
|
record.MonitorPointID = input.MonitorPointID;
|
record.SignalID = signal.ID;
|
record.RecordType = monitor.MonitorType;
|
record.SrcTime = input.SrcTime;
|
record.SrcValue = input.SrcValue;
|
record.DataTime = dataTime;
|
record.DataValue = data_value;
|
record.DataStatus = data_status;
|
record.DataYear= input.DataYear;
|
record.DataMonth = input.DataMonth;
|
bol = _service.InsertSupplement(record);
|
}
|
}
|
}
|
break;
|
case Model.eMonitorType.Vibration:
|
{
|
var sub_record_list = AddMonitorSubRecordInput.ToList(input.SrcValue);
|
if (sub_record_list != null && sub_record_list.Count > 0)
|
{
|
var record_list = new List<Model.MonitorMonthRecordPure>();
|
foreach (var sub_record in sub_record_list)
|
{
|
var signal = monitor.SignalList?.FirstOrDefault(x => x.ID == sub_record.SignalID);
|
if (signal == null)
|
continue;
|
var data_status = new List<string>();
|
var data_value = MonitorHandleHelper.Handle(monitor, signal, lastRecord: null, input.SrcTime, sub_record.SrcValue, data_status);
|
if (string.IsNullOrEmpty(data_value))
|
continue;
|
var record = new Model.MonitorMonthRecordPure();
|
record.CorpID = input.CorpID;
|
record.MonitorPointID = input.MonitorPointID;
|
record.SignalID = signal.ID;
|
record.RecordType = monitor.MonitorType;
|
record.SrcTime = input.SrcTime;
|
record.SrcValue = sub_record.SrcValue;
|
record.DataTime = dataTime;
|
record.DataValue = data_value;
|
record.DataStatus = data_status;
|
record.DataYear = input.DataYear;
|
record.DataMonth = input.DataMonth;
|
record_list.Add(record);
|
}
|
if (record_list.Count > 0)
|
{
|
bol = _service.InsertsSupplement(record_list);
|
}
|
}
|
}
|
break;
|
default: break;
|
}
|
|
return bol;
|
}
|
|
/// <summary>
|
/// 补录多条
|
/// </summary>
|
[Route("InsertsSupplement@V1.0")]
|
[HttpPost]
|
public bool InsertsSupplement([Required] List<SupplementMonitorMonthRecordInput> list)
|
{
|
var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
|
if (corpIds.Count > 1)
|
{
|
return false;
|
}
|
|
var dataTime = DateTime.Now;
|
var record_list = new List<Model.MonitorMonthRecordPure>();
|
foreach (var item in list)
|
{
|
var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(item.CorpID, item.MonitorPointID);
|
if (monitor.CronType != Model.Monitor.eCronType.EachMonth)
|
{
|
continue;
|
}
|
switch (monitor.MonitorType)
|
{
|
case Model.eMonitorType.General:
|
{
|
var signal = monitor.SignalList?.FirstOrDefault();
|
if (signal != null)
|
{
|
var data_status = new List<string>();
|
var data_value = MonitorHandleHelper.Handle(monitor, signal, lastRecord: null, item.SrcTime, item.SrcValue, data_status);
|
if (!string.IsNullOrEmpty(data_value))
|
{
|
var record = new Model.MonitorMonthRecordPure();
|
record.CorpID = item.CorpID;
|
record.MonitorPointID = item.MonitorPointID;
|
record.SignalID = signal.ID;
|
record.RecordType = monitor.MonitorType;
|
record.SrcTime = item.SrcTime;
|
record.SrcValue = item.SrcValue;
|
record.DataTime = dataTime;
|
record.DataValue = data_value;
|
record.DataStatus = data_status;
|
record.DataYear = item.DataYear;
|
record.DataMonth = item.DataMonth;
|
record_list.Add(record);
|
}
|
}
|
}
|
break;
|
case Model.eMonitorType.Vibration:
|
{
|
var sub_record_list = AddMonitorSubRecordInput.ToList(item.SrcValue);
|
if (sub_record_list != null && sub_record_list.Count > 0)
|
{
|
foreach (var sub_record in sub_record_list)
|
{
|
var signal = monitor.SignalList?.FirstOrDefault(x => x.ID == sub_record.SignalID);
|
if (signal == null)
|
continue;
|
var data_status = new List<string>();
|
var data_value = MonitorHandleHelper.Handle(monitor, signal, lastRecord: null, item.SrcTime, sub_record.SrcValue, data_status);
|
if (string.IsNullOrEmpty(data_value))
|
continue;
|
var record = new Model.MonitorMonthRecordPure();
|
record.CorpID = item.CorpID;
|
record.MonitorPointID = item.MonitorPointID;
|
record.SignalID = signal.ID;
|
record.RecordType = monitor.MonitorType;
|
record.SrcTime = item.SrcTime;
|
record.SrcValue = sub_record.SrcValue;
|
record.DataTime = dataTime;
|
record.DataValue = data_value;
|
record.DataStatus = data_status;
|
record.DataYear = item.DataYear;
|
record.DataMonth = item.DataMonth;
|
record_list.Add(record);
|
}
|
}
|
}
|
break;
|
default: break;
|
}
|
}
|
|
if (record_list.Count < 1)
|
{
|
return false;
|
}
|
var bol = _service.InsertsSupplement(record_list);
|
return bol;
|
}
|
|
}
|
}
|