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 WarehousingService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
public WarehousingService(SqlSugarRepository rep)
{
_rep = rep;
}
///
/// 分页查询入库单
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task> Page(WarehousingInput input)
{
var query = _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
u.CodeNum.Contains(input.SearchKey.Trim())
|| u.BusinessType.Contains(input.SearchKey.Trim())
|| u.Supplier.Contains(input.SearchKey.Trim())
)
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeNum), u => u.CodeNum.Contains(input.CodeNum.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.Supplier), u => u.Supplier.Contains(input.Supplier.Trim()))
.WhereIF(input.ExaminerId>0, u => u.ExaminerId == input.ExaminerId)
.Select();
if(input.StartDateRange != null && input.StartDateRange.Count >0)
{
DateTime? start= input.StartDateRange[0];
query = query.WhereIF(start.HasValue, u => u.StartDate > start);
if (input.StartDateRange.Count >1 && input.StartDateRange[1].HasValue)
{
var end = input.StartDateRange[1].Value.AddDays(1);
query = query.Where(u => u.StartDate < end);
}
}
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
}
///
/// 增加入库单
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Add")]
public async Task Add(AddWarehousingInput input)
{
var entity = input.Adapt();
await _rep.InsertAsync(entity);
return entity.Id;
}
///
/// 删除入库单
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
public async Task Delete(DeleteWarehousingInput 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(UpdateWarehousingInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
///
/// 获取入库单
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task Detail([FromQuery] QueryByIdWarehousingInput input)
{
return await _rep.GetFirstAsync(u => u.Id == input.Id);
}
///
/// 获取入库单列表
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "List")]
public async Task> List()
{
return await _rep.AsQueryable().Select().ToListAsync();
}
}