优化调整
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using JNPF;
|
||||||
using JNPF.Common.Core.Manager;
|
using JNPF.Common.Core.Manager;
|
||||||
using JNPF.Common.Enums;
|
using JNPF.Common.Enums;
|
||||||
using JNPF.Common.Extension;
|
using JNPF.Common.Extension;
|
||||||
@@ -22,6 +23,7 @@ using SqlSugar;
|
|||||||
using Tnb.BasicData;
|
using Tnb.BasicData;
|
||||||
using Tnb.BasicData.Entities;
|
using Tnb.BasicData.Entities;
|
||||||
using Tnb.BasicData.Entities.Dto;
|
using Tnb.BasicData.Entities.Dto;
|
||||||
|
using Tnb.Common.Extension;
|
||||||
using Tnb.EquipMgr.Entities;
|
using Tnb.EquipMgr.Entities;
|
||||||
using Tnb.PerMgr.Entities;
|
using Tnb.PerMgr.Entities;
|
||||||
using Tnb.ProductionMgr.Entities;
|
using Tnb.ProductionMgr.Entities;
|
||||||
@@ -32,6 +34,8 @@ using Tnb.ProductionMgr.Interfaces;
|
|||||||
using Tnb.QcMgr.Entities;
|
using Tnb.QcMgr.Entities;
|
||||||
using Tnb.QcMgr.Entities.Enums;
|
using Tnb.QcMgr.Entities.Enums;
|
||||||
using Tnb.QcMgr.Interfaces;
|
using Tnb.QcMgr.Interfaces;
|
||||||
|
using Tnb.WarehouseMgr.Entities.Configs;
|
||||||
|
using Tnb.Common.Utils;
|
||||||
|
|
||||||
// using Tnb.PerMgr.Entities;
|
// using Tnb.PerMgr.Entities;
|
||||||
|
|
||||||
@@ -57,6 +61,7 @@ namespace Tnb.ProductionMgr
|
|||||||
private readonly IBillRullService _billRuleService;
|
private readonly IBillRullService _billRuleService;
|
||||||
private readonly IPrdInstockService _prdInstockService;
|
private readonly IPrdInstockService _prdInstockService;
|
||||||
private readonly IQcCheckPlanService _qcCheckPlanService;
|
private readonly IQcCheckPlanService _qcCheckPlanService;
|
||||||
|
private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>();
|
||||||
|
|
||||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||||
public PrdMoTaskService(
|
public PrdMoTaskService(
|
||||||
@@ -1051,308 +1056,368 @@ namespace Tnb.ProductionMgr
|
|||||||
{
|
{
|
||||||
throw new ArgumentException($"{nameof(input.Behavior)} not be null or empty");
|
throw new ArgumentException($"{nameof(input.Behavior)} not be null or empty");
|
||||||
}
|
}
|
||||||
//var taskList = await _db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.id) && it.mo_task_status == DictConst.ToBeScheduledEncode).ToListAsync();
|
ISqlSugarClient db = _repository.AsSugarClient();
|
||||||
//if (taskList?.Count > 0)
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
||||||
{
|
{
|
||||||
static string SetTaskStatus(PrdTaskBehavior behavior)
|
List<PrdMoTask> prdTaskList = new List<PrdMoTask>();
|
||||||
|
//var taskList = await _db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.id) && it.mo_task_status == DictConst.ToBeScheduledEncode).ToListAsync();
|
||||||
|
//if (taskList?.Count > 0)
|
||||||
{
|
{
|
||||||
return behavior switch
|
static string SetTaskStatus(PrdTaskBehavior behavior)
|
||||||
{
|
{
|
||||||
PrdTaskBehavior.Release => DictConst.ToBeStartedEnCode,
|
return behavior switch
|
||||||
PrdTaskBehavior.Start => DictConst.InProgressEnCode,
|
|
||||||
PrdTaskBehavior.Closed => DictConst.ClosedEnCode,
|
|
||||||
PrdTaskBehavior.Compled => DictConst.ComplatedEnCode,
|
|
||||||
PrdTaskBehavior.Pause => DictConst.MoStatusPauseCode,
|
|
||||||
_ => throw new NotImplementedException(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
PrdTaskBehavior behavior = input.Behavior.ToEnum<PrdTaskBehavior>();
|
|
||||||
string status = SetTaskStatus(behavior);
|
|
||||||
ISqlSugarClient db = _repository.AsSugarClient();
|
|
||||||
List<PrdMoTask>? list = await db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.id)).Select(it => it).ToListAsync();
|
|
||||||
if (behavior == PrdTaskBehavior.Compled)
|
|
||||||
{
|
|
||||||
// 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);
|
|
||||||
// // }
|
|
||||||
//
|
|
||||||
// int reportedWorkQty = list.Sum(x => x.last_process_complete_qty) ?? 0;
|
|
||||||
// int scrapQty = list.Sum(x => x.scrap_qty) ?? 0;
|
|
||||||
// int scheduledQty = list.Sum(x => x.scheduled_qty) ?? 0;
|
|
||||||
// if (scheduledQty >= reportedWorkQty+scrapQty)
|
|
||||||
// {
|
|
||||||
// throw new AppFriendlyException("已完成数量大于等于任务单数量,才可完成", 500);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<PrdMoTask> taskReportLogs = new();
|
|
||||||
List<PrdMoTask> prdTaskList = await db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.id)).ToListAsync();
|
|
||||||
if (prdTaskList?.Count > 0)
|
|
||||||
{
|
|
||||||
#region 质检模块
|
|
||||||
//质检
|
|
||||||
if (prdTaskList.Where(p => p.mo_task_status == "Pause").Count() > 0 && status == "InProgress")
|
|
||||||
{
|
|
||||||
foreach (PrdMoTask? task in prdTaskList.Where(p => p.mo_task_status == "Pause").ToList())
|
|
||||||
{
|
{
|
||||||
TriggerPlanEntity entity = new()
|
PrdTaskBehavior.Release => DictConst.ToBeStartedEnCode,
|
||||||
{
|
PrdTaskBehavior.Start => DictConst.InProgressEnCode,
|
||||||
materialid = task.material_id,
|
PrdTaskBehavior.Closed => DictConst.ClosedEnCode,
|
||||||
processid = task.process_id,
|
PrdTaskBehavior.Compled => DictConst.ComplatedEnCode,
|
||||||
workid = task.workstation_id,
|
PrdTaskBehavior.Pause => DictConst.MoStatusPauseCode,
|
||||||
triggerevent = EnumTriggerEvent.首件检生产任务暂停
|
_ => throw new NotImplementedException(),
|
||||||
};
|
};
|
||||||
await _qcCheckPlanService.CreateTask(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
foreach (PrdMoTask item in prdTaskList)
|
|
||||||
{
|
|
||||||
switch (behavior)
|
|
||||||
{
|
|
||||||
// case PrdTaskBehavior.Release:
|
|
||||||
// if (item.mo_task_status == status)
|
|
||||||
// {
|
|
||||||
// throw Oops.Bah("已下发的不能再下发");
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
case PrdTaskBehavior.Start:
|
|
||||||
if (item.mo_task_status == status)
|
|
||||||
{
|
|
||||||
throw Oops.Bah("已开始的不能再开始");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.schedule_type == 2)
|
|
||||||
{
|
|
||||||
if (await db.Queryable<PrdMoTask>().AnyAsync(x => x.workstation_id == item.workstation_id && x.mo_task_status == DictConst.InProgressEnCode && x.id != item.id))
|
|
||||||
{
|
|
||||||
throw Oops.Bah("该工位已有生产中的任务单");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.mo_task_status is not DictConst.ToBeStartedEnCode and not DictConst.MoStatusPauseCode)
|
|
||||||
{
|
|
||||||
throw Oops.Bah("状态错误无法开始");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PrdTaskBehavior.Pause:
|
|
||||||
if (item.mo_task_status == status)
|
|
||||||
{
|
|
||||||
throw Oops.Bah("已暂停的不能再暂停");
|
|
||||||
}
|
|
||||||
if (item.mo_task_status != DictConst.InProgressEnCode)
|
|
||||||
{
|
|
||||||
throw Oops.Bah("状态错误无法暂停");
|
|
||||||
}
|
|
||||||
|
|
||||||
item.pause_reason = input.PauseReeson;
|
|
||||||
break;
|
|
||||||
case PrdTaskBehavior.Compled:
|
|
||||||
if (item.mo_task_status == status)
|
|
||||||
{
|
|
||||||
throw Oops.Bah("已完成的不能再完成");
|
|
||||||
}
|
|
||||||
if (item.mo_task_status is not DictConst.InProgressEnCode and not DictConst.MoStatusPauseCode)
|
|
||||||
{
|
|
||||||
throw Oops.Bah("状态错误无法完成");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PrdTaskBehavior.Closed:
|
|
||||||
if (item.mo_task_status == status)
|
|
||||||
{
|
|
||||||
throw Oops.Bah("已关闭的不能再关闭");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prdTaskList.ForEach(x => x.mo_task_status = status);
|
PrdTaskBehavior behavior = input.Behavior.ToEnum<PrdTaskBehavior>();
|
||||||
if (behavior == PrdTaskBehavior.Start)
|
string status = SetTaskStatus(behavior);
|
||||||
{
|
|
||||||
prdTaskList.ForEach(x => x.act_start_date = DateTime.Now);
|
List<PrdMoTask>? list = await db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.id)).Select(it => it).ToListAsync();
|
||||||
}
|
|
||||||
if (behavior == PrdTaskBehavior.Compled)
|
if (behavior == PrdTaskBehavior.Compled)
|
||||||
{
|
{
|
||||||
prdTaskList.ForEach(x => x.act_end_date = DateTime.Now);
|
// 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);
|
||||||
|
// // }
|
||||||
|
//
|
||||||
|
// int reportedWorkQty = list.Sum(x => x.last_process_complete_qty) ?? 0;
|
||||||
|
// int scrapQty = list.Sum(x => x.scrap_qty) ?? 0;
|
||||||
|
// int scheduledQty = list.Sum(x => x.scheduled_qty) ?? 0;
|
||||||
|
// if (scheduledQty >= reportedWorkQty+scrapQty)
|
||||||
|
// {
|
||||||
|
// throw new AppFriendlyException("已完成数量大于等于任务单数量,才可完成", 500);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
row = await db.Updateable(prdTaskList).ExecuteCommandAsync();
|
|
||||||
foreach (PrdMoTask item in prdTaskList)
|
|
||||||
|
|
||||||
|
List<PrdMoTask> taskReportLogs = new();
|
||||||
|
prdTaskList = await db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.id)).ToListAsync();
|
||||||
|
if (prdTaskList?.Count > 0)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(item.parent_id))
|
#region 质检模块
|
||||||
|
//质检
|
||||||
|
if (prdTaskList.Where(p => p.mo_task_status == "Pause").Count() > 0 && status == "InProgress")
|
||||||
{
|
{
|
||||||
continue;
|
foreach (PrdMoTask? task in prdTaskList.Where(p => p.mo_task_status == "Pause").ToList())
|
||||||
|
{
|
||||||
|
TriggerPlanEntity entity = new()
|
||||||
|
{
|
||||||
|
materialid = task.material_id,
|
||||||
|
processid = task.process_id,
|
||||||
|
workid = task.workstation_id,
|
||||||
|
triggerevent = EnumTriggerEvent.首件检生产任务暂停
|
||||||
|
};
|
||||||
|
await _qcCheckPlanService.CreateTask(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//子任务所有状态相同才修改父任务状态
|
#endregion
|
||||||
int count1 = await db.Queryable<PrdMoTask>().CountAsync(y => y.parent_id == item.parent_id);
|
|
||||||
int count2 = await db.Queryable<PrdMoTask>().CountAsync(y => y.parent_id == item.parent_id && y.mo_task_status == status);
|
foreach (PrdMoTask item in prdTaskList)
|
||||||
if (count1 == count2)
|
|
||||||
{
|
{
|
||||||
_ = await db.Updateable<PrdMoTask>().SetColumns(x => x.mo_task_status == status)
|
switch (behavior)
|
||||||
.Where(x => x.id == item.parent_id).ExecuteCommandAsync();
|
{
|
||||||
|
// case PrdTaskBehavior.Release:
|
||||||
|
// if (item.mo_task_status == status)
|
||||||
|
// {
|
||||||
|
// throw Oops.Bah("已下发的不能再下发");
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
case PrdTaskBehavior.Start:
|
||||||
|
if (item.mo_task_status == status)
|
||||||
|
{
|
||||||
|
throw Oops.Bah("已开始的不能再开始");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.schedule_type == 2)
|
||||||
|
{
|
||||||
|
if (await db.Queryable<PrdMoTask>().AnyAsync(x => x.workstation_id == item.workstation_id && x.mo_task_status == DictConst.InProgressEnCode && x.id != item.id))
|
||||||
|
{
|
||||||
|
throw Oops.Bah("该工位已有生产中的任务单");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.mo_task_status is not DictConst.ToBeStartedEnCode and not DictConst.MoStatusPauseCode)
|
||||||
|
{
|
||||||
|
throw Oops.Bah("状态错误无法开始");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PrdTaskBehavior.Pause:
|
||||||
|
if (item.mo_task_status == status)
|
||||||
|
{
|
||||||
|
throw Oops.Bah("已暂停的不能再暂停");
|
||||||
|
}
|
||||||
|
if (item.mo_task_status != DictConst.InProgressEnCode)
|
||||||
|
{
|
||||||
|
throw Oops.Bah("状态错误无法暂停");
|
||||||
|
}
|
||||||
|
|
||||||
|
item.pause_reason = input.PauseReeson;
|
||||||
|
break;
|
||||||
|
case PrdTaskBehavior.Compled:
|
||||||
|
if (item.mo_task_status == status)
|
||||||
|
{
|
||||||
|
throw Oops.Bah("已完成的不能再完成");
|
||||||
|
}
|
||||||
|
if (item.mo_task_status is not DictConst.InProgressEnCode and not DictConst.MoStatusPauseCode)
|
||||||
|
{
|
||||||
|
throw Oops.Bah("状态错误无法完成");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PrdTaskBehavior.Closed:
|
||||||
|
if (item.mo_task_status == status)
|
||||||
|
{
|
||||||
|
throw Oops.Bah("已关闭的不能再关闭");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prdTaskList.ForEach(x => x.mo_task_status = status);
|
||||||
|
if (behavior == PrdTaskBehavior.Start)
|
||||||
|
{
|
||||||
|
prdTaskList.ForEach(x => x.act_start_date = DateTime.Now);
|
||||||
|
}
|
||||||
|
if (behavior == PrdTaskBehavior.Compled)
|
||||||
|
{
|
||||||
|
prdTaskList.ForEach(x => x.act_end_date = DateTime.Now);
|
||||||
|
}
|
||||||
|
row = await db.Updateable(prdTaskList).ExecuteCommandAsync();
|
||||||
|
foreach (PrdMoTask item in prdTaskList)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(item.parent_id))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//子任务所有状态相同才修改父任务状态
|
||||||
|
int count1 = await db.Queryable<PrdMoTask>().CountAsync(y => y.parent_id == item.parent_id);
|
||||||
|
int count2 = await db.Queryable<PrdMoTask>().CountAsync(y => y.parent_id == item.parent_id && y.mo_task_status == status);
|
||||||
|
if (count1 == count2)
|
||||||
|
{
|
||||||
|
_ = await db.Updateable<PrdMoTask>().SetColumns(x => x.mo_task_status == status)
|
||||||
|
.Where(x => x.id == item.parent_id).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (row > 0)
|
||||||
|
{
|
||||||
|
taskReportLogs.AddRange(prdTaskList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (row > 0)
|
if (row > 0)
|
||||||
{
|
{
|
||||||
taskReportLogs.AddRange(prdTaskList);
|
//更新子任务
|
||||||
}
|
List<PrdMoTask> subMoTaskList = await db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.parent_id)).ToListAsync();
|
||||||
}
|
if (subMoTaskList?.Count > 0)
|
||||||
if (row > 0)
|
|
||||||
{
|
|
||||||
//更新子任务
|
|
||||||
List<PrdMoTask> subMoTaskList = await db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.parent_id)).ToListAsync();
|
|
||||||
if (subMoTaskList?.Count > 0)
|
|
||||||
{
|
|
||||||
List<string> subTaskIds = subMoTaskList.Select(it => it.id).ToList();
|
|
||||||
row = await db.Updateable<PrdMoTask>()
|
|
||||||
.SetColumns(it => new PrdMoTask { mo_task_status = status })
|
|
||||||
.Where(it => subTaskIds.Contains(it.id))
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
if (row > 0)
|
|
||||||
{
|
{
|
||||||
taskReportLogs.AddRange(subMoTaskList);
|
List<string> subTaskIds = subMoTaskList.Select(it => it.id).ToList();
|
||||||
}
|
row = await db.Updateable<PrdMoTask>()
|
||||||
}
|
.SetColumns(it => new PrdMoTask { mo_task_status = status })
|
||||||
}
|
.Where(it => subTaskIds.Contains(it.id))
|
||||||
//插入操作记录日志
|
.ExecuteCommandAsync();
|
||||||
List<PrdMoTask> prdMOTasks = await _db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.id) && string.IsNullOrEmpty(it.parent_id)).ToListAsync();
|
if (row > 0)
|
||||||
if (prdMOTasks?.Count > 0)
|
|
||||||
{
|
|
||||||
List<PrdTaskLog> taskLogEntities = new();
|
|
||||||
foreach (string taskId in input.TaskIds)
|
|
||||||
{
|
|
||||||
PrdTaskLog? taskLog = await db.Queryable<PrdTaskLog>().FirstAsync(it => it.mo_task_id == taskId);
|
|
||||||
if (taskLog is null)
|
|
||||||
{
|
|
||||||
PrdMoTask? taskItem = list?.Find(x => x.id == taskId);
|
|
||||||
taskLog = new PrdTaskLog
|
|
||||||
{
|
{
|
||||||
id = SnowflakeIdHelper.NextId()
|
taskReportLogs.AddRange(subMoTaskList);
|
||||||
};
|
|
||||||
if (taskItem != null)
|
|
||||||
{
|
|
||||||
if (taskItem.mo_id!.IsNotEmptyOrNull())
|
|
||||||
{
|
|
||||||
taskLog.mo_code = (await db.Queryable<PrdMo>().FirstAsync(it => it.id == taskItem.mo_id))?.mo_code!;
|
|
||||||
}
|
|
||||||
if (taskItem.eqp_id!.IsNotEmptyOrNull())
|
|
||||||
{
|
|
||||||
taskLog.eqp_code = (await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == taskItem.eqp_id))?.code!;
|
|
||||||
}
|
|
||||||
if (taskItem.mold_id!.IsNotEmptyOrNull())
|
|
||||||
{
|
|
||||||
taskLog.mold_code = (await db.Queryable<ToolMolds>().FirstAsync(it => it.id == taskItem.mold_id))?.mold_code!;
|
|
||||||
}
|
|
||||||
if (taskItem.material_id!.IsNotEmptyOrNull())
|
|
||||||
{
|
|
||||||
BasMaterial? material = await db.Queryable<BasMaterial>().FirstAsync(it => it.id == taskItem.material_id);
|
|
||||||
taskLog.item_code = material?.code!;
|
|
||||||
taskLog.item_standard = material?.material_standard!;
|
|
||||||
}
|
|
||||||
taskLog.operator_name = _userManager.RealName;
|
|
||||||
taskLog.status = status;
|
|
||||||
taskLog.create_id = _userManager.UserId;
|
|
||||||
taskLog.create_time = DateTime.Now;
|
|
||||||
taskLog.mo_task_id = taskItem.id;
|
|
||||||
}
|
}
|
||||||
taskLogEntities.Add(taskLog);
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
//插入操作记录日志
|
||||||
|
List<PrdMoTask> prdMOTasks = await _db.Queryable<PrdMoTask>().Where(it => input.TaskIds.Contains(it.id) && string.IsNullOrEmpty(it.parent_id)).ToListAsync();
|
||||||
|
if (prdMOTasks?.Count > 0)
|
||||||
|
{
|
||||||
|
List<PrdTaskLog> taskLogEntities = new();
|
||||||
|
foreach (string taskId in input.TaskIds)
|
||||||
{
|
{
|
||||||
List<PrdTaskLog> records = await db.Queryable<PrdTaskLog>().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync();
|
PrdTaskLog? taskLog = await db.Queryable<PrdTaskLog>().FirstAsync(it => it.mo_task_id == taskId);
|
||||||
if (records != null && !records.Select(x => x.status).Contains(status))
|
if (taskLog is null)
|
||||||
{
|
{
|
||||||
taskLog.id = SnowflakeIdHelper.NextId();
|
PrdMoTask? taskItem = list?.Find(x => x.id == taskId);
|
||||||
taskLog.status = status;
|
taskLog = new PrdTaskLog
|
||||||
|
{
|
||||||
|
id = SnowflakeIdHelper.NextId()
|
||||||
|
};
|
||||||
|
if (taskItem != null)
|
||||||
|
{
|
||||||
|
if (taskItem.mo_id!.IsNotEmptyOrNull())
|
||||||
|
{
|
||||||
|
taskLog.mo_code = (await db.Queryable<PrdMo>().FirstAsync(it => it.id == taskItem.mo_id))?.mo_code!;
|
||||||
|
}
|
||||||
|
if (taskItem.eqp_id!.IsNotEmptyOrNull())
|
||||||
|
{
|
||||||
|
taskLog.eqp_code = (await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == taskItem.eqp_id))?.code!;
|
||||||
|
}
|
||||||
|
if (taskItem.mold_id!.IsNotEmptyOrNull())
|
||||||
|
{
|
||||||
|
taskLog.mold_code = (await db.Queryable<ToolMolds>().FirstAsync(it => it.id == taskItem.mold_id))?.mold_code!;
|
||||||
|
}
|
||||||
|
if (taskItem.material_id!.IsNotEmptyOrNull())
|
||||||
|
{
|
||||||
|
BasMaterial? material = await db.Queryable<BasMaterial>().FirstAsync(it => it.id == taskItem.material_id);
|
||||||
|
taskLog.item_code = material?.code!;
|
||||||
|
taskLog.item_standard = material?.material_standard!;
|
||||||
|
}
|
||||||
|
taskLog.operator_name = _userManager.RealName;
|
||||||
|
taskLog.status = status;
|
||||||
|
taskLog.create_id = _userManager.UserId;
|
||||||
|
taskLog.create_time = DateTime.Now;
|
||||||
|
taskLog.mo_task_id = taskItem.id;
|
||||||
|
}
|
||||||
taskLogEntities.Add(taskLog);
|
taskLogEntities.Add(taskLog);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
}
|
|
||||||
if (taskLogEntities?.Count > 0)
|
|
||||||
{
|
|
||||||
row = await db.Insertable(taskLogEntities).ExecuteCommandAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PrdReportRecord> prdReportLogs = new();
|
|
||||||
List<PrdMoTaskDefectRecord> prdTaskDefectLogs = new();
|
|
||||||
if (taskReportLogs?.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (PrdMoTask taskInfo in taskReportLogs)
|
|
||||||
{
|
|
||||||
//组装生产提报对象
|
|
||||||
BasMaterial? material = await db.Queryable<BasMaterial>().FirstAsync(it => it.id == taskInfo.material_id);
|
|
||||||
PrdMo? mo = await db.Queryable<PrdMo>().FirstAsync(it => it.id == taskInfo.mo_id);
|
|
||||||
PrdReportRecord record = taskInfo.Adapt<PrdReportRecord>();
|
|
||||||
record.id = SnowflakeIdHelper.NextId();
|
|
||||||
record.masterial_code = material?.code;
|
|
||||||
record.masterial_name = material?.name;
|
|
||||||
record.plan_start_date = taskInfo.estimated_start_date;
|
|
||||||
record.plan_end_date = taskInfo.estimated_end_date;
|
|
||||||
record.plan_qty = taskInfo.plan_qty;
|
|
||||||
record.eqp_code = (await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == taskInfo.eqp_id))?.code;
|
|
||||||
record.mo_task_type = mo?.mo_type;
|
|
||||||
record.status = taskInfo.mo_task_status;
|
|
||||||
record.mo_task_id = taskInfo.id;
|
|
||||||
record.mo_code = mo?.mo_code ?? "";
|
|
||||||
//record.completed_qty = (await db.Queryable<PrdReport>().Where(it => it.mo_task_code == taskInfo.mo_task_code).SumAsync(it => it.reported_work_qty)).Value;
|
|
||||||
prdReportLogs.Add(record);
|
|
||||||
|
|
||||||
//组装自检报废对象
|
|
||||||
PrdMoTaskDefectRecord sacipRecord = new()
|
|
||||||
{
|
{
|
||||||
id = SnowflakeIdHelper.NextId(),
|
List<PrdTaskLog> records = await db.Queryable<PrdTaskLog>().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync();
|
||||||
material_code = material?.code!,
|
if (records != null && !records.Select(x => x.status).Contains(status))
|
||||||
material_name = material?.name!,
|
{
|
||||||
eqp_code = (await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == taskInfo.eqp_id))?.code!,
|
taskLog.id = SnowflakeIdHelper.NextId();
|
||||||
mold_name = (await db.Queryable<ToolMolds>().FirstAsync(it => it.id == taskInfo.mold_id))?.mold_name!,
|
taskLog.status = status;
|
||||||
estimated_start_date = taskInfo.estimated_start_date,
|
taskLogEntities.Add(taskLog);
|
||||||
estimated_end_date = taskInfo.estimated_end_date,
|
}
|
||||||
plan_qty = taskInfo.plan_qty,
|
}
|
||||||
scrap_qty = taskInfo.scrap_qty.HasValue ? taskInfo.scrap_qty.Value : 0,
|
}
|
||||||
status = taskInfo.mo_task_status,
|
if (taskLogEntities?.Count > 0)
|
||||||
create_id = _userManager.UserId,
|
{
|
||||||
create_time = DateTime.Now,
|
row = await db.Insertable(taskLogEntities).ExecuteCommandAsync();
|
||||||
mo_task_id = taskInfo.id,
|
}
|
||||||
mo_task_code = taskInfo.mo_task_code,
|
|
||||||
mo_task_type = mo?.mo_type,
|
List<PrdReportRecord> prdReportLogs = new();
|
||||||
mo_code = mo?.mo_code ?? "",
|
List<PrdMoTaskDefectRecord> prdTaskDefectLogs = new();
|
||||||
};
|
if (taskReportLogs?.Count > 0)
|
||||||
sacipRecord.status = taskInfo.mo_task_status;
|
{
|
||||||
prdTaskDefectLogs.Add(sacipRecord);
|
foreach (PrdMoTask taskInfo in taskReportLogs)
|
||||||
|
{
|
||||||
|
//组装生产提报对象
|
||||||
|
BasMaterial? material = await db.Queryable<BasMaterial>().FirstAsync(it => it.id == taskInfo.material_id);
|
||||||
|
PrdMo? mo = await db.Queryable<PrdMo>().FirstAsync(it => it.id == taskInfo.mo_id);
|
||||||
|
PrdReportRecord record = taskInfo.Adapt<PrdReportRecord>();
|
||||||
|
record.id = SnowflakeIdHelper.NextId();
|
||||||
|
record.masterial_code = material?.code;
|
||||||
|
record.masterial_name = material?.name;
|
||||||
|
record.plan_start_date = taskInfo.estimated_start_date;
|
||||||
|
record.plan_end_date = taskInfo.estimated_end_date;
|
||||||
|
record.plan_qty = taskInfo.plan_qty;
|
||||||
|
record.eqp_code = (await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == taskInfo.eqp_id))?.code;
|
||||||
|
record.mo_task_type = mo?.mo_type;
|
||||||
|
record.status = taskInfo.mo_task_status;
|
||||||
|
record.mo_task_id = taskInfo.id;
|
||||||
|
record.mo_code = mo?.mo_code ?? "";
|
||||||
|
//record.completed_qty = (await db.Queryable<PrdReport>().Where(it => it.mo_task_code == taskInfo.mo_task_code).SumAsync(it => it.reported_work_qty)).Value;
|
||||||
|
prdReportLogs.Add(record);
|
||||||
|
|
||||||
|
//组装自检报废对象
|
||||||
|
PrdMoTaskDefectRecord sacipRecord = new()
|
||||||
|
{
|
||||||
|
id = SnowflakeIdHelper.NextId(),
|
||||||
|
material_code = material?.code!,
|
||||||
|
material_name = material?.name!,
|
||||||
|
eqp_code = (await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == taskInfo.eqp_id))?.code!,
|
||||||
|
mold_name = (await db.Queryable<ToolMolds>().FirstAsync(it => it.id == taskInfo.mold_id))?.mold_name!,
|
||||||
|
estimated_start_date = taskInfo.estimated_start_date,
|
||||||
|
estimated_end_date = taskInfo.estimated_end_date,
|
||||||
|
plan_qty = taskInfo.plan_qty,
|
||||||
|
scrap_qty = taskInfo.scrap_qty.HasValue ? taskInfo.scrap_qty.Value : 0,
|
||||||
|
status = taskInfo.mo_task_status,
|
||||||
|
create_id = _userManager.UserId,
|
||||||
|
create_time = DateTime.Now,
|
||||||
|
mo_task_id = taskInfo.id,
|
||||||
|
mo_task_code = taskInfo.mo_task_code,
|
||||||
|
mo_task_type = mo?.mo_type,
|
||||||
|
mo_code = mo?.mo_code ?? "",
|
||||||
|
};
|
||||||
|
sacipRecord.status = taskInfo.mo_task_status;
|
||||||
|
prdTaskDefectLogs.Add(sacipRecord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<string> reportTaskIds = prdReportLogs.Select(it => it.mo_task_id).ToList();
|
||||||
|
if (reportTaskIds?.Count > 0)
|
||||||
|
{
|
||||||
|
List<PrdReportRecord> items = await db.Queryable<PrdReportRecord>().Where(it => reportTaskIds.Contains(it.mo_task_id)).ToListAsync();
|
||||||
|
if (items == null || items.Count < 1)
|
||||||
|
{
|
||||||
|
row = await db.Insertable(prdReportLogs).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<string?> defectTaskIds = prdTaskDefectLogs.Select(it => it.mo_task_id).ToList();
|
||||||
|
if (defectTaskIds?.Count > 0)
|
||||||
|
{
|
||||||
|
List<PrdMoTaskDefectRecord> items = await db.Queryable<PrdMoTaskDefectRecord>().Where(it => defectTaskIds.Contains(it.mo_task_id)).ToListAsync();
|
||||||
|
if (items == null || items.Count < 1)
|
||||||
|
{
|
||||||
|
row = await db.Insertable(prdTaskDefectLogs).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<string> reportTaskIds = prdReportLogs.Select(it => it.mo_task_id).ToList();
|
|
||||||
if (reportTaskIds?.Count > 0)
|
foreach (var item in prdTaskList)
|
||||||
{
|
{
|
||||||
List<PrdReportRecord> items = await db.Queryable<PrdReportRecord>().Where(it => reportTaskIds.Contains(it.mo_task_id)).ToListAsync();
|
if (PrdTaskBehavior.Start==behavior && item.schedule_type == 2)
|
||||||
if (items == null || items.Count < 1)
|
|
||||||
{
|
{
|
||||||
row = await db.Insertable(prdReportLogs).ExecuteCommandAsync();
|
PrdMo prdMo = await db.Queryable<PrdMo>().SingleAsync(x => x.id == item.mo_id);
|
||||||
}
|
if (prdMo.mo_type == DictConst.PrdMoTypeBZ)
|
||||||
}
|
{
|
||||||
List<string?> defectTaskIds = prdTaskDefectLogs.Select(it => it.mo_task_id).ToList();
|
if (await _db.Queryable<PrdOutPackMarkLabel>().Where(x =>
|
||||||
if (defectTaskIds?.Count > 0)
|
x.mo_task_code == item.mo_task_code && x.status == "0" && x.is_label == null && x.is_mark==0).AnyAsync())
|
||||||
{
|
{
|
||||||
List<PrdMoTaskDefectRecord> items = await db.Queryable<PrdMoTaskDefectRecord>().Where(it => defectTaskIds.Contains(it.mo_task_id)).ToListAsync();
|
await _db.Updateable<PrdOutPackMarkLabel>()
|
||||||
if (items == null || items.Count < 1)
|
.SetColumns(x => x.is_label == 0)
|
||||||
{
|
.Where(x => x.mo_task_code == item.mo_task_code && x.status == "0" && x.is_label == null &&
|
||||||
row = await db.Insertable(prdTaskDefectLogs).ExecuteCommandAsync();
|
x.is_mark == 0)
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PrdOutPackMarkLabel prdOutPackMarkLabel = new PrdOutPackMarkLabel()
|
||||||
|
{
|
||||||
|
is_mark = null,
|
||||||
|
is_label = 0,
|
||||||
|
mo_task_code = item.mo_task_code,
|
||||||
|
material_code = item.material_code,
|
||||||
|
create_time = DateTime.Now,
|
||||||
|
};
|
||||||
|
|
||||||
|
await _db.Insertable<PrdOutPackMarkLabel>(prdOutPackMarkLabel).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
PrdMoTask parent = await _db.Queryable<PrdMoTask>().SingleAsync(x => x.id == item.parent_id);
|
||||||
|
BasMaterial basMaterial = await _db.Queryable<BasMaterial>().SingleAsync(x=>x.id==parent.material_id);
|
||||||
|
|
||||||
|
string code = $"(01){basMaterial.di ?? ""}(11){DateTime.Now.ToString("yyMMdd")}(17){DateTime.Now.AddMonths(basMaterial.quality_guarantee_period ?? 0).ToString("yyMMdd")}(10){parent.batch??""}#{basMaterial.material_standard}*{DateTime.Now.ToString("yyyyMMdd")}*{DateTime.Now.AddMonths(basMaterial.quality_guarantee_period ?? 0).ToString("yyyyMMdd")}*{basMaterial.container_no}";
|
||||||
|
Dictionary<string, string> dicCommand1 = new(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
["DevName"] = "外包装箱码垛线",
|
||||||
|
["token"] = _eleCtlCfg.token,
|
||||||
|
["TagName"] = "WBZX_tb_cs",
|
||||||
|
["Value"] = code,
|
||||||
|
};
|
||||||
|
Dictionary<string, string> dicCommand2 = new(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
["DevName"] = "外包装箱码垛线",
|
||||||
|
["token"] = _eleCtlCfg.token,
|
||||||
|
["TagName"] = "WBZX_pm_cs",
|
||||||
|
["Value"] = code,
|
||||||
|
};
|
||||||
|
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand1);
|
||||||
|
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
//else
|
//else
|
||||||
// throw new AppFriendlyException("只有待下发状态的任务才可下发", 500);
|
// throw new AppFriendlyException("只有待下发状态的任务才可下发", 500);
|
||||||
return row > 0;
|
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -2208,22 +2273,22 @@ namespace Tnb.ProductionMgr
|
|||||||
ToolMolds toolMolds = await db.Queryable<ToolMolds>().SingleAsync(x => x.id == input.molds_id);
|
ToolMolds toolMolds = await db.Queryable<ToolMolds>().SingleAsync(x => x.id == input.molds_id);
|
||||||
if (toolMolds == null)
|
if (toolMolds == null)
|
||||||
{
|
{
|
||||||
throw Oops.Bah("没找到模具");
|
throw Oops.Bah("没找到模具,预计完成时间无法计算");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toolMolds?.mold_cavity <= 0)
|
if (toolMolds?.mold_cavity <= 0)
|
||||||
{
|
{
|
||||||
throw Oops.Bah("模穴数错误");
|
throw Oops.Bah("模穴数错误,预计完成时间无法计算");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processStandardsH == null)
|
if (processStandardsH == null)
|
||||||
{
|
{
|
||||||
throw Oops.Bah("工艺标准成型周期错误");
|
throw Oops.Bah("工艺标准成型周期错误,预计完成时间无法计算");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processStandardsH?.moulding_cycle <= 0)
|
if (processStandardsH?.moulding_cycle <= 0)
|
||||||
{
|
{
|
||||||
throw Oops.Bah("工艺标准成型周期错误");
|
throw Oops.Bah("工艺标准成型周期错误,预计完成时间无法计算");
|
||||||
}
|
}
|
||||||
|
|
||||||
decimal? addTime = (((input.scheduled_qty * processStandardsH?.moulding_cycle) - 1) / toolMolds.mold_cavity) + 1;
|
decimal? addTime = (((input.scheduled_qty * processStandardsH?.moulding_cycle) - 1) / toolMolds.mold_cavity) + 1;
|
||||||
@@ -2235,6 +2300,10 @@ namespace Tnb.ProductionMgr
|
|||||||
.LeftJoin<BasStandardTime>((a, b) => a.process_id == b.process_id && b.enabled == 1)
|
.LeftJoin<BasStandardTime>((a, b) => a.process_id == b.process_id && b.enabled == 1)
|
||||||
.Where((a, b) => a.mbom_id == input.mbom_id).Select((a, b) => b).ToListAsync();
|
.Where((a, b) => a.mbom_id == input.mbom_id).Select((a, b) => b).ToListAsync();
|
||||||
|
|
||||||
|
if (list.IsEmpty())
|
||||||
|
{
|
||||||
|
throw Oops.Bah("无标准工时,预计完成时间无法计算");
|
||||||
|
}
|
||||||
decimal max = list.Select(x => Convert.ToDecimal(x.standard_time)).Max(x => x);
|
decimal max = list.Select(x => Convert.ToDecimal(x.standard_time)).Max(x => x);
|
||||||
decimal? addTime = input.scheduled_qty * max;
|
decimal? addTime = input.scheduled_qty * max;
|
||||||
return input.estimated_start_date.AddSeconds((double)addTime.Value).ToString("yyyy-MM-dd HH:mm:ss");
|
return input.estimated_start_date.AddSeconds((double)addTime.Value).ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
@@ -2939,6 +3008,7 @@ namespace Tnb.ProductionMgr
|
|||||||
public async Task<dynamic> GetLabelInfo(MarkingLabelInput input)
|
public async Task<dynamic> GetLabelInfo(MarkingLabelInput input)
|
||||||
{
|
{
|
||||||
Log.Information($"获取喷码贴标信息参数:{JsonConvert.SerializeObject(input)}");
|
Log.Information($"获取喷码贴标信息参数:{JsonConvert.SerializeObject(input)}");
|
||||||
|
//TODO 之后要改
|
||||||
Dictionary<String, String> dic = new Dictionary<string, string>()
|
Dictionary<String, String> dic = new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
["WBZX1"] = "30019971917589",//血路管自动生产线1线
|
["WBZX1"] = "30019971917589",//血路管自动生产线1线
|
||||||
|
|||||||
@@ -108,10 +108,10 @@ namespace Tnb.ProductionMgr
|
|||||||
["TagName"] = eqpDaq3.label_point,
|
["TagName"] = eqpDaq3.label_point,
|
||||||
["Value"] = "false",
|
["Value"] = "false",
|
||||||
};
|
};
|
||||||
Log.Information($"称重完成参数:{JsonConvert.SerializeObject(dicCommand)}");
|
Log.Information($"称重完成参数:{JsonConvert.SerializeObject(dicCommand2)}");
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand);
|
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -225,8 +225,8 @@ namespace Tnb.ProductionMgr
|
|||||||
string startLocationCode = cs01==false ? "ZSSSXCTU01" : cs03==false ? "ZSSSXCTU02" : "";
|
string startLocationCode = cs01==false ? "ZSSSXCTU01" : cs03==false ? "ZSSSXCTU02" : "";
|
||||||
if (startLocationCode.IsEmpty())
|
if (startLocationCode.IsEmpty())
|
||||||
{
|
{
|
||||||
Log.Error($"起始库位为空");
|
Log.Error($"输送线无空载具");
|
||||||
return "起始库位为空";
|
return "输送线无空载具";
|
||||||
}
|
}
|
||||||
|
|
||||||
var db = _repository.AsSugarClient();
|
var db = _repository.AsSugarClient();
|
||||||
|
|||||||
Reference in New Issue
Block a user