From 34f29703657162441e5b3c3be03145643d14cbd1 Mon Sep 17 00:00:00 2001 From: liangzongpeng <532365025@qq.com> Date: Tue, 16 Apr 2024 17:05:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E6=96=99=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin.NET.Application/Entity/Materials.cs | 5 + .../Entity/PackageInfo.cs | 66 +++ .../Service/Materials/Dto/MaterialsInput.cs | 408 ++++++++++-------- .../Service/Materials/MaterialsService.cs | 46 +- .../Service/PackageInfo/Dto/PackageInfoDto.cs | 93 ++++ .../PackageInfo/Dto/PackageInfoInput.cs | 196 +++++++++ .../PackageInfo/Dto/PackageInfoOutput.cs | 100 +++++ .../Service/PackageInfo/PackageInfoService.cs | 151 +++++++ 8 files changed, 894 insertions(+), 171 deletions(-) create mode 100644 Admin.NET/Admin.NET.Application/Entity/PackageInfo.cs create mode 100644 Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoDto.cs create mode 100644 Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoInput.cs create mode 100644 Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoOutput.cs create mode 100644 Admin.NET/Admin.NET.Application/Service/PackageInfo/PackageInfoService.cs diff --git a/Admin.NET/Admin.NET.Application/Entity/Materials.cs b/Admin.NET/Admin.NET.Application/Entity/Materials.cs index caba1fa..e2977ac 100644 --- a/Admin.NET/Admin.NET.Application/Entity/Materials.cs +++ b/Admin.NET/Admin.NET.Application/Entity/Materials.cs @@ -129,6 +129,11 @@ public class Materials : EntityTenant [SugarColumn(ColumnName = "PackagId", ColumnDescription = "包装关系ID")] public long? PackagId { get; set; } + [Navigate(NavigateType.OneToOne, nameof(Id))] + [Newtonsoft.Json.JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public List PackageInfos { get; set; } + /// /// 推广ID /// diff --git a/Admin.NET/Admin.NET.Application/Entity/PackageInfo.cs b/Admin.NET/Admin.NET.Application/Entity/PackageInfo.cs new file mode 100644 index 0000000..067d21c --- /dev/null +++ b/Admin.NET/Admin.NET.Application/Entity/PackageInfo.cs @@ -0,0 +1,66 @@ +using Admin.NET.Core; +namespace Admin.NET.Application.Entity; + +/// +/// 包装关系 +/// +[SugarTable("PackageInfo","包装关系")] +public class PackageInfo : EntityTenant +{ + /// + /// 物料Id + /// + [Required] + [SugarColumn(ColumnName = "MaterialsId", ColumnDescription = "物料Id")] + public long MaterialsId { get; set; } + + /// + /// 是否启用 + /// + [Required] + [SugarColumn(ColumnName = "IsEnable", ColumnDescription = "是否启用")] + public bool IsEnable { get; set; } + + /// + /// 条码类型编码 + /// + [SugarColumn(ColumnName = "CodeTypeNum", ColumnDescription = "条码类型编码", Length = 32)] + public string? CodeTypeNum { get; set; } + + /// + /// 条码类型 + /// + [SugarColumn(ColumnName = "CodeType", ColumnDescription = "条码类型", Length = 32)] + public string? CodeType { get; set; } + + /// + /// 包装关系名称 + /// + [SugarColumn(ColumnName = "PackageName", ColumnDescription = "包装关系名称", Length = 32)] + public string? PackageName { get; set; } + + /// + /// 单位Id + /// + [SugarColumn(ColumnName = "UnitId", ColumnDescription = "单位Id")] + public long? UnitId { get; set; } + + /// + /// 单位 + /// + [SugarColumn(ColumnName = "Unit", ColumnDescription = "单位名称", Length = 32)] + public string? Unit { get; set; } + + /// + /// 单位组Id + /// + [SugarColumn(ColumnName = "UnitGroupId", ColumnDescription = "单位组Id")] + public long? UnitGroupId { get; set; } + + /// + /// 产品数量 + /// + [SugarColumn(ColumnName = "ProductCount", ColumnDescription = "产品数量", Length = 32)] + public string? ProductCount { get; set; } + +} diff --git a/Admin.NET/Admin.NET.Application/Service/Materials/Dto/MaterialsInput.cs b/Admin.NET/Admin.NET.Application/Service/Materials/Dto/MaterialsInput.cs index f8a56c7..d0973da 100644 --- a/Admin.NET/Admin.NET.Application/Service/Materials/Dto/MaterialsInput.cs +++ b/Admin.NET/Admin.NET.Application/Service/Materials/Dto/MaterialsInput.cs @@ -3,189 +3,259 @@ using System.ComponentModel.DataAnnotations; namespace Admin.NET.Application; - /// - /// 物料基础输入参数 +/// +/// 物料基础输入参数 +/// +public class MaterialsBaseInput +{ + /// + /// 名称 /// - public class MaterialsBaseInput - { - /// - /// 名称 - /// - public virtual string? Name { get; set; } - - /// - /// 分类 - /// - public virtual long Classify { get; set; } - - /// - /// 编码 - /// - public virtual string? CodeNum { get; set; } - - /// - /// 别名 - /// - public virtual string? AliasName { get; set; } - - /// - /// 助记码 - /// - public virtual string? SimpleNumber { get; set; } - - /// - /// 规格型号 - /// - public virtual string? Specifications { get; set; } - - /// - /// 可用状态 - /// - public virtual bool IsEnable { get; set; } - - /// - /// 备注 - /// - public virtual string? Remarks { get; set; } - - /// - /// 租户Id - /// - public virtual long? TenantId { get; set; } - - /// - /// 创建时间 - /// - public virtual DateTime? CreateTime { get; set; } - - /// - /// 更新时间 - /// - public virtual DateTime? UpdateTime { get; set; } - - /// - /// 创建者Id - /// - public virtual long? CreateUserId { get; set; } - - /// - /// 创建者姓名 - /// - public virtual string? CreateUserName { get; set; } - - /// - /// 修改者Id - /// - public virtual long? UpdateUserId { get; set; } - - /// - /// 修改者姓名 - /// - public virtual string? UpdateUserName { get; set; } - - /// - /// 软删除 - /// - public virtual bool IsDelete { get; set; } - - } + public virtual string? Name { get; set; } /// - /// 物料分页查询输入参数 + /// 分类 /// - public class MaterialsInput : BasePageInput - { - /// - /// 关键字查询 - /// - public string? SearchKey { get; set; } - - /// - /// 名称 - /// - public string? Name { get; set; } - - /// - /// 分类 - /// - public long? Classify { get; set; } - - /// - /// 编码 - /// - public string? CodeNum { get; set; } - - /// - /// 别名 - /// - public string? AliasName { get; set; } - - /// - /// 助记码 - /// - public string? SimpleNumber { get; set; } - - /// - /// 规格型号 - /// - public string? Specifications { get; set; } - - /// - /// 可用状态 - /// - public bool? IsEnable { get; set; } - - } + public virtual long Classify { get; set; } /// - /// 物料增加输入参数 + /// 编码 /// - public class AddMaterialsInput : MaterialsBaseInput - { - /// - /// 分类 - /// - [Required(ErrorMessage = "分类不能为空")] - public override long Classify { get; set; } - - /// - /// 可用状态 - /// - [Required(ErrorMessage = "可用状态不能为空")] - public override bool IsEnable { get; set; } - - /// - /// 软删除 - /// - [Required(ErrorMessage = "软删除不能为空")] - public override bool IsDelete { get; set; } - - } + public virtual string? CodeNum { get; set; } /// - /// 物料删除输入参数 + /// 别名 /// - public class DeleteMaterialsInput : BaseIdInput - { - } + public virtual string? AliasName { get; set; } /// - /// 物料更新输入参数 + /// 助记码 /// - public class UpdateMaterialsInput : MaterialsBaseInput - { - /// - /// 主键Id - /// - [Required(ErrorMessage = "主键Id不能为空")] - public long Id { get; set; } - - } + public virtual string? SimpleNumber { get; set; } /// - /// 物料主键查询输入参数 + /// 规格型号 /// - public class QueryByIdMaterialsInput : DeleteMaterialsInput - { + public virtual string? Specifications { get; set; } - } + /// + /// 可用状态 + /// + public virtual bool IsEnable { get; set; } + + /// + /// 品牌 + /// + public virtual string? Brand { get; set; } + + /// + /// 保质期 + /// + public virtual int? ShelfLife { get; set; } + + /// + /// 保质期单位 + /// + public virtual string? ShelfLifeUnit { get; set; } + + /// + /// 统一零售价 + /// + public virtual decimal? Price { get; set; } + + /// + /// 条形码 + /// + public virtual string? BarCode { get; set; } + + /// + /// 单位组ID + /// + public virtual long? UnitGroupId { get; set; } + + /// + /// 基本单位 + /// + public virtual string? Unit { get; set; } + + /// + /// 生产单位 + /// + public virtual string? ProductUnit { get; set; } + + /// + /// 采购单位 + /// + public virtual string? ProcureUnit { get; set; } + + /// + /// 库存单位 + /// + public virtual string? InventoryUnit { get; set; } + + /// + /// 销售单位 + /// + public virtual string? SaleUnit { get; set; } + + /// + /// 分销单位 + /// + public virtual string? RetailStoreUnit { get; set; } + + /// + /// 包装关系ID + /// + //public virtual long? PackagId { get; set; } + + /// + /// 推广ID + /// + public virtual long? PromotionId { get; set; } + + /// + /// 备注 + /// + public virtual string? Remarks { get; set; } + + /// + /// 租户Id + /// + public virtual long? TenantId { get; set; } + + /// + /// 创建时间 + /// + public virtual DateTime? CreateTime { get; set; } + + /// + /// 更新时间 + /// + public virtual DateTime? UpdateTime { get; set; } + + /// + /// 创建者Id + /// + public virtual long? CreateUserId { get; set; } + + /// + /// 创建者姓名 + /// + public virtual string? CreateUserName { get; set; } + + /// + /// 修改者Id + /// + public virtual long? UpdateUserId { get; set; } + + /// + /// 修改者姓名 + /// + public virtual string? UpdateUserName { get; set; } + + /// + /// 软删除 + /// + public virtual bool IsDelete { get; set; } + +} + +/// +/// 物料分页查询输入参数 +/// +public class MaterialsInput : BasePageInput +{ + /// + /// 关键字查询 + /// + public string? SearchKey { get; set; } + + /// + /// 名称 + /// + public string? Name { get; set; } + + /// + /// 分类 + /// + public long? Classify { get; set; } + + /// + /// 编码 + /// + public string? CodeNum { get; set; } + + /// + /// 别名 + /// + public string? AliasName { get; set; } + + /// + /// 助记码 + /// + public string? SimpleNumber { get; set; } + + /// + /// 规格型号 + /// + public string? Specifications { get; set; } + + /// + /// 可用状态 + /// + public bool? IsEnable { get; set; } + +} + +/// +/// 物料增加输入参数 +/// +public class AddMaterialsInput : MaterialsBaseInput +{ + /// + /// 分类 + /// + [Required(ErrorMessage = "分类不能为空")] + public override long Classify { get; set; } + + /// + /// 可用状态 + /// + [Required(ErrorMessage = "可用状态不能为空")] + public override bool IsEnable { get; set; } + + /// + /// 软删除 + /// + [Required(ErrorMessage = "软删除不能为空")] + public override bool IsDelete { get; set; } + +} + +/// +/// 物料删除输入参数 +/// +public class DeleteMaterialsInput : BaseIdInput +{ +} + +/// +/// 物料更新输入参数 +/// +public class UpdateMaterialsInput : MaterialsBaseInput +{ + /// + /// 主键Id + /// + [Required(ErrorMessage = "主键Id不能为空")] + public long Id { get; set; } + +} + +/// +/// 物料主键查询输入参数 +/// +public class QueryByIdMaterialsInput : DeleteMaterialsInput +{ + +} diff --git a/Admin.NET/Admin.NET.Application/Service/Materials/MaterialsService.cs b/Admin.NET/Admin.NET.Application/Service/Materials/MaterialsService.cs index 5bbbaf4..8ba9473 100644 --- a/Admin.NET/Admin.NET.Application/Service/Materials/MaterialsService.cs +++ b/Admin.NET/Admin.NET.Application/Service/Materials/MaterialsService.cs @@ -10,9 +10,18 @@ namespace Admin.NET.Application; public class MaterialsService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; - public MaterialsService(SqlSugarRepository rep) + private readonly SysUnitService _repUnit; + private readonly SysUnitGroupService _repUnitGroup; + private readonly PackageInfoService _repPackage; + public MaterialsService(SqlSugarRepository rep, + PackageInfoService repPackage, + SysUnitService repUnit, + SysUnitGroupService repUnitGroup) { _rep = rep; + _repPackage = repPackage; + _repUnit = repUnit; + _repUnitGroup = repUnitGroup; } /// @@ -92,7 +101,13 @@ public class MaterialsService : IDynamicApiController, ITransient [ApiDescriptionSettings(Name = "Detail")] public async Task Detail([FromQuery] QueryByIdMaterialsInput input) { - return await _rep.GetFirstAsync(u => u.Id == input.Id); + //return await _rep.GetFirstAsync(u => u.Id == input.Id); + var model = await _rep.GetFirstAsync(u => u.Id == input.Id); + if (model != null) + { + model.PackageInfos = await GetPackageList(input.Id); + } + return model; } /// @@ -107,7 +122,34 @@ public class MaterialsService : IDynamicApiController, ITransient return await _rep.AsQueryable().Select().ToListAsync(); } + /// + /// 获取物料 + /// + /// + /// + [HttpGet] + [ApiDescriptionSettings(Name = "GetById")] + public async Task GetById(long materialsId) + { + var model = await _rep.GetFirstAsync(u => u.Id == materialsId); + if (model!=null) + { + model.PackageInfos = await GetPackageList(materialsId); + } + return model; + } + /// + /// 获取包装关系列表 + /// + /// + /// + [HttpGet] + [ApiDescriptionSettings(Name = "PackageList")] + public async Task> GetPackageList(long materialsId) + { + return await _repPackage.List(materialsId); + } diff --git a/Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoDto.cs b/Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoDto.cs new file mode 100644 index 0000000..43786e8 --- /dev/null +++ b/Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoDto.cs @@ -0,0 +1,93 @@ +namespace Admin.NET.Application; + + /// + /// 包装关系输出参数 + /// + public class PackageInfoDto + { + /// + /// 主键Id + /// + public long Id { get; set; } + + /// + /// 物料Id + /// + public long MaterialsId { get; set; } + + /// + /// 是否启用 + /// + public bool IsEnable { get; set; } + + /// + /// 条码类型编码 + /// + public string? CodeTypeNum { get; set; } + + /// + /// 条码类型 + /// + public string? CodeType { get; set; } + + /// + /// 包装关系名称 + /// + public string? PackageName { get; set; } + + /// + /// 单位Id + /// + public long? UnitId { get; set; } + + /// + /// 单位组Id + /// + public long? UnitGroupId { get; set; } + + /// + /// 产品数量 + /// + public string? ProductCount { get; set; } + + /// + /// 租户Id + /// + public long? TenantId { get; set; } + + /// + /// 创建时间 + /// + public DateTime? CreateTime { get; set; } + + /// + /// 更新时间 + /// + public DateTime? UpdateTime { get; set; } + + /// + /// 创建者Id + /// + public long? CreateUserId { get; set; } + + /// + /// 创建者姓名 + /// + public string? CreateUserName { get; set; } + + /// + /// 修改者Id + /// + public long? UpdateUserId { get; set; } + + /// + /// 修改者姓名 + /// + public string? UpdateUserName { get; set; } + + /// + /// 软删除 + /// + public bool IsDelete { get; set; } + + } diff --git a/Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoInput.cs b/Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoInput.cs new file mode 100644 index 0000000..cebebad --- /dev/null +++ b/Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoInput.cs @@ -0,0 +1,196 @@ +using Admin.NET.Core; +using System.ComponentModel.DataAnnotations; + +namespace Admin.NET.Application; + + /// + /// 包装关系基础输入参数 + /// + public class PackageInfoBaseInput + { + /// + /// 物料Id + /// + public virtual long MaterialsId { get; set; } + + /// + /// 是否启用 + /// + public virtual bool IsEnable { get; set; } + + /// + /// 条码类型编码 + /// + public virtual string? CodeTypeNum { get; set; } + + /// + /// 条码类型 + /// + public virtual string? CodeType { get; set; } + + /// + /// 包装关系名称 + /// + public virtual string? PackageName { get; set; } + + /// + /// 单位Id + /// + public virtual long? UnitId { get; set; } + + /// + /// 单位组Id + /// + public virtual long? UnitGroupId { get; set; } + + /// + /// 产品数量 + /// + public virtual string? ProductCount { get; set; } + + /// + /// 租户Id + /// + public virtual long? TenantId { get; set; } + + /// + /// 创建时间 + /// + public virtual DateTime? CreateTime { get; set; } + + /// + /// 更新时间 + /// + public virtual DateTime? UpdateTime { get; set; } + + /// + /// 创建者Id + /// + public virtual long? CreateUserId { get; set; } + + /// + /// 创建者姓名 + /// + public virtual string? CreateUserName { get; set; } + + /// + /// 修改者Id + /// + public virtual long? UpdateUserId { get; set; } + + /// + /// 修改者姓名 + /// + public virtual string? UpdateUserName { get; set; } + + /// + /// 软删除 + /// + public virtual bool IsDelete { get; set; } + + } + + /// + /// 包装关系分页查询输入参数 + /// + public class PackageInfoInput : BasePageInput + { + /// + /// 关键字查询 + /// + public string? SearchKey { get; set; } + + /// + /// 物料Id + /// + public long? MaterialsId { get; set; } + + /// + /// 是否启用 + /// + public bool? IsEnable { get; set; } + + /// + /// 条码类型编码 + /// + public string? CodeTypeNum { get; set; } + + /// + /// 条码类型 + /// + public string? CodeType { get; set; } + + /// + /// 包装关系名称 + /// + public string? PackageName { get; set; } + + /// + /// 单位Id + /// + public long? UnitId { get; set; } + + /// + /// 单位组Id + /// + public long? UnitGroupId { get; set; } + + /// + /// 产品数量 + /// + public string? ProductCount { get; set; } + + } + + /// + /// 包装关系增加输入参数 + /// + public class AddPackageInfoInput : PackageInfoBaseInput + { + /// + /// 物料Id + /// + [Required(ErrorMessage = "物料Id不能为空")] + public override long MaterialsId { get; set; } + + /// + /// 是否启用 + /// + [Required(ErrorMessage = "是否启用不能为空")] + public override bool IsEnable { get; set; } + + /// + /// 软删除 + /// + [Required(ErrorMessage = "软删除不能为空")] + public override bool IsDelete { get; set; } + + } + + /// + /// 包装关系删除输入参数 + /// + public class DeletePackageInfoInput : BaseIdInput + { + } + + /// + /// 包装关系更新输入参数 + /// + public class UpdatePackageInfoInput : PackageInfoBaseInput + { + /// + /// 主键Id + /// + [Required(ErrorMessage = "主键Id不能为空")] + public long Id { get; set; } + + } + + /// + /// 包装关系主键查询输入参数 + /// + public class QueryByIdPackageInfoInput : DeletePackageInfoInput + { + + } diff --git a/Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoOutput.cs b/Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoOutput.cs new file mode 100644 index 0000000..a318f2d --- /dev/null +++ b/Admin.NET/Admin.NET.Application/Service/PackageInfo/Dto/PackageInfoOutput.cs @@ -0,0 +1,100 @@ +namespace Admin.NET.Application; + +/// +/// 包装关系输出参数 +/// +public class PackageInfoOutput +{ + /// + /// 主键Id + /// + public long Id { get; set; } + + /// + /// 物料Id + /// + public long MaterialsId { get; set; } + + /// + /// 是否启用 + /// + public bool IsEnable { get; set; } + + /// + /// 条码类型编码 + /// + public string? CodeTypeNum { get; set; } + + /// + /// 条码类型 + /// + public string? CodeType { get; set; } + + /// + /// 包装关系名称 + /// + public string? PackageName { get; set; } + + /// + /// 单位Id + /// + public long? UnitId { get; set; } + + /// + /// 单位 + /// + public string? Unit { get; set; } + + /// + /// 单位组Id + /// + public long? UnitGroupId { get; set; } + + /// + /// 产品数量 + /// + public string? ProductCount { get; set; } + + /// + /// 租户Id + /// + public long? TenantId { get; set; } + + /// + /// 创建时间 + /// + public DateTime? CreateTime { get; set; } + + /// + /// 更新时间 + /// + public DateTime? UpdateTime { get; set; } + + /// + /// 创建者Id + /// + public long? CreateUserId { get; set; } + + /// + /// 创建者姓名 + /// + public string? CreateUserName { get; set; } + + /// + /// 修改者Id + /// + public long? UpdateUserId { get; set; } + + /// + /// 修改者姓名 + /// + public string? UpdateUserName { get; set; } + + /// + /// 软删除 + /// + public bool IsDelete { get; set; } + + } + + diff --git a/Admin.NET/Admin.NET.Application/Service/PackageInfo/PackageInfoService.cs b/Admin.NET/Admin.NET.Application/Service/PackageInfo/PackageInfoService.cs new file mode 100644 index 0000000..f6ba6a5 --- /dev/null +++ b/Admin.NET/Admin.NET.Application/Service/PackageInfo/PackageInfoService.cs @@ -0,0 +1,151 @@ +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 PackageInfoService : IDynamicApiController, ITransient +{ + private readonly SqlSugarRepository _rep; + private readonly SysUnitService _unitService; + public PackageInfoService(SqlSugarRepository rep, SysUnitService unitService) + { + _rep = rep; + _unitService = unitService; + } + + /// + /// 分页查询包装关系 + /// + /// + /// + [HttpPost] + [ApiDescriptionSettings(Name = "Page")] + public async Task> Page(PackageInfoInput input) + { + var query = _rep.AsQueryable() + .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(); + return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize); + } + + /// + /// 增加包装关系 + /// + /// + /// + [HttpPost] + [ApiDescriptionSettings(Name = "Add")] + public async Task Add(AddPackageInfoInput input) + { + var entity = input.Adapt(); + await _rep.InsertAsync(entity); + return entity.Id; + } + /// + /// 增加包装关系 + /// + /// + /// + [HttpPost] + [ApiDescriptionSettings(Name = "AddEntity")] + public async Task AddEntity(AddPackageInfoInput input) + { + var entity = input.Adapt(); + await _rep.InsertAsync(entity); + return entity; + } + /// + /// 删除包装关系 + /// + /// + /// + [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); //真删除 + } + + /// + /// 更新包装关系 + /// + /// + /// + [HttpPost] + [ApiDescriptionSettings(Name = "Update")] + public async Task Update(UpdatePackageInfoInput input) + { + var entity = input.Adapt(); + await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); + } + + /// + /// 获取包装关系 + /// + /// + /// + [HttpGet] + [ApiDescriptionSettings(Name = "Detail")] + public async Task Detail([FromQuery] QueryByIdPackageInfoInput input) + { + return await _rep.GetFirstAsync(u => u.Id == input.Id); + } + + /// + /// 获取包装关系列表 + /// + /// + /// + [HttpGet] + [ApiDescriptionSettings(Name = "List")] + public async Task> List(long materialsId) + { + var list = await _rep.AsQueryable().Where(u => u.MaterialsId == materialsId)?.Select().ToListAsync(); + 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(); + var newList = new List(); + 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().ToListAsync(); + } + } + + +} +