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 |  135 +++++++++++++++++++++++++++++----------------
 1 files changed, 87 insertions(+), 48 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 f466db3..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,19 +1,12 @@
+using Serilog.Core;
 using System.Diagnostics.CodeAnalysis;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Enums;
-using WIDESEAWCS_DTO;
 using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_Model.Models;
-using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.Models;
-using WIDESEAWCS_QuartzJob.Service;
-using WIDESEAWCS_Core;
-using WIDESEAWCS_Core.Enums;
-using WIDESEAWCS_Model.Models;
-using WIDESEAWCS_QuartzJob;
-using WIDESEAWCS_QuartzJob.Models;
-using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_Tasks;
 
 namespace WIDESEAWCS_TaskInfoService;
 
@@ -101,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>
@@ -165,7 +167,6 @@
             string oldCurrentPos = task.CurrentAddress;
             string oldNextPos = task.NextAddress;
 
-
             Dt_Router routers = _routerService.QueryNextRoute(oldNextPos, task.TargetAddress);
             if (routers == null) throw new Exception($"鏈壘鍒拌澶囪矾鐢变俊鎭�");
 
@@ -181,7 +182,45 @@
         }
         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;
+    }
+
+    /// <summary>
+    /// 鏍规嵁浠诲姟鍙枫�佸綋鍓嶅湴鍧�鏇存柊浠诲姟浣嶇疆淇℃伅
+    /// </summary>
+    /// <param name="taskNum">浠诲姟鍙�</param>
+    /// <param name="currentAddress">褰撳墠鍦板潃</param>
+    /// <param name="nextAddress">涓嬩竴鍦板潃</param>
+    /// <returns></returns>
+    public Dt_Task? UpdatePosition(int taskNum, string currentAddress, string nextAddress)
+    {
+        try
+        {
+            if (string.IsNullOrEmpty(currentAddress))
+                throw new ArgumentNullException(nameof(currentAddress), "褰撳墠鍦板潃涓嶈兘涓虹┖");
+
+            Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress);
+            if (task == null) throw new Exception($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
+
+            string oldCurrentPos = task.CurrentAddress;
+            string oldNextPos = task.NextAddress;
+
+            task.CurrentAddress = task.NextAddress;
+            task.NextAddress = nextAddress;
+
+            task.ModifyDate = DateTime.Now;
+            task.Modifier = "System";
+            BaseDal.UpdateData(task);
+
+            _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"绯荤粺鑷姩娴佺▼锛屾洿鏂板綋鍓嶄綅缃�恵oldCurrentPos} ----> {task.CurrentAddress}銆戝拰涓嬩竴浣嶇疆銆恵oldNextPos} ----> {task.NextAddress}銆�");
+            return task;
+        }
+        catch (Exception ex)
+        {
+            QuartzLogHelper.LogError(Logger.None, $"UpdatePosition 鏇存柊浠诲姟浣嶇疆澶辫触,浠诲姟鍙�:銆恵taskNum}銆�,閿欒淇℃伅:銆恵ex.Message}銆�", "UpdatePosition");
         }
         return null;
     }

--
Gitblit v1.9.3