From e22fd748a991ac84a63bc4a2eaafc4c9cb6110c4 Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Thu, 27 Apr 2023 16:59:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7bom=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/BasMbom/MbomSaveDataInput.cs | 115 +++++ .../Entity/BasMaterial.cs | 454 +++++++++--------- .../Tnb.BasicData.Entitys/Entity/BasMbom.cs | 2 +- .../Entity/BasMbomProcess.cs | 7 + BasicData/Tnb.BasicData/BasMbomService.cs | 203 +++++++- 5 files changed, 544 insertions(+), 237 deletions(-) create mode 100644 BasicData/Tnb.BasicData.Entitys/Dto/BasMbom/MbomSaveDataInput.cs diff --git a/BasicData/Tnb.BasicData.Entitys/Dto/BasMbom/MbomSaveDataInput.cs b/BasicData/Tnb.BasicData.Entitys/Dto/BasMbom/MbomSaveDataInput.cs new file mode 100644 index 00000000..82a4d303 --- /dev/null +++ b/BasicData/Tnb.BasicData.Entitys/Dto/BasMbom/MbomSaveDataInput.cs @@ -0,0 +1,115 @@ +using Tnb.BasicData.Entities; + +namespace Tnb.BasicData.Entities.Dto +{ + public class MbomSaveDataInput + { + /// + /// 生产bomid + /// + public string id { get; set; } + + /// + /// 物料id + /// + public string material_id { get; set; } + + /// + /// 数量 + /// + public int num { get; set; } + + /// + /// 单位id + /// + public string unit_id { get; set; } + + /// + /// 版本号 + /// + public string version { get; set; } + + /// + /// 有效开始时间 + /// + public DateTime? start_time { get; set; } + + /// + /// 有效结束时间 + /// + public DateTime? end_time { get; set; } + + /// + /// 物料清单id + /// + public string ebom_id { get; set; } + + /// + /// 工艺路线id + /// + public string route_id { get; set; } + + /// + /// 物料均再首道工序投产 + /// + public int is_first { get; set; } + + /// + /// 备注 + /// + public string remark { get; set; } + + /// + /// 工序 + /// + public List processes { get; set; } + } + + public class MbomProcessDto + { + /// + /// Desc:生产bomid + /// Default: + /// Nullable:False + /// + public string mbom_id { get; set; } + + /// + /// Desc:工序id + /// Default: + /// Nullable:False + /// + public string process_id { get; set; } + + /// + /// Desc:准备时间 + /// Default: + /// Nullable:False + /// + public decimal preparation_time { get; set; } + + /// + /// Desc:工位 + /// Default:NULL::character varying + /// Nullable:True + /// + public string station { get; set; } + + /// + /// Desc:副产出管控 0 不启用 1 启用 + /// Default: + /// Nullable:False + /// + public int byproduct_status { get; set; } + + /// + /// 投入物料 + /// + public List inputs { get; set; } + + /// + /// 产出物料 + /// + public List outputs { get; set; } + } +} \ No newline at end of file diff --git a/BasicData/Tnb.BasicData.Entitys/Entity/BasMaterial.cs b/BasicData/Tnb.BasicData.Entitys/Entity/BasMaterial.cs index da4c31b6..34df5803 100644 --- a/BasicData/Tnb.BasicData.Entitys/Entity/BasMaterial.cs +++ b/BasicData/Tnb.BasicData.Entitys/Entity/BasMaterial.cs @@ -1,5 +1,6 @@ using SqlSugar; using Tnb.Common.Contracts; + namespace Tnb.BasicData.Entities { /// @@ -8,275 +9,260 @@ namespace Tnb.BasicData.Entities [SugarTable("bas_material")] public class BasMaterial : BaseEntity { - public BasMaterial(){ + public BasMaterial() + { + } + /// + /// Desc:批次管理 + /// Default: + /// Nullable:True + /// + public int? is_batch_enabled { get; set; } - } - /// - /// Desc:物料代码 - /// Default: - /// Nullable:False - /// - public string code {get;set;} + /// + /// Desc:标签管理 + /// Default: + /// Nullable:True + /// + public int? is_label_enabled { get; set; } - /// - /// Desc:物料名称 - /// Default: - /// Nullable:False - /// - public string name {get;set;} + /// + /// Desc:附件 + /// Default:NULL::character varying + /// Nullable:True + /// + public string attachment { get; set; } - /// - /// Desc:物料分类ID - /// Default: - /// Nullable:False - /// - public string category_id {get;set;} + /// + /// Desc:物料代码 + /// Default: + /// Nullable:False + /// + public string code { get; set; } - /// - /// Desc:单位ID - /// Default: - /// Nullable:False - /// - public string unit_id {get;set;} + /// + /// Desc:物料名称 + /// Default: + /// Nullable:False + /// + public string name { get; set; } - /// - /// Desc:辅助单位id - /// Default: - /// Nullable:False - /// - public string pickunit_id {get;set;} + /// + /// Desc:物料分类ID + /// Default: + /// Nullable:False + /// + public string category_id { get; set; } - /// - /// Desc:单价 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="cost")] - public decimal? cost {get;set;} + /// + /// Desc:单位ID + /// Default: + /// Nullable:False + /// + public string unit_id { get; set; } - /// - /// Desc:毛重 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="grossweight")] - public decimal? grossweight {get;set;} + /// + /// Desc:单价 + /// Default: + /// Nullable:True + /// + public decimal? cost { get; set; } - /// - /// Desc:净重 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="netweight")] - public decimal? netweight {get;set;} + /// + /// Desc:毛重 + /// Default: + /// Nullable:True + /// + public decimal? grossweight { get; set; } - /// - /// Desc:长 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="length")] - public decimal? length {get;set;} + /// + /// Desc:净重 + /// Default: + /// Nullable:True + /// + public decimal? netweight { get; set; } - /// - /// Desc:宽 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="width")] - public decimal? width {get;set;} + /// + /// Desc:长 + /// Default: + /// Nullable:True + /// + public decimal? length { get; set; } - /// - /// Desc:高 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="high")] - public decimal? high {get;set;} + /// + /// Desc:宽 + /// Default: + /// Nullable:True + /// + public decimal? width { get; set; } - /// - /// Desc:体积 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="volumn")] - public decimal? volumn {get;set;} + /// + /// Desc:高 + /// Default: + /// Nullable:True + /// + public decimal? high { get; set; } - /// - /// Desc:是否免检 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="isexemption")] - public int? isexemption {get;set;} + /// + /// Desc:体积 + /// Default: + /// Nullable:True + /// + public decimal? volumn { get; set; } - /// - /// Desc:安全库存 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="safeqty")] - public decimal? safeqty {get;set;} + /// + /// Desc:是否免检 + /// Default: + /// Nullable:True + /// + public int? isexemption { get; set; } - /// - /// Desc:保质期 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="qualityperiod")] - public int? qualityperiod {get;set;} + /// + /// Desc:安全库存 + /// Default: + /// Nullable:True + /// + public decimal? safeqty { get; set; } - /// - /// Desc:最小包装 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="minpacking")] - public decimal? minpacking {get;set;} + /// + /// Desc:保质期 + /// Default: + /// Nullable:True + /// + public int? qualityperiod { get; set; } - /// - /// Desc:先进先出间隔天数,批次间隔天数 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="fifo_interval_days")] - public int? fifo_interval_days {get;set;} + /// + /// Desc:最小包装 + /// Default: + /// Nullable:True + /// + public decimal? minpacking { get; set; } - /// - /// Desc:创建时间 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="create_time")] - public DateTime? create_time {get;set;} + /// + /// Desc:先进先出间隔天数,批次间隔天数 + /// Default: + /// Nullable:True + /// + public int? fifo_interval_days { get; set; } - /// - /// Desc:最后修改时间 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="modify_time")] - public DateTime? modify_time {get;set;} + /// + /// Desc:创建时间 + /// Default: + /// Nullable:True + /// + public DateTime? create_time { get; set; } - /// - /// Desc:扩展字段 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="extras")] - public string extras {get;set;} + /// + /// Desc:最后修改时间 + /// Default: + /// Nullable:True + /// + public DateTime? modify_time { get; set; } - /// - /// Desc:所属组织ID - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="org_id")] - public string org_id {get;set;} + /// + /// Desc:扩展字段 + /// Default: + /// Nullable:True + /// + public string extras { get; set; } - /// - /// Desc:是否过期允许出库 - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="expireout")] - public string expireout {get;set;} + /// + /// Desc:所属组织ID + /// Default:NULL::character varying + /// Nullable:True + /// + public string org_id { get; set; } - /// - /// Desc:是否先进先出管控 - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="fifo")] - public string fifo {get;set;} + /// + /// Desc:是否过期允许出库 + /// Default:NULL::character varying + /// Nullable:True + /// + public string expireout { get; set; } - /// - /// Desc:物料规格型号 - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="material_standard")] - public string material_standard {get;set;} + /// + /// Desc:是否先进先出管控 + /// Default:NULL::character varying + /// Nullable:True + /// + public string fifo { get; set; } - /// - /// Desc:海关编码 - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="fhscode")] - public string fhscode {get;set;} + /// + /// Desc:物料规格型号 + /// Default:NULL::character varying + /// Nullable:True + /// + public string material_standard { get; set; } - /// - /// Desc:附属性 - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="attribute")] - public string attribute {get;set;} + /// + /// Desc:海关编码 + /// Default:NULL::character varying + /// Nullable:True + /// + public string fhscode { get; set; } - /// - /// Desc:管控类型: 批管控:Lot 单管控:KeyParts 非管控:NoControl - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="controltype")] - public string controltype {get;set;} + /// + /// Desc:附属性 + /// Default:NULL::character varying + /// Nullable:True + /// + public string attribute { get; set; } - /// - /// Desc:备注 - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="remark")] - public string remark {get;set;} + /// + /// Desc:管控类型: 批管控:Lot 单管控:KeyParts 非管控:NoControl + /// Default:NULL::character varying + /// Nullable:True + /// + public string controltype { get; set; } - /// - /// Desc:创建人员ID - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="create_id")] - public string create_id {get;set;} + /// + /// Desc:备注 + /// Default:NULL::character varying + /// Nullable:True + /// + public string remark { get; set; } - /// - /// Desc:最后修改人员ID - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="modify_id")] - public string modify_id {get;set;} + /// + /// Desc:创建人员ID + /// Default:NULL::character varying + /// Nullable:True + /// + public string create_id { get; set; } - /// - /// Desc:状态 - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="state")] - public string state {get;set;} + /// + /// Desc:最后修改人员ID + /// Default:NULL::character varying + /// Nullable:True + /// + public string modify_id { get; set; } - /// - /// Desc:物料属性 - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="material_property")] - public string material_property {get;set;} + /// + /// Desc:状态 + /// Default:NULL::character varying + /// Nullable:True + /// + public string state { get; set; } - /// - /// Desc:标签 - /// Default:NULL::character varying - /// Nullable:True - /// - [SugarColumn(ColumnName="label")] - public string label {get;set;} + /// + /// Desc:物料属性 + /// Default:NULL::character varying + /// Nullable:True + /// + public string material_property { get; set; } - /// - /// Desc:描述 - /// Default:NULL::character varying - /// Nullable:True - /// - public string descrip {get;set;} + /// + /// Desc:标签 + /// Default:NULL::character varying + /// Nullable:True + /// + public string label { get; set; } + /// + /// Desc:描述 + /// Default:NULL::character varying + /// Nullable:True + /// + public string descrip { get; set; } } } \ No newline at end of file diff --git a/BasicData/Tnb.BasicData.Entitys/Entity/BasMbom.cs b/BasicData/Tnb.BasicData.Entitys/Entity/BasMbom.cs index f9ae86da..6ff5a46b 100644 --- a/BasicData/Tnb.BasicData.Entitys/Entity/BasMbom.cs +++ b/BasicData/Tnb.BasicData.Entitys/Entity/BasMbom.cs @@ -109,7 +109,7 @@ namespace Tnb.BasicData.Entities /// Default:NULL::character varying /// Nullable:True /// - public string is_first {get;set;} + public int is_first {get;set;} /// /// Desc:创建用户 diff --git a/BasicData/Tnb.BasicData.Entitys/Entity/BasMbomProcess.cs b/BasicData/Tnb.BasicData.Entitys/Entity/BasMbomProcess.cs index 56ba219b..8b6d5c8f 100644 --- a/BasicData/Tnb.BasicData.Entitys/Entity/BasMbomProcess.cs +++ b/BasicData/Tnb.BasicData.Entitys/Entity/BasMbomProcess.cs @@ -47,5 +47,12 @@ namespace Tnb.BasicData.Entities /// Nullable:True /// public string station { get; set; } + + /// + /// Desc:副产出管控 0 不启用 1 启用 + /// Default: + /// Nullable:False + /// + public int byproduct_status { get; set; } } } \ No newline at end of file diff --git a/BasicData/Tnb.BasicData/BasMbomService.cs b/BasicData/Tnb.BasicData/BasMbomService.cs index 30b65047..4c979e4b 100644 --- a/BasicData/Tnb.BasicData/BasMbomService.cs +++ b/BasicData/Tnb.BasicData/BasMbomService.cs @@ -1,4 +1,5 @@ using JNPF.Common.Core.Manager; +using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.Systems.Interfaces.System; @@ -6,6 +7,7 @@ using Microsoft.AspNetCore.Mvc; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.BasicData.Interfaces; +using Tnb.BasicData.Entities.Dto; namespace Tnb.BasicData { @@ -19,14 +21,211 @@ namespace Tnb.BasicData private readonly ISqlSugarRepository _repository; private readonly DataBaseManager _dbManager; private readonly IDictionaryDataService _dictionaryDataService; + private readonly IUserManager _userManager; public BasMbomService( - ISqlSugarRepository repository,DataBaseManager dbManager,IDictionaryDataService dictionaryDataService) + ISqlSugarRepository repository, + DataBaseManager dbManager, + IUserManager userManager, + IDictionaryDataService dictionaryDataService) { _repository = repository; _dbManager = dbManager; + _userManager = userManager; _dictionaryDataService = dictionaryDataService; } - + + /// + /// 保存生产bom + /// + /// + /// + [HttpPost] + public async Task SaveData(MbomSaveDataInput mbomSaveDataInput) + { + DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () => + { + //新增 + if (string.IsNullOrEmpty(mbomSaveDataInput.id)) + { + string mbomId = SnowflakeIdHelper.NextId(); + string orgId = _userManager.GetUserInfo().Result.organizeId; + BasMbom mbom = new BasMbom() + { + id = mbomId, + org_id = orgId, + material_id= mbomSaveDataInput.material_id, + num = mbomSaveDataInput.num, + unit_id = mbomSaveDataInput.unit_id, + version = mbomSaveDataInput.version, + start_time = mbomSaveDataInput.start_time, + end_time = mbomSaveDataInput.end_time, + ebom_id = mbomSaveDataInput.ebom_id, + route_id = mbomSaveDataInput.route_id, + is_first = mbomSaveDataInput.is_first, + remark = mbomSaveDataInput.remark, + create_id = _userManager.UserId, + create_time = DateTime.Now, + + }; + await _repository.InsertAsync(mbom); + List processes = new List(); + List inputs = new List(); + List outputs = new List(); + + foreach (var process in mbomSaveDataInput.processes) + { + string mbomProcessId = SnowflakeIdHelper.NextId(); + processes.Add(new BasMbomProcess() + { + id = mbomProcessId, + org_id = orgId, + mbom_id= mbomId, + process_id = process.process_id, + preparation_time = process.preparation_time, + station = process.station, + byproduct_status = process.byproduct_status, + + }); + + foreach (var input in process.inputs) + { + string inputId = SnowflakeIdHelper.NextId(); + inputs.Add(new BasMbomInput() + { + id = inputId, + mbom_id = mbomId, + mbom_process_id = mbomProcessId, + process_id = process.process_id, + material_id = input.material_id, + num = input.num, + org_id = orgId, + }); + } + + foreach (var output in process.outputs) + { + string outputId = SnowflakeIdHelper.NextId(); + outputs.Add(new BasMbomOutput() + { + id = outputId, + mbom_id = mbomId, + mbom_process_id = mbomProcessId, + process_id = process.process_id, + material_id = output.material_id, + num = output.num, + org_id = orgId, + }); + } + } + + if (processes.Count > 0) + { + await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync(); + } + + if (inputs.Count > 0) + { + await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync(); + } + + if (outputs.Count > 0) + { + await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync(); + } + } + else//修改 + { + string orgId = _userManager.GetUserInfo().Result.organizeId; + await _repository.UpdateAsync(x=>new BasMbom() + { + // org_id = orgId, + material_id= mbomSaveDataInput.material_id, + num = mbomSaveDataInput.num, + unit_id = mbomSaveDataInput.unit_id, + version = mbomSaveDataInput.version, + start_time = mbomSaveDataInput.start_time, + end_time = mbomSaveDataInput.end_time, + ebom_id = mbomSaveDataInput.ebom_id, + route_id = mbomSaveDataInput.route_id, + is_first = mbomSaveDataInput.is_first, + remark = mbomSaveDataInput.remark, + modify_id = _userManager.UserId, + modify_time = DateTime.Now, + + },x=>x.id==mbomSaveDataInput.id); + List processes = new List(); + List inputs = new List(); + List outputs = new List(); + + foreach (var process in mbomSaveDataInput.processes) + { + string mbomProcessId = SnowflakeIdHelper.NextId(); + processes.Add(new BasMbomProcess() + { + id = mbomProcessId, + org_id = orgId, + mbom_id= mbomSaveDataInput.id, + process_id = process.process_id, + preparation_time = process.preparation_time, + station = process.station, + byproduct_status = process.byproduct_status, + + }); + + foreach (var input in process.inputs) + { + string inputId = SnowflakeIdHelper.NextId(); + inputs.Add(new BasMbomInput() + { + id = inputId, + mbom_id = mbomSaveDataInput.id, + mbom_process_id = mbomProcessId, + process_id = process.process_id, + material_id = input.material_id, + num = input.num, + org_id = orgId, + }); + } + + foreach (var output in process.outputs) + { + string outputId = SnowflakeIdHelper.NextId(); + outputs.Add(new BasMbomOutput() + { + id = outputId, + mbom_id = mbomSaveDataInput.id, + mbom_process_id = mbomProcessId, + process_id = process.process_id, + material_id = output.material_id, + num = output.num, + org_id = orgId, + }); + } + } + + await _repository.AsSugarClient().Deleteable().Where(x=>x.mbom_id==mbomSaveDataInput.id).ExecuteCommandAsync(); + await _repository.AsSugarClient().Deleteable().Where(x=>x.mbom_id==mbomSaveDataInput.id).ExecuteCommandAsync(); + await _repository.AsSugarClient().Deleteable().Where(x=>x.mbom_id==mbomSaveDataInput.id).ExecuteCommandAsync(); + if (processes.Count > 0) + { + await _repository.AsSugarClient().Insertable(processes).ExecuteCommandAsync(); + } + + if (inputs.Count > 0) + { + await _repository.AsSugarClient().Insertable(inputs).ExecuteCommandAsync(); + } + + if (outputs.Count > 0) + { + await _repository.AsSugarClient().Insertable(outputs).ExecuteCommandAsync(); + } + } + + }); + + return result.IsSuccess ? "保存成功" : result.ErrorMessage; + } } } \ No newline at end of file