From afbd9149dd39d33d66bb27eaf9ac34c3de36ac7a Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期二, 03 三月 2026 10:29:58 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/RuiShengZhiNeng/GaoPuLiTiKu

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs |  105 +++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 74 insertions(+), 31 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 ea6d384..23e4393 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"
@@ -7,6 +7,7 @@
 using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.LocationEnum;
 using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Core.BaseRepository;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_DTO;
 using WIDESEAWCS_DTO.RGV.FOURBOT;
@@ -128,56 +129,98 @@
         /// <param name="tasks"></param>
         public void SendCheckShapeingOkTask(List<Dt_Task> tasks)
         {
-            FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
             try
             {
                 Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("鏈壘鍒板洓鍚戣溅浠诲姟涓嬪彂鎺ュ彛閰嶇疆淇℃伅锛佽妫�鏌ユ帴鍙i厤缃�");
-                List<Dt_RGVLocationInfo> rGVLocationInfos = new List<Dt_RGVLocationInfo>();
-                List<Dt_StationManger> stationMangers = new List<Dt_StationManger>();
+                var tasksToUpdate = new List<Dt_Task>();
+                var locationsToUpdate = new List<Dt_RGVLocationInfo>();
+                var stationsToUpdate = new List<Dt_StationManger>();
+                #region 浠诲姟涓嬪彂
                 foreach (var item in tasks)
                 {
-                    #region 鑾峰彇璐т綅
-                    var rGVLocationInfo = _rGVLocationInfoService.GetFreeLocationInfo(item.Roadway);
-                    if (rGVLocationInfo == null)
+                    try
                     {
-                        item.ExceptionMessage = $"鏈壘鍒扮粓鐐瑰簱鍖恒�恵item.Roadway}銆戝彲鐢ㄧ┖璐т綅锛�";
-                    }
-                    #endregion
-                    else
-                    {
+                        #region 鑾峰彇璐т綅
+                        var rGVLocationInfo = _rGVLocationInfoService.GetFreeLocationInfo(item.Roadway);
+                        if (rGVLocationInfo == null)
+                        {
+                            item.ExceptionMessage = $"鏈壘鍒扮粓鐐瑰簱鍖恒�恵item.Roadway}銆戝彲鐢ㄧ┖璐т綅锛�";
+                            continue;
+                        }
+                        #endregion
+                        var fOURBOTnewMovePodTask = new FOURBOTnewMovePodTask
+                        {
+                            priority = item.Grade,
+                            podID = item.PalletCode,
+                            destination = rGVLocationInfo.LocationCode,
+                            desExt = new { unload = 1 }, // 鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
+                            desType = 2
+                        };
                         item.CurrentAddress = item.NextAddress;
                         item.NextAddress = rGVLocationInfo.LocationCode;
                         item.Roadway = rGVLocationInfo.RoadwayNo;
-                        fOURBOTnewMovePodTask.priority = item.Grade;
-                        fOURBOTnewMovePodTask.podID = item.PalletCode;
-                        fOURBOTnewMovePodTask.destination = item.NextAddress;
-                        fOURBOTnewMovePodTask.desExt = new
-                        {
-                            unload = 1//鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
-                        };
-                        fOURBOTnewMovePodTask.desType = 2;
+
                         string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
-                        FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+                        var fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+
                         if (fOURBOTReturn.returnCode == 0)
                         {
-                            FOURBOTnewMovePodTaskResponseData fOURBO = fOURBOTReturn.data as FOURBOTnewMovePodTaskResponseData ?? throw new Exception("鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID");
+                            var data = fOURBOTReturn.data.ToString();
+                            var fOURBO = data.DeserializeObject<FOURBOTnewMovePodTaskResponseData>();
+
                             item.RGVTaskId = fOURBO.taskID;
                             item.TaskState = (int)TaskStatusEnum.Puting;
+
                             rGVLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
-                            rGVLocationInfos.Add(rGVLocationInfo);
+                            locationsToUpdate.Add(rGVLocationInfo);
+
                             #region 閲婃斁鍏ュ簱绔欏彴
-                            Dt_StationManger stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
-                            stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
-                            stationMangers.Add(stationManger);
+                            var stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
+                            if (stationManger != null)
+                            {
+                                stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
+                                stationsToUpdate.Add(stationManger);
+                            }
                             #endregion
                         }
+                        else
+                        {
+                            item.ExceptionMessage = $"鍥涘悜杞︽帴鍙h繑鍥為敊璇細{fOURBOTReturn.returnMsg}";
+                            // 璁板綍澶辫触鐨勪换鍔�
+                        }
                     }
-                }
-                _taskService.Db.Ado.BeginTran();
-                _taskService.UpdateData(tasks);
-                _rGVLocationInfoService.UpdateData(rGVLocationInfos);
-                _stationMangerService.UpdateData(stationMangers);
-                _taskService.Db.Ado.CommitTran();
+                    catch (Exception ex)
+                    {
+                        item.ExceptionMessage = $"澶勭悊浠诲姟寮傚父锛歿ex.Message}";
+                        WriteError($"{nameof(TaskJob)}-{item.TaskId}", ex.Message, ex);
+                    }
+                    tasksToUpdate.Add(item);
+                } 
+                #endregion
+                #region 鏇存柊鏁版嵁
+                // 濡傛灉鏈夐渶瑕佹洿鏂扮殑鏁版嵁锛屾墠鎵ц浜嬪姟
+                if (tasksToUpdate.Any() || locationsToUpdate.Any() || stationsToUpdate.Any())
+                {
+                    try
+                    {
+                        _unitOfWorkManage.BeginTran();
+
+                        if (tasksToUpdate.Any())
+                            _taskService.UpdateData(tasksToUpdate);
+                        if (locationsToUpdate.Any())
+                            _rGVLocationInfoService.UpdateData(locationsToUpdate);
+                        if (stationsToUpdate.Any())
+                            _stationMangerService.UpdateData(stationsToUpdate);
+
+                        _unitOfWorkManage.CommitTran();
+                    }
+                    catch (Exception ex)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        WriteError(nameof(TaskJob), ex.Message, ex);
+                    }
+                } 
+                #endregion
             }
             catch (Exception ex)
             {

--
Gitblit v1.9.3