From 75dcfe564467731b993519eb59ce330703ed1d5b Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期六, 25 四月 2026 16:26:04 +0800
Subject: [PATCH] Merge branch 'dev' of http://115.159.85.185:8098/r/SuZhouGuanHong/ShanMeiXinNengYuan into dev

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs |  149 +++++++++++++++++++++++++++++--------------------
 1 files changed, 89 insertions(+), 60 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs
index 9f8828c..a567ad2 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs
@@ -1,12 +1,12 @@
 using MapsterMapper;
-using Microsoft.Extensions.Logging;
+using Serilog;
+using System.Threading.Tasks;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
-using WIDESEAWCS_Core.Helper;
-using WIDESEAWCS_Core.LogHelper;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Service;
 
 namespace WIDESEAWCS_Tasks
@@ -105,8 +105,7 @@
         {
             // 娓呴櫎浠诲姟鍙凤紝琛ㄧず褰撳墠绌洪棽
             conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, 0, childDeviceCode);
-            _logger.LogDebug("HeartBeat锛氬瓙璁惧 {ChildDeviceCode} 蹇冭烦", childDeviceCode);
-            QuartzLogger.Debug($"HeartBeat锛氬瓙璁惧 {childDeviceCode} 蹇冭烦", conveyorLine.DeviceCode);
+            QuartzLogHelper.LogDebug(_logger, $"HeartBeat锛氬瓙璁惧 {childDeviceCode} 蹇冭烦", conveyorLine.DeviceCode);
         }
 
         /// <summary>
@@ -125,8 +124,7 @@
         /// <param name="childDeviceCode">瀛愯澶囩紪鐮�</param>
         public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
         {
-            _logger.LogInformation("RequestInbound锛氬瓙璁惧 {ChildDeviceCode} 璇锋眰鍏ュ簱", childDeviceCode);
-            QuartzLogger.Info($"璇锋眰鍏ュ簱锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
+            QuartzLogHelper.LogInfo(_logger, $"璇锋眰鍏ュ簱锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
 
             // 鍚� WMS 璇锋眰鏂颁换鍔★紙鍩轰簬鏉$爜锛�
             if (_taskFilter.RequestWmsTask(command.Barcode, childDeviceCode))
@@ -147,8 +145,7 @@
                     // 鏇存柊浠诲姟鐘舵�佸埌涓嬩竴闃舵
                     _taskService.UpdateTaskStatusToNext(task);
 
-                    _logger.LogInformation("RequestInbound锛氬叆搴撲换鍔″凡涓嬪彂锛屼换鍔″彿: {TaskNum}锛屽瓙璁惧: {ChildDeviceCode}", task.TaskNum, childDeviceCode);
-                    QuartzLogger.Info($"鍏ュ簱浠诲姟宸蹭笅鍙戯紝浠诲姟鍙�: {task.TaskNum}锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
+                    QuartzLogHelper.LogInfo(_logger, $"鍏ュ簱浠诲姟宸蹭笅鍙戯紝浠诲姟鍙�: {task.TaskNum}锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
                 }
             }
         }
@@ -169,24 +166,47 @@
             Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
             if (task == null)
             {
-                _logger.LogDebug("RequestInNextAddress锛氫换鍔� {TaskNo} 涓嶅瓨鍦�", command.TaskNo);
-                QuartzLogger.Debug($"RequestInNextAddress锛氫换鍔� {command.TaskNo} 涓嶅瓨鍦�", conveyorLine.DeviceCode);
+                QuartzLogHelper.LogDebug(_logger, $"RequestInNextAddress锛氫换鍔� {command.TaskNo} 涓嶅瓨鍦�", conveyorLine.DeviceCode);
                 return;
             }
 
-            _logger.LogInformation("RequestInNextAddress锛氬叆搴撲笅涓�鍦板潃锛屼换鍔″彿: {TaskNum}锛屽瓙璁惧: {ChildDeviceCode}", task.TaskNum, childDeviceCode);
-            QuartzLogger.Info($"RequestInNextAddress锛氬叆搴撲笅涓�鍦板潃锛屼换鍔″彿: {task.TaskNum}锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
+            QuartzLogHelper.LogInfo(_logger, $"RequestInNextAddress锛氬叆搴撲笅涓�鍦板潃锛屼换鍔″彿: {task.TaskNum}锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
 
-            // 濡傛灉涓嶆槸绌烘墭鐩樹换鍔★紝澶勭悊鐩爣鍦板潃锛堜笌鎷樻潫鏈�/鎻掓嫈閽夋満浜や簰锛�
-            if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
+            bool isEmptyTask = task.TaskType == (int)TaskOutboundTypeEnum.OutEmpty;
+
+            // 纭畾鐩爣鍦板潃
+            string targetAddress;
+            if (isEmptyTask)
             {
-                _targetAddressSelector.HandleInboundNextAddress(conveyorLine, task.NextAddress, childDeviceCode);
+                targetAddress = "2125";
+                QuartzLogHelper.LogDebug(_logger, $"瀛愯澶�: {childDeviceCode}锛屽叆搴撲笅涓�鐩爣鍦板潃: {2125}", conveyorLine.DeviceCode);
+            }
+            else
+            {
+                Dt_Router routers = _routerService.QueryNextRoute(task.NextAddress, task.TargetAddress);
+                if (routers == null) throw new Exception($"鏈壘鍒拌澶囪矾鐢变俊鎭�");
+                targetAddress = routers.ChildPosi;
             }
 
-            // 鏇存柊浠诲姟褰撳墠浣嶇疆
-            _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
+            // 澶勭悊鐩爣鍦板潃锛欳hildPosi == "2125" 鏃惰烦杩� HandleInboundNextAddress
+            if (targetAddress == "2125")
+            {
+                conveyorLine.SetValue(ConveyorLineDBNameNew.Target, "2125", childDeviceCode);
+            }
+            else if (!_targetAddressSelector.HandleInboundNextAddress(conveyorLine, targetAddress, childDeviceCode))
+            {
+                return;
+            }
 
-            // 璁剧疆 WCS_STB 鏍囧織锛岃〃绀� WCS 宸插鐞�
+            // 鏇存柊浠诲姟褰撳墠浣嶇疆鍜� WCS_ACK
+            if (isEmptyTask)
+            {
+                _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress, "2125");
+            }
+            else
+            {
+                _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
+            }
             conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
         }
 
@@ -206,18 +226,13 @@
             Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
             if (task != null)
             {
-
                 // 鏇存柊浠诲姟鐘舵�佸埌涓嬩竴闃舵锛堥�氬父鏄畬鎴愶級
                 if (_taskService.UpdateTaskStatusToNext(task).Status)
                 {
-
+                    // 鍥炲 ACK 纭
+                    conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
+                    QuartzLogHelper.LogInfo(_logger, $"鍏ュ簱瀹屾垚锛屼换鍔″彿: {task.TaskNum},瀛愯澶�:{childDeviceCode}", conveyorLine.DeviceCode);
                 }
-
-                // 鍥炲 ACK 纭
-                conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
-
-                _logger.LogInformation("ConveyorLineInFinish锛氬叆搴撳畬鎴愶紝浠诲姟鍙�: {TaskNum}锛屽瓙璁惧: {ChildDeviceCode}", task.TaskNum, childDeviceCode);
-                QuartzLogger.Info($"鍏ュ簱瀹屾垚锛屼换鍔″彿: {task.TaskNum}", conveyorLine.DeviceCode);
             }
         }
 
@@ -234,30 +249,42 @@
         /// <param name="conveyorLine">杈撻�佺嚎璁惧瀵硅薄</param>
         /// <param name="command">PLC 鍛戒护鏁版嵁</param>
         /// <param name="childDeviceCode">瀛愯澶囩紪鐮�</param>
-        public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
+        public Task RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
         {
             // 鏌ヨ寰呭鐞嗕换鍔�
             Dt_Task? task = _taskFilter.QueryPendingTask(conveyorLine.DeviceCode, childDeviceCode);
-            if (task != null)
+            if (task == null) return Task.CompletedTask;
+
+            // 纭畾鐩爣鍦板潃锛氱┖鎵樼洏浠诲姟浣跨敤 "2201"锛屽叾浠栦换鍔′娇鐢� NextAddress
+            var isEmptyTask = task.TaskType == (int)TaskOutboundTypeEnum.OutEmpty;
+            var targetAddress = task.CurrentAddress == "2217" ? (isEmptyTask ? "2201" : task.NextAddress) : task.NextAddress;
+
+            // 澶勭悊鐗规畩鍦板潃 2217锛岄渶瑕佽皟鐢ㄧ洰鏍囧湴鍧�閫夋嫨鍣�
+            if (task.CurrentAddress == "2217" && !_targetAddressSelector.HandleOutboundNextAddress(conveyorLine, targetAddress, childDeviceCode))
             {
-                // 璁剧疆浠诲姟鍙�
-                conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, task.TaskNum, childDeviceCode);
-
-                // 璁剧疆鎵樼洏鏉$爜
-                conveyorLine.SetValue(ConveyorLineDBNameNew.Barcode, task.PalletCode, childDeviceCode);
-
-                // 璁剧疆鐩爣鍦板潃
-                conveyorLine.SetValue(ConveyorLineDBNameNew.Target, task.NextAddress, childDeviceCode);
-
-                // 鍥炲 ACK 纭
-                conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
-
-                // 鏇存柊浠诲姟鐘舵��
-                _taskService.UpdateTaskStatusToNext(task);
-
-                _logger.LogInformation("RequestOutbound锛氬嚭搴撲换鍔″凡涓嬪彂锛屼换鍔″彿: {TaskNum}锛屽瓙璁惧: {ChildDeviceCode}", task.TaskNum, childDeviceCode);
-                QuartzLogger.Info($"鍑哄簱浠诲姟宸蹭笅鍙戯紝浠诲姟鍙�: {task.TaskNum}", conveyorLine.DeviceCode);
+                return Task.CompletedTask; ;
             }
+
+            // 璁剧疆浠诲姟鍙枫�佹墭鐩樻潯鐮併�佺洰鏍囧湴鍧�銆乄CS_ACK
+            conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, task.TaskNum, childDeviceCode);
+            conveyorLine.SetValue(ConveyorLineDBNameNew.Barcode, task.PalletCode, childDeviceCode);
+            conveyorLine.SetValue(ConveyorLineDBNameNew.Target, targetAddress, childDeviceCode);
+            conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
+
+            // 鏇存柊浠诲姟鐘舵�佹垨浣嶇疆
+            if (isEmptyTask && task.NextAddress == "2217")
+            {
+                task.TaskStatus = task.TaskStatus.GetNextNotCompletedStatus<TaskOutStatusEnum>();
+                task.NextAddress = "2201";
+                _taskService.Repository.UpdateData(task);
+            }
+            else
+            {
+                _taskService.UpdateTaskStatusToNext(task);
+            }
+
+            QuartzLogHelper.LogInfo(_logger, "RequestOutbound锛氬嚭搴撲换鍔″凡涓嬪彂锛屼换鍔″彿: {TaskNum}锛屽瓙璁惧: {ChildDeviceCode}", $"鍑哄簱浠诲姟宸蹭笅鍙戯紝浠诲姟鍙�: {task.TaskNum}", conveyorLine.DeviceCode, task.TaskNum, childDeviceCode);
+            return Task.CompletedTask;
         }
 
         /// <summary>
@@ -265,7 +292,6 @@
         /// </summary>
         /// <remarks>
         /// 褰撳嚭搴撲换鍔℃墽琛屽埌鏌愪釜涓棿绔欑偣鏃惰皟鐢ㄣ��
-        /// 鏍规嵁涓嬩竴鍦板潃鍒ゆ柇鏄惁闇�瑕佷笌鎷樻潫鏈�/鎻掓嫈閽夋満绛夎澶囦氦浜掋��
         /// </remarks>
         /// <param name="conveyorLine">杈撻�佺嚎璁惧瀵硅薄</param>
         /// <param name="command">PLC 鍛戒护鏁版嵁</param>
@@ -276,19 +302,20 @@
             Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
             if (task == null)
             {
-                _logger.LogDebug("RequestOutNextAddress锛氫换鍔� {TaskNo} 涓嶅瓨鍦�", command.TaskNo);
-                QuartzLogger.Debug($"RequestOutNextAddress锛氫换鍔� {command.TaskNo} 涓嶅瓨鍦�", conveyorLine.DeviceCode);
+                QuartzLogHelper.LogDebug(_logger, $"RequestOutNextAddress锛氫换鍔� {command.TaskNo} 涓嶅瓨鍦�", conveyorLine.DeviceCode);
                 return;
             }
 
-            _logger.LogInformation("RequestOutNextAddress锛氬嚭搴撲笅涓�鍦板潃锛屼换鍔″彿: {TaskNum}锛屽瓙璁惧: {ChildDeviceCode}", task.TaskNum, childDeviceCode);
-            QuartzLogger.Info($"RequestOutNextAddress锛氬嚭搴撲笅涓�鍦板潃锛屼换鍔″彿: {task.TaskNum}锛屽瓙璁惧: {childDeviceCode}", conveyorLine.DeviceCode);
+            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);
@@ -316,12 +343,14 @@
                 // 鏇存柊浠诲姟鐘舵�佸埌涓嬩竴闃舵锛堥�氬父鏄畬鎴愶級
                 WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
 
-                // 鍥炲 ACK 纭
-                conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
+                if (content.Status)
+                {
+                    // 鍥炲 ACK 纭
+                    conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
+                }
 
-                _logger.LogInformation("ConveyorLineOutFinish锛氬嚭搴撳畬鎴愶紝浠诲姟鍙�: {TaskNum}锛屽瓙璁惧: {ChildDeviceCode}", task.TaskNum, childDeviceCode);
-                QuartzLogger.Info($"鍑哄簱瀹屾垚锛屼换鍔″彿: {task.TaskNum}", conveyorLine.DeviceCode);
+                QuartzLogHelper.LogInfo(_logger, $"鍑哄簱瀹屾垚锛屽畬鎴愮粨鏋滐細{content.Status}锛屼换鍔″彿: {task.TaskNum}锛岄敊璇秷鎭細{content.Message}", conveyorLine.DeviceCode);
             }
         }
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3