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 Microsoft.AspNetCore.Http;
|
using Furion.DependencyInjection;
|
using Microsoft.AspNetCore.Authorization;
|
using Furion.DataEncryption;
|
using Furion.FriendlyException;
|
|
namespace IStation.Application
|
{
|
/// <summary>
|
/// MonitorRecord
|
/// </summary>
|
[AllowAnonymous]
|
[Route("LinuxTest/MonitorRecord")]
|
[ApiDescriptionSettings("LinuxTest", Name = "监测记录", Order = 999)]
|
public class MonitorRecord_Controller : IDynamicApiController, ITransient
|
{
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
/// <summary>
|
///
|
/// </summary>
|
public MonitorRecord_Controller(IHttpContextAccessor httpContextAccessor)
|
{
|
_httpContextAccessor = httpContextAccessor;
|
}
|
|
//服务
|
private readonly Service.MonitorRecord _service = new Service.MonitorRecord();
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
[Route("Insert@V1.0")]
|
[HttpPost]
|
public bool Insert([Required] AddMonitorRecordInput input)
|
{
|
if (input == null)
|
return default;
|
var model = input.Adapt<AddMonitorRecordInput, Model.MonitorRecord>();
|
var bol = _service.InsertLastRecord(model, out bool redis);
|
if (!redis)
|
{
|
throw Oops.Oh("Redis 创建失败!");
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
[Route("Inserts@V1.0")]
|
[HttpPost]
|
public bool Inserts([Required] List<AddMonitorRecordInput> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
return false;
|
var list = inputList.Select(x => x.Adapt<AddMonitorRecordInput, Model.MonitorRecord>()).ToList();
|
var bol = _service.InsertsLastRecord(list);
|
return bol;
|
}
|
|
#endregion
|
|
#region 获取所有
|
|
/// <summary>
|
/// 获取所有
|
/// </summary>
|
[Route("GetAll")]
|
[HttpGet]
|
public List<MonitorRecordDto> GetAll()
|
{
|
var list = _service.GetAll();
|
var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
#endregion
|
|
#region 获取最近记录
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取最近一条数据
|
/// </summary>
|
[Route("GetLastRecordByMonitorPointID")]
|
[HttpGet]
|
public MonitorRecordDto GetLastRecordByMonitorPointID([FromQuery][Required] MonitorPointIDInput input)
|
{
|
var model = _service.GetLastRecord( input.MonitorPointID);
|
if (model == null)
|
return default;
|
return new MonitorRecordDto(model);
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointIds 获取最近一条数据
|
/// </summary>
|
[Route("GetLastRecordByMonitorPointIds")]
|
[HttpGet]
|
public List<MonitorRecordDto> GetLastRecordByMonitorPointIds([FromQuery][Required] MonitorPointIdsInput input)
|
{
|
var ids = LongListHelper.ToList(input.MonitorPointIds);
|
var list = _service.GetLastRecord(ids);
|
var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
#endregion
|
|
#region 通过测点标识获取
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取某天的数据
|
/// </summary>
|
[Route("GetByMonitorPointIDOfDay")]
|
[HttpGet]
|
public List<MonitorRecordDto> GetByMonitorPointIDOfDay
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
|
long MonitorPointID,
|
[Required]
|
DateTime Day
|
)
|
{
|
var list = _service.GetByMonitorPointIDOfDay( MonitorPointID, Day);
|
var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取日期区间内的数据
|
/// </summary>
|
[Route("GetByMonitorPointIDOfDayRange")]
|
[HttpGet]
|
public List<MonitorRecordDto> GetByMonitorPointIDOfDayRange
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
|
long MonitorPointID,
|
[Required]
|
DateTime StartDay,
|
[Required]
|
DateTime EndDay
|
)
|
{
|
if (StartDay.Date > EndDay.Date)
|
{
|
return default;
|
}
|
var list = _service.GetByMonitorPointIDOfDayRange( MonitorPointID, StartDay, EndDay);
|
var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取时间区间内的数据
|
/// </summary>
|
[Route("GetByMonitorPointIDOfTimeRange")]
|
[HttpGet]
|
public List<MonitorRecordDto> GetByMonitorPointIDOfTimeRange
|
(
|
[Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
|
long MonitorPointID,
|
[Required]
|
DateTime StartTime,
|
[Required]
|
DateTime EndTime
|
)
|
{
|
if (StartTime > EndTime)
|
{
|
return default;
|
}
|
var list = _service.GetByMonitorPointIDOfTimeRange( MonitorPointID, StartTime, EndTime);
|
var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
|
return vmList;
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
}
|
}
|