From a8f45091019012eeafec563913dee71cda3d9790 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 11 三月 2026 16:36:49 +0800
Subject: [PATCH] refactor: modularize WIDESEAWCS_Tasks workflows

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotTaskProcessor.cs |   43 ++++++++++++++++++++++++-------------------
 1 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotTaskProcessor.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotTaskProcessor.cs
index f379baa..724a3a8 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotTaskProcessor.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotTaskProcessor.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+锘縰sing Newtonsoft.Json;
 using WIDESEA_Core;
 using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.HttpEnum;
@@ -10,29 +10,30 @@
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
-using WIDESEAWCS_Tasks.SocketServer;
+using WIDESEAWCS_Tasks.Workflow.Abstractions;
 
 namespace WIDESEAWCS_Tasks
 {
     /// <summary>
-    /// 鏈烘鎵嬩换鍔″鐞嗗櫒 - 璐熻矗鏈烘鎵嬩换鍔℃墽琛屽拰澶勭悊
+    /// 鏈哄櫒浜轰换鍔″鐞嗗櫒锛氳礋璐d换鍔¤幏鍙栥�佷笅鍙戙�佸叆搴撲换鍔″洖浼犲強搴撳瓨 DTO 鏋勫缓銆�
     /// </summary>
     public class RobotTaskProcessor
     {
-        private readonly TcpSocketServer _tcpSocket;
+        // 閫氳繃缃戝叧璁块棶 Socket锛岄伩鍏嶄笟鍔″眰鐩存帴渚濊禆 TcpSocketServer銆�
+        private readonly ISocketClientGateway _socketClientGateway;
         private readonly RobotStateManager _stateManager;
         private readonly IRobotTaskService _robotTaskService;
         private readonly ITaskService _taskService;
         private readonly HttpClientHelper _httpClientHelper;
 
         public RobotTaskProcessor(
-            TcpSocketServer tcpSocket,
+            ISocketClientGateway socketClientGateway,
             RobotStateManager stateManager,
             IRobotTaskService robotTaskService,
             ITaskService taskService,
             HttpClientHelper httpClientHelper)
         {
-            _tcpSocket = tcpSocket;
+            _socketClientGateway = socketClientGateway;
             _stateManager = stateManager;
             _robotTaskService = robotTaskService;
             _taskService = taskService;
@@ -40,7 +41,7 @@
         }
 
         /// <summary>
-        /// 鑾峰彇鏈烘鎵嬩换鍔�
+        /// 鎸夎澶囩紪鐮佽幏鍙栧綋鍓嶆満鍣ㄤ汉浠诲姟銆�
         /// </summary>
         public Dt_RobotTask? GetTask(RobotCraneDevice robotCrane)
         {
@@ -48,7 +49,7 @@
         }
 
         /// <summary>
-        /// 鑾峰彇鏈烘鎵嬩换鍔�
+        /// 鍒犻櫎鏈哄櫒浜轰换鍔°��
         /// </summary>
         public bool? DeleteTask(int ID)
         {
@@ -56,26 +57,27 @@
         }
 
         /// <summary>
-        /// 鍙戦�佹満姊版墜鍙栬揣鍛戒护
+        /// 涓嬪彂鍙栬揣鎸囦护锛圥ickbattery锛夊埌鏈哄櫒浜哄鎴风銆�
         /// </summary>
         public async Task SendSocketRobotPickAsync(Dt_RobotTask task, RobotSocketState state)
         {
             string taskString = $"Pickbattery,{task.RobotSourceAddress}";
-            // 鍙戦�佷换鍔℃寚浠�
-            bool result = await _tcpSocket.SendToClientAsync(state.IPAddress, taskString);
+            bool result = await _socketClientGateway.SendToClientAsync(state.IPAddress, taskString);
             if (result)
             {
                 task.RobotTaskState = TaskRobotStatusEnum.RobotExecuting.GetHashCode();
                 state.CurrentTask = task;
 
-                // 鏇存柊缂撳瓨涓殑鐘舵�侊紙浣跨敤瀹夊叏鏇存柊闃叉骞跺彂瑕嗙洊锛�
+                // 淇濇寔鍘熻涔夛細浠呭湪鐘舵�佸畨鍏ㄥ啓鍏ユ垚鍔熷悗鍐嶆洿鏂颁换鍔$姸鎬併��
                 if (_stateManager.TryUpdateStateSafely(state.IPAddress, state))
+                {
                     await _robotTaskService.UpdateRobotTaskAsync(task);
+                }
             }
         }
 
         /// <summary>
-        /// 澶勭悊鍏ュ簱浠诲姟
+        /// 澶勭悊鍏ュ簱浠诲姟鍥炰紶锛堟媶鐩�/缁勭洏/鎹㈢洏鍦烘櫙锛夈��
         /// </summary>
         public async Task<bool> HandleInboundTaskAsync(RobotSocketState state, bool useSourceAddress)
         {
@@ -92,7 +94,6 @@
             string SourceAddress = currentTask.RobotTargetAddressLineCode;
             string TargetAddress = currentTask.RobotSourceAddressLineCode;
             string PalletCode = string.Empty;
-            // 鐩存帴杞崲涓烘灇涓剧被鍨嬭繘琛屾瘮杈�
             var robotTaskType = (RobotTaskTypeEnum)currentTask.RobotTaskType;
 
             if (useSourceAddress)
@@ -134,6 +135,7 @@
                 PalletType = 1,
                 TaskType = taskType
             };
+
             var result = _httpClientHelper.Post<WebResponseContent>(nameof(ConfigKey.CreateTaskInboundAsync), taskDto.ToJson());
             if (!result.Data.Status && result.IsSuccess)
             {
@@ -142,10 +144,12 @@
 
             WMSTaskDTO taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(result.Data.Data.ToJson() ?? string.Empty) ?? new WMSTaskDTO();
             var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
-            if (!content.Status) return false;
+            if (!content.Status)
+            {
+                return false;
+            }
 
             var taskInfo = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToJson() ?? string.Empty) ?? new Dt_Task();
-
             string sourceAddress = taskDTO.SourceAddress;
 
             IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceProDTOs.Any(d => d.DeviceChildCode == sourceAddress));
@@ -161,11 +165,12 @@
                     return true;
                 }
             }
+
             return false;
         }
 
         /// <summary>
-        /// 鏋勫缓搴撳瓨DTO
+        /// 鏋勫缓搴撳瓨鍥炰紶 DTO銆�
         /// </summary>
         public static StockDTO BuildStockDTO(RobotSocketState state, int[] positions)
         {
@@ -189,7 +194,7 @@
         }
 
         /// <summary>
-        /// 璋冪敤鎷嗙洏API
+        /// 璋冪敤鎷嗙洏 API銆�
         /// </summary>
         public HttpResponseResult<WebResponseContent> PostSplitPalletAsync(StockDTO stockDTO)
         {
@@ -197,7 +202,7 @@
         }
 
         /// <summary>
-        /// 璋冪敤缁勭洏鎴栨崲鐩楢PI
+        /// 璋冪敤缁勭洏/鎹㈢洏 API銆�
         /// </summary>
         public HttpResponseResult<WebResponseContent> PostGroupPalletAsync(string configKey, StockDTO stockDTO)
         {

--
Gitblit v1.9.3