From 6cc35000a6e138cfad96e7b02f8aeddcdb4ba6bf Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期二, 24 六月 2025 09:57:25 +0800
Subject: [PATCH] 代码提交

---
 代码管理/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs |   57 ++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 34 insertions(+), 23 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs"
index 7ba609f..afd92de 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs"
@@ -1,4 +1,5 @@
-锘縰sing WIDESEAWCS_Common.AGVEnum;
+锘縰sing System.Threading.Tasks;
+using WIDESEAWCS_Common.AGVEnum;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_ITaskInfoRepository;
@@ -283,22 +284,22 @@
                     }
 
                     // 璇诲彇浠诲姟鐘舵��
-                    int taskFbInteractive = plcClient.Communicator.Read<int>(taskFbInteractiveR);
-                    int taskFbInteractiveW = plcClient.Communicator.Read<int>(taskFbInteractive2);
-                    int resetTaskFbInteractiveRValue = plcClient.Communicator.Read<int>(resetTaskFbInteractiveR);
+                    int taskFbInteractive = plcClient.Communicator.Read<ushort>(taskFbInteractiveR);
+                    int taskFbInteractiveW = plcClient.Communicator.Read<ushort>(taskFbInteractive2);
+                    int resetTaskFbInteractiveRValue = plcClient.Communicator.Read<ushort>(resetTaskFbInteractiveR);
 
                     // 濡傛灉resetTaskFbInteractiveR涓�1锛屽垯閲嶇疆taskFbInteractiveW涓�0锛屽苟绛夊緟鍏跺彉涓�0
                     if (resetTaskFbInteractiveRValue == 1)
                     {
-                        plcClient.Communicator.Write(taskFbInteractive2, 0);
+                        plcClient.Communicator.Write<ushort>(taskFbInteractive2, 0);
                         // 閬垮厤浣跨敤Thread.Sleep鏉ョ瓑寰呯姸鎬佸彉鍖栵紝浣跨敤鏇撮珮鏁堢殑绛夊緟鏈哄埗
                         for (int i = 0; i < 5; i++)
                         {
                             Task.Delay(300).Wait(); // 浣跨敤Task.Delay鏇夸唬Thread.Sleep锛岄伩鍏嶉樆濉炵嚎绋嬫睜涓殑绾跨▼
-                            int agvNumber = plcClient.Communicator.Read<int>(taskFbInteractive2);
+                            int agvNumber = plcClient.Communicator.Read<ushort>(taskFbInteractive2);
                             if (agvNumber != 0)
                             {
-                                plcClient.Communicator.Write(taskFbInteractive2, 0);
+                                plcClient.Communicator.Write<ushort>(taskFbInteractive2, 0);
                             }
                             else
                             {
@@ -310,8 +311,8 @@
                     // 鍙湁褰搕askFbInteractive涓�1涓攖askFbInteractiveW涓�0鏃舵墠澶勭悊浠诲姟鐘舵��
                     if (taskFbInteractive == 1 && taskFbInteractiveW == 0)
                     {
-                        string taskId = plcClient.Communicator.Read<int>(taskIDFb).ToString(); // 浠诲姟ID
-                        int taskState = plcClient.Communicator.Read<int>(taskStatusFb); // 浠诲姟鐘舵��
+                        string taskId = plcClient.Communicator.Read<string>(taskIDFb).ToString(); // 浠诲姟ID
+                        int taskState = plcClient.Communicator.Read<ushort>(taskStatusFb); // 浠诲姟鐘舵��
 
                         // 濡傛灉浠诲姟鐘舵�佹棤鏁堬紝鍒欑洿鎺ヨ繑鍥�
                         if (taskState == 0)
@@ -320,10 +321,11 @@
                         }
 
                         // 鏍规嵁浠诲姟ID鏌ヨ鏁版嵁搴撲腑鐨勪换鍔�
-                        var agvTask = taskRepository.QueryFirst(r => r.TaskNum.ToString() == taskId);
+                        int tasknum = int.Parse(taskId.Split('-')[1]);
+                        var agvTask = taskRepository.QueryFirst(r => r.TaskNum.ToString() == tasknum.ToString());
                         if (agvTask == null)
                         {
-                            plcClient.Communicator.Write(taskFbInteractive2, 1);
+                            plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1);
                             return; // 濡傛灉浠诲姟涓嶅瓨鍦紝鐩存帴杩斿洖锛屼笉闇�瑕佸啀娆″啓鍏�
                         }
 
@@ -342,7 +344,7 @@
                         }
                         else if (taskState == 4) // 浠诲姟缁堢偣瀹屾垚
                         {
-                            if (agvTask.TaskState != (int)TaskInStatusEnum.SC_InExecuting)
+                            if (agvTask.TaskState != (int)TaskInStatusEnum.SC_InFinish)
                             {
                                 // 濡傛灉浠诲姟鐘舵�佷笉鏄粓鐐规墽琛屼腑锛屾姏鍑哄紓甯�
                                 throw new Exception($"浠诲姟鐘舵�佹洿鏀逛负4缁堢偣宸插畬鎴愬け璐�,浠诲姟ID:{taskId},褰撳墠鐘舵��:{agvTask.TaskState}");
@@ -354,7 +356,16 @@
                                 {
                                     // 绌虹洏绾胯繘鐑樼
                                     // TODO: 浠诲姟鎴彇瀹屾暣鏉$爜
-                                    var materials = new List<BakingClass>();
+                                    var details = agvTask.ExceptionMessage;
+                                    string[] splitDetails = details.Split(','); 
+
+                                    var materials = splitDetails
+                                        .Select(part => new BakingClass
+                                        {
+                                            MaterialType = "", 
+                                            BarCode = part 
+                                        })
+                                        .ToList();
 
                                     MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials);
                                     if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; }
@@ -373,7 +384,7 @@
                                     //        })
                                     //        .ToList();
 
-                                    var details = _detailsRepository.QueryData(x => x.TaskEndAddress == agvTask.TargetAddress && x.TaskName == agvTask.Roadway).OrderBy(x => x.CreateDate).ToList();
+                                    var details = _detailsRepository.QueryData(x => x.TaskEndAddress == agvTask.TargetAddress).ToList();
 
                                     if (details.Count >= 2)
                                     {
@@ -398,19 +409,19 @@
 
                             // 鍒犻櫎宸插畬鎴愮殑浠诲姟
                             taskRepository.DeleteData(agvTask);
-                            plcClient.Communicator.Write(taskFbInteractive2, 1);
+                            plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1);
                             EnsureTaskFeedback(taskFbInteractive2, plcClient);
                         }
                         else if (taskState == 5)
                         {
-                            plcClient.Communicator.Write(taskFbInteractive2, 1);
+                            plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1);
                         }
                     }
 
                     // 濡傛灉taskFbInteractive涓�0涓攖askFbInteractiveW涓�1锛屽垯閲嶇疆taskFbInteractiveW涓�0
                     if (taskFbInteractive == 0 && taskFbInteractiveW == 1)
                     {
-                        plcClient.Communicator.Write(taskFbInteractive2, 0);
+                        plcClient.Communicator.Write<ushort>(taskFbInteractive2, 0);
                         EnsureTaskFeedback(taskFbInteractive2, plcClient);
                     }
                 }
@@ -429,15 +440,15 @@
         // 鏇存柊浠诲姟鐘舵�佸苟鍐欏叆AGV鍙嶉鍦板潃
         private static void UpdateTaskStatus(AGV plcClient, Dt_Task agvTask, TaskInStatusEnum targetStatus, ITaskRepository taskRepository, string taskFbInteractive2)
         {
-            if (agvTask.TaskState != (int)targetStatus)
-            {
-                plcClient.Communicator.Write(taskFbInteractive2, 1); // 鐘舵�佷笉鍖归厤锛屽啓鍏ュ弽棣�
-            }
+            //if (agvTask.TaskState != (int)targetStatus)
+            //{
+            //    plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); // 鐘舵�佷笉鍖归厤锛屽啓鍏ュ弽棣�
+            //}
 
             // 鏇存柊浠诲姟鐘舵�佷负涓嬩竴涓湭瀹屾垚鐘舵��
             agvTask.TaskState = agvTask.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
             taskRepository.UpdateData(agvTask);
-            plcClient.Communicator.Write(taskFbInteractive2, 1);
+            plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1);
             EnsureTaskFeedback(taskFbInteractive2, plcClient);
         }
 
@@ -450,7 +461,7 @@
                 int agvNumber = plcClient.Communicator.Read<int>(taskFbInteractive2);
                 if (agvNumber != 1)
                 {
-                    plcClient.Communicator.Write(taskFbInteractive2, 1);
+                    plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1);
                 }
                 else
                 {

--
Gitblit v1.9.3