2024-05-31 10:13:10 +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 ProductWarehousingService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<ProductWarehousing> _rep;
|
|
|
|
|
private readonly WarehouseDetailsService _warehouseDetails;
|
|
|
|
|
private readonly MaterialsService _materialsService;
|
|
|
|
|
private readonly SysUnitService _sysUnitService;
|
|
|
|
|
private readonly MaterialClassifyService _materialClassifyService;
|
|
|
|
|
private readonly WarehousingStatisticsService _warehousingStatisticsService;
|
|
|
|
|
public ProductWarehousingService(SqlSugarRepository<ProductWarehousing> rep,
|
|
|
|
|
WarehouseDetailsService warehouseDetails,
|
|
|
|
|
MaterialsService materialsService,
|
|
|
|
|
SysUnitService sysUnitService,
|
|
|
|
|
MaterialClassifyService materialClassifyService,
|
|
|
|
|
WarehousingStatisticsService warehousingStatisticsService)
|
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
|
|
|
|
_warehouseDetails = warehouseDetails;
|
|
|
|
|
_materialsService = materialsService;
|
|
|
|
|
_sysUnitService = sysUnitService;
|
|
|
|
|
_materialClassifyService = materialClassifyService;
|
|
|
|
|
_warehousingStatisticsService = warehousingStatisticsService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询产品入库
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Page")]
|
|
|
|
|
public async Task<SqlSugarPagedList<ProductWarehousingOutput>> Page(ProductWarehousingInput input)
|
|
|
|
|
{
|
2024-06-04 10:20:10 +00:00
|
|
|
|
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
|
2024-05-31 10:13:10 +00:00
|
|
|
|
.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())
|
|
|
|
|
|| u.WarehousingType.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.CodeNum.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Supplier.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.OddNumber.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.ProductionLine.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(input.MaterialsId>0, u => u.MaterialsId == input.MaterialsId)
|
|
|
|
|
.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(input.WarehouseId>0, u => u.WarehouseId == input.WarehouseId)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ExpandField), u => u.ExpandField.Contains(input.ExpandField.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.WarehousingType), u => u.WarehousingType.Contains(input.WarehousingType.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeNum), u => u.CodeNum.Contains(input.CodeNum.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Supplier), u => u.Supplier.Contains(input.Supplier.Trim()))
|
|
|
|
|
.WhereIF(input.Status>0, u => u.Status == input.Status)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.OddNumber), u => u.OddNumber.Contains(input.OddNumber.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ProductionLine), u => u.ProductionLine.Contains(input.ProductionLine.Trim()))
|
|
|
|
|
.Select<ProductWarehousingOutput>();
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(input.WarehousingDateRange != null && input.WarehousingDateRange.Count >0)
|
|
|
|
|
{
|
|
|
|
|
DateTime? start= input.WarehousingDateRange[0];
|
|
|
|
|
query = query.WhereIF(start.HasValue, u => u.WarehousingDate > start);
|
|
|
|
|
if (input.WarehousingDateRange.Count >1 && input.WarehousingDateRange[1].HasValue)
|
|
|
|
|
{
|
|
|
|
|
var end = input.WarehousingDateRange[1].Value.AddDays(1);
|
|
|
|
|
query = query.Where(u => u.WarehousingDate < end);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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(AddProductWarehousingInput input)
|
|
|
|
|
{
|
|
|
|
|
SysUnitOutput unit = null;
|
2024-06-04 10:20:10 +00:00
|
|
|
|
try
|
2024-05-31 10:13:10 +00:00
|
|
|
|
{
|
2024-06-04 10:20:10 +00:00
|
|
|
|
var materials = await _materialsService.Detail(new QueryByIdMaterialsInput() { Id = input.MaterialsId.Value });
|
|
|
|
|
|
|
|
|
|
string unitScale = string.Empty;
|
|
|
|
|
if (materials != null)
|
2024-05-31 10:13:10 +00:00
|
|
|
|
{
|
2024-06-04 10:20:10 +00:00
|
|
|
|
input.Specifications = materials.Specifications;
|
|
|
|
|
input.CodeNum = materials.CodeNum;
|
|
|
|
|
input.Brand = materials.Brand;
|
|
|
|
|
var units = await _sysUnitService.ListByGroupId(materials.UnitGroupId.Value);
|
|
|
|
|
unit = units.Find(a => a.Name == input.Unit);
|
|
|
|
|
if (unit != null)
|
|
|
|
|
{
|
|
|
|
|
input.BaseCount = input.Count * unit.Rate;
|
|
|
|
|
input.BaseUnit = units.FirstOrDefault(a => a.IsBaseUnit == true).Name;
|
|
|
|
|
unitScale = SysUnitService.GetUnitScale(units);
|
|
|
|
|
}
|
|
|
|
|
input.GoodCode = materials.BarCode;
|
|
|
|
|
input.MaterialsNum = materials.CodeNum;
|
|
|
|
|
input.UnitPrice = materials.Price;
|
|
|
|
|
input.Custom = input.Supplier;
|
|
|
|
|
if (unit != null)
|
|
|
|
|
{
|
|
|
|
|
input.BaseCount = input.Count * unit.Rate;
|
|
|
|
|
}
|
|
|
|
|
input.TotalPrice = input.BaseCount * materials.Price;
|
|
|
|
|
input.PackageScale = unitScale;
|
|
|
|
|
input.Classify = (await _materialClassifyService.Detail(new QueryByIdMaterialClassifyInput() { Id = materials.Classify })).Name;
|
2024-05-31 10:13:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-04 10:20:10 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 10:13:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var entity = input.Adapt<ProductWarehousing>();
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
|
|
|
|
|
var details = await _warehouseDetails.List();
|
|
|
|
|
if (details != null && details.Any(a => a.MaterialsId == input.MaterialsId && a.Unit == input.Unit))
|
|
|
|
|
{
|
|
|
|
|
var detail = details.Find(a => a.MaterialsId == input.MaterialsId && a.Unit == input.Unit);
|
|
|
|
|
detail.Count += input.Count;
|
|
|
|
|
if (unit != null)
|
|
|
|
|
{
|
|
|
|
|
detail.BaseCount = detail.Count * unit.Rate;
|
|
|
|
|
}
|
|
|
|
|
await _warehouseDetails.UpdateByEntity(detail.Adapt<WarehouseDetails>());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var newEnt = input.Adapt<AddWarehouseDetailsInput>();
|
|
|
|
|
newEnt.SourceId = entity.Id;
|
|
|
|
|
var addId = await _warehouseDetails.Add(newEnt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var newDetail = input.Adapt<AddWarehousingStatisticsInput>();
|
|
|
|
|
newDetail.SourceId = entity.Id;
|
|
|
|
|
await _warehousingStatisticsService.Add(newDetail);
|
|
|
|
|
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除产品入库
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Delete")]
|
|
|
|
|
public async Task Delete(DeleteProductWarehousingInput 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(UpdateProductWarehousingInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<ProductWarehousing>();
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取产品入库
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Detail")]
|
|
|
|
|
public async Task<ProductWarehousing> Detail([FromQuery] QueryByIdProductWarehousingInput 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<ProductWarehousingOutput>> List([FromQuery] ProductWarehousingInput input)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.AsQueryable().Select<ProductWarehousingOutput>().ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|