From d4702c1fd55c5cb5cb0de6dd3e962cc28f3a18a1 Mon Sep 17 00:00:00 2001 From: "DEVICE8\\12494" Date: Mon, 8 May 2023 17:01:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=8E=92=E4=BA=A7=EF=BC=8C=E6=96=B0=E5=A2=9E=20=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=20=E4=B8=8B=E5=8F=91=E3=80=81=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E3=80=81=E5=85=B3=E9=97=AD=E3=80=81=E5=AE=8C=E6=88=90=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.BasicData.Entitys/Consts/DictConst.cs | 12 ++++ .../Dto/PrdManage/PrdTaskReleaseUpInput.cs | 9 +++ .../Enums/Behavior.cs | 23 +++++++ .../Tnb.ProductionMgr/PrdMoService.cs | 60 +++++++++++++++---- .../Tnb.Common/Extension/StringExtensions.cs | 11 ++++ 5 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entitys/Enums/Behavior.cs diff --git a/BasicData/Tnb.BasicData.Entitys/Consts/DictConst.cs b/BasicData/Tnb.BasicData.Entitys/Consts/DictConst.cs index c93708d7..cf2926d9 100644 --- a/BasicData/Tnb.BasicData.Entitys/Consts/DictConst.cs +++ b/BasicData/Tnb.BasicData.Entitys/Consts/DictConst.cs @@ -40,6 +40,18 @@ public static class DictConst /// public const string ToBeStartedEnCode = "ToBeStarted"; /// + /// 任务单状态-进行中 + /// + public const string InProgressEnCode = "InProgress"; + /// + /// 任务单状态-关闭编码 + /// + public const string ClosedEnCode = "Closed"; + /// + /// 任务单状态-完工编码 + /// + public const string ComplatedEnCode = "Complated"; + /// /// 任务单状态-待排产 /// public const string ToBeScheduledEncode = "ToBeScheduled"; diff --git a/ProductionMgr/Tnb.ProductionMgr.Entitys/Dto/PrdManage/PrdTaskReleaseUpInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entitys/Dto/PrdManage/PrdTaskReleaseUpInput.cs index a2317542..37d943f1 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entitys/Dto/PrdManage/PrdTaskReleaseUpInput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entitys/Dto/PrdManage/PrdTaskReleaseUpInput.cs @@ -15,5 +15,14 @@ namespace Tnb.ProductionMgr.Entities.Dto /// 生产任务ID列表 /// public List TaskIds { get; set; } + /// + /// 行为: + ///
Release(任务下发), + ///
Start(任务开始), + ///
Closed(任务关闭), + ///
Compled(任务完成) + ///
+ public string Behavior { get; set; } + } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entitys/Enums/Behavior.cs b/ProductionMgr/Tnb.ProductionMgr.Entitys/Enums/Behavior.cs new file mode 100644 index 00000000..1af1896b --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entitys/Enums/Behavior.cs @@ -0,0 +1,23 @@ +namespace Tnb.ProductionMgr.Entities.Enums +{ + public enum Behavior + { + /// + /// 任务下发 + /// + Release = 1, + /// + /// 任务开始 + /// + Start = 2, + /// + /// 任务关闭 + /// + Closed = 4, + /// + /// 任务完成 + /// + Compled = 8, + } +} + diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs index fe68257f..6b1d2dd3 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs @@ -1,10 +1,12 @@ using System.Reflection.Emit; +using Aop.Api.Domain; using JNPF.Common.Core.Manager; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; +using JNPF.Extensitions.EventBus; using JNPF.FriendlyException; using JNPF.Logging; using JNPF.Systems.Interfaces.System; @@ -19,6 +21,7 @@ using Tnb.BasicData.Entitys.Entity; using Tnb.EquipMgr.Entities; using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Entities.Dto; +using Tnb.ProductionMgr.Entities.Enums; using Tnb.ProductionMgr.Interfaces; namespace Tnb.ProductionMgr @@ -164,7 +167,7 @@ namespace Tnb.ProductionMgr return data; } /// - /// 查看工单操作记录 + /// 查看生产任务操作记录 /// /// 任务ID /// @@ -383,7 +386,7 @@ namespace Tnb.ProductionMgr if (row > 0) { - if (icmoEntities?.Count > 0 && combineMoCodes?.FirstOrDefault() is not null) + if (icmoEntities?.Count > 0 && combineMoCodes?.FirstOrDefault() is not null) { var moList = await db.Queryable().Where(it => combineMoCodes.Contains(it.combine_mo_code)).ToListAsync(); var combinePlanQty = icmoEntities?.Sum(x => x.plan_qty); //合并工单后的计划数量 @@ -458,23 +461,59 @@ namespace Tnb.ProductionMgr return row > 0; } /// - /// 生产任务下发 + /// 生产任务下发,开始 、结束、完成 /// + /// 输入参数 /// + /// + /// [HttpPost] public async Task PrdTaskRelease(PrdTaskReleaseUpInput input) { + var row = -1; if (input is null) { throw new ArgumentNullException(nameof(input)); } + if (input.TaskIds is null) + { + throw new ArgumentNullException(nameof(input.TaskIds)); + } + if (input.Behavior.IsNullOrWhiteSpace()) + { + throw new ArgumentException($"{nameof(input.Behavior)} not be null or empty"); + } + string SetTaskStatus(Behavior behavior) => behavior switch + { + Behavior.Release => DictConst.ToBeStartedEnCode, + Behavior.Start => DictConst.InProgressEnCode, + Behavior.Closed => DictConst.ClosedEnCode, + Behavior.Compled => DictConst.ComplatedEnCode, + _ => throw new NotImplementedException(), + }; + Behavior behavior = input.Behavior.ToEnum(); + var status = SetTaskStatus(behavior); var db = _repository.AsSugarClient(); - var row = await db.Updateable() - .SetColumns(it => new PrdTask { status = DictConst.ToBeStartedEnCode }) - .Where(it => input.TaskIds.Contains(it.id)) - .ExecuteCommandAsync(); + if (behavior == Behavior.Compled) + { + var list = await db.Queryable().Where(it => input.TaskIds.Contains(it.id)).Select(it => it).ToListAsync(); + if (list?.Count > 0) + { + var schedQtySum = list.Sum(x => x.scheduled_qty); + var planQtySum = list.Sum(x => x.plan_qty); + if (schedQtySum < planQtySum) + { + throw new AppFriendlyException("任务数量必须大于等于生产计划数量,才可完成", 500); + } + } + } + row = await db.Updateable() + .SetColumns(it => new PrdTask { status = status }) + .Where(it => input.TaskIds.Contains(it.id)) + .ExecuteCommandAsync(); return (row > 0); } + /// /// 生产任务单修改 /// @@ -486,7 +525,7 @@ namespace Tnb.ProductionMgr { var row = -1; var db = _repository.AsSugarClient(); - if(input.icmo_id.IsNullOrWhiteSpace()) + if (input.icmo_id.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(input.icmo_id)); var icmoItem = await db.Queryable().FirstAsync(it => it.id == input.icmo_id); switch (input.category) @@ -533,7 +572,7 @@ namespace Tnb.ProductionMgr if (row > 0) { var prdMo = await db.Queryable().FirstAsync(it => it.id == prdTask.mo_id); - if (prdMo is not null) + if (prdMo is not null) { prdMo.input_qty += prdTask.scheduled_qty; prdMo.icmo_status = DictConst.ToBeScheduledEncode; @@ -546,4 +585,5 @@ namespace Tnb.ProductionMgr } } -} \ No newline at end of file +} + diff --git a/common/Tnb.Common/Extension/StringExtensions.cs b/common/Tnb.Common/Extension/StringExtensions.cs index 3d07967a..189a3c6d 100644 --- a/common/Tnb.Common/Extension/StringExtensions.cs +++ b/common/Tnb.Common/Extension/StringExtensions.cs @@ -938,5 +938,16 @@ public static class StringExtensions return kq * q / ((kq * q) + (kr * r) + (ks * s)); } + /// + /// 字符串转枚举 + /// + /// 枚举类型 + /// 字符串值 + /// 枚举值 + public static T ToEnum(this string value) + { + return (T)System.Enum.Parse(typeof(T), value, true); + } + #endregion } \ No newline at end of file From afbf8383c93102f9a4eb02d4e6d9a1f28ea5e275 Mon Sep 17 00:00:00 2001 From: "DEVICE8\\12494" Date: Mon, 8 May 2023 17:07:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Enums/Behavior.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Enums/Behavior.cs diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Enums/Behavior.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Enums/Behavior.cs new file mode 100644 index 00000000..1af1896b --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Enums/Behavior.cs @@ -0,0 +1,23 @@ +namespace Tnb.ProductionMgr.Entities.Enums +{ + public enum Behavior + { + /// + /// 任务下发 + /// + Release = 1, + /// + /// 任务开始 + /// + Start = 2, + /// + /// 任务关闭 + /// + Closed = 4, + /// + /// 任务完成 + /// + Compled = 8, + } +} +