From ba88ed23ec7a76842d6a3b8b112270fd145d5d41 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期三, 18 三月 2026 16:44:43 +0800
Subject: [PATCH] 添加WMS下发成品移库任务逻辑

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RGVTaskMethods.cs |  150 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 130 insertions(+), 20 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RGVTaskMethods.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RGVTaskMethods.cs"
index 055df4a..d08eab7 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RGVTaskMethods.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RGVTaskMethods.cs"
@@ -10,6 +10,10 @@
 using WIDESEAWCS_DTO.WMS;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_Core.Helper;
+using HslCommunication.Core.IMessage;
+using WIDESEAWCS_DTO.RGV.FOURBOT;
+using Newtonsoft.Json;
+using System.Reflection.Metadata;
 
 namespace WIDESEAWCS_TaskInfoService
 {
@@ -24,19 +28,21 @@
         /// <returns></returns>
         public WebResponseContent CreateRGVNewInTask(TaskDTO taskDTO, int taskType)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
-                //List<Dt_RGVLocationInfo>? rGVLocationInfos = _rGVLocationInfoService.Repository.QueryData(x => x.WarehouseId.ToString() == taskDTO.toAreaCode && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt());
-                //if (rGVLocationInfos.Count < 1) throw new Exception($"鏈壘鍒扮粓鐐瑰簱鍖恒�恵taskDTO.toAreaCode}銆戝彲鐢ㄧ┖璐т綅锛�");
-                //var rGVLocationInfo = rGVLocationInfos.OrderBy(x => x.Depth).First();
-                //var rGVLocationInfo = _rGVLocationInfoService.GetFreeLocationInfo(taskDTO.toAreaCode) ?? throw new Exception($"鏈壘鍒扮粓鐐瑰簱鍖恒�恵taskDTO.toAreaCode}銆戝彲鐢ㄧ┖璐т綅锛�");
+                #region 鐐瑰埌鐐�
+                //if (!string.IsNullOrEmpty(taskDTO.toLocationCode))
+                //{
+                //    var LocationInfo = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"鏈壘鍒扮粓鐐硅揣浣嶃�恵taskDTO.toLocationCode}銆�");
+                //    if (LocationInfo.LocationStatus != LocationStatusEnum.Free.ObjToInt()) throw new Exception($"缁堢偣璐т綅銆恵taskDTO.toLocationCode}銆戣揣浣嶇姸鎬佷笉涓虹┖璐т綅");
+                //}
+                #endregion
                 Dt_StationManger stationManger = _stationMangerService.GetInStationInfo(taskDTO.fromLocationCode) ?? throw new Exception($"鏈壘鍒拌捣鐐逛綅缃�恵taskDTO.fromLocationCode}銆戠珯鍙颁俊鎭紒");
-                //if (stationManger.IsOccupied == 1) throw new Exception($"璧风偣浣嶇疆銆恵taskDTO.fromLocationCode}銆戠珯鍙拌鍗犵敤锛岃閲婃斁锛�");
                 Dt_Task dt_Task = new()
                 {
                     TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                     WMSTaskNum = taskDTO.taskCode,
-                    //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                     Grade = taskDTO.taskPriority,
                     PalletCode = taskDTO.containerCode,
                     Roadway = taskDTO.toAreaCode,
@@ -44,22 +50,25 @@
                     TaskType = taskType,
                     SourceAddress = taskDTO.fromLocationCode,
                     CurrentAddress = taskDTO.fromLocationCode,
-                    NextAddress = stationManger.RGVStationCode,//鎵惧叆搴撶珯鍙板搴旂殑澶栧舰妫�娴嬬紪鍙�
+                    NextAddress = stationManger.RGVStationCode,
                     TargetAddress = "",
-                    //Remark = taskDTO.toAreaCode,
                     Creater = "WMS",
                 };
-                //rGVLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
-                //Db.Ado.BeginTran();
                 BaseDal.AddData(dt_Task);
-                //_rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo);
-                //Db.Ado.CommitTran();
-                return WebResponseContent.Instance.OK();
+                return content.OK(data: new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = "鎴愬姛锛�"
+                });
             }
             catch (Exception ex)
             {
-                //Db.Ado.RollbackTran();
-                throw new Exception(ex.Message);
+                content.Data = new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = $"澶辫触锛亄ex.Message}"
+                };
+                return content.Error(ex.Message);
             }
         }
         /// <summary>
@@ -70,17 +79,21 @@
         /// <returns></returns>
         public WebResponseContent CreateRGVNewOutTask(TaskDTO taskDTO, int taskType)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
-                //Dt_Task dt_Task = BaseDal.QueryFirst(x => x.PalletCode == taskDTO.containerCode);
-                //if (dt_Task != null) throw new Exception($"鎵樼洏鍙枫�恵taskDTO.containerCode}銆戝凡瀛樺湪浠诲姟");
+                var stationManger = _stationMangerService.GetOutStationInfo(taskDTO.toLocationCode);
+                if (stationManger == null)
+                {
+                    return content.Error($"{taskDTO.toLocationCode}涓嶆槸鍑哄簱绔欏彴");
+                }
                 Dt_RGVLocationInfo rGVLocationInfo = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"鏈壘鍒拌捣鐐瑰簱浣嶃�恵taskDTO.fromLocationCode}銆戯紒");
                 if (rGVLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) throw new Exception($"璧风偣搴撲綅銆恵taskDTO.fromLocationCode}銆戝綋鍓嶅簱浣嶇姸鎬佷笉鍙嚭搴擄紒");
+                if (rGVLocationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"璧风偣搴撲綅銆恵taskDTO.fromLocationCode}銆戠粦瀹氭枡绠卞彿銆恵rGVLocationInfo.PalletCode}銆戜笌浠诲姟鏂欑鍙枫�恵taskDTO.containerCode}銆戜笉鍖归厤锛�");
                 Dt_Task dt_Task = new()
                 {
                     TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                     WMSTaskNum = taskDTO.taskCode,
-                    //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                     Grade = taskDTO.taskPriority,
                     PalletCode = taskDTO.containerCode,
                     Roadway = rGVLocationInfo.RoadwayNo,
@@ -105,13 +118,110 @@
                     Db.Ado.RollbackTran();
                     throw new Exception(ex.Message);
                 }
-                return WebResponseContent.Instance.OK();
+                return content.OK(data: new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = "鎴愬姛锛�"
+                });
             }
             catch (Exception ex)
             {
-                throw new Exception(ex.Message);
+                content.Data = new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = $"澶辫触锛亄ex.Message}"
+                };
+                return content.Error(ex.Message);
             }
         }
         #endregion
+        /// <summary>
+        /// 绉诲簱浠诲姟
+        /// </summary>
+        /// <param name="taskDTO"></param>
+        /// <param name="taskType"></param>
+        /// <returns></returns>
+        public WebResponseContent CreateRGVNewMoveTask(TaskDTO taskDTO, int taskType)
+        {
+            WebResponseContent content = new WebResponseContent();
+            FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
+            try
+            {
+                if (string.IsNullOrEmpty(taskDTO.fromLocationCode)) throw new Exception($"璧风偣搴撲綅涓嶈兘涓虹┖锛�");
+                if (string.IsNullOrEmpty(taskDTO.toLocationCode)) throw new Exception($"缁堢偣搴撲綅涓嶈兘涓虹┖锛�");
+                Dt_RGVLocationInfo rGVLocationInfo = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"鏈壘鍒拌捣鐐瑰簱浣嶃�恵taskDTO.fromLocationCode}銆戯紒");
+                if (rGVLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) throw new Exception($"璧风偣搴撲綅銆恵taskDTO.fromLocationCode}銆戝綋鍓嶅簱浣嶇姸鎬佷笉鍙嚭搴擄紒");
+                if (rGVLocationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"璧风偣搴撲綅銆恵taskDTO.fromLocationCode}銆戠粦瀹氭枡绠卞彿銆恵rGVLocationInfo.PalletCode}銆戜笌浠诲姟鏂欑鍙枫�恵taskDTO.containerCode}銆戜笉鍖归厤锛�");
+                Dt_RGVLocationInfo rGVLocationInfo1 = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"鏈壘鍒扮粓鐐瑰簱浣嶃�恵taskDTO.toLocationCode}銆戯紒");
+                if (rGVLocationInfo1.LocationStatus != LocationStatusEnum.Free.ObjToInt()) throw new Exception($"缁堢偣搴撲綅銆恵taskDTO.toLocationCode}銆戝綋鍓嶅簱浣嶇姸鎬佷笉涓虹┖闂诧紒");
+                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("鏈壘鍒板洓鍚戣溅浠诲姟涓嬪彂鎺ュ彛閰嶇疆淇℃伅锛佽妫�鏌ユ帴鍙i厤缃�");
+                Dt_Task dt_Task = new()
+                {
+                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
+                    WMSTaskNum = taskDTO.taskCode,
+                    Grade = taskDTO.taskPriority,
+                    PalletCode = taskDTO.containerCode,
+                    Roadway = rGVLocationInfo.RoadwayNo,
+                    TaskState = TaskStatusEnum.New.ObjToInt(),
+                    TaskType = taskType,
+                    SourceAddress = taskDTO.fromLocationCode,
+                    CurrentAddress = taskDTO.fromLocationCode,
+                    NextAddress = taskDTO.toLocationCode,
+                    TargetAddress = taskDTO.toLocationCode,
+                    Creater = "WMS",
+                };
+                rGVLocationInfo.LocationStatus = LocationStatusEnum.MoveLock.ObjToInt();
+                rGVLocationInfo1.LocationStatus = LocationStatusEnum.MoveLock.ObjToInt();
+                #region 涓嬪彂鍥涘悜杞︿换鍔�
+                fOURBOTnewMovePodTask = new FOURBOTnewMovePodTask
+                {
+                    priority = dt_Task.Grade,
+                    podID = dt_Task.PalletCode,
+                    desStorageID = dt_Task.TargetAddress,
+                    desExt = new { unload = 1 }, // 鏄惁鏀句笅瀹瑰櫒,0鍚�1鏄�
+                    desType = 2
+                };
+                fOURBOTnewMovePodTask.taskExt = new
+                {
+                    autoToRest = 1
+                };
+                string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
+                var fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
+                content.OK(data: fOURBOTReturn);
+                if (fOURBOTReturn.returnCode != 0) throw new Exception($"涓嬪彂鎴愬搧绉诲簱浠诲姟閿欒锛歿fOURBOTReturn.returnMsg}");
+                var data = fOURBOTReturn.data.ToString();
+                var fOURBO = data.DeserializeObject<FOURBOTnewMovePodTaskResponseData>();
+                dt_Task.RGVTaskId = fOURBO.taskID;
+                dt_Task.TaskState = TaskStatusEnum.RGV_MoveTaskSend.ObjToInt();
+                #endregion
+                try
+                {
+                    Db.Ado.BeginTran();
+                    BaseDal.AddData(dt_Task);
+                    _rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo);
+                    _rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo1);
+                    Db.Ado.CommitTran();
+                }
+                catch (Exception ex)
+                {
+                    Db.Ado.RollbackTran();
+                    throw new Exception(ex.Message);
+                }
+                return content.OK(data: new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = "鎴愬姛锛�"
+                });
+            }
+            catch (Exception ex)
+            {
+                content.Data = new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = $"澶辫触锛亄ex.Message}"
+                };
+                return content.Error(ex.Message);
+            }
+        }
     }
 }

--
Gitblit v1.9.3