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