diff --git a/ProductionMgr/Tnb.ProductionMgr.Entitys/Consts/DictionaryConstants.cs b/ProductionMgr/Tnb.ProductionMgr.Entitys/Consts/DictionaryConstants.cs
index 903c5d76..33ee5dc5 100644
--- a/ProductionMgr/Tnb.ProductionMgr.Entitys/Consts/DictionaryConstants.cs
+++ b/ProductionMgr/Tnb.ProductionMgr.Entitys/Consts/DictionaryConstants.cs
@@ -16,6 +16,10 @@ namespace Tnb.ProductionMgr.Entitys.新文件夹
/// 工单状态 已下发字典Id
///
public const string IssueId = "25019232867093";
+ ///
+ /// 任务单状态-待开工编码
+ ///
+ public const string ToBeStartedEnCode = "ToBeStarted";
}
///
diff --git a/ProductionMgr/Tnb.ProductionMgr.Entitys/Dto/PrdManage/TransferPlatformUpInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entitys/Dto/PrdManage/TransferPlatformUpInput.cs
new file mode 100644
index 00000000..4ae9808a
--- /dev/null
+++ b/ProductionMgr/Tnb.ProductionMgr.Entitys/Dto/PrdManage/TransferPlatformUpInput.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Principal;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tnb.ProductionMgr.Entitys.Dto.PrdManage
+{
+ ///
+ /// 转移机台输入参数
+ ///
+ public class TransferPlatformUpInput
+ {
+ ///
+ /// 设备Id
+ ///
+ public string eqp_id { get; set; }
+ ///
+ /// 生产任务单Id
+ ///
+ public string icmo_id { get; set; }
+ }
+}
diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs
index c8d2e4f9..629705df 100644
--- a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs
+++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs
@@ -49,216 +49,10 @@ namespace Tnb.ProductionPlanMgr
_userManager = userManager;
_dictionaryDataService = dictionaryDataService;
}
- ///
- /// 生产工单创建-生产工单下发
- ///
- /// 生产工单下发输入参数
- ///
- [HttpPut("workorder-issue")]
- public async Task WorkOrderIssue(MoCrInput input)
- {
- if (input is null)
- {
- throw new ArgumentNullException(nameof(input));
- }
-
- var db = _repository.AsSugarClient();
- //获取同组工单的Id,一起下发
- var combineMoCodes = await db.Queryable().Where(it => input.WorkOrderIds.Contains(it.id)).Select(it => it.combine_mo_code).ToListAsync();
- if (combineMoCodes?.Count > 0)
- {
- var moIds = await db.Queryable().Where(it => combineMoCodes.Contains(it.combine_mo_code) && !input.WorkOrderIds.Contains(it.id)).Select(it => it.id).ToListAsync();
- input.WorkOrderIds = input.WorkOrderIds.Concat(moIds).ToList();
- }
-
- var row = await db.Updateable()
- .SetColumns(it => new PrdMo { mo_status = DictionaryConstants.IssueId })
- .Where(it => input.WorkOrderIds.Contains(it.id))
- .ExecuteCommandAsync();
- return (row > 0);
- }
- ///
- /// 关联同组工单
- ///
- /// 关联同组工单输入参数
- ///
- [HttpPost("relevancy")]
- public async Task RelevancySameGroupMo(MoCrInput input)
- {
- (bool executeRes, string errMsg) multi = (true, "");
- var list = await _repository.AsSugarClient().Queryable()
- .InnerJoin((a, b) => a.item_code == b.item_id)
- .Where((a, b) => input.WorkOrderIds.Contains(a.id))
- .Select((a, b) => new
- {
- planDate = a.plan_start_date,
- mold_code = b.mold_code,
- }).ToListAsync();
- var planDateAll = true;
- var moldIdAll = true;
- if (list?.Count > 0)
- {
- var planDate = list.FirstOrDefault()?.planDate;
- var moldCode = list.FirstOrDefault()?.mold_code;
-
- planDateAll = list.Skip(1).All(x => x.planDate == planDate);
- moldIdAll = list.Skip(1).All(x => x.mold_code == moldCode);
- if (planDateAll && moldIdAll)
- {
- var groupId = SnowflakeIdHelper.NextId();
- multi.executeRes = await _repository.AsSugarClient().Updateable()
- .SetColumns(c => new PrdMo { combine_mo_code = groupId })
- .Where(it => input.WorkOrderIds.Contains(it.id))
- .ExecuteCommandHasChangeAsync();
- }
- else
- {
- multi.executeRes = false;
- if (!planDateAll)
- {
- throw new AppFriendlyException("计划开始日期不一致", null);
- }
- if (!moldIdAll)
- {
- throw new AppFriendlyException("未关联到同一模具下", null);
- }
- }
-
- }
- else
- {
- multi.executeRes = false;
- if (!planDateAll)
- {
- throw new AppFriendlyException("计划开始日期不一致", null);
- }
- if (!moldIdAll)
- {
- throw new AppFriendlyException("未关联到同一模具下", null);
- }
- }
- return multi;
- }
-
- ///
- /// 取消关联
- ///
- /// 取消关联输入参数
- ///
- [HttpPost("CanelRelevancy")]
- public async Task CanelRelevancy(MoCrInput input)
- {
- return await _repository.AsSugarClient().Updateable()
- .SetColumns(c => new PrdMo { combine_mo_code = "" })
- .Where(it => input.WorkOrderIds.Contains(it.id))
- .ExecuteCommandHasChangeAsync();
- }
- ///
- /// 生产工单-生产排产
- ///
- ///
- ///
{
- ///
Id:生产任务主键Id
- ///
MoType:工单类型 1、注塑/挤出 2、组装/包装
- ///
MoId:工单Id
- ///
ItemId:产品编号
- ///
ItemName:产品名称
- ///
MoldId:模具Id
- ///
MoldName:模具名称
- ///
EqpId:设备Id
- ///
EqpName:设备名称
- ///
LineId:产线编号
- ///
LineName:产线名称
- ///
}
- ///
- ///
- [HttpPost("scheduling")]
- public async Task ProductionScheduling(ProductionSchedulingCrInput input)
- {
- var row = -1;
- if (input.mo_type.HasValue && input.mo_type.Value == 1)
- {
- input.id ??= SnowflakeIdHelper.NextId();
- var entity = input.Adapt();
- entity.status = "ToBeScheduled"; //任务单状态默认,待排产
- entity.create_id = _userManager.UserId;
- entity.create_time = DateTime.Now;
- entity.prd_task_id = input.id;
- var db = _repository.AsSugarClient();
- try
- {
- await db.Ado.BeginTranAsync();
-
-
- row = await db.Storageable(entity).ExecuteCommandAsync();
- var taskLogEntity = input.Adapt();
- taskLogEntity.id ??= SnowflakeIdHelper.NextId();
- taskLogEntity.task_id = input.id;
- taskLogEntity.status ??= "ToBeStarted";
- taskLogEntity.create_id = _userManager.UserId;
- taskLogEntity.create_time = DateTime.Now;
- taskLogEntity.operator_name = _userManager.RealName;
-
- //任务状态变更时插入操作记录
- if (!db.Queryable().Where(it => it.task_id == input.id && it.status == taskLogEntity.status).Any())
- {
- row = await db.Insertable(taskLogEntity).ExecuteCommandAsync();
- }
-
- if (row > 0)
- {
- var obj = (await db.Queryable().FirstAsync(it => it.id == input.mo_id));
- obj.input_qty += entity.scheduled_qty;
- var moStatus = "";
- //判断,已排产数量>=计划数量时将状态改为 已排产
- if (obj.input_qty >= obj.plan_qty)
- {
- moStatus = MoStatus.AlreadyId;
- }
- else
- {
- //修改工单状态为待排产,同事修改已排产数量
- moStatus = MoStatus.WaitProductId;
- }
- row = await db.Updateable().SetColumns(it => new PrdMo
- {
- mo_status = moStatus,
- input_qty = obj.input_qty
- })
- .Where(it => it.id == entity.mo_id).ExecuteCommandAsync();
- }
-
- await db.Ado.CommitTranAsync();
- }
- catch (Exception ex)
- {
- Log.Error("生产任务发布时发生错误", ex);
- await db.Ado.RollbackTranAsync();
- }
- }
- return row > 0;
- }
- ///
- /// 生产任务下发
- ///
- ///
- [HttpPost("task-release")]
- public async Task PrdTaskRelease(PrdTaskReleaseUpInput input)
- {
- if (input is null)
- {
- throw new ArgumentNullException(nameof(input));
- }
- var db = _repository.AsSugarClient();
- var row = await db.Updateable()
- .SetColumns(it => new PrdTask { status = "ToBeStarted" })
- .Where(it => input.TaskIds.Contains(it.id))
- .ExecuteCommandAsync();
- return (row > 0);
- }
+ #region Get
///
/// 根据产品ID获取模具列表
@@ -359,17 +153,6 @@ namespace Tnb.ProductionPlanMgr
}).ToList();
return data;
}
- ///
- /// 工单调整-转移机台
- ///
- ///
- [HttpPost("tran-platform")]
- public async Task TransferPlatform()
- {
- return null;
- }
-
-
///
/// 查看工单操作记录
///
@@ -384,5 +167,220 @@ namespace Tnb.ProductionPlanMgr
_repository.AsSugarClient().ThenMapper(data, x => x.statusName = dic.ContainsKey(x.status) ? dic[x.status].ToString() : "");
return data;
}
+
+ #endregion
+
+ #region Post
+
+ ///
+ /// 生产工单创建-生产工单下发
+ ///
+ /// 生产工单下发输入参数
+ ///
+ [HttpPut("workorder-issue")]
+ public async Task WorkOrderIssue(MoCrInput input)
+ {
+ if (input is null)
+ {
+ throw new ArgumentNullException(nameof(input));
+ }
+
+ var db = _repository.AsSugarClient();
+ //获取同组工单的Id,一起下发
+ var combineMoCodes = await db.Queryable().Where(it => input.WorkOrderIds.Contains(it.id)).Select(it => it.combine_mo_code).ToListAsync();
+ if (combineMoCodes?.Count > 0)
+ {
+ var moIds = await db.Queryable().Where(it => combineMoCodes.Contains(it.combine_mo_code) && !input.WorkOrderIds.Contains(it.id)).Select(it => it.id).ToListAsync();
+ input.WorkOrderIds = input.WorkOrderIds.Concat(moIds).ToList();
+ }
+
+ var row = await db.Updateable()
+ .SetColumns(it => new PrdMo { mo_status = DictionaryConstants.IssueId })
+ .Where(it => input.WorkOrderIds.Contains(it.id))
+ .ExecuteCommandAsync();
+ return (row > 0);
+ }
+ ///
+ /// 关联同组工单
+ ///
+ /// 关联同组工单输入参数
+ ///
+ [HttpPost("relevancy")]
+ public async Task RelevancySameGroupMo(MoCrInput input)
+ {
+ (bool executeRes, string errMsg) multi = (true, "");
+ var list = await _repository.AsSugarClient().Queryable()
+ .InnerJoin((a, b) => a.item_code == b.item_id)
+ .Where((a, b) => input.WorkOrderIds.Contains(a.id))
+ .Select((a, b) => new
+ {
+ planDate = a.plan_start_date,
+ mold_code = b.mold_code,
+ }).ToListAsync();
+ var planDateAll = true;
+ var moldIdAll = true;
+ if (list?.Count > 0)
+ {
+ var planDate = list.FirstOrDefault()?.planDate;
+ var moldCode = list.FirstOrDefault()?.mold_code;
+
+ planDateAll = list.Skip(1).All(x => x.planDate == planDate);
+ moldIdAll = list.Skip(1).All(x => x.mold_code == moldCode);
+ if (planDateAll && moldIdAll)
+ {
+ var groupId = SnowflakeIdHelper.NextId();
+ multi.executeRes = await _repository.AsSugarClient().Updateable()
+ .SetColumns(c => new PrdMo { combine_mo_code = groupId })
+ .Where(it => input.WorkOrderIds.Contains(it.id))
+ .ExecuteCommandHasChangeAsync();
+ }
+ else
+ {
+ multi.executeRes = false;
+ if (!planDateAll)
+ {
+ throw new AppFriendlyException("计划开始日期不一致", null);
+ }
+ if (!moldIdAll)
+ {
+ throw new AppFriendlyException("未关联到同一模具下", null);
+ }
+ }
+ }
+ return multi;
+ }
+
+ ///
+ /// 取消关联
+ ///
+ /// 取消关联输入参数
+ ///
+ [HttpPost("CanelRelevancy")]
+ public async Task CanelRelevancy(MoCrInput input)
+ {
+ return await _repository.AsSugarClient().Updateable()
+ .SetColumns(c => new PrdMo { combine_mo_code = "" })
+ .Where(it => input.WorkOrderIds.Contains(it.id))
+ .ExecuteCommandHasChangeAsync();
+ }
+
+ ///
+ /// 生产工单-生产排产
+ ///
+ ///
+ ///
{
+ ///
Id:生产任务主键Id
+ ///
MoType:工单类型 1、注塑/挤出 2、组装/包装
+ ///
MoId:工单Id
+ ///
ItemId:产品编号
+ ///
ItemName:产品名称
+ ///
MoldId:模具Id
+ ///
MoldName:模具名称
+ ///
EqpId:设备Id
+ ///
EqpName:设备名称
+ ///
LineId:产线编号
+ ///
LineName:产线名称
+ ///
}
+ ///
+ ///
+
+ [HttpPost("scheduling")]
+ public async Task ProductionScheduling(ProductionSchedulingCrInput input)
+ {
+ var row = -1;
+ if (input.mo_type.HasValue && input.mo_type.Value == 1)
+ {
+ input.id ??= SnowflakeIdHelper.NextId();
+ var entity = input.Adapt();
+ entity.status = "ToBeScheduled"; //任务单状态默认,待排产
+ entity.create_id = _userManager.UserId;
+ entity.create_time = DateTime.Now;
+ entity.prd_task_id = input.id;
+ var db = _repository.AsSugarClient();
+ try
+ {
+ await db.Ado.BeginTranAsync();
+
+
+ row = await db.Storageable(entity).ExecuteCommandAsync();
+ var taskLogEntity = input.Adapt();
+ taskLogEntity.id ??= SnowflakeIdHelper.NextId();
+ taskLogEntity.task_id = input.id;
+ taskLogEntity.status ??= "ToBeStarted";
+ taskLogEntity.create_id = _userManager.UserId;
+ taskLogEntity.create_time = DateTime.Now;
+ taskLogEntity.operator_name = _userManager.RealName;
+
+ //任务状态变更时插入操作记录
+ if (!db.Queryable().Where(it => it.task_id == input.id && it.status == taskLogEntity.status).Any())
+ {
+ row = await db.Insertable(taskLogEntity).ExecuteCommandAsync();
+ }
+
+ if (row > 0)
+ {
+ var obj = (await db.Queryable().FirstAsync(it => it.id == input.mo_id));
+ obj.input_qty += entity.scheduled_qty;
+ var moStatus = "";
+ //判断,已排产数量>=计划数量时将状态改为 已排产
+ if (obj.input_qty >= obj.plan_qty)
+ {
+ moStatus = MoStatus.AlreadyId;
+ }
+ else
+ {
+ //修改工单状态为待排产,同事修改已排产数量
+ moStatus = MoStatus.WaitProductId;
+ }
+ row = await db.Updateable().SetColumns(it => new PrdMo
+ {
+ mo_status = moStatus,
+ input_qty = obj.input_qty
+ })
+ .Where(it => it.id == entity.mo_id).ExecuteCommandAsync();
+ }
+
+ await db.Ado.CommitTranAsync();
+ }
+ catch (Exception ex)
+ {
+ Log.Error("生产任务发布时发生错误", ex);
+ await db.Ado.RollbackTranAsync();
+ }
+ }
+ return row > 0;
+ }
+ ///
+ /// 生产任务下发
+ ///
+ ///
+ [HttpPost("task-release")]
+ public async Task PrdTaskRelease(PrdTaskReleaseUpInput input)
+ {
+ if (input is null)
+ {
+ throw new ArgumentNullException(nameof(input));
+ }
+ var db = _repository.AsSugarClient();
+ var row = await db.Updateable()
+ .SetColumns(it => new PrdTask { status = DictionaryConstants.ToBeStartedEnCode })
+ .Where(it => input.TaskIds.Contains(it.id))
+ .ExecuteCommandAsync();
+ return (row > 0);
+ }
+
+ ///
+ /// 工单调整-转移机台
+ ///
+ ///
+ [HttpPost]
+ public async Task TransferPlatform(TransferPlatformUpInput input)
+ {
+ return await _repository.AsSugarClient().Updateable()
+ .SetColumns(it => new PrdTask { eqp_id = input.eqp_id })
+ .Where(it => it.id == input.icmo_id)
+ .ExecuteCommandHasChangeAsync();
+ }
+ #endregion
}
}
\ No newline at end of file