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 { /// /// 设备报警记录服务 /// [ApiDescriptionSettings("统计查询", Name = "WareDeviceWarning", Order = 100)] [Route("api/[Controller]")] public class WareDeviceWarningService : IWareDeviceWarningService, IDynamicApiController, ITransient { private readonly IRepository _wareDeviceWarningRep; public WareDeviceWarningService( IRepository wareDeviceWarningRep ) { _wareDeviceWarningRep = wareDeviceWarningRep; } /// /// 分页查询设备报警记录 /// /// /// [HttpGet("page")] public async Task> 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(input)) .OrderByDescending(u => u.CreatedTime) .ProjectToType() .ToADPagedListAsync(input.PageNo, input.PageSize); return wareDeviceWarnings; } /// /// 增加设备报警记录 /// /// /// [HttpPost("add")] public async Task Add(AddWareDeviceWarningInput input) { var wareDeviceWarning = input.Adapt(); await _wareDeviceWarningRep.InsertAsync(wareDeviceWarning); } /// /// 删除设备报警记录 /// /// /// [HttpPost("delete")] public async Task Delete(DeleteWareDeviceWarningInput input) { var wareDeviceWarning = await _wareDeviceWarningRep.FirstOrDefaultAsync(u => u.Id == input.Id); await _wareDeviceWarningRep.DeleteAsync(wareDeviceWarning); } /// /// 更新设备报警记录 /// /// /// [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(); await _wareDeviceWarningRep.UpdateAsync(wareDeviceWarning,ignoreNullValues:true); } /// /// 获取设备报警记录 /// /// /// [HttpGet("detail")] public async Task Get([FromQuery] QueryeWareDeviceWarningInput input) { return (await _wareDeviceWarningRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id)).Adapt(); } /// /// 获取设备报警记录列表 /// /// /// [HttpGet("list")] public async Task> List([FromQuery] WareDeviceWarningInput input) { return await _wareDeviceWarningRep.DetachedEntities.ProjectToType().ToListAsync(); } } }