From 9ce6731460179c71f0f2c636b2a1598324d5194e Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期六, 20 九月 2025 15:16:48 +0800
Subject: [PATCH] 最新代码更新

---
 项目代码/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs |  217 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 183 insertions(+), 34 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 4724199..0628b3d 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"
@@ -15,9 +15,12 @@
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.DTO;
+using WIDESEAWCS_QuartzJob.Models;
+using WIDESEAWCS_QuartzJob.Repository;
 using WIDESEAWCS_Tasks;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
 using WIDESEAWCS_Tasks.DBNames;
+using static Dm.net.buffer.ByteArrayBuffer;
 
 namespace WIDESEAWCS_Server.Controllers
 {
@@ -28,12 +31,14 @@
         private readonly IStationMangerRepository _stationMangerRepository;
         private readonly ITaskService _taskService;
         private readonly ITaskRepository _taskRepository;
+        private readonly IRouterRepository _routerRepository;
 
-        public AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository)
+        public AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository,IRouterRepository routerRepository)
         {
             _stationMangerRepository = stationMangerRepository;
             _taskService = taskService;
             _taskRepository = taskRepository;
+            _routerRepository = routerRepository;
         }
 
         
@@ -49,26 +54,50 @@
             AgvResponse agvResponse = new AgvResponse();
             try
             {
+                if (secureApplyModel.ReceiveTaskID=="100")
+                {
+                    return agvResponse.OK("鎴愬姛", "0");
+                }
                 var task = _taskRepository.QueryFirst(x => secureApplyModel.ReceiveTaskID.ObjToInt() == x.TaskNum);
                 if (task == null) throw new Exception("鏈壘鍒颁换鍔�");
                 if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                 {
-                    var content = TakeRequest(task.CurrentAddress);
-                    if (!content.Status)
+                    if (task.TaskState==TaskStatusEnum.AGV_Executing.ObjToInt())//鍑哄簱鍙栬揣璇锋眰
                     {
-                        throw new Exception(content.Message);
+                        var content = TakeRequest(secureApplyModel.WbCode);
+                        if (!content.Status)
+                        {
+                            throw new Exception(content.Message);
+                        }
+                    }
+                    else//鍑哄簱鏀捐揣璇锋眰
+                    {
+                        var content = PutRequest(task.NextAddress, task.PalletType);
+                        if (!content.Status)
+                        {
+                            throw new Exception(content.Message);
+                        }
                     }
                 }
                 else
                 {
-                    var content = PutRequest(task.NextAddress, task.PalletType);
-                    if (!content.Status)
+                    if (task.TaskState == TaskStatusEnum.AGV_Executing.ObjToInt())//鍏ュ簱鍙栬揣璇锋眰
                     {
-                        throw new Exception(content.Message);
+                        var content = TakeRequest(secureApplyModel.WbCode);
+                        if (!content.Status)
+                        {
+                            throw new Exception(content.Message);
+                        }
+                    }
+                    else//鍏ュ簱鏀捐揣璇锋眰
+                    {
+                        var content = PutRequest(task.NextAddress, task.TaskNum);
+                        if (!content.Status)
+                        {
+                            throw new Exception(content.Message);
+                        }
                     }
                 }
-                task.TaskState = TaskStatusEnum.AGV_Puting.ObjToInt();
-                var up = _taskRepository.UpdateData(task);
                 agvResponse.OK("鎴愬姛","0");
             }
             catch (Exception ex)
@@ -201,6 +230,9 @@
                 switch (agvUpdateModel.GoodsState)
                 {
                     case "1"://鍑哄簱鏍规嵁杩欎釜淇″彿鍒ゆ柇鍙栬揣瀹屾垚
+
+                        //鏇存柊浠诲姟鐘舵��
+                        _taskService.UpdateTask(task, TaskStatusEnum.AGV_TakeFinish);
                         if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                         {
                             var content = TakeFinish(task.CurrentAddress);
@@ -208,9 +240,19 @@
                             {
                                 throw new Exception(content.Message);
                             };
-                            return agvResponse.OK("鎴愬姛", "0");
                         }
-                        break;
+                        else
+                        {
+                            if (task.TaskType == TaskTypeEnum.PrintYLInbound.ObjToInt() || task.TaskType == TaskTypeEnum.PrintYLBackInbound.ObjToInt())
+                            {
+                                var content = TakeFinish(task.CurrentAddress);
+                                if (!content.Status)
+                                {
+                                    throw new Exception(content.Message);
+                                };
+                            }
+                        }
+                        return agvResponse.OK("鎴愬姛", "0");
                     case "2"://鍏ュ簱鏍规嵁杩欎釜淇″彿鍒ゆ柇鏀捐揣瀹屾垚
                         if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                         {
@@ -219,19 +261,41 @@
                             {
                                 throw new Exception($"{task.NextAddress}AGV绔欏彴鏈畾涔�");
                             }
-                            task.CurrentAddress = dt_Station.StationCode;
-                            task.NextAddress = "";
-                            task.TaskState = TaskStatusEnum.AGV_Finish.ObjToInt();
-                            task.DeviceCode = dt_Station.StationDeviceCode;
-                            var up = _taskRepository.UpdateData(task);
+                            if (task.TaskType == TaskTypeEnum.PrintYLInbound.ObjToInt() || task.TaskType == TaskTypeEnum.PrintYLBackInbound.ObjToInt())
+                            {
+                                List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.NextAddress == x.StartPosi);
+                                Dt_Router router = routers.FirstOrDefault();
+                                if (router == null)
+                                {
+                                    throw new Exception($"浠诲姟鍙�:{task.TaskNum}鏈壘鍒拌矾鐢遍厤缃俊鎭�");
+                                }
+                                string oldAddress = task.NextAddress;
+                                //鏇存柊浠诲姟鐘舵��
+                                task.CurrentAddress = router.NextPosi;
+                                task.NextAddress = "";
+                                task.DeviceCode = router.ChildPosiDeviceCode;
+                                _taskService.UpdateTask(task, TaskStatusEnum.AGV_Finish);
+                                PutFinish(oldAddress, task.TaskNum);
+                            }
+                            else
+                            {
+                                task.CurrentAddress = dt_Station.StationCode;
+                                task.NextAddress = "";
+                                task.TaskState = TaskStatusEnum.AGV_Finish.ObjToInt();
+                                task.DeviceCode = dt_Station.StationDeviceCode;
+                                _taskRepository.UpdateData(task);
+                            }
                             return agvResponse.OK("鎴愬姛","0");
                         }
-                        else if(task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+                        else
                         {
                             _taskService.TaskCompleted(task.TaskNum);
+                            if (task.TaskType==TaskTypeEnum.PrintYLOutbound.ObjToInt())
+                            {
+                                PutFinish(task.NextAddress);
+                            }
                             return agvResponse.OK("鎴愬姛", "0");
                         }
-                        break;
                     default:
                         throw new Exception($"鏈畾涔夋柟娉曞悕銆恵agvUpdateModel.TaskState}銆�");
                 }
@@ -241,7 +305,6 @@
                 agvResponse.Error(ex.Message);
             }
             return agvResponse;
-            //return _taskService.AgvUpdateTask(agvUpdateModel);
         }
 
         /// <summary>
@@ -251,7 +314,7 @@
         /// <param name="palletType"></param>
         /// <returns></returns>
         [HttpPost, HttpGet, Route("PutRequest"), AllowAnonymous]
-        public WebResponseContent PutRequest(string code, int palletType)
+        public WebResponseContent PutRequest(string code, int taskNum)
         {
             WebResponseContent content = new WebResponseContent();
             try
@@ -269,15 +332,57 @@
 
                 OtherDevice otherDevice = (OtherDevice)device;
 
-                short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
-                if (Command == 3)
+                if (device.DeviceCode.Contains("CP"))//鎴愬搧杈撻�佺嚎
                 {
-                    content.OK("鍏佽鏀炬枡");
+                    short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
+                    if (Command == 3)
+                    {
+                        content.OK("鍏佽鏀炬枡");
+                    }
+                    else
+                    {
+                        return content.Error("绂佹鏀炬枡");
+                    }
                 }
-                else
+                else if (device.DeviceCode.Contains("Coveryor"))//鎺ラ┏鍙�
                 {
-                    return content.Error("绂佹鏀炬枡");
+                    bool RequestPut = otherDevice.GetValue<CoveryorDB, bool>(CoveryorDB.C_RequestPut, stationManger.StationDeviceCode);
+                    if (!RequestPut)
+                    {
+                        otherDevice.SetValue(CoveryorDB.C_InTaskNum, taskNum, stationManger.StationDeviceCode);
+                        otherDevice.SetValue(CoveryorDB.C_RequestPut, true, stationManger.StationDeviceCode);
+                        Thread.Sleep(1000);
+                    }
+                    bool AllowFinish = otherDevice.GetValue<CoveryorDB, bool>(CoveryorDB.C_AllowFinish, stationManger.StationDeviceCode);
+                    if (AllowFinish)
+                    {
+                        content.OK("鍏佽鏀炬枡");
+                    }
+                    else
+                    {
+                        return content.Error("绂佹鏀炬枡");
+                    }
                 }
+                else if (device.DeviceCode.Contains("Retract"))//浼哥缉璐у弶
+                {
+                    bool RequestPut = otherDevice.GetValue<RetractDB, bool>(RetractDB.Ret_RequestPut, stationManger.StationDeviceCode);
+                    if (!RequestPut)
+                    {
+                        otherDevice.SetValue(RetractDB.Ret_TargetAddress, Convert.ToInt16(stationManger.StationCode), stationManger.StationDeviceCode);
+                        otherDevice.SetValue(RetractDB.Ret_RequestPut, true, stationManger.StationDeviceCode);
+                        Thread.Sleep(1000);
+                    }
+                    bool AllowFinish = otherDevice.GetValue<RetractDB, bool>(RetractDB.Ret_AllowFinish, stationManger.StationDeviceCode);
+                    if (AllowFinish)
+                    {
+                        content.OK("鍏佽鏀炬枡");
+                    }
+                    else
+                    {
+                        return content.Error("绂佹鏀炬枡");
+                    }
+                }
+                
                 return content;
             }
             catch (Exception ex)
@@ -293,11 +398,11 @@
         /// <param name="code"></param>
         /// <returns></returns>
         [HttpPost, HttpGet, Route("PutFinish"), AllowAnonymous]
-        public WebResponseContent PutFinish(string code)
+        public WebResponseContent PutFinish(string code,int taskNum=0)
         {
             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($"鏈壘鍒扮珯鍙伴厤缃�");
@@ -309,7 +414,14 @@
                 }
 
                 OtherDevice otherDevice = (OtherDevice)device;
-                otherDevice.SetValue(GroundStationDBName.W_PutFinish, true, stationManger.StationCode);
+                if (device.DeviceCode.Contains("Coveryor"))//鎺ラ┏鍙�
+                {
+                    otherDevice.SetValue(CoveryorDB.C_PutFinish, true, stationManger.StationDeviceCode);
+                }
+                else if (device.DeviceCode.Contains("Retract"))//浼哥缉璐у弶
+                {
+                    otherDevice.SetValue(RetractDB.Ret_PutFinish, true, stationManger.StationDeviceCode);
+                }
                 return WebResponseContent.Instance.OK();
             }
             catch (Exception ex)
@@ -330,7 +442,7 @@
             WebResponseContent content = new WebResponseContent();
             try
             {
-                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == code);
+                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == code);
                 if (stationManger == null)
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒扮珯鍙伴厤缃畕code}");
@@ -343,15 +455,43 @@
 
                 OtherDevice otherDevice = (OtherDevice)device;
 
-                short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
-                if (Command == 2)
+                if (otherDevice.DeviceCode.Contains("CP"))//鎴愬搧杈撻�佺嚎
                 {
-                    content.OK("鍏佽鍙栨枡");
+                    short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
+                    if (Command == 2)
+                    {
+                        content.OK("鍏佽鍙栨枡");
+                    }
+                    else
+                    {
+                        return content.Error("绂佹鍙栨枡");
+                    }
                 }
-                else
+                else if (device.DeviceCode.Contains("Coveryor"))//鎺ラ┏鍙�
                 {
-                    return content.Error("绂佹鍙栨枡");
+                    bool AllowTake = otherDevice.GetValue<CoveryorDB, bool>(CoveryorDB.C_AllowTake, stationManger.StationDeviceCode);
+                    if (AllowTake)
+                    {
+                        content.OK("鍏佽鍙栨枡");
+                    }
+                    else
+                    {
+                        return content.Error("绂佹鍙栨枡");
+                    }
                 }
+                else if (device.DeviceCode.Contains("Retract"))//浼哥缉璐у弶
+                {
+                    bool AllowTake = otherDevice.GetValue<RetractDB, bool>(RetractDB.Ret_AllowTake, stationManger.StationDeviceCode);
+                    if (AllowTake)
+                    {
+                        content.OK("鍏佽鍙栨枡");
+                    }
+                    else
+                    {
+                        return content.Error("绂佹鍙栨枡");
+                    }
+                }
+
                 return content;
             }
             catch (Exception ex)
@@ -387,6 +527,15 @@
                 {
                     otherDevice.SetValue(W_ConveyorLineCPDB.W_Command, 2, stationManger.StationCode);
                 }
+                else if (device.DeviceCode.Contains("Coveryor"))
+                {
+                    otherDevice.SetValue(CoveryorDB.C_TakeFinish, true, stationManger.StationDeviceCode);
+                }
+                else if (device.DeviceCode.Contains("Retract"))//浼哥缉璐у弶
+                {
+                    otherDevice.SetValue(RetractDB.Ret_TakeFinish, true, stationManger.StationDeviceCode);
+                }
+
                 return WebResponseContent.Instance.OK();
             }
             catch (Exception ex)

--
Gitblit v1.9.3