From 4ad27940cc8a276616af9cdc9ac85d793a6b1d9e Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 10 四月 2026 16:02:28 +0800
Subject: [PATCH] 添加四向车任务跟站台信息绑定

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs |  302 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 269 insertions(+), 33 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs"
index b13e3a4..efd9545 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs"
@@ -8,6 +8,7 @@
 using System.Reflection.Metadata;
 using System.Text;
 using System.Text.Json;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.LocationEnum;
@@ -21,6 +22,7 @@
 using WIDESEAWCS_DTO.WMS;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DTO;
 
 namespace WIDESEAWCS_TaskInfoService
 {
@@ -77,25 +79,156 @@
                     switch (hIKROBOT.extra.values.method)
                     {
                         case "start":
-                            task.TaskState = (int)TaskStatusEnum.Takeing;
-                            TaskFeedback(task, 1);
+                            if (task.TaskState == (int)TaskStatusEnum.CallingHKtransportation && task.TaskType == (int)TaskTypeEnum.MOVE)
+                            {
+                                task.TaskState = (int)TaskStatusEnum.HktransportIng;
+                                BaseDal.UpdateData(task);
+                            }
+                            else
+                            {
+                                task.TaskState = (int)TaskStatusEnum.Takeing;
+                                TaskFeedback(task, 1);
+                            }
                             break;
                         case "outbin"://绂诲紑璧风偣
                             {
-                                if (task.TaskType == TaskTypeEnum.CK3F.ObjToInt() && task.TaskState == (int)TaskStatusEnum.AGV_ToExecute)
+                                TaskFromCompleted(task, deviceTypeEnum); //浠诲姟鐘朵綋鏀逛负3鍙栬揣瀹屾垚锛屾洿鏂拌捣鐐硅揣浣嶇姸鎬侊紝骞跺弽棣圵MS璧风偣瀹屾垚
+                            }
+                            break;
+                        case "finish"://绂诲紑鎻愬崌鏈�
+                            {
+                                //鍏ユ彁鍗囨満
+                                if (task.TaskType == TaskTypeEnum.RK3F.ObjToInt() && task.TaskState == (int)TaskStatusEnum.CheckPalletCodeFinish)
                                 {
                                     var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
                                     if (device == null) task.ExceptionMessage = "鏈壘鍒版彁鍗囨満淇℃伅";
                                     else
                                     {
+                                        bool Work = false;
                                         if (device.IsConnected)
-                                            device.SetValue(HoistEnum.Outboundboxon, 1);
-                                        else
-                                            task.ExceptionMessage = "鎻愬崌鏈轰俊鎭澶囪繛鎺ュけ璐�";
+                                        {
+                                            int i = 0;
+                                            while (!Work && i <= 3)
+                                            {
+                                                i++;
+                                                Work = device.SetValue(HoistEnum.Inboundboxon, 1, task.TargetAddress);
+                                                Thread.Sleep(500);
+                                            }
+                                        }
+                                        if (!Work)
+                                        {
+                                            task.ExceptionMessage = $"銆恵task.TargetAddress}銆戝啓鍏�3妤煎叆搴撶鏀惧埌浣嶅け璐�";
+                                            task.Remark = $"{device.DeviceCode}_Inboundboxon_{1}_{task.TargetAddress}";
+                                        }
                                     }
+                                    BaseDal.UpdateData(task);
                                 }
-                                ///鍒ゆ柇浠诲姟鏄惁璺熻澶囨湁鍏�
-                                TaskFromCompleted(task, deviceTypeEnum);
+
+                                //3 鍑烘彁鍗囨満 涔嬪墠鏄疉GV_ToExecute
+                                else if (task.TaskType == TaskTypeEnum.CK3F.ObjToInt() && task.TaskState == (int)TaskStatusEnum.TakeFinish)
+                                {
+                                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
+                                    if (device == null) task.ExceptionMessage = "鏈壘鍒版彁鍗囨満淇℃伅";
+                                    else
+                                    {
+                                        bool Work = false;
+                                        if (device.IsConnected)
+                                        {
+                                            int i = 0;
+                                            while (!Work && i <= 3)
+                                            {
+                                                i++;
+                                                Work = device.SetValue(HoistEnum.Outboundboxon, 1, task.SourceAddress);//鍑哄簱瀹屾垚
+                                                Thread.Sleep(500);
+                                            }
+                                        }
+                                        if (!Work)
+                                        {
+                                            task.ExceptionMessage = $"銆恵task.SourceAddress}銆戝啓鍏�3妤煎嚭搴撶鏀惧埌浣嶅け璐�";
+                                            task.Remark = $"{device.DeviceCode}_Outboundboxon_{1}_{task.SourceAddress}";
+                                        }
+                                    }
+                                    BaseDal.UpdateData(task);
+                                }
+                                //鍥涙ゼ 鍑哄簱  
+                                else if ((task.TaskType == TaskTypeEnum.CHUKU1.ObjToInt() || task.TaskType == TaskTypeEnum.F04.ObjToInt()) && task.TaskState == (int)TaskStatusEnum.AGV_ToExecute)
+                                {
+                                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
+                                    if (device == null) task.ExceptionMessage = "鏈壘鍒版彁鍗囨満淇℃伅";
+                                    else
+                                    {
+                                        bool Work = false;
+                                        if (device.IsConnected)
+                                        {
+                                            int i = 0;
+                                            while (!Work && i <= 3)
+                                            {
+                                                i++;
+                                                Work = device.SetValue(HoistEnum.Emptyboxplacedinposition, 1, task.TargetAddress);
+                                                Thread.Sleep(500);
+                                            }
+                                        }
+                                        if (!Work)
+                                        {
+                                            task.ExceptionMessage = $"銆恵task.TargetAddress}銆戝啓鍏�4妤肩┖绠辨斁鍒颁綅澶辫触";
+                                            task.Remark = $"{device.DeviceCode}_Emptyboxplacedinposition_{1}_{task.TargetAddress}";
+                                        }
+                                    }
+                                    BaseDal.UpdateData(task);
+                                }
+                                // //鍥涙ゼ鍑烘彁鍗囨満 鍏ュ簱 涔嬪墠鏄疉GV_ToExecute  //瑕佸啓鎴愬彇璐у畬鎴愮姸鎬乀akeFinish
+                                else if ((task.TaskType == TaskTypeEnum.Q1TSJ4.ObjToInt() || task.TaskType == TaskTypeEnum.F03.ObjToInt()) && task.TaskState == (int)TaskStatusEnum.TakeFinish)
+                                {
+                                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
+                                    if (device == null) task.ExceptionMessage = "鏈壘鍒版彁鍗囨満淇℃伅";
+                                    else
+                                    {
+                                        bool Work = false;
+                                        if (device.IsConnected)
+                                        {
+                                            int i = 0;
+                                            while (!Work && i <= 3)
+                                            {
+                                                i++;
+                                                Work = device.SetValue(HoistEnum.Outboundboxretrievalcompleted, 1, task.SourceAddress);
+                                                Thread.Sleep(500);
+                                            }
+                                        }
+                                        if (!Work)
+                                        {
+                                            task.ExceptionMessage = $"銆恵task.SourceAddress}銆戝啓鍏�4妤煎嚭搴撳彇绠卞畬鎴愬け璐�";
+                                            task.Remark = $"{device.DeviceCode}_Outboundboxretrievalcompleted_{1}_{task.SourceAddress}";
+                                        }
+                                    }
+                                    BaseDal.UpdateData(task);
+                                }
+                                //璺ㄦゼ灞�
+                                else if (task.TaskType == TaskTypeEnum.Q3RK.ObjToInt() || task.TaskType == TaskTypeEnum.Q3CK.ObjToInt()/* && task.TaskState == (int)TaskStatusEnum.TakeFinish*/)
+                                {
+                                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "F1") as OtherDevice;
+                                    if (device == null) task.ExceptionMessage = "鏈壘鍒拌川妫�闂ㄤ俊鎭�";
+                                    else
+                                    {
+                                        bool Wok = false;
+                                        var Address = task.TaskType == TaskTypeEnum.Q3RK.ObjToInt() ? task.TargetAddress : task.SourceAddress;
+                                        if (device.IsConnected)
+                                        {
+                                            int i = 0;
+                                            while (!Wok && i <= 3)
+                                            {
+                                                i++;
+                                                Wok = device.SetValue(QualityInspectionCommandEnum.RequestToEnter, false, Address);
+                                                Thread.Sleep(500);
+                                            }
+                                        }
+                                        if (!Wok)
+                                        {
+                                            task.ExceptionMessage = $"銆恵Address}銆戝叧闂姹傝繘鍏ュけ璐ワ紒";
+                                            task.Remark = $"{device.DeviceCode}_RequestToEnter_{false}_{Address}";
+                                        }
+                                    }
+                                    BaseDal.UpdateData(task);
+                                }
                             }
                             break;
                         case "into"://鐢宠杩涘叆鎻愬崌鏈�
@@ -106,26 +239,65 @@
                             break;
                         case "wait"://鎵爜绛夊緟
                             {
+                                //瑕佸厛寮�鍚壂鐮佷俊鍙�
+                                var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
+                                if (device == null) task.ExceptionMessage = "鏈壘鍒版彁鍗囨満淇℃伅";
+                                else
+                                {
+                                    bool Wok = false;
+                                    if (device.IsConnected)
+                                    {
+                                        int i = 0;
+                                        while (!Wok && i <= 3)
+                                        {
+                                            i++;
+                                            Wok = device.SetValue<HoistEnum, short>(HoistEnum.Codereadingtriggered, 1, "TSJR3F");
+                                            Thread.Sleep(500);
+                                        }
+                                    }
+                                    if (!Wok)
+                                    {
+                                        task.ExceptionMessage = $"銆怲SJR3F銆�3妤艰鐮佽Е鍙戝け璐ワ紒";
+                                        task.Remark = $"{device.DeviceCode}_Codereadingtriggered_{1}_TSJR3F";
+                                    }
+                                }
                                 task.TaskState = (int)TaskStatusEnum.CheckPalletCodeing;
                                 BaseDal.UpdateData(task);
                             }
                             break;
                         case "end"://浠诲姟瀹屾垚閫氱煡
                             {
-                                ///鍒ゆ柇浠诲姟鏄惁璺熻澶囨湁鍏�
-                                if (task.TaskType == TaskTypeEnum.RK3F.ObjToInt() && task.TaskState == (int)TaskStatusEnum.CheckPalletCodeFinish)
+                                if (task.TaskType == (int)TaskTypeEnum.MOVE)
                                 {
-                                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
-                                    if (device == null) task.ExceptionMessage = "鏈壘鍒版彁鍗囨満淇℃伅";
-                                    else
-                                    {
-                                        if (device.IsConnected)
-                                            device.SetValue(HoistEnum.Inboundboxon, 1);
-                                        else
-                                            task.ExceptionMessage = "鎻愬崌鏈轰俊鎭澶囪繛鎺ュけ璐�";
-                                    }
+                                    task.TaskState = TaskStatusEnum.Finish.ObjToInt();
+                                    BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+                                    var Task = BaseDal.QueryFirst(x => task.WMSTaskNum.Contains(x.WMSTaskNum));
+                                    Task.TaskState = TaskStatusEnum.HkTransportCompleted.ObjToInt();
+                                    BaseDal.UpdateData(Task);
                                 }
-                                TaskCompleted(task, deviceTypeEnum);
+                                else
+                                {
+                                    TaskCompleted(task, deviceTypeEnum);
+                                }
+                            }
+                            break;
+                        case "intolift": //杩涘叆鐢垫
+                            {
+                                //鍏ゼ鍒颁竴妤肩殑鍏ュ簱浠诲姟
+                                if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01 || task.TaskType == (int)TaskTypeEnum.Q3CK)
+                                {
+                                    task.TaskState = TaskStatusEnum.Hkintolift.ObjToInt();
+                                    BaseDal.UpdateData(task);
+                                }
+                            }
+                            break;
+                        case "leavelift": //绂诲紑鐢垫
+                            {
+                                if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01|| task.TaskType == (int)TaskTypeEnum.Q3CK)
+                                {
+                                    task.TaskState = TaskStatusEnum.HKleavelift.ObjToInt();
+                                    BaseDal.UpdateData(task);
+                                }
                             }
                             break;
                         default:
@@ -220,6 +392,21 @@
                                     TaskCompleted(task, deviceTypeEnum);
                                 }
                             }
+                            if (Rgv.content.status == 5)
+                            {
+                                task.ExceptionMessage = Rgv.content.errorReason;
+                                var Error = _taskErrorMessageService.Repository.QueryFirst(x => x.ErrorCode == Rgv.content.errorCode && x.DeviceType == (int)deviceTypeEnum);
+                                if (Error != null)
+                                {
+                                    task.ExceptionMessage = Error.ExceptionMessage;
+                                    MatchCollection matches = Regex.Matches(Rgv.content.errorReason, @"\(([^)]+)\)");
+                                    if (matches.Count > 0)
+                                        task.ExceptionMessage = ReplacePlaceholders(Rgv.content.errorReason, Error.ExceptionMessage);
+                                    ErrorTaskFeedback(task, true, Error.ErrorCode.ToString());
+                                }
+                                else
+                                    ErrorTaskFeedback(task, true);
+                            }
                         }
                     }
                 }
@@ -234,6 +421,30 @@
                 _trackloginfoService.AddTrackLog(TaskDTO, content, $"{deviceName}浠诲姟鐘舵�佸弽棣�", "", "");
             }
             return content;
+        }
+        #endregion
+
+        #region 寮傚父淇℃伅杞崲
+        /// <summary>
+        /// 寮傚父淇℃伅()鍐呭杞崲
+        /// </summary>
+        /// <param name="source"></param>
+        /// <param name="targetTemplate"></param>
+        /// <returns></returns>
+        public string ReplacePlaceholders(string source, string targetTemplate)
+        {
+            // 鎻愬彇婧愬瓧绗︿覆涓殑鎵�鏈夋嫭鍙峰��
+            var values = Regex.Matches(source, @"\(([^)]+)\)")
+                              .Cast<Match>()
+                              .Select(m => m.Groups[1].Value)
+                              .ToList();
+
+            // 鏇挎崲鐩爣妯℃澘涓殑鎵�鏈� (%v)
+            int idx = 0;
+            string result = Regex.Replace(targetTemplate, @"\(\%v\)", _ =>
+                idx < values.Count ? values[idx++] : "");
+
+            return result;
         }
         #endregion
 
@@ -318,7 +529,7 @@
             try
             {
                 dt_Task.TaskState = TaskStatusEnum.Finish.ObjToInt();
-                TaskFeedback(dt_Task, 2);
+                TaskFeedback(dt_Task, 2, string.IsNullOrEmpty(dt_Task.Remark));
                 //Db.Ado.BeginTran();
                 UpdateLocationStatus(dt_Task.TargetAddress, dt_Task.PalletCode, deviceTypeEnum, LocationStatusEnum.InStock);
 
@@ -392,6 +603,21 @@
                         stationInfo.StationStatus = locationStatusEnum.ObjToInt();
                         _stationInfo.UpdateData(stationInfo);
                     }
+                    Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == locationCode);
+                    if (stationManger != null)
+                    {
+                        if (locationStatusEnum == LocationStatusEnum.Free) //濡傛灉璧风偣瀹屾垚灏辩粰璐т綅璧嬪�兼墭鐩樺彿
+                        {
+                            stationManger.Remark = "";
+                            stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
+                        }
+                        else
+                        {
+                            stationManger.Remark = palletCode;
+                            stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
+                        }
+                        _stationMangerService.UpdateData(stationManger);
+                    }
                 }
                 else if (deviceTypeEnum == DeviceTypeEnum.YuanLiJuHe)
                 {
@@ -411,10 +637,22 @@
                         dt_RGVLocationInfo.LocationStatus = locationStatusEnum.ObjToInt();
                         _rGVLocationInfoService.Repository.UpdateData(dt_RGVLocationInfo);
                     }
-                }
-                else//骞冲簱搴撲綅
-                {
 
+                    Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == locationCode);
+                    if (stationManger != null)
+                    {
+                        if (locationStatusEnum == LocationStatusEnum.Free) //濡傛灉璧风偣瀹屾垚灏辩粰璐т綅璧嬪�兼墭鐩樺彿
+                        {
+                            stationManger.Remark = "";
+                            stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
+                        }
+                        else
+                        {
+                            stationManger.Remark = palletCode;
+                            stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
+                        }
+                        _stationMangerService.UpdateData(stationManger);
+                    }
                 }
                 return WebResponseContent.Instance.OK();
             }
@@ -426,7 +664,7 @@
         #endregion
 
         #region 涓婃姤WMS
-        public WebResponseContent TaskFeedback(Dt_Task dt_Task, int Status)
+        public WebResponseContent TaskFeedback(Dt_Task dt_Task, int Status, bool Del = false)
         {
             WebResponseContent content = new WebResponseContent();
             WMSInOutBoundCompleteFeedback boundCompleteFeedback = new WMSInOutBoundCompleteFeedback();
@@ -460,7 +698,7 @@
             finally
             {
                 _trackloginfoService.AddTrackLog(boundCompleteFeedback, content, "鍑哄叆搴撲换鍔$姸鎬佸弽棣圵MS", "", "");
-                if (agvContent != null && agvContent.code == 200 && Status == 2)
+                if (agvContent != null && agvContent.code == 200 && Del)
                     BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.鑷姩瀹屾垚);
                 else
                     BaseDal.UpdateData(dt_Task);
@@ -469,7 +707,7 @@
         }
         #endregion
         #region 澶辫触浠诲姟涓婃姤WMS骞跺垹闄や换鍔�
-        public WebResponseContent ErrorTaskFeedback(Dt_Task dt_Task, bool Del)
+        public WebResponseContent ErrorTaskFeedback(Dt_Task dt_Task, bool Del = false, string ErrorCode = "")
         {
             WebResponseContent content = new WebResponseContent();
             WMSInOutBoundCompleteFeedback boundCompleteFeedback = new WMSInOutBoundCompleteFeedback();
@@ -485,11 +723,12 @@
                     boundCompleteFeedback.fromStationCode = dt_Task.SourceAddress;
                     boundCompleteFeedback.toLocationCode = dt_Task.TargetAddress;
                     boundCompleteFeedback.status = 3;
-                    boundCompleteFeedback.custStatus = "";
+                    boundCompleteFeedback.custStatus = ErrorCode;
                     boundCompleteFeedback.memo = dt_Task.ExceptionMessage;
                     string response = HttpHelper.Post(apiInfo.ApiAddress, boundCompleteFeedback.Serialize());
                     agvContent = response.DeserializeObject<WMSReturn>();
                     content.OK(data: agvContent);
+                    content.Message = dt_Task.ExceptionMessage;
                     if (agvContent.code != 200)
                     {
                         dt_Task.ExceptionMessage = agvContent.message;
@@ -505,15 +744,12 @@
             finally
             {
                 _trackloginfoService.AddTrackLog(boundCompleteFeedback, content, "鍑哄叆搴撲换鍔$姸鎬佸弽棣圵MS", "", "");
-                if (agvContent != null && agvContent.code == 200 && Del) BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.鑷姩鍒犻櫎);
+                if (agvContent != null && agvContent.code == 200 && Del)
+                    BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.鑷姩鍒犻櫎);
                 else BaseDal.UpdateData(dt_Task);
             }
             return content;
         }
         #endregion
-
-
-
-
     }
 }

--
Gitblit v1.9.3