From f319fd5d5e5e0332c4c7e209df64c351dfbe6887 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期六, 25 四月 2026 22:13:19 +0800
Subject: [PATCH] fix: 修复PLC通信及任务处理中的多个问题

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/StackerCraneTaskSelector.cs |   44 +++++++++++++++++++++++---------------------
 1 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/StackerCraneTaskSelector.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/StackerCraneTaskSelector.cs
index 87e03ab..cdd7a09 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/StackerCraneTaskSelector.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/StackerCraneTaskSelector.cs
@@ -1,6 +1,7 @@
 using Newtonsoft.Json;
 using Serilog;
 using System.Diagnostics.CodeAnalysis;
+using System.Threading.Tasks;
 using WIDESEA_Core;
 using WIDESEAWCS_Common.Constants;
 using WIDESEAWCS_Common.HttpEnum;
@@ -101,14 +102,14 @@
             Dt_Task? candidateTask;
             var deviceCode = commonStackerCrane.DeviceCode;
 
-            QuartzLogHelper.LogDebug(_logger, $"寮�濮嬮�夋嫨浠诲姟锛岃澶�: {deviceCode}锛屼笂涓�浠诲姟绫诲瀷: {commonStackerCrane.LastTaskType}",commonStackerCrane.DeviceName);
+            QuartzLogHelper.LogInfo(_logger, $"寮�濮嬮�夋嫨浠诲姟锛岃澶�: {deviceCode}锛屼笂涓�浠诲姟绫诲瀷: {commonStackerCrane.LastTaskType}", commonStackerCrane.DeviceName);
 
             // 鏍规嵁涓婁竴浠诲姟绫诲瀷鍐冲畾鏌ヨ绛栫暐
             if (commonStackerCrane.LastTaskType == null || commonStackerCrane.LastTaskType == TaskRelocationTypeEnum.Relocation.GetHashCode())
             {
                 // 娌℃湁涓婁竴浠诲姟绫诲瀷锛屾煡璇㈡櫘閫氫换鍔�
                 candidateTask = _taskService.QueryStackerCraneTask(deviceCode);
-                QuartzLogHelper.LogDebug(_logger, $"鏌ヨ鏅�氫换鍔★紝璁惧: {deviceCode}锛岀粨鏋�: {candidateTask?.TaskNum}", commonStackerCrane.DeviceName);
+                QuartzLogHelper.LogInfo(_logger, $"鏌ヨ鏅�氫换鍔★紝璁惧: {deviceCode}锛岀粨鏋�: {candidateTask?.TaskNum}", commonStackerCrane.DeviceName);
             }
             else if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
             {
@@ -116,26 +117,29 @@
                 candidateTask = _taskService.QueryStackerCraneInTask(deviceCode);
                 // 濡傛灉娌℃湁鍏ュ簱浠诲姟锛屽啀鏌ヤ竴涓嬪嚭搴撲换鍔�
                 candidateTask ??= _taskService.QueryStackerCraneOutTask(deviceCode);
-                QuartzLogHelper.LogDebug(_logger, $"鍑哄簱鍚庝紭鍏堟煡鍏ュ簱锛岃澶�: {deviceCode}锛岀粨鏋�: {candidateTask?.TaskNum}", commonStackerCrane.DeviceName);
+                QuartzLogHelper.LogInfo(_logger, $"鍑哄簱鍚庝紭鍏堟煡鍏ュ簱锛岃澶�: {deviceCode}锛岀粨鏋�: {candidateTask?.TaskNum}", commonStackerCrane.DeviceName);
             }
             else
             {
                 // 涓婁竴浠诲姟鏄叆搴擄紙闈炲嚭搴擄級锛屼紭鍏堟煡鍑哄簱浠诲姟
                 candidateTask = _taskService.QueryStackerCraneOutTask(deviceCode);
-                QuartzLogHelper.LogDebug(_logger, $"鍏ュ簱鍚庝紭鍏堟煡鍑哄簱锛岃澶�: {deviceCode}锛岀粨鏋�: {candidateTask?.TaskNum}", commonStackerCrane.DeviceName);
+
+                // 濡傛灉娌℃湁鍑哄簱浠诲姟锛屽啀鏌ヤ竴涓嬪叆搴撲换鍔�
+                candidateTask ??= _taskService.QueryStackerCraneInTask(deviceCode);
+                QuartzLogHelper.LogInfo(_logger, $"鍏ュ簱鍚庝紭鍏堟煡鍑哄簱锛岃澶�: {deviceCode}锛岀粨鏋�: {candidateTask?.TaskNum}", commonStackerCrane.DeviceName);
             }
 
             // 濡傛灉娌℃湁鍊欓�変换鍔★紝杩斿洖 null
             if (candidateTask == null)
             {
-                QuartzLogHelper.LogDebug(_logger, $"娌℃湁鍊欓�変换鍔★紝璁惧: {deviceCode}", commonStackerCrane.DeviceName);
+                QuartzLogHelper.LogInfo(_logger, $"娌℃湁鍊欓�変换鍔★紝璁惧: {deviceCode}", commonStackerCrane.DeviceName);
                 return null;
             }
 
             // 濡傛灉涓嶆槸鍑哄簱浠诲姟锛岀洿鎺ヨ繑鍥�
             if (candidateTask.TaskType.GetTaskTypeGroup() != TaskTypeGroup.OutbondGroup)
             {
-                QuartzLogHelper.LogDebug(_logger, $"閫変腑闈炲嚭搴撲换鍔★紝浠诲姟鍙�: {candidateTask.TaskNum}锛屼换鍔$被鍨�: {candidateTask.TaskType}", commonStackerCrane.DeviceName);
+                QuartzLogHelper.LogInfo(_logger, $"閫変腑闈炲嚭搴撲换鍔★紝浠诲姟鍙�: {candidateTask.TaskNum}锛屼换鍔$被鍨�: {candidateTask.TaskType}", commonStackerCrane.DeviceName);
                 return candidateTask;
             }
 
@@ -143,14 +147,14 @@
             Dt_Task? selectedTask = TrySelectOutboundTask(candidateTask);
             if (selectedTask != null)
             {
-                QuartzLogHelper.LogDebug(_logger, $"閫変腑鍑哄簱浠诲姟锛屼换鍔″彿: {selectedTask.TaskNum}", commonStackerCrane.DeviceName);
+                QuartzLogHelper.LogInfo(_logger, $"閫変腑鍑哄簱浠诲姟锛屼换鍔″彿: {selectedTask.TaskNum}", commonStackerCrane.DeviceName);
                 return selectedTask;
             }
 
-            // ===== TargetAddress 涓嶅彲鐢ㄦ椂锛屽厛灏濊瘯鍚� NextAddress 鐨勫叾浠栦换鍔� =====
+            // ===== TargetAddress 涓嶅彲鐢ㄦ椂锛屽厛灏濊瘯鍚� NextAddress涓嶅悓TargetAddress 鐨勫叾浠栦换鍔� =====
             var sameStationTasks = _taskService
                 .QueryStackerCraneOutTasks(deviceCode, new List<string> { candidateTask.NextAddress })
-                .Where(x => x.TaskId != candidateTask.TaskId)
+                .Where(x => x.TaskId != candidateTask.TaskId && x.TargetAddress != candidateTask.TargetAddress)
                 .ToList();
 
             foreach (var sameStationTask in sameStationTasks)
@@ -158,33 +162,28 @@
                 selectedTask = TrySelectOutboundTask(sameStationTask);
                 if (selectedTask != null)
                 {
-                    QuartzLogHelper.LogDebug(_logger, $"閫変腑鍚岀珯鍙板閫夊嚭搴撲换鍔★紝浠诲姟鍙�: {selectedTask.TaskNum}", commonStackerCrane.DeviceName);
+                    QuartzLogHelper.LogInfo(_logger, $"閫変腑鍚岀珯鍙板閫夊嚭搴撲换鍔★紝浠诲姟鍙�: {selectedTask.TaskNum}", commonStackerCrane.DeviceName);
                     return selectedTask;
                 }
             }
 
             // ===== 鍚� NextAddress 鏃犲彲鐢ㄤ换鍔★紝灏濊瘯涓嶅悓 NextAddress 鐨勪换鍔� =====
             // 鏌ユ壘鍏朵粬鍙敤鐨勫嚭搴撶珯鍙�
-            var otherOutStationCodes = _routerService
-                .QueryNextRoutes(deviceCode, candidateTask.NextAddress, candidateTask.TaskType)
-                .Select(x => x.ChildPosi)
-                .ToList();
-
             // 鏌ヨ鍏朵粬绔欏彴鐨勫嚭搴撲换鍔�
-            var tasks = _taskService.QueryStackerCraneOutTasks(deviceCode, otherOutStationCodes);
+            var tasks = _taskService.QueryStackerCraneOutTasks(deviceCode, new List<string> { candidateTask.NextAddress }, false);
             foreach (var alternativeTask in tasks)
             {
                 selectedTask = TrySelectOutboundTask(alternativeTask);
                 if (selectedTask != null)
                 {
-                    QuartzLogHelper.LogDebug(_logger, $"閫変腑澶囬�夊嚭搴撲换鍔★紝浠诲姟鍙�: {selectedTask.TaskNum}", commonStackerCrane.DeviceName);
+                    QuartzLogHelper.LogInfo(_logger, $"閫変腑澶囬�夊嚭搴撲换鍔★紝浠诲姟鍙�: {selectedTask.TaskNum}", commonStackerCrane.DeviceName);
                     return selectedTask;
                 }
             }
 
             // 娌℃湁鍙敤鍑哄簱浠诲姟锛屽皾璇曡繑鍥炲叆搴撲换鍔�
             var inboundTask = _taskService.QueryStackerCraneInTask(deviceCode);
-            QuartzLogHelper.LogDebug(_logger, $"杩斿洖鍏ュ簱浠诲姟锛屼换鍔″彿: {inboundTask?.TaskNum}", commonStackerCrane.DeviceName);
+            QuartzLogHelper.LogInfo(_logger, $"杩斿洖鍏ュ簱浠诲姟锛屼换鍔″彿: {inboundTask?.TaskNum}", commonStackerCrane.DeviceName);
             return inboundTask;
         }
 
@@ -204,10 +203,13 @@
         {
             // 鍏堣繘琛屾湰鍦扮珯鍙版鏌ワ紙PLC 璇诲彇锛屽揩閫燂級锛岄伩鍏嶄笉蹇呰鐨� WMS HTTP 璋冪敤
 
-            // 鍒ゆ柇 TargetAddress 杈撻�佺嚎绔欏彴鏄惁绌洪棽
-            if (!IsTargetAddressConveyorStationAvailable(outboundTask))
+            if (outboundTask.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
             {
-                return null;
+                // 鍒ゆ柇 TargetAddress 杈撻�佺嚎绔欏彴鏄惁绌洪棽
+                if (!IsTargetAddressConveyorStationAvailable(outboundTask))
+                {
+                    return null;
+                }
             }
 
             // 鍒ゆ柇 NextAddress 鍑哄簱绔欏彴鏄惁鍙敤

--
Gitblit v1.9.3