using Furion.DatabaseAccessor;
|
using Furion.DatabaseAccessor.Extensions;
|
using Furion.DependencyInjection;
|
using Furion.DynamicApiController;
|
using Furion.FriendlyException;
|
using iWare.Wms.Core;
|
using Mapster;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.EntityFrameworkCore;
|
using System.Linq.Dynamic.Core;
|
|
namespace iWare.Wms.Application
|
{
|
/// <summary>
|
/// 设备报警记录服务
|
/// </summary>
|
[ApiDescriptionSettings("统计查询", Name = "WareDeviceWarning", Order = 100)]
|
[Route("api/[Controller]")]
|
public class WareDeviceWarningService : IWareDeviceWarningService, IDynamicApiController, ITransient
|
{
|
private readonly IRepository<WareDeviceWarning,MasterDbContextLocator> _wareDeviceWarningRep;
|
|
|
public WareDeviceWarningService(
|
IRepository<WareDeviceWarning,MasterDbContextLocator> wareDeviceWarningRep
|
)
|
{
|
_wareDeviceWarningRep = wareDeviceWarningRep;
|
}
|
|
/// <summary>
|
/// 分页查询设备报警记录
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet("page")]
|
public async Task<PageResult<WareDeviceWarningOutput>> Page([FromQuery] WareDeviceWarningSearch input)
|
{
|
var wareDeviceWarnings = await _wareDeviceWarningRep.DetachedEntities
|
.Where(input.WarningTime != null, u => u.WarningTime == input.WarningTime)
|
.Where(!string.IsNullOrEmpty(input.DeviceCode), u => u.DeviceCode == input.DeviceCode)
|
.Where(!string.IsNullOrEmpty(input.DeviceName), u => EF.Functions.Like(u.DeviceName, $"%{input.DeviceName.Trim()}%"))
|
.Where(!string.IsNullOrEmpty(input.WarningCode), u => u.WarningCode == input.WarningCode)
|
.Where(!string.IsNullOrEmpty(input.WarningDbAddress), u => u.WarningDbAddress == input.WarningDbAddress)
|
.Where(!string.IsNullOrEmpty(input.WarningContent), u => u.WarningContent == input.WarningContent)
|
.Where(input.Status != null, u => u.Status == input.Status)
|
.Where(!string.IsNullOrEmpty(input.StatusName), u => u.StatusName == input.StatusName)
|
.Where(!string.IsNullOrEmpty(input.CloseContent), u => u.CloseContent == input.CloseContent)
|
.Where(input.FinishTime != null, u => u.FinishTime == input.FinishTime)
|
.Where(!string.IsNullOrEmpty(input.DurationTime), u => u.DurationTime == input.DurationTime)
|
.Where(!string.IsNullOrEmpty(input.OperationRemark), u => u.OperationRemark == input.OperationRemark)
|
.Where(input.DeviceType != null, u => u.DeviceType == input.DeviceType)
|
.Where(!string.IsNullOrEmpty(input.DeviceTypeName), u => u.DeviceTypeName == input.DeviceTypeName)
|
//.OrderBy(PageInputOrder.OrderBuilder<WareDeviceWarningSearch>(input))
|
.OrderByDescending(u => u.CreatedTime)
|
.ProjectToType<WareDeviceWarningOutput>()
|
.ToADPagedListAsync(input.PageNo, input.PageSize);
|
return wareDeviceWarnings;
|
}
|
|
/// <summary>
|
/// 增加设备报警记录
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("add")]
|
public async Task Add(AddWareDeviceWarningInput input)
|
{
|
var wareDeviceWarning = input.Adapt<WareDeviceWarning>();
|
await _wareDeviceWarningRep.InsertAsync(wareDeviceWarning);
|
}
|
|
/// <summary>
|
/// 删除设备报警记录
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("delete")]
|
public async Task Delete(DeleteWareDeviceWarningInput input)
|
{
|
var wareDeviceWarning = await _wareDeviceWarningRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
await _wareDeviceWarningRep.DeleteAsync(wareDeviceWarning);
|
}
|
|
/// <summary>
|
/// 更新设备报警记录
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("edit")]
|
public async Task Update(UpdateWareDeviceWarningInput input)
|
{
|
var isExist = await _wareDeviceWarningRep.AnyAsync(u => u.Id == input.Id, false);
|
if (!isExist) throw Oops.Oh(ErrorCode.D3000);
|
|
var wareDeviceWarning = input.Adapt<WareDeviceWarning>();
|
await _wareDeviceWarningRep.UpdateAsync(wareDeviceWarning,ignoreNullValues:true);
|
}
|
|
/// <summary>
|
/// 获取设备报警记录
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet("detail")]
|
public async Task<WareDeviceWarningOutput> Get([FromQuery] QueryeWareDeviceWarningInput input)
|
{
|
return (await _wareDeviceWarningRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id)).Adapt<WareDeviceWarningOutput>();
|
}
|
|
/// <summary>
|
/// 获取设备报警记录列表
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet("list")]
|
public async Task<List<WareDeviceWarningOutput>> List([FromQuery] WareDeviceWarningInput input)
|
{
|
return await _wareDeviceWarningRep.DetachedEntities.ProjectToType<WareDeviceWarningOutput>().ToListAsync();
|
}
|
|
}
|
}
|