From 88724eca51a5863f20ee0a552af741aeebf4e8f2 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 11 二月 2026 17:31:45 +0800
Subject: [PATCH] 添加堆垛机配置并重构任务

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs |   80 ++++++++++++++++++++++++++++-----------
 1 files changed, 57 insertions(+), 23 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
index 6a945d5..b63717b 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
@@ -25,15 +25,19 @@
         private readonly TcpSocketServer _TcpSocket;
         private static readonly ConcurrentDictionary<string, RobotSocketState> _socketStates = new();
         private static int _eventSubscribedFlag;
-        private readonly IRobotTaskService _taskService;
+
+
+        private readonly ITaskService _taskService;
+        private readonly IRobotTaskService _robottaskService;
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
         private readonly ITaskRepository _taskRepository;
         private readonly IRouterService _routerService;
 
-        public RobotJob(TcpSocketServer TcpSocket, IRobotTaskService taskService)
+        public RobotJob(TcpSocketServer TcpSocket, IRobotTaskService RobottaskService, ITaskService TaskService)
         {
             _TcpSocket = TcpSocket;
-            _taskService = taskService;
+            _robottaskService = RobottaskService;
+            this._taskService = TaskService;
         }
 
         public async Task Execute(IJobExecutionContext context)
@@ -130,10 +134,9 @@
         /// <returns></returns>
         private async Task<string?> _TcpSocket_MessageReceived(string message, bool isJson, TcpClient client, RobotSocketState state)
         {
-            WebResponseContent content = new WebResponseContent();
             string messageLower = message.ToLowerInvariant();
 
-            if (IsSimpleCommand(messageLower, state))
+            if (await IsSimpleCommandAsync(messageLower, state))
             {
                 return null;
             }
@@ -174,9 +177,8 @@
                             state.LastPickPositions = positions;
 
                             var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), state.CurrentTask?.RobotTaskType == 2 ? nameof(ConfigKey.ChangePalletAsync) : nameof(ConfigKey.SplitPalletAsync));
-                            content = JsonConvert.DeserializeObject<WebResponseContent>(result);
 
-                            if (content.Status)
+                            if (result.Status)
                             {
                                 state.CurrentAction = "PickFinished";
                             }
@@ -205,9 +207,8 @@
                                         .ToList()
                                 };
                                 var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), nameof(ConfigKey.GroupPalletAsync));
-                                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
 
-                                if (content.Status)
+                                if (result.Status)
                                 {
                                     state.CurrentAction = "PutFinished";
                                 }
@@ -229,7 +230,7 @@
         /// <param name="message"></param>
         /// <param name="state"></param>
         /// <returns></returns>
-        private bool IsSimpleCommand(string message, RobotSocketState state)
+        private async Task<bool> IsSimpleCommandAsync(string message, RobotSocketState state)
         {
             switch (message)
             {
@@ -253,7 +254,7 @@
                     state.CurrentAction = "AllPickFinished";
                     if (state.CurrentTask?.RobotTaskType == 2 || state.CurrentTask?.RobotTaskType == 3)
                     {
-                        // TODO 鏈烘鎵嬪彇璐у畬鎴愶紝鍒ゆ柇鏄惁鎹㈢洏銆佹媶鐩樹换鍔★紝鍒涘缓绌烘墭鐩樺洖搴撲换鍔�
+                        await HandleInboundTaskAsync(state, useSourceAddress: true);
                     }
                     return true;
 
@@ -261,17 +262,7 @@
                     state.CurrentAction = "AllPutFinished";
                     if (state.CurrentTask?.RobotTaskType == 1)
                     {
-                        // TODO 鏈烘鎵嬪彇璐у畬鎴愶紝鍒ゆ柇鏄惁缁勭洏浠诲姟锛屽垱寤虹粍鐩樺叆搴撲换鍔�
-                        CreateTaskDto taskDto = new CreateTaskDto()
-                        {
-                            PalletCode = state.CurrentTask?.RobotTargetAddressPalletCode ?? string.Empty,
-                            SourceAddress = state.CurrentTask?.RobotTargetAddress ?? string.Empty,
-                            TargetAddress = state.CurrentTask?.RobotTargetAddress ?? string.Empty,
-                            Roadway = state.CurrentTask?.RobotRoadway == "1" ? "GWSC001" : state.CurrentTask?.RobotRoadway == "2" ? "HCSC001" : "SC001" ?? string.Empty,
-                            WarehouseId = state.CurrentTask?.RobotRoadway == "1" ? 1 : state.CurrentTask?.RobotRoadway == "2" ? 2 : 3,
-                            PalletType = 1,
-                            TaskType = 4
-                        };
+                        await HandleInboundTaskAsync(state, useSourceAddress: false);
                     }
                     return true;
 
@@ -320,6 +311,49 @@
             }
         }
 
+        private async Task HandleInboundTaskAsync(RobotSocketState state, bool useSourceAddress)
+        {
+            var currentTask = state.CurrentTask;
+            if (currentTask == null)
+            {
+                return;
+            }
+
+            string roadway = currentTask.RobotRoadway == "1" ? "GWSC001" : currentTask.RobotRoadway == "2" ? "HCSC001" : "SC001";
+            int warehouseId = currentTask.RobotRoadway == "1" ? 1 : currentTask.RobotRoadway == "2" ? 2 : 3;
+
+            CreateTaskDto taskDto = new CreateTaskDto
+            {
+                PalletCode = currentTask.RobotTargetAddressPalletCode ?? string.Empty,
+                SourceAddress = currentTask.RobotTargetAddress ?? string.Empty,
+                TargetAddress = currentTask.RobotTargetAddress ?? string.Empty,
+                Roadway = roadway,
+                WarehouseId = warehouseId,
+                PalletType = 1,
+                TaskType = 4
+            };
+
+            var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), taskDto.ToJsonString(), nameof(ConfigKey.CreateTaskInboundAsync));
+            if (!result.Status)
+            {
+                return;
+            }
+
+            WMSTaskDTO taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(result.Data.ToString() ?? string.Empty) ?? new WMSTaskDTO();
+            var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
+            if (!content.Status) return;
+
+            var taskInfo = _taskService.QueryByTaskNum(taskDTO.TaskNum);
+
+
+            string targetAddress = useSourceAddress ? taskDTO.SourceAddress : taskDTO.TargetAddress;
+
+            IDevice? device = Storage.Devices.Where(x => x.DeviceProDTOs.Select(x => x.DeviceChildCode == taskDTO.SourceAddress).FirstOrDefault()).FirstOrDefault() ?? null;
+            device?.Communicator.Write(nameof(ConveyorLineDBNameNew.Target), taskInfo.NextAddress);
+            device?.Communicator.Write(nameof(ConveyorLineDBNameNew.TaskNo), taskDTO.TaskNum);
+            device?.Communicator.Write(nameof(ConveyorLineDBNameNew.WCS_STB), 1);
+        }
+
         /// <summary>
         /// 鏈烘鎵嬪墠缂�鍛戒护澶勭悊
         /// </summary>
@@ -332,7 +366,7 @@
 
         private Dt_RobotTask? GetTask(RobotCraneDevice robotCrane)
         {
-            return _taskService.QueryRobotCraneTask(robotCrane.DeviceCode);
+            return _robottaskService.QueryRobotCraneTask(robotCrane.DeviceCode);
         }
     }
 

--
Gitblit v1.9.3