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_TaskInfoService/TaskMethods.cs |   96 +++++++++++++++++++++++++-----------------------
 1 files changed, 50 insertions(+), 46 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 ac17fd7..7380d53 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"
@@ -83,12 +83,6 @@
                                 task.TaskState = (int)TaskStatusEnum.HktransportIng;
                                 BaseDal.UpdateData(task);
                             }
-                            else if (task.TaskType == (int)TaskTypeEnum.Q3CK|| task.TaskType == (int)TaskTypeEnum.Q3RK)
-                            {
-                                //UpdateStandStatus(task, task.SourceAddress, LocationStatusEnum.Lock);
-                                task.TaskState = (int)TaskStatusEnum.Takeing;
-                                TaskFeedback(task, 1);
-                            }
                             else
                             {
                                 task.TaskState = (int)TaskStatusEnum.Takeing;
@@ -97,24 +91,11 @@
                             break;
                         case "outbin"://绂诲紑璧风偣
                             {
-                                  if (task.TaskType == (int)TaskTypeEnum.Q3RK|| task.TaskType == (int)TaskTypeEnum.Q3CK)
-                                {
-                                    UpdateStandStatus(task, task.SourceAddress, LocationStatusEnum.Free);
-                                    task.TaskState = TaskStatusEnum.TakeFinish.ObjToInt();
-                                    BaseDal.UpdateData(task);
-                                    TaskFeedback(task, 1);
-                                }
-                                else
-                                {
-                                    
-                                    TaskFromCompleted(task, deviceTypeEnum); //浠诲姟鐘朵綋鏀逛负3鍙栬揣瀹屾垚锛屾洿鏂拌捣鐐硅揣浣嶇姸鎬侊紝骞跺弽棣圵MS璧风偣瀹屾垚
-                                }
-                                ///鍒ゆ柇浠诲姟鏄惁璺熻澶囨湁鍏�
+                                TaskFromCompleted(task, deviceTypeEnum); //浠诲姟鐘朵綋鏀逛负3鍙栬揣瀹屾垚锛屾洿鏂拌捣鐐硅揣浣嶇姸鎬侊紝骞跺弽棣圵MS璧风偣瀹屾垚
                             }
                             break;
                         case "finish"://绂诲紑鎻愬崌鏈�
                             {
-
                                 //鍏ユ彁鍗囨満
                                 if (task.TaskType == TaskTypeEnum.RK3F.ObjToInt() && task.TaskState == (int)TaskStatusEnum.CheckPalletCodeFinish)
                                 {
@@ -146,7 +127,7 @@
                                     BaseDal.UpdateData(task);
                                 }
                                 //鍥涙ゼ 鍑哄簱  
-                                else if ((task.TaskType == TaskTypeEnum.CHUKU1.ObjToInt() || task.TaskType == TaskTypeEnum.F04.ObjToInt()) && task.TaskState == (int)TaskStatusEnum.AGV_ToExecute) 
+                                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 = "鏈壘鍒版彁鍗囨満淇℃伅";
@@ -160,7 +141,7 @@
                                     BaseDal.UpdateData(task);
                                 }
                                 // //鍥涙ゼ鍑烘彁鍗囨満 鍏ュ簱 涔嬪墠鏄疉GV_ToExecute  //瑕佸啓鎴愬彇璐у畬鎴愮姸鎬乀akeFinish
-                                if ((task.TaskType == TaskTypeEnum.Q1TSJ4.ObjToInt() || task.TaskType == TaskTypeEnum.F03.ObjToInt()) && task.TaskState == (int)TaskStatusEnum.AGV_ToExecute)
+                                else if ((task.TaskType == TaskTypeEnum.Q1TSJ4.ObjToInt() || task.TaskType == TaskTypeEnum.F03.ObjToInt()) && task.TaskState == (int)TaskStatusEnum.AGV_ToExecute)
                                 {
                                     var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
                                     if (device == null) task.ExceptionMessage = "鏈壘鍒版彁鍗囨満淇℃伅";
@@ -175,21 +156,29 @@
                                     BaseDal.UpdateData(task);
                                 }
                                 //璺ㄦゼ灞�
-                                else if (task.TaskType == TaskTypeEnum.Q3RK.ObjToInt() || task.TaskType == TaskTypeEnum.Q3CK.ObjToInt() && task.TaskState == (int)TaskStatusEnum.TakeFinish)
+                                else if (task.TaskType == TaskTypeEnum.Q3RK.ObjToInt() || task.TaskType == TaskTypeEnum.Q3CK.ObjToInt()/* && task.TaskState == (int)TaskStatusEnum.TakeFinish*/)
                                 {
-                                    if (task.TaskType == TaskTypeEnum.Q3RK.ObjToInt()|| task.TaskType == TaskTypeEnum.Q3RK.ObjToInt())
+                                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "F1") as OtherDevice;
+                                    if (device == null) task.ExceptionMessage = "鏈壘鍒拌川妫�闂ㄤ俊鎭�";
+                                    else
                                     {
-                                        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)
                                         {
-                                            if (device.IsConnected)
-                                                //鍐欎互涓�涓嚭搴撳畬鎴愪俊鍙�
-                                                device.SetValue(QualityInspectionCommandEnum.RequestToEnter, false, task.TargetAddress);
-                                            else
-                                                task.ExceptionMessage = "璐ㄦ闂ㄤ俊鎭澶囪繛鎺ュけ璐�";
+                                            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);
                                 }
@@ -209,8 +198,8 @@
                                 else
                                 {
                                     if (device.IsConnected)
-                                         //鎵撳紑鎵爜鍣�
-                                       device.SetValue<HoistEnum, short>(HoistEnum.Codereadingtriggered, 1);
+                                        //鎵撳紑鎵爜鍣�
+                                        device.SetValue<HoistEnum, short>(HoistEnum.Codereadingtriggered, 1);
                                     else
                                         task.ExceptionMessage = "鎻愬崌鏈轰俊鎭澶囪繛鎺ュけ璐�";
                                 }
@@ -220,16 +209,16 @@
                             break;
                         case "end"://浠诲姟瀹屾垚閫氱煡
                             {
-                                 if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.Q3CK|| task.TaskType == (int)TaskTypeEnum.MOVE)
+                                if (task.TaskType == (int)TaskTypeEnum.MOVE)
                                 {
                                     task.TaskState = TaskStatusEnum.Finish.ObjToInt();
-                                    BaseDal.UpdateData(task);
-                                    TaskFeedback(task, 2);
                                     BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+                                    var Task = BaseDal.QueryFirst(x => task.WMSTaskNum.Contains(x.WMSTaskNum));
+                                    Task.TaskState = TaskStatusEnum.HkTransportCompleted.ObjToInt();
+                                    BaseDal.UpdateData(Task);
                                 }
                                 else
                                 {
-                                    ///鍒ゆ柇浠诲姟鏄惁璺熻澶囨湁鍏�
                                     TaskCompleted(task, deviceTypeEnum);
                                 }
                             }
@@ -237,14 +226,14 @@
                         case "intolift": //杩涘叆鐢垫
                             {
                                 //鍏ゼ鍒颁竴妤肩殑鍏ュ簱浠诲姟
-                                if (task.TaskType==(int)TaskTypeEnum.Q3RK||task.TaskType==(int)TaskTypeEnum.MOVE||task.TaskType==(int)TaskTypeEnum.F01)
+                                if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01)
                                 {
                                     task.TaskState = TaskStatusEnum.Hkintolift.ObjToInt();
                                     BaseDal.UpdateData(task);
                                 }
                             }
                             break;
-                            case "leavelift": //绂诲紑鐢垫
+                        case "leavelift": //绂诲紑鐢垫
                             {
                                 if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01)
                                 {
@@ -443,7 +432,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);
 
@@ -517,6 +506,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)
                 {
@@ -551,7 +555,7 @@
         #endregion
 
         #region 鏇存柊涓�妤肩珯鍙扮姸鎬�
-        public WebResponseContent UpdateStandStatus(Dt_Task task,string stationCode,LocationStatusEnum locationStatusEnum)
+        public WebResponseContent UpdateStandStatus(Dt_Task task, string stationCode, LocationStatusEnum locationStatusEnum)
         {
             try
             {
@@ -579,7 +583,7 @@
         #endregion
 
         #region 涓婃姤WMS
-        public WebResponseContent TaskFeedback(Dt_Task dt_Task, int Status)
+        public WebResponseContent TaskFeedback(Dt_Task dt_Task, int Status, bool Del = true)
         {
             WebResponseContent content = new WebResponseContent();
             WMSInOutBoundCompleteFeedback boundCompleteFeedback = new WMSInOutBoundCompleteFeedback();
@@ -596,7 +600,7 @@
                     boundCompleteFeedback.toLocationCode = dt_Task.TargetAddress;
                     boundCompleteFeedback.status = Status;
                     boundCompleteFeedback.custStatus = "";
-                    string response = HttpHelper.Post(apiInfo.ApiAddress,boundCompleteFeedback.Serialize());
+                    string response = HttpHelper.Post(apiInfo.ApiAddress, boundCompleteFeedback.Serialize());
                     agvContent = response.DeserializeObject<WMSReturn>();
                     content.OK(data: agvContent);
                     if (agvContent.code != 200)
@@ -613,7 +617,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);

--
Gitblit v1.9.3