From 853f7a71577bd8694c848985e1eb21c74d30eba9 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 21 四月 2026 21:19:23 +0800
Subject: [PATCH] fix(WCS): 修复输送线任务处理逻辑并更新设备映射

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs |   85 +++++++++++++++++++++++++++++-------------
 1 files changed, 59 insertions(+), 26 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs
index 24700ff..a113186 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs
@@ -1,10 +1,11 @@
 using MapsterMapper;
+using Serilog;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
-using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Service;
 
 namespace WIDESEAWCS_Tasks
@@ -47,6 +48,11 @@
         private readonly IMapper _mapper;
 
         /// <summary>
+        /// 鏃ュ織璁板綍鍣�
+        /// </summary>
+        private readonly ILogger _logger;
+
+        /// <summary>
         /// 杈撻�佺嚎浠诲姟杩囨护鍣�
         /// </summary>
         /// <remarks>
@@ -69,16 +75,18 @@
         /// <param name="taskExecuteDetailService">浠诲姟鎵ц鏄庣粏鏈嶅姟</param>
         /// <param name="routerService">璺敱鏈嶅姟</param>
         /// <param name="mapper">瀵硅薄鏄犲皠鍣�</param>
-        public ConveyorLineDispatchHandler(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper)
+        /// <param name="logger">鏃ュ織璁板綍鍣�</param>
+        public ConveyorLineDispatchHandler(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ILogger logger)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
             _routerService = routerService;
             _mapper = mapper;
+            _logger = logger;
 
             // 鍒濆鍖栦换鍔¤繃婊ゅ櫒鍜岀洰鏍囧湴鍧�閫夋嫨鍣�
-            _taskFilter = new ConveyorLineTaskFilter(taskService);
-            _targetAddressSelector = new ConveyorLineTargetAddressSelector();
+            _taskFilter = new ConveyorLineTaskFilter(taskService, _logger);
+            _targetAddressSelector = new ConveyorLineTargetAddressSelector(_logger);
         }
 
         /// <summary>
@@ -96,6 +104,7 @@
         {
             // 娓呴櫎浠诲姟鍙凤紝琛ㄧず褰撳墠绌洪棽
             conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, 0, childDeviceCode);
+            QuartzLogHelper.LogDebug(_logger, $"HeartBeat锛氬瓙璁惧 {childDeviceCode} 蹇冭烦", conveyorLine.DeviceCode);
         }
 
         /// <summary>
@@ -114,6 +123,8 @@
         /// <param name="childDeviceCode">瀛愯澶囩紪鐮�</param>
         public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
         {
+            QuartzLogHelper.LogInfo(_logger, $"璇锋眰鍏ュ簱锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
+
             // 鍚� WMS 璇锋眰鏂颁换鍔★紙鍩轰簬鏉$爜锛�
             if (_taskFilter.RequestWmsTask(command.Barcode, childDeviceCode))
             {
@@ -132,6 +143,8 @@
 
                     // 鏇存柊浠诲姟鐘舵�佸埌涓嬩竴闃舵
                     _taskService.UpdateTaskStatusToNext(task);
+
+                    QuartzLogHelper.LogInfo(_logger, $"鍏ュ簱浠诲姟宸蹭笅鍙戯紝浠诲姟鍙�: {task.TaskNum}锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
                 }
             }
         }
@@ -152,20 +165,27 @@
             Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
             if (task == null)
             {
+                QuartzLogHelper.LogDebug(_logger, $"RequestInNextAddress锛氫换鍔� {command.TaskNo} 涓嶅瓨鍦�", conveyorLine.DeviceCode);
                 return;
             }
 
-            // 濡傛灉涓嶆槸绌烘墭鐩樹换鍔★紝澶勭悊鐩爣鍦板潃锛堜笌鎷樻潫鏈�/鎻掓嫈閽夋満浜や簰锛�
-            if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
-            {
-                _targetAddressSelector.HandleInboundNextAddress(conveyorLine, task.NextAddress, childDeviceCode);
-            }
+            QuartzLogHelper.LogInfo(_logger, $"RequestInNextAddress锛氬叆搴撲笅涓�鍦板潃锛屼换鍔″彿: {task.TaskNum}锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
+
+            //// 濡傛灉涓嶆槸绌烘墭鐩樹换鍔★紝澶勭悊鐩爣鍦板潃
+            //if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
+            //{
+
+            Dt_Router routers = _routerService.QueryNextRoute(task.NextAddress, task.TargetAddress);
+            if (routers == null) throw new Exception($"鏈壘鍒拌澶囪矾鐢变俊鎭�");
+
+            _targetAddressSelector.HandleInboundNextAddress(conveyorLine, routers.ChildPosi, childDeviceCode);
+            //}
 
             // 鏇存柊浠诲姟褰撳墠浣嶇疆
             _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
 
             // 璁剧疆 WCS_STB 鏍囧織锛岃〃绀� WCS 宸插鐞�
-            conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_STB, 1, childDeviceCode);
+            conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
         }
 
         /// <summary>
@@ -184,12 +204,13 @@
             Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
             if (task != null)
             {
-                // 鍥炲 ACK 纭
-                conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
-
                 // 鏇存柊浠诲姟鐘舵�佸埌涓嬩竴闃舵锛堥�氬父鏄畬鎴愶級
-                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
-                Console.Out.WriteLine(content.Serialize());
+                if (_taskService.UpdateTaskStatusToNext(task).Status)
+                {
+                    // 鍥炲 ACK 纭
+                    conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
+                    QuartzLogHelper.LogInfo(_logger, $"鍏ュ簱瀹屾垚锛屼换鍔″彿: {task.TaskNum},瀛愯澶�:{childDeviceCode}", conveyorLine.DeviceCode);
+                }
             }
         }
 
@@ -222,10 +243,12 @@
                 conveyorLine.SetValue(ConveyorLineDBNameNew.Target, task.NextAddress, childDeviceCode);
 
                 // 鍥炲 ACK 纭
-                conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
+                conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
 
                 // 鏇存柊浠诲姟鐘舵��
                 _taskService.UpdateTaskStatusToNext(task);
+
+                QuartzLogHelper.LogInfo(_logger, "RequestOutbound锛氬嚭搴撲换鍔″凡涓嬪彂锛屼换鍔″彿: {TaskNum}锛屽瓙璁惧: {ChildDeviceCode}", $"鍑哄簱浠诲姟宸蹭笅鍙戯紝浠诲姟鍙�: {task.TaskNum}", conveyorLine.DeviceCode, task.TaskNum, childDeviceCode);
             }
         }
 
@@ -245,20 +268,26 @@
             Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
             if (task == null)
             {
+                QuartzLogHelper.LogDebug(_logger, $"RequestOutNextAddress锛氫换鍔� {command.TaskNo} 涓嶅瓨鍦�", conveyorLine.DeviceCode);
                 return;
             }
 
+            QuartzLogHelper.LogInfo(_logger, $"RequestOutNextAddress锛氬嚭搴撲笅涓�鍦板潃锛屼换鍔″彿: {task.TaskNum}锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
+
             // 濡傛灉涓嶆槸绌烘墭鐩樹换鍔★紝澶勭悊鐩爣鍦板潃
-            if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
-            {
-                _targetAddressSelector.HandleOutboundNextAddress(conveyorLine, task.NextAddress, childDeviceCode);
-            }
+            //if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
+            //{
+            Dt_Router routers = _routerService.QueryNextRoute(task.NextAddress, task.TargetAddress);
+            if (routers == null) throw new Exception($"鏈壘鍒拌澶囪矾鐢变俊鎭�");
+
+            _targetAddressSelector.HandleOutboundNextAddress(conveyorLine, routers.ChildPosi, childDeviceCode);
+            //}
 
             // 鏇存柊浠诲姟褰撳墠浣嶇疆
             _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
 
             // 鍥炲 ACK 纭
-            conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
+            conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
         }
 
         /// <summary>
@@ -277,13 +306,17 @@
             Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
             if (task != null)
             {
-                // 鍥炲 ACK 纭
-                conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
-
                 // 鏇存柊浠诲姟鐘舵�佸埌涓嬩竴闃舵锛堥�氬父鏄畬鎴愶級
                 WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
-                Console.Out.WriteLine(content.Serialize());
+
+                if (content.Status)
+                {
+                    // 鍥炲 ACK 纭
+                    conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
+                }
+
+                QuartzLogHelper.LogInfo(_logger, $"鍑哄簱瀹屾垚锛屽畬鎴愮粨鏋滐細{content.Status}锛屼换鍔″彿: {task.TaskNum}锛岄敊璇秷鎭細{content.Message}", conveyorLine.DeviceCode);
             }
         }
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3