using Admin.NET.Core.Service;
using Admin.NET.Application.Const;
using Admin.NET.Application.Entity;
using Microsoft.AspNetCore.Http;
namespace Admin.NET.Application;
///
/// 出库详细服务
///
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
public class OutboundDetailService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
public OutboundDetailService(SqlSugarRepository rep)
{
_rep = rep;
}
///
/// 分页查询出库详细
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task> 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();
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
}
///
/// 增加出库详细
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Add")]
public async Task Add(AddOutboundDetailInput input)
{
var entity = input.Adapt();
await _rep.InsertAsync(entity);
return entity.Id;
}
///
/// 删除出库详细
///
///
///
[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); //真删除
}
///
/// 更新出库详细
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Update")]
public async Task Update(UpdateOutboundDetailInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
///
/// 获取出库详细
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task Detail([FromQuery] QueryByIdOutboundDetailInput input)
{
return await _rep.GetFirstAsync(u => u.Id == input.Id);
}
///
/// 获取出库详细列表
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "List")]
public async Task> List()
{
return await _rep.AsQueryable().Select().ToListAsync();
}
///
/// 获取出库详细
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "GetByOutboundId")]
public async Task GetByOutboundId(long? outboundId)
{
return await _rep.GetFirstAsync(u => u.OutboundId == outboundId);
}
}