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 = "WareFlowRecord", Order = 100)] [Route("api/[Controller]")] public class WareFlowRecordService : IWareFlowRecordService, IDynamicApiController, ITransient { private readonly IRepository _wareFlowRecordRep; public WareFlowRecordService( IRepository wareFlowRecordRep ) { _wareFlowRecordRep = wareFlowRecordRep; } /// /// 分页查询记录流水管理 /// /// /// [HttpGet("page")] public async Task> Page([FromQuery] WareFlowRecordSearch input) { var wareFlowRecords = await _wareFlowRecordRep.DetachedEntities .Where(input.RecordType != null, u => u.RecordType == input.RecordType) .Where(!string.IsNullOrEmpty(input.ReservoirArea), u => u.ReservoirArea == input.ReservoirArea) .Where(!string.IsNullOrEmpty(input.BarCode), u => u.BarCode == input.BarCode) .Where(!string.IsNullOrEmpty(input.SourceWareLocationCode), u => u.SourceWareLocationCode == input.SourceWareLocationCode) .Where(!string.IsNullOrEmpty(input.ToWareLocationCode), u => u.ToWareLocationCode == input.ToWareLocationCode) .Where(!string.IsNullOrEmpty(input.WareContainerCode), u => u.WareContainerCode == input.WareContainerCode) .Where(!string.IsNullOrEmpty(input.WareContainerName), u => u.WareContainerName == input.WareContainerName) .Where(!string.IsNullOrEmpty(input.WareMaterialCode), u => u.WareMaterialCode == input.WareMaterialCode) .Where(!string.IsNullOrEmpty(input.WareMaterialName), u => u.WareMaterialName == input.WareMaterialName) .Where(input.Quantity != null, u => u.Quantity == input.Quantity) .Where(input.Status != null, u => u.Status == input.Status) .Where(!string.IsNullOrEmpty(input.Remarks), u => u.Remarks == input.Remarks) .OrderBy(PageInputOrder.OrderBuilder(input)) .ProjectToType() .ToADPagedListAsync(input.PageNo, input.PageSize); return wareFlowRecords; } /// /// 增加记录流水管理 /// /// /// [HttpPost("add")] public async Task Add(AddWareFlowRecordInput input) { var wareFlowRecord = input.Adapt(); await _wareFlowRecordRep.InsertAsync(wareFlowRecord); } /// /// 删除记录流水管理 /// /// /// [HttpPost("delete")] public async Task Delete(DeleteWareFlowRecordInput input) { var wareFlowRecord = await _wareFlowRecordRep.FirstOrDefaultAsync(u => u.Id == input.Id); await _wareFlowRecordRep.DeleteAsync(wareFlowRecord); } /// /// 更新记录流水管理 /// /// /// [HttpPost("edit")] public async Task Update(UpdateWareFlowRecordInput input) { var isExist = await _wareFlowRecordRep.AnyAsync(u => u.Id == input.Id, false); if (!isExist) throw Oops.Oh(ErrorCode.D3000); var wareFlowRecord = input.Adapt(); await _wareFlowRecordRep.UpdateAsync(wareFlowRecord,ignoreNullValues:true); } /// /// 获取记录流水管理 /// /// /// [HttpGet("detail")] public async Task Get([FromQuery] QueryeWareFlowRecordInput input) { return (await _wareFlowRecordRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id)).Adapt(); } /// /// 获取记录流水管理列表 /// /// /// [HttpGet("list")] public async Task> List([FromQuery] WareFlowRecordInput input) { return await _wareFlowRecordRep.DetachedEntities.ProjectToType().ToListAsync(); } } }