DigitalFactory/Admin.NET/Admin.NET.Application/Service/OutboundDetail/OutboundDetailService.cs

118 lines
3.6 KiB
C#
Raw Normal View History

2024-06-14 10:08:48 +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 OutboundDetailService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<OutboundDetail> _rep;
public OutboundDetailService(SqlSugarRepository<OutboundDetail> rep)
{
_rep = rep;
}
/// <summary>
/// 分页查询出库详细
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task<SqlSugarPagedList<OutboundDetailOutput>> Page(OutboundDetailInput input)
{
var query = _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
u.CodeTableIds.Contains(input.SearchKey.Trim())
)
.WhereIF(input.OutboundId>0, u => u.OutboundId == input.OutboundId)
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeTableIds), u => u.CodeTableIds.Contains(input.CodeTableIds.Trim()))
.Select<OutboundDetailOutput>();
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(AddOutboundDetailInput input)
{
var entity = input.Adapt<OutboundDetail>();
await _rep.InsertAsync(entity);
return entity.Id;
}
/// <summary>
/// 删除出库详细
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
public async Task Delete(DeleteOutboundDetailInput 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(UpdateOutboundDetailInput input)
{
var entity = input.Adapt<OutboundDetail>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 获取出库详细
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task<OutboundDetail> Detail([FromQuery] QueryByIdOutboundDetailInput 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<OutboundDetailOutput>> List()
{
return await _rep.AsQueryable().Select<OutboundDetailOutput>().ToListAsync();
}
/// <summary>
/// 获取出库详细
/// </summary>
/// <param name="outboundId"></param>
/// <returns></returns>
[HttpGet]
[ApiDescriptionSettings(Name = "GetByOutboundId")]
public async Task<OutboundDetail> GetByOutboundId(long? outboundId)
{
return await _rep.GetFirstAsync(u => u.OutboundId == outboundId);
}
}