From f319fd5d5e5e0332c4c7e209df64c351dfbe6887 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期六, 25 四月 2026 22:13:19 +0800
Subject: [PATCH] fix: 修复PLC通信及任务处理中的多个问题

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService/TaskService.Status.cs |   90 +++++++++++++++++++++++++-------------------
 1 files changed, 51 insertions(+), 39 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService/TaskService.Status.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService/TaskService.Status.cs
index c760e6f..ad39698 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService/TaskService.Status.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService/TaskService.Status.cs
@@ -1,3 +1,4 @@
+using Serilog.Core;
 using System.Diagnostics.CodeAnalysis;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
@@ -5,6 +6,7 @@
 using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob.Models;
+using WIDESEAWCS_Tasks;
 
 namespace WIDESEAWCS_TaskInfoService;
 
@@ -92,49 +94,58 @@
     /// <returns></returns>
     public WebResponseContent UpdateTaskStatusToNext([NotNull] Dt_Task task)
     {
-        int oldState = task.TaskStatus;
-
-        var result = task.TaskType.GetTaskTypeGroup() switch
+        WebResponseContent content = new WebResponseContent();
+        try
         {
-            TaskTypeGroup.OutbondGroup => _outboundTaskFlowService.MoveToNextStatus(task),
-            TaskTypeGroup.InboundGroup => _inboundTaskFlowService.MoveToNextStatus(task),
-            TaskTypeGroup.RelocationGroup => _relocationTaskFlowService.MoveToNextStatus(task),
-            TaskTypeGroup.OtherGroup => _robotTaskFlowService.MoveToNextStatus(task),
-            _ => WebResponseContent.Instance.Error($"浠诲姟绫诲瀷閿欒,鏈壘鍒拌浠诲姟绫诲瀷,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟绫诲瀷:銆恵task.TaskType}銆�")
-        };
+            int oldState = task.TaskStatus;
 
-        if (!result.Status)
-            return result;
+            var result = task.TaskType.GetTaskTypeGroup() switch
+            {
+                TaskTypeGroup.OutbondGroup => _outboundTaskFlowService.MoveToNextStatus(task),
+                TaskTypeGroup.InboundGroup => _inboundTaskFlowService.MoveToNextStatus(task),
+                TaskTypeGroup.RelocationGroup => _relocationTaskFlowService.MoveToNextStatus(task),
+                TaskTypeGroup.OtherGroup => _robotTaskFlowService.MoveToNextStatus(task),
+                _ => content.Error($"浠诲姟绫诲瀷閿欒,鏈壘鍒拌浠诲姟绫诲瀷,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟绫诲瀷:銆恵task.TaskType}銆�")
+            };
 
-        // 鍑哄簱瀹屾垚绾夸綋鑺傜偣鏃讹紝鍙兘闇�瑕佹帴鏀跺叆搴撴柊浠诲姟銆�
-        if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup
-            && result.Data is List<WMSTaskDTO> wmsTasks
-            && wmsTasks.Count > 0)
-        {
-            WebResponseContent content = ReceiveWMSTask(wmsTasks);
-            if (!content.Status)
-                return content;
+            if (!result.Status)
+                return result;
+
+            // 鍑哄簱瀹屾垚绾夸綋鑺傜偣鏃讹紝鍙兘闇�瑕佹帴鏀跺叆搴撴柊浠诲姟銆�
+            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup
+                && result.Data is List<WMSTaskDTO> wmsTasks
+                && wmsTasks.Count > 0)
+            {
+                content = ReceiveWMSTask(wmsTasks);
+                if (!content.Status)
+                    return content;
+            }
+
+            // 鏇存柊浠诲姟鏁版嵁
+            task.ModifyDate = DateTime.Now;
+            task.Modifier = "System";
+            if (task.TaskStatus == (int)TaskOutStatusEnum.Line_OutFinish)
+            {
+                BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+            }
+            else
+            {
+                BaseDal.UpdateData(task);
+            }
+
+            // 璁板綍浠诲姟鎵ц璇︽儏
+            string logMessage = App.User.UserId > 0
+                ? $"浜哄伐鎵嬪姩灏嗕换鍔$姸鎬佷粠銆恵oldState}銆戣烦杞埌銆恵task.TaskStatus}銆�"
+                : $"绯荤粺鑷姩娴佺▼锛屼换鍔$姸鎬佷粠銆恵oldState}銆戣浆鍒般�恵task.TaskStatus}銆�";
+            _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, logMessage);
+
+            return content.OK();
         }
-
-        // 鏇存柊浠诲姟鏁版嵁
-        task.ModifyDate = DateTime.Now;
-        task.Modifier = "System";
-        if (task.TaskStatus == (int)TaskOutStatusEnum.Line_OutFinish)
+        catch (Exception ex)
         {
-            BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+            QuartzLogHelper.LogError(Logger.None, $"UpdateTaskStatusToNext 鏇存柊灏嗕换鍔$姸鎬佷慨鏀逛负涓嬩竴涓姸鎬佸け璐�,浠诲姟鍙�:銆恵task.TaskNum}銆�,閿欒淇℃伅:銆恵ex.Message}銆�", "UpdateTaskStatusToNext");
+            return content.Error(ex.Message);
         }
-        else
-        {
-            BaseDal.UpdateData(task);
-        }
-
-        // 璁板綍浠诲姟鎵ц璇︽儏
-        string logMessage = App.User.UserId > 0
-            ? $"浜哄伐鎵嬪姩灏嗕换鍔$姸鎬佷粠銆恵oldState}銆戣烦杞埌銆恵task.TaskStatus}銆�"
-            : $"绯荤粺鑷姩娴佺▼锛屼换鍔$姸鎬佷粠銆恵oldState}銆戣浆鍒般�恵task.TaskStatus}銆�";
-        _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, logMessage);
-
-        return WebResponseContent.Instance.OK();
     }
 
     /// <summary>
@@ -171,7 +182,8 @@
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"UpdatePosition 鏇存柊浠诲姟浣嶇疆澶辫触,浠诲姟鍙�:銆恵taskNum}銆�,閿欒淇℃伅:銆恵ex.Message}銆�");
+            QuartzLogHelper.LogError(Logger.None, $"UpdatePosition 鏇存柊浠诲姟浣嶇疆澶辫触,浠诲姟鍙�:銆恵taskNum}銆�,閿欒淇℃伅:銆恵ex.Message}銆�", "UpdatePosition");
+            //Console.WriteLine($"UpdatePosition 鏇存柊浠诲姟浣嶇疆澶辫触,浠诲姟鍙�:銆恵taskNum}銆�,閿欒淇℃伅:銆恵ex.Message}銆�");
         }
         return null;
     }
@@ -208,7 +220,7 @@
         }
         catch (Exception ex)
         {
-            Console.WriteLine($"UpdatePosition 鏇存柊浠诲姟浣嶇疆澶辫触,浠诲姟鍙�:銆恵taskNum}銆�,閿欒淇℃伅:銆恵ex.Message}銆�");
+            QuartzLogHelper.LogError(Logger.None, $"UpdatePosition 鏇存柊浠诲姟浣嶇疆澶辫触,浠诲姟鍙�:銆恵taskNum}銆�,閿欒淇℃伅:銆恵ex.Message}銆�", "UpdatePosition");
         }
         return null;
     }

--
Gitblit v1.9.3