DigitalFactory/Admin.NET/Admin.NET.Application/Service/Outbound/OutboundService.cs

117 lines
4.0 KiB
C#
Raw Normal View History

2024-03-20 06:11:00 +00:00
using Admin.NET.Core.Service;
using Admin.NET.Application.Const;
using Admin.NET.Application.Entity;
using Microsoft.AspNetCore.Http;
namespace Admin.NET.Application;
/// <summary>
/// 出库单服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
public class OutboundService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<Outbound> _rep;
public OutboundService(SqlSugarRepository<Outbound> rep)
{
_rep = rep;
}
/// <summary>
/// 分页查询出库单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task<SqlSugarPagedList<OutboundOutput>> Page(OutboundInput input)
{
2024-05-20 10:06:52 +00:00
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
2024-03-20 06:11:00 +00:00
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
u.CodeNum.Contains(input.SearchKey.Trim())
|| u.SourceCodeNum.Contains(input.SearchKey.Trim())
|| u.StartDate.Contains(input.SearchKey.Trim())
|| u.BusinessType.Contains(input.SearchKey.Trim())
|| u.Consignee.Contains(input.SearchKey.Trim())
)
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeNum), u => u.CodeNum.Contains(input.CodeNum.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.SourceCodeNum), u => u.SourceCodeNum.Contains(input.SourceCodeNum.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.StartDate), u => u.StartDate.Contains(input.StartDate.Trim()))
.WhereIF(input.State>0, u => u.State == input.State)
.WhereIF(!string.IsNullOrWhiteSpace(input.BusinessType), u => u.BusinessType.Contains(input.BusinessType.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Consignee), u => u.Consignee.Contains(input.Consignee.Trim()))
.WhereIF(input.ExaminerId>0, u => u.ExaminerId == input.ExaminerId)
.Select<OutboundOutput>();
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
}
/// <summary>
/// 增加出库单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Add")]
public async Task<long> Add(AddOutboundInput input)
{
var entity = input.Adapt<Outbound>();
await _rep.InsertAsync(entity);
return entity.Id;
}
/// <summary>
/// 删除出库单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
public async Task Delete(DeleteOutboundInput input)
{
var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
await _rep.FakeDeleteAsync(entity); //假删除
//await _rep.DeleteAsync(entity); //真删除
}
/// <summary>
/// 更新出库单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Update")]
public async Task Update(UpdateOutboundInput input)
{
var entity = input.Adapt<Outbound>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 获取出库单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task<Outbound> Detail([FromQuery] QueryByIdOutboundInput input)
{
return await _rep.GetFirstAsync(u => u.Id == input.Id);
}
/// <summary>
/// 获取出库单列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "List")]
public async Task<List<OutboundOutput>> List()
{
2024-05-24 10:22:01 +00:00
return await _rep.AsQueryable().Where(a => !a.IsDelete).Select<OutboundOutput>().ToListAsync();
2024-03-20 06:11:00 +00:00
}
}