using System; using System.Collections.Generic; using System.Linq; using HH.WCS.Mobox3.Template.Entity; using HH.WCS.Mobox3.Template.Util.Helper; namespace HH.WCS.Mobox3.Template.Controller.Service; /// /// 任务 /// public static class TaskService { /// /// 创建作业 /// /// public static void CreateTask() { // 1. 查询任务是否已创建 var operation = AdoSqlHelper.QueryFirstByDecs(p => p.N_B_STATE == 0, p => p.T_CREATE); if (operation == null) { return; } // 任务存在,根据任务类型做不同的操作 if (operation.N_TYPE == 1) { var inputLocation = InputLocation(operation.S_CNTR_CODE); if (inputLocation == null) { LogHelper.Info($"当前容器未绑定物料,请检查", "出入库流程日志"); return; } // 任务 var task = new Task() { // 作业编码 S_OP_CODE = operation.S_CODE, // 任务号 S_CODE = HelperMethod.GenerateTaskNo("任务号", "TA"), // 任务类型 N_TYPE = operation.N_TYPE, // 任务类型 S_TYPE = Task.GetStateType(operation.N_TYPE), // 起点货位 S_START_LOC = operation.S_START_LOC, // 终点货位 S_END_LOC = inputLocation.S_CODE, // 容器编码 S_CNTR_CODE = operation.S_CNTR_CODE, }; // 修改作业状态为执行中 operation.N_B_STATE = 1; operation.S_B_STATE = "执行"; operation.T_START_TIME = DateTime.Now; var querySqlSugarClient = AdoSqlHelper.QuerySqlSugarClient(); try { querySqlSugarClient.BeginTran(); AdoSqlHelper.AddFirstTran(querySqlSugarClient, task); AdoSqlHelper.UpdateFirstTran(querySqlSugarClient, operation, p => new { p.N_B_STATE, p.S_B_STATE, p.T_START_TIME }); querySqlSugarClient.CommitTran(); } catch (Exception e) { if (operation.N_TYPE == 1) { LogHelper.Info($"作业号为:{operation.S_CODE}的任务创建失败", "出入库流程日志"); } else { LogHelper.Info($"作业号为:{operation.S_CODE}的任务创建失败", "出入库流程日志"); } querySqlSugarClient.RollbackTran(); } } } /// /// 入库货位分配 /// /// private static Location InputLocation(string container) { var cntrItemDetail = AdoSqlHelper.QueryFirst(p => p.S_CNTR_CODE == container); if (cntrItemDetail == null) { return null; } return AdoSqlHelper.QueryInputLocation(cntrItemDetail.S_ITEM_CODE); } }