From d100db102ded4dc2047f1b92f4ed0ed4c18d8ee4 Mon Sep 17 00:00:00 2001 From: Huangxiaoqiang-03 <1247017146@qq.com> Date: 星期一, 11 十一月 2024 13:56:48 +0800 Subject: [PATCH] 1 --- 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs | 200 ++++++++++++++++++++++++++------------------------ 1 files changed, 104 insertions(+), 96 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" index 5e14f93..e050312 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" @@ -1,20 +1,27 @@ -锘縰sing Microsoft.AspNetCore.Components.Routing; +锘縰sing HslCommunication; +using Microsoft.AspNetCore.Components.Routing; +using Newtonsoft.Json; using Quartz; +using SqlSugar.Extensions; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Net; +using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; +using WIDESEA_Common.Log; +using WIDESEA_Core.Enums; using WIDESEAWCS_Core.Enums; using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.DeviceBase; +using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob.Models; using WIDESEAWCS_QuartzJob.Service; -using WIDESEAWCS_QuartzJob.StackerCrane.Enum; using WIDESEAWCS_Tasks.StackerCraneJob; namespace WIDESEAWCS_Tasks @@ -39,30 +46,30 @@ { try { - CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); - if (commonStackerCrane != null) + SpeStackerCrane speStackerCrane = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); + GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane); + if (speStackerCrane != null) { - if (!commonStackerCrane.IsEventSubscribed) + if (!getStackerObject.IsEventSubscribed) { - commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢 + getStackerObject.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢 } - - if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal) + if (getStackerObject.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && getStackerObject.StackerCraneStatusValue == StackerCraneStatus.Ready) { - commonStackerCrane.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆� + getStackerObject.CheckStackerCraneTaskCompleted();//妫�娴嬪畬鎴愪簨浠� - if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby) + if(getStackerObject.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby) { - Dt_Task? task = GetTask(commonStackerCrane); + Dt_Task? task = GetTask(speStackerCrane); if (task != null) { StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); if (stackerCraneTaskCommand != null) { - bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand); + bool sendFlag = getStackerObject.SendCommand(stackerCraneTaskCommand); if (sendFlag) { - commonStackerCrane.LastTaskType = task.TaskType; + speStackerCrane.LastTaskType = task.TaskType; _taskService.UpdateTaskStatusToNext(task.TaskNum); } } @@ -73,7 +80,7 @@ } catch (Exception ex) { - Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString()); + WriteLog.GetLog($"鍫嗗灈鏈哄紓甯�").Write($"{nameof(CommonStackerCraneJob)}:{ex.Message}", "鍫嗗灈鏈哄紓甯�"); } return Task.CompletedTask; } @@ -85,14 +92,14 @@ /// <param name="e"></param> private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e) { - CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane; - if (commonStackerCrane != null) + SpeStackerCrane? speStackerCrane = sender as SpeStackerCrane; + if (speStackerCrane != null) { - if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5) + if (speStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5) { Console.Out.WriteLine("TaskCompleted" + e.TaskNum); _taskService.StackCraneTaskCompleted(e.TaskNum); - commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); + speStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); } } } @@ -102,50 +109,29 @@ /// </summary> /// <param name="commonStackerCrane">鍫嗗灈鏈哄璞�</param> /// <returns></returns> - private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane) + private Dt_Task? GetTask(SpeStackerCrane speStackerCrane) { - Dt_Task task; - if (commonStackerCrane.LastTaskType == null) + Dt_Task? task; + if (speStackerCrane.LastTaskType == null) { - task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode); + task = _taskService.QueryStackerCraneTask(speStackerCrane.DeviceCode); } else { - if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) + bool flag = speStackerCrane.LastTaskType == TaskTypeEnum.Inbound.ObjToInt() || speStackerCrane.LastTaskType == TaskTypeEnum.PalletInbound.ObjToInt(); + if (flag == false) { - task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); + task = _taskService.QueryStackerCraneInTask(speStackerCrane.DeviceCode); if (task == null) { - task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); + task = _taskService.QueryStackerCraneOutTask(speStackerCrane.DeviceCode); } } else { - task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); + task = _taskService.QueryStackerCraneOutTask(speStackerCrane.DeviceCode); } } - - if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) - { - if (OutTaskStationIsOccupied(task) != null) - { - return task; - } - else - { - List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList(); - List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes); - foreach (var item in tasks) - { - if (OutTaskStationIsOccupied(task) != null) - { - return task; - } - } - task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); - } - } - return task; } @@ -179,7 +165,6 @@ } return null; } - /// <summary> /// 浠诲姟瀹炰綋杞崲鎴愬懡浠odel /// </summary> @@ -194,50 +179,66 @@ stackerCraneTaskCommand.TaskNum = task.TaskNum; stackerCraneTaskCommand.WorkType = 1; stackerCraneTaskCommand.TrayType = 0; - if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔� + if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())//鍒ゆ柇鏄惁鏄叆搴撲换鍔� { - List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.Roadway); - if (routers.Count > 0) + if (task.SourceAddress != null && task.TargetAddress != null) { - stackerCraneTaskCommand.StartRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow); - stackerCraneTaskCommand.StartColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn); - stackerCraneTaskCommand.StartLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer); - - string[] targetCodes = task.NextAddress.Split("-"); - if (targetCodes.Length == 3) + string[] sourceCodes = task.SourceAddress.Split("-"); + if (sourceCodes.Length == 3) { - stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]); - stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); - stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); + stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]); + stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]); + stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]); } else { //鏁版嵁閰嶇疆閿欒 - _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍏ュ簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�"); + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍏ュ簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.SourceAddress}銆�"); + return null; + } + string[] targetCodes = task.TargetAddress.Split("-"); + if (targetCodes.Length == 3) + { + stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]); + stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]); + stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]); + } + else + { + //鏁版嵁閰嶇疆閿欒 + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍏ュ簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.TargetAddress}銆�"); return null; } } else { - _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒扮珯鍙般�恵task.NextAddress}銆戜俊鎭紝鏃犳硶鑾峰彇瀵瑰簲鐨勫爢鍨涙満鍙栬揣绔欏彴淇℃伅"); + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒扮珯鍙般�恵task.TargetAddress},{task.SourceAddress}銆戜俊鎭紝鏃犳硶鑾峰彇瀵瑰簲鐨勫爢鍨涙満鍙栬揣绔欏彴淇℃伅"); return null; } } - else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) + else if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt()) { - List<Dt_Router> routers = _routerService.QueryNextRoutes(task.Roadway, task.TargetAddress); - if (routers.Count > 0) + if (task.SourceAddress != null && task.TargetAddress != null) { - stackerCraneTaskCommand.EndRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow); - stackerCraneTaskCommand.EndColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn); - stackerCraneTaskCommand.EndLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer); - - string[] sourceCodes = task.CurrentAddress.Split("-"); + string[] targetCodes = task.TargetAddress.Split("-"); + if (targetCodes.Length == 3) + { + stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]); + stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]); + stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]); + } + else + { + //鏁版嵁閰嶇疆閿欒 + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍑哄簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.SourceAddress}銆�"); + return null; + } + string[] sourceCodes = task.SourceAddress.Split("-"); if (sourceCodes.Length == 3) { - stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]); - stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); - stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); + stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]); + stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]); + stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]); } else { @@ -252,33 +253,40 @@ return null; } } - else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) + else if (task.TaskType == TaskTypeEnum.Relocation.ObjToInt()) { - string[] targetCodes = task.NextAddress.Split("-"); - if (targetCodes.Length == 3) + if (task.SourceAddress != null && task.TargetAddress != null) { - stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]); - stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); - stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); + string[] targetCodes = task.TargetAddress.Split("-"); + if (targetCodes.Length == 3) + { + stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]); + stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]); + stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]); + } + else + { + //鏁版嵁閰嶇疆閿欒 + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.TargetAddress}銆�"); + return null; + } + string[] sourceCodes = task.SourceAddress.Split("-"); + if (sourceCodes.Length == 3) + { + stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]); + stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]); + stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]); + } + else + { + //鏁版嵁閰嶇疆閿欒 + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.SourceAddress}銆�"); + return null; + } } else { - //鏁版嵁閰嶇疆閿欒 - _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�"); - return null; - } - string[] sourceCodes = task.CurrentAddress.Split("-"); - if (sourceCodes.Length == 3) - { - stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]); - stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); - stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); - } - else - { - //鏁版嵁閰嶇疆閿欒 - _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�"); - return null; + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟璧风偣缁堢偣閿欒锛岃捣鐐癸細銆恵task.SourceAddress}銆戯紝缁堢偣锛氥�恵task.TargetAddress}銆�"); } } return stackerCraneTaskCommand; -- Gitblit v1.9.3