From 3b7569285434bb38736627821f7d7eb34fabca28 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 09 四月 2026 16:32:30 +0800
Subject: [PATCH] 优化海康跨楼层任务,处理设备信息写入失败任务

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs |   62 +++++++++++++++++++++++--------
 1 files changed, 46 insertions(+), 16 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs"
index 92b7341..d1d3cfd 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs"
@@ -1,6 +1,7 @@
 锘縰sing Newtonsoft.Json;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -46,7 +47,7 @@
                         desStationCodes = task.SourceAddress,
                         desType = 5
                     };
-                    fOURBOTnewMovePodTask.requestID += i;
+                    fOURBOTnewMovePodTask.requestID += task.TaskId;
                     try
                     {
                         string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
@@ -64,13 +65,23 @@
                         task.RGVTaskId = fOURBO.taskID;
                         task.ExceptionMessage = "";
                         task.TaskState = (int)TaskStatusEnum.Execut;
+                        task.Dispatchertime=DateTime.Now;
                     }
                     catch (Exception ex)
                     {
                         task.ExceptionMessage = ex.Message;
                     }
                 }
-                _taskService.UpdateData(tasks);
+                var uptasks = tasks.Where(task => string.IsNullOrEmpty(task.ExceptionMessage)).ToList();
+                if (uptasks.Count() > 0) _taskService.UpdateData(uptasks);
+                var errortasks = tasks.Where(task => !string.IsNullOrEmpty(task.ExceptionMessage)).ToList();
+                if (errortasks.Count() > 0)
+                {
+                    foreach (var item in errortasks)
+                    {
+                        _taskService.ErrorTaskFeedback(item, true);
+                    }
+                }
                 content.OK();
             }
             catch (Exception ex)
@@ -109,6 +120,7 @@
                         keepRobot = 1,
                         keepRobotTimeout = 1
                     };
+                    fOURBOTnewMovePodTask.requestID += item.TaskId;
                     fOURBOTnewMovePodTask.desType = 1;
                     fOURBOTnewMovePodTask.desNodeID = item.NextAddress;
                     string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
@@ -124,6 +136,7 @@
                         }
                         //FOURBOTnewMovePodTaskResponseData fOURBO = fOURBOTReturn.data as FOURBOTnewMovePodTaskResponseData ?? throw new Exception("鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID");
                         item.RGVTaskId = fOURBO.taskID;
+                        item.Dispatchertime = DateTime.Now;
                         item.TaskState = (int)TaskStatusEnum.TakeFinish;
                     }
                 }
@@ -136,7 +149,7 @@
             }
             finally
             {
-                _trackloginfoService.AddTrackLog(fOURBOTnewMovePodTask, content, "涓嬪彂鍥涘悜杞︽柊寤哄叆搴撲换鍔�", "", "");
+                _trackloginfoService.AddTrackLog(fOURBOTnewMovePodTask, content, "涓嬪彂鍥涘悜杞﹀褰㈡娴嬩换鍔�", "", "");
             }
         }
         #endregion
@@ -188,10 +201,18 @@
                         {
                             var task = tasks.First(x => x.PalletCode == item.outPod);
                             if (item.blockPods != null && item.blockPods.Count > 0)
+                                item.blockPods = item.blockPods.Except(PalletCodes).ToList();
+                            if (item.blockPods != null && item.blockPods.Count > 0)
                             {
+                                #region 鍒ゆ柇闃荤鎵樻槸鍚︿负鍑哄簱浠诲姟
+                                //var except = item.blockPods.Except(PalletCodes).ToList();
+                                #endregion
                                 var responseContent = AddMoveTask(item.blockPods, task);//娣诲姞绉诲簱浠诲姟
                                 if (!responseContent.Status) task.ExceptionMessage = responseContent.Message;
-                                else task.TaskState = (int)TaskStatusEnum.RGV_WaitMoveToExecute;
+                                else
+                                {
+                                    task.TaskState = (int)TaskStatusEnum.RGV_WaitMoveToExecute;
+                                }
                                 dt_Tasks.Add(task);
                             }
                             else
@@ -259,6 +280,7 @@
                             {
                                 autoToRest = 1
                             };
+                            fOURBOTnewMovePodTask.requestID = DateTime.Now.ToString("yyyyMMddHHmmssfff") + item.TaskId;
                             item.CurrentAddress = item.NextAddress;
                             item.NextAddress = rGVLocationInfo.LocationCode;
                             item.TargetAddress = rGVLocationInfo.LocationCode;
@@ -273,17 +295,17 @@
                                 var fOURBO = data.DeserializeObject<FOURBOTnewMovePodTaskResponseData>();
                                 item.RGVTaskId = fOURBO.taskID;
                                 item.TaskState = (int)TaskStatusEnum.Puting;
-
                                 rGVLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
+                                item.Dispatchertime = DateTime.Now;
                                 locationsToUpdate.Add(rGVLocationInfo);
 
                                 #region 閲婃斁鍏ュ簱绔欏彴
-                                //var stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
-                                //if (stationManger != null)
-                                //{
-                                //    stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
-                                //    stationsToUpdate.Add(stationManger);
-                                //}
+                                var stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
+                                if (stationManger != null)
+                                {
+                                    stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
+                                    stationsToUpdate.Add(stationManger);
+                                }
                                 content.OK();
                                 #endregion
                             }
@@ -301,6 +323,10 @@
                         item.ExceptionMessage = $"澶勭悊浠诲姟寮傚父锛歿ex.Message}";
                         //WriteError($"{nameof(TaskJob)}-{item.TaskId}", ex.Message, ex);
                         content.Error($"鍥涘悜杞︽帴鍙h繑鍥為敊璇細{ex.Message}");
+                    }
+                    finally
+                    {
+
                     }
                 }
                 #region MyRegion
@@ -386,8 +412,8 @@
                             _taskService.UpdateData(tasksToUpdate);
                         if (locationsToUpdate.Any())
                             _rGVLocationInfoService.UpdateData(locationsToUpdate);
-                        //if (stationsToUpdate.Any())
-                        //    _stationMangerService.UpdateData(stationsToUpdate);
+                        if (stationsToUpdate.Any())
+                            _stationMangerService.UpdateData(stationsToUpdate);
 
                         _unitOfWorkManage.CommitTran();
                     }
@@ -406,7 +432,7 @@
             }
             finally
             {
-                _trackloginfoService.AddTrackLog(fOURBOTnewMovePodTask, content, "涓嬪彂澶栧舰妫�娴嬩换鍔″け璐�", "", "");
+                _trackloginfoService.AddTrackLog(fOURBOTnewMovePodTask, content, "涓嬪彂澶栧舰妫�娴嬫垚鍔熶换鍔�", "", "");
             }
         }
         #endregion
@@ -452,6 +478,7 @@
                         }
                         item.RGVTaskId = fOURBO.taskID;
                         item.TaskState = (int)TaskStatusEnum.Puting;
+                        item.Dispatchertime = DateTime.Now;
                     }
                 }
                 _taskService.UpdateData(tasks);
@@ -484,7 +511,7 @@
                 tasks.ForEach(x =>
                 {
                     x.TaskNum = _taskService.GetTaskNum(nameof(SequenceEnum.SeqTaskNum));
-                    x.WMSTaskNum = task.WMSTaskNum;
+                    //x.WMSTaskNum = task.WMSTaskNum;
                 });
                 rGVLocationInfos.ForEach(x =>
                 {
@@ -556,6 +583,7 @@
                         var task = tasks.First(x => x.PalletCode == item.podID);
                         task.RGVTaskId = item.taskID;
                         task.TaskState = TaskStatusEnum.RGV_MoveTaskSend.ObjToInt();
+                        task.Dispatchertime = DateTime.Now;
                         dt_Tasks.Add(task);
                     }
                     _taskService.UpdateData(dt_Tasks);
@@ -584,6 +612,7 @@
                     if (takes == null)
                     {
                         item.TaskState = (int)TaskStatusEnum.RGV_WaitSend;
+                        item.Dispatchertime = DateTime.Now;
                     }
                 }
                 _taskService.UpdateData(tasks);
@@ -628,7 +657,7 @@
                         autoToRest = 1
                     };
                     fOURBOTnewMovePodTask.desType = 5;
-                    fOURBOTnewMovePodTask.requestID = DateTime.Now.ToString("yyyyMMddHHmmss") + i;
+                    fOURBOTnewMovePodTask.requestID = DateTime.Now.ToString("yyyyMMddHHmmssfff") + item.TaskId;
                     string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
                     FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                     content.OK(data: fOURBOTReturn);
@@ -642,6 +671,7 @@
                         }
                         item.RGVTaskId = fOURBO.taskID;
                         item.TaskState = (int)TaskStatusEnum.Execut;
+                        item.Dispatchertime = DateTime.Now;
                         //stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
                         //_stationMangerService.UpdateData(stationManger);
                     }

--
Gitblit v1.9.3