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 |  146 ++++++++++++++++++++++++++++++++++++------------
 1 files changed, 110 insertions(+), 36 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
index 1030119..b63717b 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
@@ -1,7 +1,13 @@
-锘縰sing Quartz;
+锘縰sing HslCommunication;
+using Newtonsoft.Json;
+using Quartz;
 using System.Collections.Concurrent;
 using System.Net.Sockets;
+using System.Text.Json;
+using WIDESEAWCS_Common.HttpEnum;
+using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Core.Http;
 using WIDESEAWCS_DTO.Stock;
 using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_ITaskInfoRepository;
@@ -19,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)
@@ -126,7 +136,7 @@
         {
             string messageLower = message.ToLowerInvariant();
 
-            if (IsSimpleCommand(messageLower, state))
+            if (await IsSimpleCommandAsync(messageLower, state))
             {
                 return null;
             }
@@ -147,13 +157,6 @@
 
                         if (cmd.StartsWith("pickfinished"))
                         {
-                            state.LastPickPositions = positions;
-                            state.CurrentAction = "PickFinished";
-                        }
-                        else if (cmd.StartsWith("putfinished"))
-                        {
-                            state.LastPutPositions = positions;
-                            // 鍙戦�佹暟鎹粰WMS缁勭洏/鎹㈢洏
                             StockDTO stockDTO = new StockDTO
                             {
                                 SourceLineNo = state.CurrentTask?.RobotSourceAddressLineCode,
@@ -161,17 +164,55 @@
                                 TargetPalletNo = state.CurrentTask?.RobotTargetAddressPalletCode,
                                 TargetLineNo = state.CurrentTask?.RobotTargetAddressLineCode,
                                 Details = positions
-                                    .Where(x => x > 0)
-                                    .OrderBy(x => x)
-                                    .Select((x, idx) => new StockDetailDTO
-                                    {
-                                        Quantity = state.CurrentTask?.RobotTaskTotalNum ?? 1,
-                                        Channel = x > 0 ? x : throw new ArgumentOutOfRangeException(nameof(x), "Channel must be positive"),
-                                        CellBarcode = state.CellBarcode[idx]
-                                    })
-                                    .ToList()
+                                        .Where(x => x > 0)
+                                        .OrderBy(x => x)
+                                        .Select((x, idx) => new StockDetailDTO
+                                        {
+                                            Quantity = state.CurrentTask?.RobotTaskTotalNum ?? 1,
+                                            Channel = x > 0 ? x : throw new ArgumentOutOfRangeException(nameof(x), "Channel must be positive"),
+                                            CellBarcode = state.CellBarcode[idx]
+                                        })
+                                        .ToList()
                             };
-                            state.CurrentAction = "PutFinished";
+                            state.LastPickPositions = positions;
+
+                            var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), state.CurrentTask?.RobotTaskType == 2 ? nameof(ConfigKey.ChangePalletAsync) : nameof(ConfigKey.SplitPalletAsync));
+
+                            if (result.Status)
+                            {
+                                state.CurrentAction = "PickFinished";
+                            }
+                        }
+                        else if (cmd.StartsWith("putfinished"))
+                        {
+                            state.LastPutPositions = positions;
+                            if (state.CurrentTask?.RobotTaskType == 1)
+                            {
+                                // 鍙戦�佹暟鎹粰WMS缁勭洏/鎹㈢洏
+                                StockDTO stockDTO = new StockDTO
+                                {
+                                    SourceLineNo = state.CurrentTask?.RobotSourceAddressLineCode,
+                                    SourcePalletNo = state.CurrentTask?.RobotSourceAddressPalletCode,
+                                    TargetPalletNo = state.CurrentTask?.RobotTargetAddressPalletCode,
+                                    TargetLineNo = state.CurrentTask?.RobotTargetAddressLineCode,
+                                    Details = positions
+                                        .Where(x => x > 0)
+                                        .OrderBy(x => x)
+                                        .Select((x, idx) => new StockDetailDTO
+                                        {
+                                            Quantity = state.CurrentTask?.RobotTaskTotalNum ?? 1,
+                                            Channel = x > 0 ? x : throw new ArgumentOutOfRangeException(nameof(x), "Channel must be positive"),
+                                            CellBarcode = state.CellBarcode[idx]
+                                        })
+                                        .ToList()
+                                };
+                                var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), nameof(ConfigKey.GroupPalletAsync));
+
+                                if (result.Status)
+                                {
+                                    state.CurrentAction = "PutFinished";
+                                }
+                            }
                         }
                     }
                 }
@@ -189,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)
             {
@@ -213,7 +254,7 @@
                     state.CurrentAction = "AllPickFinished";
                     if (state.CurrentTask?.RobotTaskType == 2 || state.CurrentTask?.RobotTaskType == 3)
                     {
-                        // TODO 鏈烘鎵嬪彇璐у畬鎴愶紝鍒ゆ柇鏄惁鎹㈢洏銆佹媶鐩樹换鍔★紝鍒涘缓绌烘墭鐩樺洖搴撲换鍔�
+                        await HandleInboundTaskAsync(state, useSourceAddress: true);
                     }
                     return true;
 
@@ -221,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;
 
@@ -280,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>
@@ -292,7 +366,7 @@
 
         private Dt_RobotTask? GetTask(RobotCraneDevice robotCrane)
         {
-            return _taskService.QueryRobotCraneTask(robotCrane.DeviceCode);
+            return _robottaskService.QueryRobotCraneTask(robotCrane.DeviceCode);
         }
     }
 

--
Gitblit v1.9.3