2024-04-16 09:05:07 +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 PackageInfoService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<PackageInfo> _rep;
|
|
|
|
|
private readonly SysUnitService _unitService;
|
|
|
|
|
public PackageInfoService(SqlSugarRepository<PackageInfo> rep, SysUnitService unitService)
|
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
|
|
|
|
_unitService = unitService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询包装关系
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Page")]
|
|
|
|
|
public async Task<SqlSugarPagedList<PackageInfoOutput>> Page(PackageInfoInput input)
|
|
|
|
|
{
|
2024-05-20 10:06:52 +00:00
|
|
|
|
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
|
2024-04-16 09:05:07 +00:00
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|
|
|
|
u.CodeTypeNum.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.CodeType.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.PackageName.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.ProductCount.Contains(input.SearchKey.Trim())
|
|
|
|
|
)
|
|
|
|
|
.WhereIF(input.MaterialsId>0, u => u.MaterialsId == input.MaterialsId)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeTypeNum), u => u.CodeTypeNum.Contains(input.CodeTypeNum.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeType), u => u.CodeType.Contains(input.CodeType.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PackageName), u => u.PackageName.Contains(input.PackageName.Trim()))
|
|
|
|
|
.WhereIF(input.UnitId>0, u => u.UnitId == input.UnitId)
|
|
|
|
|
.WhereIF(input.UnitGroupId>0, u => u.UnitGroupId == input.UnitGroupId)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ProductCount), u => u.ProductCount.Contains(input.ProductCount.Trim()))
|
|
|
|
|
.Select<PackageInfoOutput>();
|
|
|
|
|
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(AddPackageInfoInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<PackageInfo>();
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加包装关系
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "AddEntity")]
|
|
|
|
|
public async Task<PackageInfo> AddEntity(AddPackageInfoInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<PackageInfo>();
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除包装关系
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Delete")]
|
|
|
|
|
public async Task Delete(DeletePackageInfoInput 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(UpdatePackageInfoInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<PackageInfo>();
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取包装关系
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Detail")]
|
|
|
|
|
public async Task<PackageInfo> Detail([FromQuery] QueryByIdPackageInfoInput input)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.GetFirstAsync(u => u.Id == input.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取包装关系列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "List")]
|
2024-06-06 10:22:07 +00:00
|
|
|
|
public async Task<List<PackageInfoOutput>> List(long? materialsId)
|
2024-04-16 09:05:07 +00:00
|
|
|
|
{
|
2024-05-24 10:22:01 +00:00
|
|
|
|
var list = await _rep.AsQueryable().Where(u =>!u.IsDelete && u.MaterialsId == materialsId)?.Select<PackageInfoOutput>().ToListAsync();
|
2024-04-16 09:05:07 +00:00
|
|
|
|
if (list != null && list.Count > 5)
|
|
|
|
|
{
|
|
|
|
|
var units = await _unitService.List();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
item.Unit = units.Find(a => a.Id == item.UnitId)?.Name;
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var result = new List<PackageInfo>();
|
|
|
|
|
var newList = new List<AddPackageInfoInput>();
|
|
|
|
|
newList.Add(new AddPackageInfoInput() { IsEnable = true, CodeTypeNum = "BT30", CodeType = "垛", PackageName = "垛", MaterialsId = materialsId });
|
|
|
|
|
newList.Add(new AddPackageInfoInput() { IsEnable = true, CodeTypeNum = "BT25", CodeType = "层", PackageName = "层", MaterialsId = materialsId });
|
|
|
|
|
newList.Add(new AddPackageInfoInput() { IsEnable = true, CodeTypeNum = "BT20", CodeType = "箱", PackageName = "箱", MaterialsId = materialsId });
|
|
|
|
|
newList.Add(new AddPackageInfoInput() { IsEnable = true, CodeTypeNum = "BT15", CodeType = "套", PackageName = "套", MaterialsId = materialsId });
|
|
|
|
|
newList.Add(new AddPackageInfoInput() { IsEnable = true, CodeTypeNum = "BT10", CodeType = "袋", PackageName = "袋", MaterialsId = materialsId });
|
|
|
|
|
newList.Add(new AddPackageInfoInput() { IsEnable = true, CodeTypeNum = "BT00", CodeType = "个", PackageName = "个", MaterialsId = materialsId });
|
|
|
|
|
foreach (var item in newList)
|
|
|
|
|
{
|
|
|
|
|
await Add(item);
|
|
|
|
|
}
|
|
|
|
|
return await _rep.AsQueryable().Where(u => u.MaterialsId == materialsId)?.Select<PackageInfoOutput>().ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|