using Furion.DatabaseAccessor;
|
using Furion.DatabaseAccessor.Extensions;
|
using Furion.DependencyInjection;
|
using Furion.DynamicApiController;
|
using Furion.Extras.iWare.Wms.Util.LowCode.Front.Code;
|
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>
|
//[Route("api")]
|
[ApiDescriptionSettings("自己的业务", Name = "WorkPieceOutbound", Order = 100)]
|
[Route("api/[Controller]")]
|
[DisableOpLog]
|
public class WorkPieceOutboundService : IWorkPieceOutboundService, IDynamicApiController, ITransient
|
{
|
private readonly IRepository<WorkPieceOutbound,MasterDbContextLocator> _workPieceOutboundRep;
|
|
|
public WorkPieceOutboundService(
|
IRepository<WorkPieceOutbound,MasterDbContextLocator> workPieceOutboundRep
|
)
|
{
|
_workPieceOutboundRep = workPieceOutboundRep;
|
}
|
|
/// <summary>
|
/// 分页查询工件出库信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet("page")]
|
public async Task<PageResult<WorkPieceOutboundOutput>> Page([FromQuery] WorkPieceOutboundSearch input)
|
{
|
var workPieceOutbounds = await _workPieceOutboundRep.DetachedEntities
|
.Where(!string.IsNullOrEmpty(input.WorkPieceID), u => u.WorkPieceID.Contains(input.WorkPieceID))
|
.Where(!string.IsNullOrEmpty(input.OP80NewCode), u => u.OP80NewCode.Contains(input.OP80NewCode))
|
.Where(!string.IsNullOrEmpty(input.StartTimeBeginTime.ToString()), u => u.WorkPieceOutboundTime >= input.StartTimeBeginTime)
|
.Where(!string.IsNullOrEmpty(input.StartTimeEndTime.ToString()), u => u.WorkPieceOutboundTime <= input.StartTimeEndTime)
|
.OrderBy(PageInputOrder.OrderBuilder<WorkPieceOutboundSearch>(input))
|
.ProjectToType<WorkPieceOutboundOutput>()
|
.ToADPagedListAsync(input.PageNo, input.PageSize);
|
return workPieceOutbounds;
|
}
|
|
/// <summary>
|
/// 增加工件出库信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("add")]
|
public async Task Add(AddWorkPieceOutboundInput input)
|
{
|
var workPieceOutbound = input.Adapt<WorkPieceOutbound>();
|
await _workPieceOutboundRep.InsertAsync(workPieceOutbound);
|
}
|
|
/// <summary>
|
/// 删除工件出库信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("delete")]
|
public async Task Delete(DeleteWorkPieceOutboundInput input)
|
{
|
var workPieceOutbound = await _workPieceOutboundRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
await _workPieceOutboundRep.DeleteAsync(workPieceOutbound);
|
}
|
|
/// <summary>
|
/// 更新工件出库信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("edit")]
|
public async Task Update(UpdateWorkPieceOutboundInput input)
|
{
|
var isExist = await _workPieceOutboundRep.AnyAsync(u => u.Id == input.Id, false);
|
if (!isExist) throw Oops.Oh(ErrorCode.D3000);
|
|
var workPieceOutbound = input.Adapt<WorkPieceOutbound>();
|
await _workPieceOutboundRep.UpdateAsync(workPieceOutbound,ignoreNullValues:true);
|
}
|
|
/// <summary>
|
/// 获取工件出库信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet("detail")]
|
public async Task<WorkPieceOutboundOutput> Get([FromQuery] QueryeWorkPieceOutboundInput input)
|
{
|
return (await _workPieceOutboundRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id)).Adapt<WorkPieceOutboundOutput>();
|
}
|
|
/// <summary>
|
/// 获取工件出库信息列表
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet("list")]
|
public async Task<List<WorkPieceOutboundOutput>> List([FromQuery] WorkPieceOutboundInput input)
|
{
|
return await _workPieceOutboundRep.DetachedEntities.ProjectToType<WorkPieceOutboundOutput>().ToListAsync();
|
}
|
|
/// <summary>
|
/// 撤销工件出库信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost("revoke")]
|
public async Task Revoke(List<DeleteWorkPieceOutboundInput> input)
|
{
|
foreach (var item in input) {
|
var workPieceOutbound = await _workPieceOutboundRep.FirstOrDefaultAsync(u => u.Id == item.Id);
|
if (workPieceOutbound == null)
|
{
|
throw Oops.Oh("工件出库信息不存在");
|
}
|
workPieceOutbound.IsDeleted = true;
|
workPieceOutbound.Remark = workPieceOutbound.Remark??""+"撤销发货";
|
await _workPieceOutboundRep.UpdateAsync(workPieceOutbound);
|
}
|
|
}
|
|
}
|
}
|