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 WarehouseDetailsService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
private readonly PrintCodeDetailService _codeDetailService;
private readonly MaterialsService _materialsService;
private readonly SysUnitService _sysUnitService;
public WarehouseDetailsService(SqlSugarRepository rep,
PrintCodeDetailService codeDetailService,
MaterialsService materialsService,
SysUnitService sysUnitService)
{
_rep = rep;
_codeDetailService = codeDetailService;
_materialsService = materialsService;
_sysUnitService = sysUnitService;
}
///
/// 分页查询仓库统计
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task> Page(WarehouseDetailsInput input)
{
var query = _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
u.Name.Contains(input.SearchKey.Trim())
|| u.GoodCode.Contains(input.SearchKey.Trim())
|| u.MaterialsNum.Contains(input.SearchKey.Trim())
|| u.Specifications.Contains(input.SearchKey.Trim())
|| u.Classify.Contains(input.SearchKey.Trim())
|| u.Unit.Contains(input.SearchKey.Trim())
|| u.BaseUnit.Contains(input.SearchKey.Trim())
|| u.PackageScale.Contains(input.SearchKey.Trim())
|| u.Batch.Contains(input.SearchKey.Trim())
|| u.Custom.Contains(input.SearchKey.Trim())
|| u.Brand.Contains(input.SearchKey.Trim())
|| u.CodeType.Contains(input.SearchKey.Trim())
|| u.WarehouseLocation.Contains(input.SearchKey.Trim())
|| u.Remarks.Contains(input.SearchKey.Trim())
|| u.ExpandField.Contains(input.SearchKey.Trim())
)
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.GoodCode), u => u.GoodCode.Contains(input.GoodCode.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.MaterialsNum), u => u.MaterialsNum.Contains(input.MaterialsNum.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Specifications), u => u.Specifications.Contains(input.Specifications.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Classify), u => u.Classify.Contains(input.Classify.Trim()))
.WhereIF(input.Count>0, u => u.Count == input.Count)
.WhereIF(!string.IsNullOrWhiteSpace(input.Unit), u => u.Unit.Contains(input.Unit.Trim()))
.WhereIF(input.BaseCount>0, u => u.BaseCount == input.BaseCount)
.WhereIF(!string.IsNullOrWhiteSpace(input.BaseUnit), u => u.BaseUnit.Contains(input.BaseUnit.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.PackageScale), u => u.PackageScale.Contains(input.PackageScale.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Batch), u => u.Batch.Contains(input.Batch.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Custom), u => u.Custom.Contains(input.Custom.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Brand), u => u.Brand.Contains(input.Brand.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeType), u => u.CodeType.Contains(input.CodeType.Trim()))
.WhereIF(input.CodeCount>0, u => u.CodeCount == input.CodeCount)
.WhereIF(!string.IsNullOrWhiteSpace(input.WarehouseLocation), u => u.WarehouseLocation.Contains(input.WarehouseLocation.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Remarks), u => u.Remarks.Contains(input.Remarks.Trim()))
.WhereIF(input.SourceId>0, u => u.SourceId == input.SourceId)
.WhereIF(!string.IsNullOrWhiteSpace(input.ExpandField), u => u.ExpandField.Contains(input.ExpandField.Trim()))
.Select();
if(input.ProductDateRange != null && input.ProductDateRange.Count >0)
{
DateTime? start= input.ProductDateRange[0];
query = query.WhereIF(start.HasValue, u => u.ProductDate > start);
if (input.ProductDateRange.Count >1 && input.ProductDateRange[1].HasValue)
{
var end = input.ProductDateRange[1].Value.AddDays(1);
query = query.Where(u => u.ProductDate < end);
}
}
if(input.LoseDateRange != null && input.LoseDateRange.Count >0)
{
DateTime? start= input.LoseDateRange[0];
query = query.WhereIF(start.HasValue, u => u.LoseDate > start);
if (input.LoseDateRange.Count >1 && input.LoseDateRange[1].HasValue)
{
var end = input.LoseDateRange[1].Value.AddDays(1);
query = query.Where(u => u.LoseDate < end);
}
}
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
}
///
/// 增加仓库统计
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Add")]
public async Task Add(AddWarehouseDetailsInput input)
{
var entity = input.Adapt();
await _rep.InsertAsync(entity);
return entity.Id;
}
///
/// 删除仓库统计
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Delete")]
public async Task Delete(DeleteWarehouseDetailsInput 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(UpdateWarehouseDetailsInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
public async Task UpdateByEntity(WarehouseDetails entity)
{
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
///
/// 获取仓库统计
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task Detail([FromQuery] QueryByIdWarehouseDetailsInput 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 = "GetInventory")]
public async Task GetInventory([FromQuery] QueryByIdWarehousingInput input)
{
var codeDetails = await _codeDetailService.List();
var warehousingCodes = codeDetails.FindAll(a => a.WarehouseID == null || a.WarehouseID < 1);
throw new NotImplementedException();
}
}