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;
namespace IStation.Application
{
///
/// MonitorMonthRecord
///
[Route("Run/MonitorMonthRecord/Mgr")]
[ApiDescriptionSettings("Run", Name = "监测月记录(管理)", Order = 950)]
public class MonitorMonthRecord_MgrController : IDynamicApiController
{
//服务
private readonly Service.MonitorMonthRecord _service = new Service.MonitorMonthRecord();
#region 通过 MonitorPointID 获取
///
/// 通过 MonitorPointID 获取(未进行单位转换,使用的是系统单位)
///
[Route("GetByMonitorPointID@V1.0")]
[HttpGet]
public List GetByMonitorPointID_V1_0([FromQuery][Required] MonitorPointIDUnderCorpInput input)
{
var list = _service.GetByMonitorPointID(input.CorpID, input.MonitorPointID);
var vmList = list?.Select(x => new MonitorMonthRecordMgrDto(x)).ToList();
return vmList;
}
///
/// 通过 MonitorPointID 获取某年的数据(未进行单位转换,使用的是系统单位)
///
[Route("GetByMonitorPointIDOfYear@V1.0")]
[HttpGet]
public List GetByMonitorPointIDOfYear_V1_0
(
[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 vmList = list?.Select(x => new MonitorMonthRecordMgrDto(x)).ToList();
return vmList;
}
///
/// 通过 MonitorPointID 获取某月的数据(未进行单位转换,使用的是系统单位)
///
[Route("GetByMonitorPointIDOfMonth@V1.0")]
[HttpGet]
public List GetByMonitorPointIDOfMonth_V1_0
(
[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 vmList = list?.Select(x => new MonitorMonthRecordMgrDto(x)).ToList();
return vmList;
}
///
/// 通过 MonitorPointID 获取年区间内的数据(未进行单位转换,使用的是系统单位)
///
[Route("GetByMonitorPointIDOfYearRange@V1.0")]
[HttpGet]
public List GetByMonitorPointIDOfYearRange_V1_0
(
[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 vmList = list?.Select(x => new MonitorMonthRecordMgrDto(x)).ToList();
return vmList;
}
///
/// 通过 MonitorPointID 获取月区间内的数据(未进行单位转换,使用的是系统单位)
///
[Route("GetByMonitorPointIDOfMonthRange@V1.0")]
[HttpGet]
public List GetByMonitorPointIDOfMonthRange_V1_0
(
[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 vmList = list?.Select(x => new MonitorMonthRecordMgrDto(x)).ToList();
return vmList;
}
#endregion
#region 更新
///
/// 更新
///
[Route("Update@V1.0")]
[HttpPut]
public bool Update([Required] UpdateMonitorMonthRecordInput input)
{
var model = new Model.MonitorMonthRecord()
{
ID = input.ID,
CorpID = input.CorpID,
MonitorPointID = input.MonitorPointID,
SignalID = input.SignalID,
RecordType = input.RecordType,
DataYear= input.DataYear,
DataMonth= input.DataMonth,
SrcTime = input.SrcTime,
SrcValue = input.SrcValue,
DataTime = input.DataTime,
DataValue = input.DataValue,
DataStatus = input.DataStatus
};
var bol = _service.Update(model);
return bol;
}
///
/// 批量更新
///
[Route("Updates@V1.0")]
[HttpPut]
public bool Updates([Required] List list)
{
if (list == null || list.Count < 1)
return default;
var modelList = list.Select(x => new Model.MonitorMonthRecord()
{
ID = x.ID,
CorpID = x.CorpID,
MonitorPointID = x.MonitorPointID,
SignalID = x.SignalID,
RecordType = x.RecordType,
DataYear = x.DataYear,
DataMonth = x.DataMonth,
SrcTime = x.SrcTime,
SrcValue = x.SrcValue,
DataTime = x.DataTime,
DataValue = x.DataValue,
DataStatus = x.DataStatus
}).ToList();
var bol = _service.Updates(modelList);
return bol;
}
#endregion
#region 补录
///
/// 补录一条(已弃用,请选用管理下相关接口)
///
[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();
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();
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();
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;
}
///
/// 补录多条(已弃用,请选用管理下相关接口)
///
[Route("InsertsSupplement@V1.0")]
[HttpPost]
public bool InsertsSupplement([Required] List 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();
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();
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();
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;
}
#endregion
#region 重录
///
/// 重录一条(重录会删除已存在的记录)
///
[Route("InsertAgain@V1.0")]
[HttpPost]
public bool InsertAgain([Required] AgainMonitorMonthRecordInput 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();
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.InsertAgain(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();
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();
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.InsertsAgain(record_list);
}
}
}
break;
default: break;
}
return bol;
}
///
/// 重录多条(重录会删除已存在的记录)
///
[Route("InsertsAgain@V1.0")]
[HttpPost]
public bool InsertsAgain([Required] List 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();
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();
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();
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.InsertsAgain(record_list);
return bol;
}
#endregion
}
}