From 9f27cbd178b7f60975d388fa4c8a94f8b8e38117 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期六, 25 四月 2026 16:18:08 +0800
Subject: [PATCH] feat: 更新分容库出库地址并添加巷道号常量

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/StackerCraneTaskSelector.cs |   45 ++++++++++++++++++++++++++-------------------
 1 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/StackerCraneTaskSelector.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/StackerCraneTaskSelector.cs
index 4500212..abe9f65 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;
         }
 
@@ -213,6 +212,14 @@
             // 鍒ゆ柇 NextAddress 鍑哄簱绔欏彴鏄惁鍙敤
             if (!IsOutTaskStationAvailable(outboundTask))
             {
+                return null;
+            }
+
+            // 妫�鏌ユ槸鍚︽湁姝e湪鎵ц鐨勮緭閫佺嚎浠诲姟鍘诲線鍚屼竴 TargetAddress
+            if (_taskService.HasExecutingTaskToTarget(outboundTask.Roadway, outboundTask.TargetAddress))
+            {
+                QuartzLogHelper.LogInfo(_logger, "TrySelectOutboundTask锛歍argetAddress: {TargetAddress} 宸叉湁姝e湪鎵ц鐨勮緭閫佺嚎浠诲姟锛屼换鍔″彿: {TaskNum}",
+                    $"TrySelectOutboundTask锛歍argetAddress: {outboundTask.TargetAddress} 宸叉湁姝e湪鎵ц鐨勮緭閫佺嚎浠诲姟", outboundTask.Roadway, outboundTask.TargetAddress, outboundTask.TaskNum);
                 return null;
             }
 
@@ -385,7 +392,7 @@
             CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
 
             // 璇诲彇 CV_State锛孋V_State == 2 琛ㄧず绌洪棽
-            byte cvState = conveyorLine.GetValue<ConveyorLineStatus, byte>(ConveyorLineStatus.CV_State, task.TargetAddress);
+            byte cvState = conveyorLine.GetValue<ConveyorLineDBNameNew, byte>(ConveyorLineDBNameNew.CV_State, task.TargetAddress);
             bool isAvailable = cvState == 2;
             QuartzLogHelper.LogInfo(_logger, "IsTargetAddressConveyorStationAvailable锛歍argetAddress: {TargetAddress}锛孋V_State: {CV_State}锛屾槸鍚︾┖闂�: {IsAvailable}锛屼换鍔″彿: {TaskNum}",
                 $"IsTargetAddressConveyorStationAvailable锛歍argetAddress: {task.TargetAddress}锛孋V_State: {cvState}锛屾槸鍚︾┖闂�: {isAvailable}", task.Roadway, task.TargetAddress, cvState, isAvailable, task.TaskNum);

--
Gitblit v1.9.3