From ed87bd712cbada7a293a89eed0759e9e25d2d64f Mon Sep 17 00:00:00 2001 From: "DEVICE8\\12494" Date: Mon, 15 May 2023 18:11:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=9F=E4=BA=A7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E7=BB=84=E8=A3=85=E5=8C=85=E8=A3=85=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEBomId=E6=8B=86=E8=A7=A3=E7=94=9F=E4=BA=A7=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Consts/DictConst.cs | 4 + .../PrdManage/PackingSchedulingListOutput.cs | 39 ++++ .../PrdManage/ProductionSchedulingCrInput.cs | 7 +- .../Tnb.ProductionMgr/PrdMoTaskService.cs | 218 +++++++++++------- .../System/DataInterfaceService.cs | 2 +- 5 files changed, 186 insertions(+), 84 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs diff --git a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs index 1ec40090..65d4215e 100644 --- a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs +++ b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs @@ -26,6 +26,10 @@ public static class DictConst /// public const string AlreadyId = "26033187948309"; /// + /// 工单状态-已下发Id + /// + public const string ScheduledId = "25019232867093"; + /// /// 工单状态-待排产 /// public const string WaitProductId = "25019244276501"; diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs new file mode 100644 index 00000000..888e67ae --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + /// + /// 组装、包装排产列表输出类 + /// + public class PackingSchedulingListOutput + { + /// + /// 产线Id + /// + public string workline_id { get; set; } + /// + /// 产线名称 + /// + public string workline_name { get; set; } + /// + /// 生产任务单号 + /// + public string mo_task_code { get; set; } + /// + /// 物料编码 + /// + public string material_code { get; set; } + /// + /// 物料名称 + /// + public string material_name { get; set; } + /// + /// 产出数量 + /// + public string qty { get; set; } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ProductionSchedulingCrInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ProductionSchedulingCrInput.cs index 1af7cedc..54744d0d 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ProductionSchedulingCrInput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ProductionSchedulingCrInput.cs @@ -78,7 +78,7 @@ namespace Tnb.ProductionMgr.Entities.Dto /// Default:NULL::character varying /// Nullable:True /// - public string line_id { get; set; } + public string workline_id { get; set; } /// @@ -106,6 +106,11 @@ namespace Tnb.ProductionMgr.Entities.Dto /// 已排产数量 /// public int scheduled_qty { get; set; } + + /// + /// 生产bom id + /// + public string bom_id { get; set; } } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index af168855..97cd1577 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -32,6 +32,7 @@ using JNPF.VisualDev.Entitys; using Aop.Api.Domain; using Senparc.Weixin.MP.AdvancedAPIs.Card; using Aspose.Cells.Drawing.Texts; +using JNPF.Systems.Entitys.Permission; namespace Tnb.ProductionMgr { @@ -48,6 +49,7 @@ namespace Tnb.ProductionMgr private readonly IRunService _runService; private readonly IVisualDevService _visualDevService; private static Dictionary _dicDefect = new Dictionary(); + private static Dictionary _dicWorkLine = new Dictionary(); private readonly ISqlSugarClient _db; @@ -374,6 +376,7 @@ namespace Tnb.ProductionMgr } + #endregion @@ -403,99 +406,149 @@ namespace Tnb.ProductionMgr { var db = _repository.AsSugarClient(); var row = -1; - if (input.schedule_type.HasValue && input.schedule_type.Value == 1) + if (input.schedule_type.HasValue) { - var moTask = input.Adapt(); - moTask.id = SnowflakeIdHelper.NextId(); - moTask.create_id = _userManager.UserId; - moTask.create_time = DateTime.Now; - moTask.mo_task_status = DictConst.ToBeScheduledEncode; - moTask.scheduled_qty = input.scheduled_qty; + if (input.schedule_type.Value == 1) //注塑、基础排产 + { + var moTask = input.Adapt(); + moTask.id = SnowflakeIdHelper.NextId(); + moTask.create_id = _userManager.UserId; + moTask.create_time = DateTime.Now; + moTask.mo_task_status = DictConst.ToBeScheduledEncode; + moTask.scheduled_qty = input.scheduled_qty; - var mo = await db.Queryable().FirstAsync(it => it.id == input.mo_id); - var moCode = mo?.mo_code; - var taskCode = await db.Queryable().Where(it => !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)).OrderByDescending(it => it.mo_task_code).Select(it => it.mo_task_code).FirstAsync(); - if (taskCode.IsNullOrEmpty()) - { - moTask.mo_task_code = $"{moCode}-01"; - } - else - { - var pos = taskCode.IndexOf("-", StringComparison.Ordinal); - if (pos > -1) + var mo = await db.Queryable().FirstAsync(it => it.id == input.mo_id); + var moCode = mo?.mo_code; + var taskCode = await db.Queryable().Where(it => !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)).OrderByDescending(it => it.mo_task_code).Select(it => it.mo_task_code).FirstAsync(); + if (taskCode.IsNullOrEmpty()) { - var sb = new StringBuilder(); - var num = taskCode.AsSpan().Slice(pos + 1).ToString().ParseToInt(); - var code = taskCode.AsSpan().Slice(0, pos).ToString(); - var n = (num + 1).ToString().PadLeft(2, '0'); - moTask.mo_task_code = sb.Append(code).Append("-").Append(n).ToString(); + moTask.mo_task_code = $"{moCode}-01"; } - } - try - { - await db.Ado.BeginTranAsync(); - row = await db.Insertable(moTask).ExecuteCommandAsync(); - - //根据工单号获取当前工单包含的已排产数 - var schedQty = db.Queryable().Where(it => it.mo_id == input.mo_id)?.Sum(d => d.scheduled_qty); - - if (mo != null) - {//判断如果当前 工单的已排产数大于工单计划数量则更新工单状态为 已排产 - if (schedQty.HasValue && schedQty.Value >= mo.plan_qty) + else + { + var pos = taskCode.IndexOf("-", StringComparison.Ordinal); + if (pos > -1) { - mo.mo_status = DictConst.AlreadyId; - row = await db.Updateable(mo).ExecuteCommandAsync(); - } - else - { - if (schedQty.HasValue) - mo.scheduled_qty = schedQty.Value; + var sb = new StringBuilder(); + var num = taskCode.AsSpan().Slice(pos + 1).ToString().ParseToInt(); + var code = taskCode.AsSpan().Slice(0, pos).ToString(); + var n = (num + 1).ToString().PadLeft(2, '0'); + moTask.mo_task_code = sb.Append(code).Append("-").Append(n).ToString(); } } - var material = await db.Queryable().FirstAsync(it => it.id == moTask.material_id); + try + { + await db.Ado.BeginTranAsync(); + row = await db.Insertable(moTask).ExecuteCommandAsync(); - var taskLog = new PrdTaskLog(); - taskLog.id = SnowflakeIdHelper.NextId(); - taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == input.mo_id))?.mo_code; - taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == input.eqp_id))?.code; - taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == input.mold_id))?.mold_code; - taskLog.item_code = material?.code; - taskLog.item_standard = material?.material_standard; - taskLog.status = DictConst.ToBeScheduledEncode; - taskLog.operator_name = _userManager.RealName; - taskLog.create_id = _userManager.UserId; - taskLog.create_time = DateTime.Now; - taskLog.mo_task_id = moTask.id; - taskLog.mo_task_code = moTask.mo_task_code; + //根据工单号获取当前工单包含的已排产数 + var schedQty = db.Queryable().Where(it => it.mo_id == input.mo_id)?.Sum(d => d.scheduled_qty); - await db.Insertable(taskLog).ExecuteCommandAsync(); - //将生产任务插入到自检报废记录表 - var sacipRecord = new PrdMoTaskDefectRecord(); - sacipRecord.id = SnowflakeIdHelper.NextId(); - sacipRecord.material_code = material?.code; - sacipRecord.material_name = material?.name; - sacipRecord.eqp_code = (await db.Queryable().FirstAsync(it => it.id == moTask.eqp_id))?.code; - sacipRecord.mold_name = (await db.Queryable().FirstAsync(it => it.id == moTask.mold_id))?.mold_name; - sacipRecord.estimated_start_date = moTask.plan_start_date; - sacipRecord.estimated_end_date = moTask.plan_end_date; - sacipRecord.plan_qty = moTask.plan_qty; - sacipRecord.scrap_qty = moTask.scrap_qty; - sacipRecord.status = moTask.mo_task_status; - sacipRecord.create_id = _userManager.UserId; - sacipRecord.create_time = DateTime.Now; - sacipRecord.mo_task_id = moTask.id; - sacipRecord.mo_task_code = moTask.mo_task_code; - await db.Insertable(sacipRecord).ExecuteCommandAsync(); + if (mo != null) + {//判断如果当前 工单的已排产数大于工单计划数量则更新工单状态为 已排产 + if (schedQty.HasValue && schedQty.Value >= mo.plan_qty) + { + mo.mo_status = DictConst.AlreadyId; + row = await db.Updateable(mo).ExecuteCommandAsync(); + } + else + { + if (schedQty.HasValue) + mo.scheduled_qty = schedQty.Value; + } + } + var material = await db.Queryable().FirstAsync(it => it.id == moTask.material_id); - await db.Ado.CommitTranAsync(); + var taskLog = new PrdTaskLog(); + taskLog.id = SnowflakeIdHelper.NextId(); + taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == input.mo_id))?.mo_code; + taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == input.eqp_id))?.code; + taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == input.mold_id))?.mold_code; + taskLog.item_code = material?.code; + taskLog.item_standard = material?.material_standard; + taskLog.status = DictConst.ToBeScheduledEncode; + taskLog.operator_name = _userManager.RealName; + taskLog.create_id = _userManager.UserId; + taskLog.create_time = DateTime.Now; + taskLog.mo_task_id = moTask.id; + taskLog.mo_task_code = moTask.mo_task_code; + + await db.Insertable(taskLog).ExecuteCommandAsync(); + //将生产任务插入到自检报废记录表 + var sacipRecord = new PrdMoTaskDefectRecord(); + sacipRecord.id = SnowflakeIdHelper.NextId(); + sacipRecord.material_code = material?.code; + sacipRecord.material_name = material?.name; + sacipRecord.eqp_code = (await db.Queryable().FirstAsync(it => it.id == moTask.eqp_id))?.code; + sacipRecord.mold_name = (await db.Queryable().FirstAsync(it => it.id == moTask.mold_id))?.mold_name; + sacipRecord.estimated_start_date = moTask.plan_start_date; + sacipRecord.estimated_end_date = moTask.plan_end_date; + sacipRecord.plan_qty = moTask.plan_qty; + sacipRecord.scrap_qty = moTask.scrap_qty; + sacipRecord.status = moTask.mo_task_status; + sacipRecord.create_id = _userManager.UserId; + sacipRecord.create_time = DateTime.Now; + sacipRecord.mo_task_id = moTask.id; + sacipRecord.mo_task_code = moTask.mo_task_code; + await db.Insertable(sacipRecord).ExecuteCommandAsync(); + + await db.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + await db.Ado.RollbackTranAsync(); + } } - catch (Exception ex) + else if (input.schedule_type.Value == 2) //组装、包装排产 { - await db.Ado.RollbackTranAsync(); + } } return row > 0; } + /// + /// 获取组装包装排产任务列表 + /// + /// + /// + [HttpPost] + public async Task GetPackSchedulingTaskList(ProductionSchedulingCrInput input) + { + if (_dicWorkLine.Count < 1) + { + _dicWorkLine = await _db.Queryable().Where(it => it.Category == "workline").ToDictionaryAsync(x => x.Id, x => x.FullName); + } + var outputList = new List(); + var bom = await _db.Queryable().FirstAsync(it => it.id == input.bom_id); + if (bom != null && bom.route_id.IsNotEmptyOrNull()) + { + var routes = await _db.Queryable().Where(it => it.route_id == bom.route_id).ToListAsync(); + if (routes?.Count > 0) + { + var processIds = routes.Select(x => x.process_id).ToList(); + if (processIds?.Count > 0) + { + var bomOutputs = await _db.Queryable().Where(it => processIds.Contains(it.process_id)).ToListAsync(); + if (bomOutputs?.Count > 0) + { + foreach (var item in bomOutputs) + { + var material = await _db.Queryable().FirstAsync(it => it.id == item.material_id); + var output = new PackingSchedulingListOutput(); + output.workline_id = input.workline_id; + output.workline_name = _dicWorkLine.ContainsKey(input.workline_id) ? _dicWorkLine[input.workline_id].ToString() : ""; + output.material_code = material?.code; + output.material_name = material?.name; + output.qty = item.num; + outputList.Add(output); + } + } + } + } + } + return outputList; + } + /// /// 生产任务下发,开始 、结束、完成 /// @@ -588,8 +641,10 @@ namespace Tnb.ProductionMgr } else { - if (taskLog.status != status) + var records = await db.Queryable().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync(); + if (records != null && !records.Select(x => x.status).Contains(status)) { + taskLog.id = SnowflakeIdHelper.NextId(); taskLog.status = status; taskLogEntities.Add(taskLog); @@ -667,7 +722,6 @@ namespace Tnb.ProductionMgr var db = _repository.AsSugarClient(); var report = await db.Queryable().FirstAsync(it => it.mo_task_code == input.mo_task_code); - if (report is not null) { report.mo_task_code = input.mo_task_code; @@ -818,15 +872,15 @@ namespace Tnb.ProductionMgr var result = await db.Ado.UseTranAsync(async () => { var row = -1; - var prdTask = await db.Queryable().FirstAsync(it => it.id == id); + var prdTask = await db.Queryable().FirstAsync(it => it.id == id); row = await db.Deleteable().Where(it => it.id == id).ExecuteCommandAsync(); if (row > 0) { var prdMo = await db.Queryable().FirstAsync(it => it.id == prdTask.mo_id); if (prdMo is not null) { - prdMo.input_qty += prdTask.scheduled_qty; - //prdMo.icmo_status = DictConst.ToBeScheduledEncode; + prdMo.scheduled_qty += prdTask.scheduled_qty; + prdMo.mo_status = DictConst.ScheduledId; row = await db.Updateable(prdMo).ExecuteCommandAsync(); } } diff --git a/system/Tnb.Systems/System/DataInterfaceService.cs b/system/Tnb.Systems/System/DataInterfaceService.cs index 15af8000..ab5b29ba 100644 --- a/system/Tnb.Systems/System/DataInterfaceService.cs +++ b/system/Tnb.Systems/System/DataInterfaceService.cs @@ -1010,7 +1010,7 @@ public class DataInterfaceService : IDataInterfaceService, IDynamicApiController // 将逗号替换成一个单引号、逗号、单引号 item.defaultValue = item.defaultValue?.Replace(",", "','"); - entity.Query = entity.Query?.Replace("{" + item.field + "}", "'" + item.defaultValue + "'"); + entity.Query = entity.Query?.Replace("{" + item.field + "}", item.defaultValue); //自动加引号去掉 modify by ly on 20230515 } else entity.Query = entity.Query?.Replace("{" + item.field + "}", item.defaultValue);