From c2cdf0b95d4c9214646c860609b8c838d6ffa779 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 15 八月 2025 13:42:10 +0800
Subject: [PATCH] AGV,成品库代码更新上传

---
 项目代码/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs |  145 ++++++++++++++++--------------------------------
 1 files changed, 48 insertions(+), 97 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs"
index 57151fe..d4daa32 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs"
@@ -44,42 +44,38 @@
         /// <param name="secureApplyModel"></param>
         /// <returns></returns>
         [HttpPost, HttpGet, Route("AgvSecureApply"), AllowAnonymous]
-        public AgvResponseContent AgvSecureApply([FromBody] AgvSecureApplyDTO secureApplyModel)
+        public AgvResponse AgvSecureApply([FromBody] AgvSecureApplyDTO secureApplyModel)
         {
-            AgvResponseContent agvResponseContent = new AgvResponseContent();
-            agvResponseContent.ReqCode = secureApplyModel.ReqCode;
+            AgvResponse agvResponse = new AgvResponse();
             try
             {
-                var task = _taskRepository.QueryFirst(x => secureApplyModel.TaskCode == x.AgvTaskNum);
+                var task = _taskRepository.QueryFirst(x => secureApplyModel.ReceiveTaskID.ObjToInt() == x.TaskNum);
                 if (task == null) throw new Exception("鏈壘鍒颁换鍔�");
                 if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt())
                 {
                     var content = TakeRequest(task.CurrentAddress);
-                    //if (!content.Status)
-                    //{
-                    //    throw new Exception(content.Message);
-                    //}
+                    if (!content.Status)
+                    {
+                        throw new Exception(content.Message);
+                    }
                 }
                 else
                 {
                     var content = PutRequest(task.NextAddress, task.PalletType);
-                    //if (!content.Status)
-                    //{
-                    //    throw new Exception(content.Message);
-                    //}
+                    if (!content.Status)
+                    {
+                        throw new Exception(content.Message);
+                    }
                 }
-                task.TaskState = TaskStatusEnum.AGV_WaitToExecute.ObjToInt();
+                task.TaskState = TaskStatusEnum.AGV_Puting.ObjToInt();
                 var up = _taskRepository.UpdateData(task);
-                agvResponseContent.Code = up ? "0" : "1";
-                agvResponseContent.Message = up ? "鎴愬姛" : "澶辫触";
+                agvResponse.OK("鎴愬姛","0");
             }
             catch (Exception ex)
             {
-                agvResponseContent.Code = "1";
-                agvResponseContent.Message = ex.Message;
+                agvResponse.Error(ex.Message);
             }
-            return agvResponseContent;
-            //return _taskService.AgvSecureApply(secureApplyModel);
+            return agvResponse;
         }
         /// <summary>
         /// 鎻愬崌鏈虹敵璇� AGV-WCS
@@ -195,56 +191,29 @@
         /// <param name="agvUpdateModel"></param>
         /// <returns></returns>
         [HttpPost, HttpGet, Route("AgvCallback"), AllowAnonymous]
-        public AgvResponseContent AgvUpdateTask([FromBody] AgvUpdateDTO agvUpdateModel)
+        public AgvResponse AgvCallback([FromBody] AgvUpdateDTO agvUpdateModel)
         {
-            AgvResponseContent agvResponseContent = new AgvResponseContent();
+            AgvResponse agvResponse = new AgvResponse();
             try
             {
-                if (agvUpdateModel == null) throw new Exception("鏈幏鍙栧埌璇锋眰鍙傛暟");
-                agvResponseContent.ReqCode = agvUpdateModel.ReqCode;
-                var task = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode == x.AgvTaskNum);
-                if (task == null) throw new Exception($"鏈壘鍒颁换鍔�,浠诲姟鍙枫�恵agvUpdateModel.TaskCode}銆�");
-                switch (agvUpdateModel.Method)
+                var task = _taskRepository.QueryFirst(x => agvUpdateModel.ReceiveTaskID == x.TaskNum.ToString());
+                if (task == null) throw new Exception($"鏈壘鍒颁换鍔�,浠诲姟鍙枫�恵agvUpdateModel.ReceiveTaskID}銆�");
+                switch (agvUpdateModel.GoodsState)
                 {
-                    case "start":
-                        break;
-                    case "outbin"://鍑哄簱鏍规嵁杩欎釜淇″彿鍒ゆ柇鍙栬揣瀹屾垚
-                        if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt())
+                    //case 1://鍑哄簱鏍规嵁杩欎釜淇″彿鍒ゆ柇鍙栬揣瀹屾垚
+                    //    if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt())
+                    //    {
+                    //        var content = TakeFinish(task.CurrentAddress);
+                    //        if (!content.Status) throw new Exception(content.Message);
+                    //        task.TaskState = TaskStatusEnum.AGV_Finish.ObjToInt();
+                    //        var up = _taskRepository.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+                    //        _taskService.TaskCompleted(task.TaskNum);
+                    //    }
+                    //    break;
+                    case 2://鍏ュ簱鏍规嵁杩欎釜淇″彿鍒ゆ柇鏀捐揣瀹屾垚
+                        if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                         {
-                            var content = TakeFinish(task.CurrentAddress);
-                            if (!content.Status) throw new Exception(content.Message);
-                            task.TaskState = TaskStatusEnum.AGV_Finish.ObjToInt();
-                            var up = _taskRepository.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
-                            _taskService.TaskCompleted(task.TaskNum);
-                            agvResponseContent.Code = up ? "0" : "1";
-                            agvResponseContent.Message = up ? "鎴愬姛" : "澶辫触";
-                            return agvResponseContent;
-                        }
-                        break;
-                    case "getSafetySignal"://瀹夊叏淇″彿鐢宠
-                        {
-                            if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt())
-                            {
-                                var content = TakeRequest(task.CurrentAddress);
-                                //if (!content.Status) throw new Exception(content.Message);
-                            }
-                            else
-                            {
-                                var content = PutRequest(task.NextAddress, task.PalletType);
-                                //if (!content.Status) throw new Exception(content.Message);
-                            }
-                            task.TaskState = TaskStatusEnum.AGV_WaitToExecute.ObjToInt();
-                            var up = _taskRepository.UpdateData(task);
-                            agvResponseContent.Code = up ? "0" : "1";
-                            agvResponseContent.Message = up ? "鎴愬姛" : "澶辫触";
-                            return agvResponseContent;
-                        }
-                    case "end"://鍏ュ簱鏍规嵁杩欎釜淇″彿鍒ゆ柇鏀捐揣瀹屾垚
-                        if (task.TaskType != TaskTypeEnum.Outbound.ObjToInt())
-                        {
-                            var content = PutFinish(task.NextAddress);
-                            if (!content.Status) throw new Exception(content.Message);
-                            Dt_StationManger dt_Station = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == task.NextAddress);
+                            Dt_StationManger dt_Station = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress);
                             if (dt_Station == null)
                             {
                                 throw new Exception($"{task.NextAddress}AGV绔欏彴鏈畾涔�");
@@ -252,29 +221,20 @@
                             task.CurrentAddress = dt_Station.StationCode;
                             task.NextAddress = "";
                             task.TaskState = TaskStatusEnum.AGV_Finish.ObjToInt();
-                            task.DeviceCode = "SC01_CSJ";
+                            task.DeviceCode = dt_Station.StationDeviceCode;
                             var up = _taskRepository.UpdateData(task);
-                            agvResponseContent.Code = up ? "0" : "1";
-                            agvResponseContent.Message = up ? "鎴愬姛" : "澶辫触";
-                            return agvResponseContent;
+                            return agvResponse.OK("鎴愬姛","0");
                         }
                         break;
-                    case "cancel":
-                        task.TaskState = TaskStatusEnum.Cancel.ObjToInt();
-                        _taskRepository.UpdateData(task);
-                        break;
                     default:
-                        throw new Exception($"鏈畾涔夋柟娉曞悕銆恵agvUpdateModel.Method}銆�");
+                        throw new Exception($"鏈畾涔夋柟娉曞悕銆恵agvUpdateModel.TaskState}銆�");
                 }
-                agvResponseContent.Code = "0";
-                agvResponseContent.Message = "鎴愬姛";
             }
             catch (Exception ex)
             {
-                agvResponseContent.Code = "1";
-                agvResponseContent.Message = ex.Message;
+                agvResponse.Error(ex.Message);
             }
-            return agvResponseContent;
+            return agvResponse;
             //return _taskService.AgvUpdateTask(agvUpdateModel);
         }
 
@@ -287,45 +247,36 @@
         [HttpPost, HttpGet, Route("PutRequest"), AllowAnonymous]
         public WebResponseContent PutRequest(string code, int palletType)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
-                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == code);
+                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == code);
                 if (stationManger == null)
                 {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒扮珯鍙伴厤缃�");
+                    return content.Error($"鏈壘鍒扮珯鍙伴厤缃�");
                 }
                 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                 if (device == null)
                 {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒板搴旇澶�");
+                    return content.Error($"鏈壘鍒板搴旇澶�");
                 }
 
                 OtherDevice otherDevice = (OtherDevice)device;
 
-                bool canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode);
-                if (canPut)
+                short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
+                if (Command == 3)
                 {
-                    otherDevice.SetValue(GroundStationDBName.W_PutRequest, true, stationManger.StationCode);
-                    return WebResponseContent.Instance.OK();
+                    content.OK("鍏佽鏀炬枡");
                 }
                 else
                 {
-                    otherDevice.SetValue(GroundStationDBName.W_PutRequest, true, stationManger.StationCode);
-                    Thread.Sleep(1000);
-                    canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode);
-                    if (canPut)
-                    {
-                        return WebResponseContent.Instance.OK();
-                    }
-                    else
-                    {
-                        return WebResponseContent.Instance.Error($"鏀捐揣鐢宠涓�");
-                    }
+                    return content.Error("绂佹鏀炬枡");
                 }
+                return content;
             }
             catch (Exception ex)
             {
-                return WebResponseContent.Instance.Error(ex.Message);
+                return content.Error(ex.Message);
             }
         }
 

--
Gitblit v1.9.3