From bfd2cde0cc9b9871eeab1503c837beabb9ade9e5 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期二, 16 九月 2025 17:35:53 +0800
Subject: [PATCH] 增加叠盘机拆盘机流程

---
 项目代码/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs |  281 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 237 insertions(+), 44 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..8073876 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,13 @@
 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 WIDESEAWCS_Tasks.StackPlateJob;
+using static Dm.net.buffer.ByteArrayBuffer;
 
 namespace WIDESEAWCS_Server.Controllers
 {
@@ -28,12 +32,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;
         }
 
         
@@ -53,22 +59,42 @@
                 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 +227,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 +237,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 +258,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 +302,6 @@
                 agvResponse.Error(ex.Message);
             }
             return agvResponse;
-            //return _taskService.AgvUpdateTask(agvUpdateModel);
         }
 
         /// <summary>
@@ -251,7 +311,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
@@ -266,17 +326,75 @@
                 {
                     return content.Error($"鏈壘鍒板搴旇澶�");
                 }
-
-                OtherDevice otherDevice = (OtherDevice)device;
-
-                short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
-                if (Command == 3)
+                if (device.DeviceCode.Contains("Plate"))
                 {
-                    content.OK("鍏佽鏀炬枡");
+                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
+                    StackPlateTaskCommandCommand command = commonConveyorLine.ReadCustomer<StackPlateTaskCommandCommand>(device.DeviceCode);
+
+                    if (command != null && command.State == 2 && command.InteractiveSignal == 1)
+                    {
+                        return content.OK("鍏佽鏀炬枡");
+                    }
+                    else
+                    {
+                        return content.Error("绂佹鏀炬枡");
+                    }
                 }
                 else
                 {
-                    return content.Error("绂佹鏀炬枡");
+
+                    OtherDevice otherDevice = (OtherDevice)device;
+
+                    if (device.DeviceCode.Contains("CP"))//鎴愬搧杈撻�佺嚎
+                    {
+                        short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
+                        if (Command == 3)
+                        {
+                            content.OK("鍏佽鏀炬枡");
+                        }
+                        else
+                        {
+                            return content.Error("绂佹鏀炬枡");
+                        }
+                    }
+                    else if (device.DeviceCode.Contains("Coveryor"))//鎺ラ┏鍙�
+                    {
+                        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;
             }
@@ -293,11 +411,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($"鏈壘鍒扮珯鍙伴厤缃�");
@@ -307,9 +425,24 @@
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒板搴旇澶�");
                 }
-
-                OtherDevice otherDevice = (OtherDevice)device;
-                otherDevice.SetValue(GroundStationDBName.W_PutFinish, true, stationManger.StationCode);
+                if (device.DeviceCode.Contains("Plate"))
+                {
+                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
+                    commonConveyorLine.SetValue(StackPlateDBName.WriteInteractiveSignal, Convert.ToInt16(1), device.DeviceCode);
+                    return WebResponseContent.Instance.OK();
+                }
+                else
+                {
+                    OtherDevice otherDevice = (OtherDevice)device;
+                    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 +463,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}");
@@ -340,17 +473,60 @@
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒板搴旇澶噞stationManger.StationDeviceCode}");
                 }
-
-                OtherDevice otherDevice = (OtherDevice)device;
-
-                short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
-                if (Command == 2)
+                if (device.DeviceCode.Contains("Plate"))
                 {
-                    content.OK("鍏佽鍙栨枡");
+                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
+                    StackPlateTaskCommandCommand command = commonConveyorLine.ReadCustomer<StackPlateTaskCommandCommand>(device.DeviceCode);
+                    
+                    if (command != null&&command.State == 2 && command.InteractiveSignal == 2)
+                    {
+                        return content.OK("鍏佽鍙栨枡");
+                    }
+                    else
+                    {
+                        return content.Error("绂佹鍙栨枡");
+                    }
                 }
                 else
                 {
-                    return content.Error("绂佹鍙栨枡");
+                    OtherDevice otherDevice = (OtherDevice)device;
+
+                    if (otherDevice.DeviceCode.Contains("CP"))//鎴愬搧杈撻�佺嚎
+                    {
+                        short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
+                        if (Command == 2)
+                        {
+                            content.OK("鍏佽鍙栨枡");
+                        }
+                        else
+                        {
+                            return content.Error("绂佹鍙栨枡");
+                        }
+                    }
+                    else if (device.DeviceCode.Contains("Coveryor"))//鎺ラ┏鍙�
+                    {
+                        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;
             }
@@ -381,12 +557,29 @@
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒板搴旇澶�");
                 }
-
-                OtherDevice otherDevice = (OtherDevice)device;
-                if (device.DeviceCode.Contains("CP"))
+                if (device.DeviceCode.Contains("Plate"))
                 {
-                    otherDevice.SetValue(W_ConveyorLineCPDB.W_Command, 2, stationManger.StationCode);
+                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
+                    commonConveyorLine.SetValue(StackPlateDBName.WriteInteractiveSignal, Convert.ToInt16(2), device.DeviceCode);
+                    return WebResponseContent.Instance.OK();
                 }
+                else
+                {
+                    OtherDevice otherDevice = (OtherDevice)device;
+                    if (device.DeviceCode.Contains("CP"))
+                    {
+                        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