From 75f34e9ba2e8b249c96333f3d7936c8968e12ec7 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 11 二月 2026 14:44:12 +0800
Subject: [PATCH] 集成WMS调用与入库任务处理

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs |   83 +++++++++++++++++++++++++++++++----------
 1 files changed, 63 insertions(+), 20 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..d780e0b 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)
@@ -133,7 +137,7 @@
             WebResponseContent content = new WebResponseContent();
             string messageLower = message.ToLowerInvariant();
 
-            if (IsSimpleCommand(messageLower, state))
+            if (await IsSimpleCommandAsync(messageLower, state))
             {
                 return null;
             }
@@ -174,7 +178,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);
+                            WebResponseContent? contentNullable = JsonConvert.DeserializeObject<WebResponseContent>(result);
+                            content = contentNullable ?? new WebResponseContent();
 
                             if (content.Status)
                             {
@@ -205,7 +210,8 @@
                                         .ToList()
                                 };
                                 var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), nameof(ConfigKey.GroupPalletAsync));
-                                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+                                WebResponseContent? contentNullable = JsonConvert.DeserializeObject<WebResponseContent>(result);
+                                content = contentNullable ?? new WebResponseContent();
 
                                 if (content.Status)
                                 {
@@ -229,7 +235,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 +259,7 @@
                     state.CurrentAction = "AllPickFinished";
                     if (state.CurrentTask?.RobotTaskType == 2 || state.CurrentTask?.RobotTaskType == 3)
                     {
-                        // TODO 鏈烘鎵嬪彇璐у畬鎴愶紝鍒ゆ柇鏄惁鎹㈢洏銆佹媶鐩樹换鍔★紝鍒涘缓绌烘墭鐩樺洖搴撲换鍔�
+                        await HandleInboundTaskAsync(state, useSourceAddress: true);
                     }
                     return true;
 
@@ -261,17 +267,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 +316,53 @@
             }
         }
 
+        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));
+            WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result) ?? new WebResponseContent();
+            if (!content.Status)
+            {
+                return;
+            }
+
+            WMSTaskDTO taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString() ?? string.Empty) ?? new WMSTaskDTO();
+            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 +375,7 @@
 
         private Dt_RobotTask? GetTask(RobotCraneDevice robotCrane)
         {
-            return _taskService.QueryRobotCraneTask(robotCrane.DeviceCode);
+            return _robottaskService.QueryRobotCraneTask(robotCrane.DeviceCode);
         }
     }
 

--
Gitblit v1.9.3