From e03fda5ae1f01829ab28996a9ea15552ebb24f5e Mon Sep 17 00:00:00 2001 From: zhou keda <1315948824@qq.com> Date: Mon, 11 Dec 2023 09:28:12 +0800 Subject: [PATCH] =?UTF-8?q?erp=E7=89=A9=E6=96=99=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/BasMaterial/ErpBasMaterialInput.cs | 370 ++++++++++++++++++ .../Entity/BasMaterial.cs | 5 + .../BasMaterialIntoFactorySpecifications.cs | 2 +- BasicData/Tnb.BasicData/BasMaterialService.cs | 183 +++++++++ 4 files changed, 559 insertions(+), 1 deletion(-) create mode 100644 BasicData/Tnb.BasicData.Entities/Dto/BasMaterial/ErpBasMaterialInput.cs diff --git a/BasicData/Tnb.BasicData.Entities/Dto/BasMaterial/ErpBasMaterialInput.cs b/BasicData/Tnb.BasicData.Entities/Dto/BasMaterial/ErpBasMaterialInput.cs new file mode 100644 index 00000000..0ccd30c4 --- /dev/null +++ b/BasicData/Tnb.BasicData.Entities/Dto/BasMaterial/ErpBasMaterialInput.cs @@ -0,0 +1,370 @@ +namespace Tnb.BasicData.Entities.Dto +{ + public class ErpBasMaterialInput + { + public ErpBasMaterial bas_material { get; set; } + public List bas_material_units { get; set; } = new List(); + + // public List bas_material_into_factory_specificationses { get; set; } = new List(); + // + // public List bas_substitution_materials { get; set; } = new List(); + // + // public List bas_material_send_warehouses { get; set; } = new List(); + // + // public List bas_material_inbound_whs { get; set; } = new List(); + } + + public class ErpBasMaterial + { + /// + /// 物料代码 + /// + public string code { get; set; } = string.Empty; + + /// + /// 物料名称 + /// + public string name { get; set; } = string.Empty; + + /// + /// 物料分类ID + /// + public string category_id { get; set; } = string.Empty; + + /// + /// 单位ID + /// + public string unit_id { get; set; } = string.Empty; + + // /// + // /// 单价 + // /// + // public decimal? cost { get; set; } + // + // /// + // /// 毛重 + // /// + // public decimal? grossweight { get; set; } + // + // /// + // /// 净重 + // /// + // public decimal? netweight { get; set; } + // + // /// + // /// 长 + // /// + // public decimal? length { get; set; } + // + // /// + // /// 宽 + // /// + // public decimal? width { get; set; } + // + // /// + // /// 高 + // /// + // public decimal? high { get; set; } + // + // /// + // /// 体积 + // /// + // public decimal? volumn { get; set; } + // + // /// + // /// 是否免检 + // /// + // public int? isexemption { get; set; } + + /// + /// 安全库存 + /// + public decimal? safeqty { get; set; } + + /// + /// 保质期 + /// + public int? qualityperiod { get; set; } + + // /// + // /// 是否过期允许出库 + // /// + // public string? expireout { get; set; } + + /// + /// 最小包装 + /// + public decimal? minpacking { get; set; } + + /// + /// 是否先进先出管控 + /// + public string? fifo { get; set; } + + // /// + // /// 先进先出间隔天数,批次间隔天数 + // /// + // public int? fifo_interval_days { get; set; } + + /// + /// 物料规格型号 + /// + public string? material_standard { get; set; } + + // /// + // /// 海关编码 + // /// + // public string? fhscode { get; set; } + + // /// + // /// 附属性 + // /// + // public string? attribute { get; set; } + + // /// + // /// 管控类型: 批管控:Lot 单管控:KeyParts 非管控:NoControl + // /// + // public string? controltype { get; set; } + + /// + /// 备注 + /// + public string? remark { get; set; } + + // /// + // /// 创建用户 + // /// + // public string? create_id { get; set; } + + /// + /// 创建用户 + /// + public string? create_count { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + // /// + // /// 修改用户 + // /// + // public string? modify_id { get; set; } + + /// + /// 修改用户 + /// + public string? modify_count { get; set; } + + /// + /// 修改时间 + /// + public DateTime? modify_time { get; set; } + + // /// + // /// 扩展字段 + // /// + // public string? extras { get; set; } + + /// + /// 状态 + /// + public string? state { get; set; } + + /// + /// 物料属性 + /// + public string? material_property { get; set; } + + /// + /// 标签 + /// + public string? label { get; set; } + + /// + /// 描述 + /// + public string? descrip { get; set; } + + /// + /// 批次管理 + /// + public int? is_batch_enabled { get; set; } + + /// + /// 标签管理 + /// + public int? is_label_enabled { get; set; } + + // /// + // /// 附件 + // /// + // public string? attachment { get; set; } + + /// + /// 先进先出 0否 1是 + /// + public int? first_in_out { get; set; } + + /// + /// 存储有效期(天) + /// + public int? storage_valid_day { get; set; } + + /// + /// 预警提前期(天) + /// + public int? early_warn_day { get; set; } + + /// + /// 安全库存 + /// + public int? safe_stock { get; set; } + + /// + /// 安全库存包含状态 + /// + public string? safe_stock_stauts { get; set; } + + /// + /// 发料仓库id + /// + public string? send_warehouse_id { get; set; } + + /// + /// 入厂单位id + /// + public string? into_factory_unit_id { get; set; } + + /// + /// 投料单位 + /// + public string? material_in_unit_id { get; set; } + + /// + /// 产出单位 + /// + public string? material_out_unit_id { get; set; } + + /// + /// 请料方式 1按计划排程请料 2自行管控 + /// + public string? material_request_method { get; set; } + + /// + /// 是否包含入库数 + /// + public int? is_contain_into_num { get; set; } + + /// + /// 是否创建子工单 + /// + public string? is_create_sub_work_order { get; set; } + + /// + /// 保质期 + /// + public int? quality_guarantee_period { get; set; } + + /// + /// DI编码 + /// + public string? di { get; set; } + + } + + public class ErpBasMaterialUnit + { + /// + /// 主单位数量 + /// + public string? number_of_primary_unit { get; set; } + + /// + /// 辅助单位数量 + /// + public string? number_of_auxiliary_unit { get; set; } + + /// + /// 辅助单位 + /// + public string auxiliary_unit_id { get; set; } = string.Empty; + + } + + public class ErpBasMaterialIntoFactorySpecifications + { + /// + /// 单位id + /// + public string unit_id { get; set; } = string.Empty; + + /// + /// 数量 + /// + public decimal num { get; set; } + } + + public class ErpBasSubstitutionMaterial + { + + /// + /// 替代料编号 + /// + public string sub_material_code { get; set; } = string.Empty; + + /// + /// 替代比例,如1(一个物料可以用一个替代料代替) + /// + public decimal proportion { get; set; } + + } + + public class ErpBasMaterialSendWarehouse + { + + /// + /// 仓库编号 + /// + public string? wh_code { get; set; } + + /// + /// 最大库存 + /// + public int? max_stock { get; set; } + + /// + /// 最小库存 + /// + public int? min_stock { get; set; } + + /// + /// 安全库存 + /// + public int? safe_stock { get; set; } + } + + public class ErpBasMaterialInboundWh + { + + /// + /// 仓库编号 + /// + public string? wh_code { get; set; } + + /// + /// 最大库存 + /// + public int? max_stock { get; set; } + + /// + /// 最小库存 + /// + public int? min_stock { get; set; } + + /// + /// 安全库存 + /// + public int? safe_stock { get; set; } + } +} \ No newline at end of file diff --git a/BasicData/Tnb.BasicData.Entities/Entity/BasMaterial.cs b/BasicData/Tnb.BasicData.Entities/Entity/BasMaterial.cs index 77335163..ceb22bc4 100644 --- a/BasicData/Tnb.BasicData.Entities/Entity/BasMaterial.cs +++ b/BasicData/Tnb.BasicData.Entities/Entity/BasMaterial.cs @@ -263,5 +263,10 @@ public partial class BasMaterial : BaseEntity /// DI编码 /// public string? di { get; set; } + + /// + /// 删除标志 + /// + public int? deleted { get; set; } } diff --git a/BasicData/Tnb.BasicData.Entities/Entity/BasMaterialIntoFactorySpecifications.cs b/BasicData/Tnb.BasicData.Entities/Entity/BasMaterialIntoFactorySpecifications.cs index 952e4a49..cf53bac8 100644 --- a/BasicData/Tnb.BasicData.Entities/Entity/BasMaterialIntoFactorySpecifications.cs +++ b/BasicData/Tnb.BasicData.Entities/Entity/BasMaterialIntoFactorySpecifications.cs @@ -5,7 +5,7 @@ using SqlSugar; namespace Tnb.BasicData.Entities; /// -/// 物料入场规格 +/// 物料入厂规格 /// [SugarTable("bas_material_into_factory_specifications")] public partial class BasMaterialIntoFactorySpecifications : BaseEntity diff --git a/BasicData/Tnb.BasicData/BasMaterialService.cs b/BasicData/Tnb.BasicData/BasMaterialService.cs index 6cb32234..386096b8 100644 --- a/BasicData/Tnb.BasicData/BasMaterialService.cs +++ b/BasicData/Tnb.BasicData/BasMaterialService.cs @@ -6,10 +6,13 @@ using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; +using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Entitys.System; using JNPF.Systems.Interfaces.System; +using Mapster; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using SQLitePCL; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.BasicData.Entities.Dto; @@ -275,5 +278,185 @@ namespace Tnb.BasicData return ids; } + + + /// + /// 物料新增修改接口 + /// + /// + /// + [HttpPost] + public async Task CreateCreateOrUpdateMaterial(ErpBasMaterialInput input) + { + var db = _repository.AsSugarClient(); + if (input == null) + { + throw Oops.Bah("参数为空"); + } + if (input.bas_material == null) + { + throw Oops.Bah("物料信息为空"); + } + if (!string.IsNullOrEmpty(input.bas_material.code)) + { + throw Oops.Bah("物料编号为空"); + } + if (!string.IsNullOrEmpty(input.bas_material.name)) + { + throw Oops.Bah("物料名称为空"); + } + DbResult result = await db.Ado.UseTranAsync(async () => + { + BasMaterial basMaterial = input.bas_material.Adapt(); + if (!await db.Queryable().AnyAsync(x => x.code == input.bas_material.code)) + { + basMaterial.id = SnowflakeIdHelper.NextId(); + } + + if (!string.IsNullOrEmpty(input.bas_material.create_count)) + { + UserEntity userEntity = await db.Queryable().FirstAsync(x=>x.Account==input.bas_material.create_count); + if (userEntity == null) + { + throw Oops.Bah($"未找到用户{input.bas_material.create_count}"); + } + basMaterial.create_id = userEntity?.Id; + } + + if (!string.IsNullOrEmpty(input.bas_material.modify_count)) + { + UserEntity userEntity = await db.Queryable().FirstAsync(x=>x.Account==input.bas_material.modify_count); + if (userEntity == null) + { + throw Oops.Bah($"未找到用户{input.bas_material.modify_count}"); + } + basMaterial.modify_id = userEntity?.Id; + } + + List basMaterialUnits = new List(); + // List basMaterialIntoFactorySpecificationsList = new List(); + // List basSubstitutionMaterials = new List(); + // List basMaterialSendWarehouses = new List(); + // List basMaterialInboundWhs = new List(); + + if (input.bas_material_units != null && input.bas_material_units.Count > 0) + { + foreach(var item in input.bas_material_units) + { + BasMaterialUnit basMaterialUnit = item.Adapt(); + basMaterialUnit.id = SnowflakeIdHelper.NextId(); + basMaterialUnit.material_id = basMaterial.id; + basMaterialUnits.Add(basMaterialUnit); + } + } + + // if (input.bas_material_into_factory_specificationses != null && input.bas_material_into_factory_specificationses.Count > 0) + // { + // foreach(var item in input.bas_material_into_factory_specificationses) + // { + // BasMaterialIntoFactorySpecifications basMaterialIntoFactorySpecifications = item.Adapt(); + // basMaterialIntoFactorySpecifications.id = SnowflakeIdHelper.NextId(); + // basMaterialIntoFactorySpecifications.material_id = basMaterial.id; + // basMaterialIntoFactorySpecificationsList.Add(basMaterialIntoFactorySpecifications); + // } + // } + // + // if (input.bas_substitution_materials != null && input.bas_substitution_materials.Count > 0) + // { + // foreach(var item in input.bas_substitution_materials) + // { + // BasSubstitutionMaterial basSubstitutionMaterial = item.Adapt(); + // basSubstitutionMaterial.id = SnowflakeIdHelper.NextId(); + // basSubstitutionMaterial.material_id = basMaterial.id; + // BasMaterial subBasMaterial = await db.Queryable().FirstAsync(x=>x.code==item.sub_material_code); + // if (subBasMaterial == null) + // { + // throw Oops.Bah($"未找到替代物料{item.sub_material_code}"); + // } + // basSubstitutionMaterial.sub_material_id = subBasMaterial?.id ?? item.sub_material_code; + // basSubstitutionMaterials.Add(basSubstitutionMaterial); + // } + // } + // + // if (input.bas_material_send_warehouses != null && input.bas_material_send_warehouses.Count > 0) + // { + // foreach(var item in input.bas_material_send_warehouses) + // { + // BasMaterialSendWarehouse basMaterialSendWarehouse = item.Adapt(); + // basMaterialSendWarehouse.id = SnowflakeIdHelper.NextId(); + // basMaterialSendWarehouse.material_id = basMaterial.id; + // BasWarehouse basWarehouse = await db.Queryable().FirstAsync(x=>x.whcode==item.wh_code); + // if (basWarehouse == null) + // { + // throw Oops.Bah($"发料仓库未找到仓库{item.wh_code}"); + // } + // basMaterialSendWarehouse.wh_id = basWarehouse?.id ?? item.wh_code; + // basMaterialSendWarehouses.Add(basMaterialSendWarehouse); + // } + // } + // + // if (input.bas_material_inbound_whs != null && input.bas_material_inbound_whs.Count > 0) + // { + // foreach(var item in input.bas_material_inbound_whs) + // { + // BasMaterialInboundWh basMaterialInboundWh = item.Adapt(); + // basMaterialInboundWh.id = SnowflakeIdHelper.NextId(); + // basMaterialInboundWh.material_id = basMaterial.id; + // BasWarehouse basWarehouse = await db.Queryable().FirstAsync(x=>x.whcode==item.wh_code); + // if (basWarehouse == null) + // { + // throw Oops.Bah($"入库仓库未找到仓库{item.wh_code}"); + // } + // basMaterialInboundWh.wh_id = basWarehouse?.id ?? item.wh_code; + // basMaterialInboundWhs.Add(basMaterialInboundWh); + // } + // } + + if (!await db.Queryable().AnyAsync(x => x.code == input.bas_material.code)) + { + await db.Insertable(basMaterial).ExecuteCommandAsync(); + } + else + { + await db.Updateable(basMaterial).ExecuteCommandAsync(); + } + + // var x= await db.Storageable(basMaterial).ToStorageAsync(); + // await x.AsInsertable.ExecuteCommandAsync();//不存在插入 + // await x.AsUpdateable.ExecuteCommandAsync();//存在更新 + + if (basMaterialUnits.Count > 0) + { + await db.Deleteable().Where(x=>x.material_id==basMaterial.id).ExecuteCommandAsync(); + await db.Insertable(basMaterialUnits).ExecuteCommandAsync(); + } + + // if (basMaterialIntoFactorySpecificationsList.Count > 0) + // { + // await db.Deleteable().Where(x=>x.material_id==basMaterial.id).ExecuteCommandAsync(); + // await db.Insertable(basMaterialIntoFactorySpecificationsList).ExecuteCommandAsync(); + // } + // + // if (basSubstitutionMaterials.Count > 0) + // { + // await db.Deleteable().Where(x=>x.material_id==basMaterial.id).ExecuteCommandAsync(); + // await db.Insertable(basSubstitutionMaterials).ExecuteCommandAsync(); + // } + // + // if (basMaterialSendWarehouses.Count > 0) + // { + // await db.Deleteable().Where(x=>x.material_id==basMaterial.id).ExecuteCommandAsync(); + // await db.Insertable(basMaterialSendWarehouses).ExecuteCommandAsync(); + // } + // + // if (basMaterialInboundWhs.Count > 0) + // { + // await db.Deleteable().Where(x=>x.material_id==basMaterial.id).ExecuteCommandAsync(); + // await db.Insertable(basMaterialInboundWhs).ExecuteCommandAsync(); + // } + + }); + return !result.IsSuccess ? throw Oops.Oh(result.ErrorMessage) : "保存成功"; + } } } \ No newline at end of file