From f56f8d4bf3bf088579a169519ef2547d40586f76 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 10 四月 2026 18:42:53 +0800
Subject: [PATCH] 添加平库货位上下架容器接口

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Task/RGVTaskExtend.cs |  681 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 630 insertions(+), 51 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 f057da7..71c5c1c 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,10 +1,16 @@
-锘縰sing System;
+锘縰sing Newtonsoft.Json;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
+using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.LocationEnum;
 using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.BaseRepository;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_DTO;
 using WIDESEAWCS_DTO.RGV.FOURBOT;
@@ -15,51 +21,225 @@
 {
     public partial class TaskJob
     {
-
-        #region 涓嬪彂鍥涘悜杞︿换鍔�
-        public void SendRGVTask(List<Dt_Task> tasks)
+        /// <summary>
+        /// 涓嬪彂鍥涘悜杞︽柊寤哄叆搴撲换鍔�
+        /// </summary>
+        /// <param name="tasks"></param>
+        public void SendRGVNewInTask(List<Dt_Task> tasks)
         {
             FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
+            WebResponseContent content = new WebResponseContent();
             try
             {
                 Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("鏈壘鍒板洓鍚戣溅浠诲姟涓嬪彂鎺ュ彛閰嶇疆淇℃伅锛佽妫�鏌ユ帴鍙i厤缃�");
-                #region 鍏ュ簱
-                var intasks = tasks.Where(x => x.TaskType == (int)TaskTypeEnum.CPInbound).ToList();
-                foreach (var item in intasks)
+                foreach (var task in tasks)
+                {
+                    fOURBOTnewMovePodTask = new()
+                    {
+                        priority = task.Grade,
+                        podID = task.PalletCode,
+                        desExt = new
+                        {
+                            unload = 0//鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
+                        },
+                        desStationCodes = task.SourceAddress,
+                        desType = 5
+                    };
+                    fOURBOTnewMovePodTask.requestID += task.TaskId;
+                    try
+                    {
+                        string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
+                        FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+                        content.OK(data: fOURBOTReturn);
+                        if (fOURBOTReturn.returnCode != 0) throw new Exception(fOURBOTReturn.returnUserMsg);
+
+                        string dataJson = fOURBOTReturn.data.ToString();
+                        FOURBOTnewMovePodTaskResponseData? fOURBO = JsonConvert.DeserializeObject<FOURBOTnewMovePodTaskResponseData>(dataJson);
+                        if (fOURBO == null || fOURBO.taskID == 0)
+                        {
+                            throw new Exception($"鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID锛岃繑鍥炴暟鎹細{response}");
+                        }
+                        //FOURBOTnewMovePodTaskResponseData fOURBO = fOURBOTReturn.data as FOURBOTnewMovePodTaskResponseData ?? throw new Exception("鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID");
+                        task.RGVTaskId = fOURBO.taskID;
+                        task.ExceptionMessage = "";
+                        task.TaskState = (int)TaskStatusEnum.Execut;
+                        task.Dispatchertime = DateTime.Now;
+                    }
+                    catch (Exception ex)
+                    {
+                        task.ExceptionMessage = ex.Message;
+                        content.Error(ex.Message);
+                    }
+                    finally
+                    {
+                        _trackloginfoService.AddTrackLog(fOURBOTnewMovePodTask, content, "涓嬪彂鍥涘悜杞︽柊寤哄叆搴撲换鍔�", "", "");
+                    }
+                }
+                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)
+                    {
+                        Thread.Sleep(500);
+                        _taskService.ErrorTaskFeedback(item, true);
+                    }
+                }
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+        }
+
+        #region 
+        /// <summary>
+        /// 涓嬪彂鍥涘悜杞﹀褰㈡娴嬩换鍔�
+        /// </summary>
+        /// <param name="tasks"></param>
+        public void SendRGVCheckShapeTask(List<Dt_Task> tasks)
+        {
+            FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("鏈壘鍒板洓鍚戣溅浠诲姟涓嬪彂鎺ュ彛閰嶇疆淇℃伅锛佽妫�鏌ユ帴鍙i厤缃�");
+                foreach (var item in tasks)
                 {
                     fOURBOTnewMovePodTask.priority = item.Grade;
                     fOURBOTnewMovePodTask.podID = item.PalletCode;
-                    fOURBOTnewMovePodTask.destination = item.NextAddress;
+                    //fOURBOTnewMovePodTask.destination = item.NextAddress;
                     fOURBOTnewMovePodTask.desExt = new
                     {
                         unload = 0//鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
                     };
-                    fOURBOTnewMovePodTask.desType = 2;
+                    fOURBOTnewMovePodTask.taskExt = new
+                    {
+                        keepRobot = 1,
+                        keepRobotTimeout = 1
+                    };
+                    fOURBOTnewMovePodTask.requestID += item.TaskId;
+                    fOURBOTnewMovePodTask.desType = 1;
+                    fOURBOTnewMovePodTask.desNodeID = item.NextAddress;
                     string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
                     FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+                    content.OK(data: fOURBOTReturn);
                     if (fOURBOTReturn.returnCode == 0)
                     {
-                        item.RGVTaskId = fOURBOTReturn.data.taskID;
-                        item.TaskState = (int)TaskStatusEnum.Execut;
+                        string dataJson = fOURBOTReturn.data.ToString();
+                        FOURBOTnewMovePodTaskResponseData? fOURBO = JsonConvert.DeserializeObject<FOURBOTnewMovePodTaskResponseData>(dataJson);
+                        if (fOURBO == null || fOURBO.taskID == 0)
+                        {
+                            throw new Exception($"鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID锛岃繑鍥炴暟鎹細{response}");
+                        }
+                        //FOURBOTnewMovePodTaskResponseData fOURBO = fOURBOTReturn.data as FOURBOTnewMovePodTaskResponseData ?? throw new Exception("鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID");
+                        item.RGVTaskId = fOURBO.taskID;
+                        item.Dispatchertime = DateTime.Now;
+                        item.TaskState = (int)TaskStatusEnum.TakeFinish;
                     }
                 }
-                _taskService.UpdateData(intasks);
-                #endregion
-
-                #region 鍑哄簱
-                var outtasks = tasks.Where(x => x.TaskType == (int)TaskTypeEnum.CPOutbound).ToList();
-                foreach (var item in outtasks)
-                {
-                    ///鍒ゆ柇鏄惁闇�瑕佺Щ搴�
-                }
-                #endregion
+                _taskService.UpdateData(tasks);
+                content.OK();
             }
             catch (Exception ex)
             {
-                WriteError(nameof(TaskJob), ex.Message, ex);
+                content.Error(ex.Message);
+            }
+            finally
+            {
+                _trackloginfoService.AddTrackLog(fOURBOTnewMovePodTask, content, "涓嬪彂鍥涘悜杞﹀褰㈡娴嬩换鍔�", "", "");
             }
         }
         #endregion
+
+        #region 澶勭悊鍑哄簱浠诲姟鏄惁闇�瑕佺Щ搴�
+        /// <summary>
+        /// 澶勭悊鍑哄簱浠诲姟鏄惁闇�瑕佺Щ搴�
+        /// </summary>
+        /// <param name="tasks"></param>
+        public void IsMoveTask(List<Dt_Task> tasks)
+        {
+
+            object requestData = null;  // 娣诲姞鍙橀噺璁板綍璇锋眰鏁版嵁
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(GetBlockPodContentDto)) ?? throw new Exception("鏈壘鍒版壒閲忚幏鍙栭樆纰嶆墭鐩樺叧绯绘帴鍙i厤缃俊鎭紒璇锋鏌ユ帴鍙i厤缃�");
+                List<Dt_Task> dt_Tasks = new List<Dt_Task>();
+                var PalletCodes = tasks.Select(x => x.PalletCode).ToList();
+                //GetBlockPodContentDto content = new GetBlockPodContentDto();
+                var request = new GetBlockPodContentListDto
+                {
+                    content = new List<GetBlockPodContentDto>
+                    {
+                        new GetBlockPodContentDto
+                        {
+                            candidatePodIDs = PalletCodes,
+                            num = 0 // 0琛ㄧず鍏ㄩ儴鍑猴紝濡傛灉闇�瑕侀檺鍒舵暟閲忓彲浠ヨ皟鏁�
+                        }
+                    }
+                };
+                requestData = request;  // 淇濆瓨璇锋眰鏁版嵁鐢ㄤ簬鏃ュ織
+                //content.candidatePodIDs = tasks.Select(x => x.PalletCode).ToList();
+                //string response = HttpHelper.Post("http://127.0.0.1:4523/m2/6165241-5857331-default/440906899?apifoxApiId=440906899", request.Serialize());
+
+                string response = HttpHelper.Post(apiInfo.ApiAddress, request.Serialize());
+                FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+                content.OK(data: fOURBOTReturn);
+                if (fOURBOTReturn.returnCode == 0)
+                {
+                    //ReturnBlockPodResultDto getBlockPod = fOURBOTReturn.data as ReturnBlockPodResultDto ?? throw new Exception("鏈幏鍙栧埌闃荤鎵樼洏鍏崇郴鏁版嵁");
+                    var dataJson = fOURBOTReturn.data.ToString();
+                    ReturnBlockPodResultDto? getBlockPod = JsonConvert.DeserializeObject<ReturnBlockPodResultDto>(dataJson);
+                    if (getBlockPod.Result.Count == 0)
+                    {
+                        throw new Exception("鏈幏鍙栧埌闃荤鎵樼洏鍏崇郴鏁版嵁");
+                    }
+                    foreach (var Result in getBlockPod.Result)
+                    {
+                        foreach (var item in Result.outPods)
+                        {
+                            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;
+                                }
+                                dt_Tasks.Add(task);
+                            }
+                            else
+                            {
+                                task.TaskState = (int)TaskStatusEnum.RGV_WaitSend;
+                                dt_Tasks.Add(task);
+                            }
+                        }
+                    }
+                    _taskService.UpdateData(dt_Tasks);
+                    content.OK();
+                }
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            finally
+            {
+                _trackloginfoService.AddTrackLog(requestData, content, "澶勭悊鍑哄簱浠诲姟鏄惁闇�瑕佺Щ搴�", "", "");
+            }
+        }
+        #endregion
+
+        #region 涓嬪彂澶栧舰妫�娴嬫垚鍔熶换鍔�
         /// <summary>
         /// 涓嬪彂澶栧舰妫�娴嬫垚鍔熶换鍔�
         /// </summary>
@@ -67,51 +247,450 @@
         public void SendCheckShapeingOkTask(List<Dt_Task> tasks)
         {
             FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
+            WebResponseContent content = new WebResponseContent();
             try
             {
                 Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("鏈壘鍒板洓鍚戣溅浠诲姟涓嬪彂鎺ュ彛閰嶇疆淇℃伅锛佽妫�鏌ユ帴鍙i厤缃�");
-                List<Dt_RGVLocationInfo> rGVLocationInfos = new List<Dt_RGVLocationInfo>();
-                foreach (var item in tasks)
+                var tasksToUpdate = new List<Dt_Task>();
+                var locationsToUpdate = new List<Dt_RGVLocationInfo>();
+                var stationsToUpdate = new List<Dt_StationManger>();
+                #region 浠诲姟涓嬪彂
+                var item = tasks.FirstOrDefault();
+                if (item != null)
                 {
-                    #region 鑾峰彇璐т綅
-                    var rGVLocationInfo = _rGVLocationInfoService.GetFreeLocationInfo(item.Roadway);
-                    if (rGVLocationInfo == null)
+                    try
                     {
-                        item.ExceptionMessage = $"鏈壘鍒扮粓鐐瑰簱鍖恒�恵item.Roadway}銆戝彲鐢ㄧ┖璐т綅锛�";
-                    }
-                    #endregion
-                    else
-                    {
-                        item.CurrentAddress = item.NextAddress;
-                        item.NextAddress = rGVLocationInfo.LocationCode;
-                        fOURBOTnewMovePodTask.priority = item.Grade;
-                        fOURBOTnewMovePodTask.podID = item.PalletCode;
-                        fOURBOTnewMovePodTask.destination = item.NextAddress;
-                        fOURBOTnewMovePodTask.desExt = new
+                        #region 鑾峰彇璐т綅
+                        var rGVLocationInfo = _rGVLocationInfoService.GetInFreeLocationInfo(item.Roadway.ObjToInt());
+                        if (rGVLocationInfo == null)
                         {
-                            unload = 1//鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
-                        };
-                        fOURBOTnewMovePodTask.desType = 2;
-                        string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
-                        FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
-                        if (fOURBOTReturn.returnCode == 0)
+                            item.ExceptionMessage = $"鏈壘鍒扮粓鐐瑰簱鍖恒�恵item.Roadway}銆戝彲鐢ㄧ┖璐т綅锛�";
+                        }
+                        #endregion
+                        else
                         {
-                            item.RGVTaskId = fOURBOTReturn.data.taskID;
-                            item.TaskState = (int)TaskStatusEnum.Puting;
-                            rGVLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
-                            rGVLocationInfos.Add(rGVLocationInfo);
+                            fOURBOTnewMovePodTask = new FOURBOTnewMovePodTask
+                            {
+                                priority = item.Grade,
+                                podID = item.PalletCode,
+                                desStorageID = rGVLocationInfo.LocationCode,
+                                //destination = rGVLocationInfo.LocationCode,
+                                desExt = new { unload = 1 }, // 鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
+                                desType = 2
+                            };
+                            fOURBOTnewMovePodTask.taskExt = new
+                            {
+                                autoToRest = 1
+                            };
+                            fOURBOTnewMovePodTask.requestID = DateTime.Now.ToString("yyyyMMddHHmmssfff") + item.TaskId;
+                            item.CurrentAddress = item.NextAddress;
+                            item.NextAddress = rGVLocationInfo.LocationCode;
+                            item.TargetAddress = rGVLocationInfo.LocationCode;
+                            item.Roadway = rGVLocationInfo.RoadwayNo;
+
+                            string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
+                            var fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+                            content.OK(data: fOURBOTReturn);
+                            if (fOURBOTReturn.returnCode == 0)
+                            {
+                                var data = fOURBOTReturn.data.ToString();
+                                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);
+                                }
+                                content.OK();
+                                #endregion
+                            }
+                            else
+                            {
+                                item.ExceptionMessage = $"鍥涘悜杞︽帴鍙h繑鍥為敊璇細{fOURBOTReturn.returnMsg}";
+                                // 璁板綍澶辫触鐨勪换鍔�
+                                content.Error($"鍥涘悜杞︽帴鍙h繑鍥為敊璇細{fOURBOTReturn.returnMsg}");
+                            }
+                            tasksToUpdate.Add(item);
                         }
                     }
+                    catch (Exception ex)
+                    {
+                        item.ExceptionMessage = $"澶勭悊浠诲姟寮傚父锛歿ex.Message}";
+                        //WriteError($"{nameof(TaskJob)}-{item.TaskId}", ex.Message, ex);
+                        content.Error($"鍥涘悜杞︽帴鍙h繑鍥為敊璇細{ex.Message}");
+                    }
+                    finally
+                    {
+
+                    }
                 }
-                _taskService.Db.Ado.BeginTran();
+                #region MyRegion
+                //foreach (var item in tasks)
+                //{
+                //    try
+                //    {
+                //        #region 鑾峰彇璐т綅
+                //        var rGVLocationInfo = _rGVLocationInfoService.GetFreeLocationInfo(item.Roadway);
+                //        if (rGVLocationInfo == null)
+                //        {
+                //            item.ExceptionMessage = $"鏈壘鍒扮粓鐐瑰簱鍖恒�恵item.Roadway}銆戝彲鐢ㄧ┖璐т綅锛�";
+                //            continue;
+                //        }
+                //        #endregion
+                //        fOURBOTnewMovePodTask = new FOURBOTnewMovePodTask
+                //        {
+                //            priority = item.Grade,
+                //            podID = item.PalletCode,
+                //            desStorageID = rGVLocationInfo.LocationCode,
+                //            //destination = rGVLocationInfo.LocationCode,
+                //            desExt = new { unload = 1 }, // 鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
+                //            desType = 2
+                //        };
+                //        fOURBOTnewMovePodTask.taskExt = new
+                //        {
+                //            autoToRest = 1
+                //        };
+                //        item.CurrentAddress = item.NextAddress;
+                //        item.NextAddress = rGVLocationInfo.LocationCode;
+                //        item.TargetAddress = rGVLocationInfo.LocationCode;
+                //        item.Roadway = rGVLocationInfo.RoadwayNo;
+
+                //        string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
+                //        var fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+                //        content.Data = fOURBOTReturn;
+                //        if (fOURBOTReturn.returnCode == 0)
+                //        {
+                //            var data = fOURBOTReturn.data.ToString();
+                //            var fOURBO = data.DeserializeObject<FOURBOTnewMovePodTaskResponseData>();
+                //            item.RGVTaskId = fOURBO.taskID;
+                //            item.TaskState = (int)TaskStatusEnum.Puting;
+
+                //            rGVLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
+                //            locationsToUpdate.Add(rGVLocationInfo);
+
+                //            #region 閲婃斁鍏ュ簱绔欏彴
+                //            var stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
+                //            if (stationManger != null)
+                //            {
+                //                stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
+                //                stationsToUpdate.Add(stationManger);
+                //            }
+                //            content.OK();
+                //            #endregion
+                //        }
+                //        else
+                //        {
+                //            item.ExceptionMessage = $"鍥涘悜杞︽帴鍙h繑鍥為敊璇細{fOURBOTReturn.returnMsg}";
+                //            // 璁板綍澶辫触鐨勪换鍔�
+                //            content.Error($"鍥涘悜杞︽帴鍙h繑鍥為敊璇細{fOURBOTReturn.returnMsg}");
+                //        }
+                //    }
+                //    catch (Exception ex)
+                //    {
+                //        item.ExceptionMessage = $"澶勭悊浠诲姟寮傚父锛歿ex.Message}";
+                //        //WriteError($"{nameof(TaskJob)}-{item.TaskId}", ex.Message, ex);
+                //        content.Error($"鍥涘悜杞︽帴鍙h繑鍥為敊璇細{ex.Message}");
+                //    }
+                //    tasksToUpdate.Add(item);
+                //} 
+                #endregion
+                #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)
+            {
+                WriteError(nameof(TaskJob), ex.Message, ex);
+                content.Error($"涓嬪彂澶栧舰妫�娴嬩换鍔″け璐ex.Message}");
+            }
+            finally
+            {
+                _trackloginfoService.AddTrackLog(fOURBOTnewMovePodTask, content, "涓嬪彂澶栧舰妫�娴嬫垚鍔熶换鍔�", "", "");
+            }
+        }
+        #endregion
+
+        #region 涓嬪彂澶栧舰妫�娴嬪け璐ヤ换鍔�
+        public void SendCheckShapeingNGTask(List<Dt_Task> tasks)
+        {
+            FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("鏈壘鍒板洓鍚戣溅浠诲姟涓嬪彂鎺ュ彛閰嶇疆淇℃伅锛佽妫�鏌ユ帴鍙i厤缃�");
+                foreach (var item in tasks)
+                {
+                    Dt_StationManger stationManger = _stationMangerService.GetInStationInfo(item.SourceAddress);
+                    item.CurrentAddress = item.NextAddress;
+                    item.NextAddress = stationManger.StationCode;
+                    fOURBOTnewMovePodTask.priority = item.Grade;
+                    fOURBOTnewMovePodTask.podID = item.PalletCode;
+                    //fOURBOTnewMovePodTask.desNodeID = item.NextAddress;
+                    fOURBOTnewMovePodTask.desStationCodes = item.NextAddress;
+                    fOURBOTnewMovePodTask.desExt = new
+                    {
+                        unload = 1//鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
+                    };
+                    fOURBOTnewMovePodTask.taskExt = new
+                    {
+                        autoToRest = 1
+                    };
+                    fOURBOTnewMovePodTask.desType = 5;
+                    string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
+                    FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+                    content.Data = fOURBOTReturn;
+                    if (fOURBOTReturn.returnCode == 0)
+                    {
+                        //FOURBOTnewMovePodTaskResponseData fOURBO = fOURBOTReturn.data as FOURBOTnewMovePodTaskResponseData ?? throw new Exception("鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID");
+                        string dataJson = fOURBOTReturn.data.ToString();
+                        FOURBOTnewMovePodTaskResponseData? fOURBO = JsonConvert.DeserializeObject<FOURBOTnewMovePodTaskResponseData>(dataJson);
+                        content.OK(data: fOURBO);
+                        if (fOURBO == null || fOURBO.taskID == 0)
+                        {
+                            throw new Exception($"鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID锛岃繑鍥炴暟鎹細{response}");
+                        }
+                        item.RGVTaskId = fOURBO.taskID;
+                        item.TaskState = (int)TaskStatusEnum.Puting;
+                        item.Dispatchertime = DateTime.Now;
+                    }
+                }
                 _taskService.UpdateData(tasks);
-                _rGVLocationInfoService.UpdateData(rGVLocationInfos);
-                _taskService.Db.Ado.CommitTran();
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            finally
+            {
+                _trackloginfoService.AddTrackLog(fOURBOTnewMovePodTask, content, "涓嬪彂澶栧舰妫�娴嬪け璐ヤ换鍔�", "", "");
+            }
+        }
+        #endregion
+
+        #region 娣诲姞绉诲簱浠诲姟
+        public WebResponseContent AddMoveTask(List<string> blockPods, Dt_Task task)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                List<Dt_RGVLocationInfo> rGVLocationInfos = _rGVLocationInfoService.Repository.QueryData(x => blockPods.Contains(x.PalletCode));
+                var Items = _rGVLocationInfoService.GetMoveFreeLocationInfo(rGVLocationInfos);
+
+                List<Dt_Task> tasks = Items.Item1;
+                List<Dt_RGVLocationInfo> _UpRGVLocationInfos = Items.Item2;
+                if (tasks.Count < blockPods.Count) throw new Exception("鍙Щ搴撶┖璐т綅灏戜簬闇�绉诲簱鎵樼洏鏁伴噺");
+
+                tasks.ForEach(x =>
+                {
+                    x.TaskNum = _taskService.GetTaskNum(nameof(SequenceEnum.SeqTaskNum));
+                    //x.WMSTaskNum = task.WMSTaskNum;
+                });
+                rGVLocationInfos.ForEach(x =>
+                {
+                    x.LocationStatus = LocationStatusEnum.MoveLock.ObjToInt();
+                });
+                _UpRGVLocationInfos.ForEach(x =>
+                {
+                    x.LocationStatus = LocationStatusEnum.MoveLock.ObjToInt();
+                });
+                try
+                {
+                    _unitOfWorkManage.BeginTran();
+                    _rGVLocationInfoService.UpdateData(rGVLocationInfos);
+                    _rGVLocationInfoService.UpdateData(_UpRGVLocationInfos);
+                    _taskService.AddData(tasks);
+                    _unitOfWorkManage.CommitTran();
+                    content.OK();
+                }
+                catch (Exception ex)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    throw new Exception(ex.Message);
+                }
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        #endregion
+
+        #region 涓嬪彂鍥涘悜杞︽壒閲忕Щ搴撲换鍔�
+        public void SendMoveTasks(List<Dt_Task> tasks)
+        {
+            WebResponseContent content = new WebResponseContent();
+            List<Dt_Task> dt_Tasks = new List<Dt_Task>();
+            MoveBlockPodContentDto moveBlock = new MoveBlockPodContentDto();
+            try
+            {
+
+                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(MoveBlockPodContentDto)) ?? throw new Exception("鏈壘鍒板洓鍚戣溅鎵归噺鎼繍闃荤鎵樹换鍔℃帴鍙i厤缃俊鎭紒璇锋鏌ユ帴鍙i厤缃�");
+                foreach (var item in tasks)
+                {
+                    MoveBlockPodContentDtoInfo moveBlockInfo = new MoveBlockPodContentDtoInfo()
+                    {
+                        podID = item.PalletCode,
+                        des = item.TargetAddress
+                    };
+                    moveBlock.content.Add(moveBlockInfo);
+                }
+                string response = HttpHelper.Post(apiInfo.ApiAddress, moveBlock.Serialize());
+                FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+                content.OK(data: fOURBOTReturn);
+                if (fOURBOTReturn.returnCode == 0)
+                {
+                    string dataJson = fOURBOTReturn.data.ToString();
+                    //MoveBlockPodsDataDto moveBlockPodsData = fOURBOTReturn.data as MoveBlockPodsDataDto ?? throw new Exception("鏈幏鍙栧埌鍥涘悜杞︽壒閲忔惉杩愰樆纰嶆墭杩斿洖鐨勪换鍔D");
+                    MoveBlockPodsDataDto? moveBlockPodsData = JsonConvert.DeserializeObject<MoveBlockPodsDataDto>(dataJson);
+                    if (moveBlockPodsData == null || moveBlockPodsData.succList.Count == 0)
+                    {
+                        throw new Exception($"鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID锛岃繑鍥炴暟鎹細{response}");
+                    }
+
+                    foreach (var item in moveBlockPodsData.succList)
+                    {
+                        if (item.taskID == 0)
+                            continue;  // 璺宠繃鏃犳晥鐨勪换鍔D
+                        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);
+                    content.OK();
+                }
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            finally
+            {
+                _trackloginfoService.AddTrackLog(moveBlock, content, "涓嬪彂鍥涘悜杞︽壒閲忕Щ搴撲换鍔�", "", "");
+            }
+        }
+        #endregion
+
+        #region 澶勭悊寰呯Щ搴撳悗鍑哄簱浠诲姟
+        public void MoveToExecuteTask(List<Dt_Task> tasks)
+        {
+            try
+            {
+                foreach (var item in tasks)
+                {
+                    var takes = _taskService.Repository.QueryFirst(x => x.Roadway == item.Roadway && x.TaskType == (int)TaskTypeEnum.CPMoveInventory && (x.TaskState == (int)TaskStatusEnum.RGV_NewMoveTask || x.TaskState == (int)TaskStatusEnum.RGV_MoveTaskSend));
+                    if (takes == null)
+                    {
+                        item.TaskState = (int)TaskStatusEnum.RGV_WaitSend;
+                        item.Dispatchertime = DateTime.Now;
+                    }
+                }
+                _taskService.UpdateData(tasks);
             }
             catch (Exception ex)
             {
                 WriteError(nameof(TaskJob), ex.Message, ex);
             }
         }
+        #endregion
+
+        #region 涓嬪彂鍑哄簱浠诲姟
+        public void SendOutTask(List<Dt_Task> tasks)
+        {
+            FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("鏈壘鍒板洓鍚戣溅浠诲姟涓嬪彂鎺ュ彛閰嶇疆淇℃伅锛佽妫�鏌ユ帴鍙i厤缃�");
+                var i = 0;
+                foreach (var item in tasks)
+                {
+                    i++;
+                    var stationManger = _stationMangerService.GetOutStationInfo(item.TargetAddress);
+                    //if (stationManger.IsOccupied != LocationStatusEnum.Free.ObjToInt())
+                    //{
+                    //    item.ExceptionMessage = $"鍑哄簱绔欏彴銆恵stationManger.StationCode}銆戣鍗犵敤";
+                    //    continue;
+                    //}
+                    item.NextAddress = stationManger.StationCode;
+                    #region 涓嬪彂鍑哄簱浠诲姟
+                    fOURBOTnewMovePodTask.priority = item.Grade;
+                    fOURBOTnewMovePodTask.podID = item.PalletCode;
+                    //fOURBOTnewMovePodTask.desNodeID = item.NextAddress;
+                    fOURBOTnewMovePodTask.desStationCodes = item.NextAddress;
+                    fOURBOTnewMovePodTask.desExt = new
+                    {
+                        unload = 1//鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
+                    };
+                    fOURBOTnewMovePodTask.taskExt = new
+                    {
+                        autoToRest = 1
+                    };
+                    fOURBOTnewMovePodTask.desType = 5;
+                    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);
+                    if (fOURBOTReturn.returnCode == 0)
+                    {
+                        string dataJson = fOURBOTReturn.data.ToString();
+                        FOURBOTnewMovePodTaskResponseData? fOURBO = JsonConvert.DeserializeObject<FOURBOTnewMovePodTaskResponseData>(dataJson);
+                        if (fOURBO == null || fOURBO.taskID == 0)
+                        {
+                            throw new Exception($"鏈幏鍙栧埌鍥涘悜杞﹁繑鍥炵殑浠诲姟ID锛岃繑鍥炴暟鎹細{response}");
+                        }
+                        item.RGVTaskId = fOURBO.taskID;
+                        item.TaskState = (int)TaskStatusEnum.Execut;
+                        item.Dispatchertime = DateTime.Now;
+                        //stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
+                        //_stationMangerService.UpdateData(stationManger);
+                    }
+                    #endregion
+                }
+                _taskService.UpdateData(tasks);
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            finally
+            {
+                _trackloginfoService.AddTrackLog(fOURBOTnewMovePodTask, content, "涓嬪彂鍥涘悜杞﹀嚭搴撲换鍔�", "", "");
+            }
+        }
+        #endregion
     }
 }

--
Gitblit v1.9.3