From 6e5fe70bddd5b152e00803e49e440d7b4b14a1ab Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期三, 15 一月 2025 14:52:32 +0800 Subject: [PATCH] 1 --- 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/油墨仓/StackerCraneJob_YM.cs | 195 ++++++++++++++++++++++++++---------------------- 1 files changed, 104 insertions(+), 91 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\262\271\345\242\250\344\273\223/StackerCraneJob_YM.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\262\271\345\242\250\344\273\223/StackerCraneJob_YM.cs" index 61684c3..888e499 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\262\271\345\242\250\344\273\223/StackerCraneJob_YM.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\262\271\345\242\250\344\273\223/StackerCraneJob_YM.cs" @@ -39,7 +39,6 @@ private readonly ITaskRepository _taskRepository; private readonly IRouterService _routerService; private readonly IStationMangerRepository _stationMangerRepository; - private List<Dt_ApiInfo> apiInfos; public StackerCraneJob_YM(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository) { @@ -49,56 +48,51 @@ _taskRepository = taskRepository; _routerService = routerService; _stationMangerRepository = stationMangerRepository; - - string? apiInfoStr = _cacheService.Get("apiInfos"); - if (!string.IsNullOrEmpty(apiInfoStr)) - { - apiInfos = JsonConvert.DeserializeObject<List<Dt_ApiInfo>>(apiInfoStr); - if (apiInfos == null || apiInfos.Count == 0) - { - apiInfos = new List<Dt_ApiInfo>(); - } - } } public Task Execute(IJobExecutionContext context) { - CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); - try + bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object value); + if (flag && value != null) { - if (commonStackerCrane != null) + CommonStackerCrane commonStackerCrane = (CommonStackerCrane)value; + try { - if (!commonStackerCrane.IsEventSubscribed) + if (commonStackerCrane != null) { - commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢 - } - commonStackerCrane.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆� - if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal && commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby) - { - Dt_Task? task = GetTask(commonStackerCrane); - if (task != null) + if (!commonStackerCrane.IsEventSubscribed) { - StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); - if (stackerCraneTaskCommand != null) + commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢 + } + commonStackerCrane.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆� + if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal && commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby) + { + Dt_Task? task = GetTask(commonStackerCrane); + if (task != null) { - bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand); - if (sendFlag) + StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); + if (stackerCraneTaskCommand != null) { - commonStackerCrane.LastTaskType = task.TaskType; - int oldState = task.TaskState; - task.TaskState = TaskStatusEnum.SC_Executing.ObjToInt(); - _taskRepository.UpdateData(task); - _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"绯荤粺鑷姩娴佺▼锛屼换鍔$姸鎬佷粠銆恵oldState}銆戣浆鍒般�恵task.TaskState}銆�"); + bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand); + if (sendFlag) + { + commonStackerCrane.LastTaskType = task.TaskType; + task.Dispatchertime = DateTime.Now; + task.ExceptionMessage = ""; + _taskService.UpdateTask(task, TaskStatusEnum.SC_Executing); + } } } } } } - } - catch (Exception ex) - { - WriteError(commonStackerCrane.DeviceName, ex.Message, ex); - } + catch (Exception ex) + { + WriteError(commonStackerCrane.DeviceName, ex.Message, ex); + } + } + + return Task.CompletedTask; } @@ -110,32 +104,29 @@ private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e) { CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane; - if (commonStackerCrane != null) + try { - WriteInfo(commonStackerCrane.DeviceName, $"璇诲彇鍒颁换鍔″畬鎴愪俊鍙�,{e.TaskNum}"); - if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5) + if (commonStackerCrane != null) { - Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum); - if (task != null) + if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5) { - string? url = apiInfos.FirstOrDefault(x => x.ApiCode == APIEnum.FeedBackWMSTaskCompleted.ToString())?.ApiAddress; - if (string.IsNullOrEmpty(url)) + WriteDebug(commonStackerCrane.DeviceName, $"璇诲彇鍒颁换鍔″畬鎴愪俊鍙�,{e.TaskNum}"); + Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum); + if (task != null) { - _taskExecuteDetailService.AddTaskExecuteDetail(e.TaskNum, $"鏈壘鍒板洖璋僕MS浠诲姟瀹屾垚鎺ュ彛"); - WriteInfo(commonStackerCrane.DeviceName, $"鏈壘鍒板洖璋僕MS浠诲姟瀹屾垚鎺ュ彛"); - return; + _taskService.TaskCompleted(e.TaskNum); } - - HttpHelper.Post($"{url}?taskNum={e.TaskNum}", "");//todo 璋冪敤WMS浠诲姟瀹屾垚鏂规硶 - _taskExecuteDetailService.AddTaskExecuteDetail(e.TaskNum, $"绯荤粺鑷姩娴佺▼,浠诲姟瀹屾垚"); - _taskRepository.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚); + else + { + WriteError(commonStackerCrane.DeviceName, $"璇诲彇鍒颁换鍔″畬鎴愪俊鍙�,鏈壘鍒板搴旂殑浠诲姟淇℃伅,{e.TaskNum}"); + } + commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); } - else - { - WriteInfo(commonStackerCrane.DeviceName, $"璇诲彇鍒颁换鍔″畬鎴愪俊鍙�,鏈壘鍒板搴旂殑浠诲姟淇℃伅,{e.TaskNum}"); - } - commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); } + } + catch (Exception ex) + { + WriteError(commonStackerCrane?.DeviceCode ?? nameof(StackerCraneJob_YM), ex.Message, ex); } } @@ -209,7 +200,7 @@ if (device != null) { OtherDevice client = (OtherDevice)device; - if (client.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode))//鍑哄簱绔欏彴鏈鍗犵敤 + if (client.GetValue<HoisterDBName, bool>(HoisterDBName.Tray, stationManger.StationCode))//鍑哄簱绔欏彴鏈鍗犵敤 { task.NextAddress = stationManger.StackerCraneStationCode; _taskRepository.UpdateData(task); @@ -245,22 +236,31 @@ if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔� { string[] startCodes = task.CurrentAddress.Split("-"); - - stackerCraneTaskCommand.StartRow = Convert.ToInt16(startCodes[0]); - stackerCraneTaskCommand.StartColumn = Convert.ToInt16(startCodes[1]); - stackerCraneTaskCommand.StartLayer = Convert.ToInt16(startCodes[2]); + if (startCodes.Length == 3) + { + stackerCraneTaskCommand.StartRow = Convert.ToInt16(startCodes[0]); + stackerCraneTaskCommand.StartColumn = Convert.ToInt16(startCodes[1]); + stackerCraneTaskCommand.StartLayer = Convert.ToInt16(startCodes[2]); + } + else + { + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍏ュ簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�"); + WriteError(task.DeviceCode, $"鍏ュ簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�"); + return null; + } string[] targetCodes = task.NextAddress.Split("-"); - if (targetCodes.Length == 3) + if (targetCodes.Length == 5) { - stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]); - stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); - stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); + stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]); + stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]); + stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]); } else { //鏁版嵁閰嶇疆閿欒 - _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍏ュ簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�"); + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍏ュ簱浠诲姟缁堢偣閿欒锛岀粓鐐癸細銆恵task.NextAddress}銆�"); + WriteError(task.DeviceCode, $"鍏ュ簱浠诲姟缁堢偣閿欒锛岀粓鐐癸細銆恵task.NextAddress}銆�"); return null; } } @@ -268,27 +268,6 @@ { string[] targetCodes = task.NextAddress.Split("-"); - stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]); - stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); - stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); - - 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; - } - } - else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) - { - string[] targetCodes = task.NextAddress.Split("-"); if (targetCodes.Length == 3) { stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]); @@ -298,20 +277,54 @@ else { //鏁版嵁閰嶇疆閿欒 - _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�"); + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍑哄簱浠诲姟缁堢偣閿欒锛岀粓鐐癸細銆恵task.NextAddress}銆�"); + WriteError(task.DeviceCode, $"鍑哄簱浠诲姟缁堢偣閿欒锛岀粓鐐癸細銆恵task.NextAddress}銆�"); + return null; + } + + string[] sourceCodes = task.CurrentAddress.Split("-"); + if (sourceCodes.Length == 5) + { + stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]); + stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]); + stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]); + } + else + { + //鏁版嵁閰嶇疆閿欒 + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍑哄簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�"); + WriteError(task.DeviceCode, $"鍑哄簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�"); + return null; + } + } + else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) + { + string[] targetCodes = task.NextAddress.Split("-"); + if (targetCodes.Length == 5) + { + stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]); + stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]); + stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]); + } + else + { + //鏁版嵁閰嶇疆閿欒 + _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟缁堢偣閿欒锛岀粓鐐癸細銆恵task.NextAddress}銆�"); + WriteError(task.DeviceCode, $"绉诲簱浠诲姟缁堢偣閿欒锛岀粓鐐癸細銆恵task.NextAddress}銆�"); return null; } string[] sourceCodes = task.CurrentAddress.Split("-"); - if (sourceCodes.Length == 3) + if (sourceCodes.Length == 5) { - 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 { //鏁版嵁閰嶇疆閿欒 _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�"); + WriteError(task.DeviceCode, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�"); return null; } } -- Gitblit v1.9.3