From 5368df4e3ab0f1ca849b550a9fcbd0338e7f859d Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期二, 09 十二月 2025 15:01:09 +0800
Subject: [PATCH] 优化

---
 项目代码/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs |  121 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 119 insertions(+), 2 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs"
index 6a3c278..51c7860 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs"
@@ -1,10 +1,12 @@
-锘縰sing Microsoft.AspNetCore.Authorization;
+锘縰sing Autofac.Core;
+using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using System.Text;
 using System.Text.RegularExpressions;
 using WIDESEA_DTO.Agv;
 using WIDESEA_External.Model;
+using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.APIEnum;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
@@ -13,6 +15,7 @@
 using WIDESEAWCS_Core.LogHelper;
 using WIDESEAWCS_DTO;
 using WIDESEAWCS_DTO.Agv;
+using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
@@ -43,7 +46,121 @@
             _taskRepository = taskRepository;
             _routerRepository = routerRepository;
         }
+        /// <summary>
+        /// AGV浠诲姟鏇存柊
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost, HttpGet, Route("Callback"), AllowAnonymous]
+        public WebResponseContent? Callback([FromBody]AgvUpdateDTO agvUpdateDTO)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                var task = _taskRepository.QueryFirst(x => (agvUpdateDTO.ContainerCode ?? "")==x.PalletCode);
+                switch (agvUpdateDTO.MissionStatus)
+                {
+                    case nameof(AGVStatusEnum.PICKER_RECEIVE):
+                        if (task == null) throw new Exception($"鏈壘鍒版枡绠便�恵agvUpdateDTO.ContainerCode}銆戜换鍔�");
+                        _taskService.UpdateTask(task, TaskStatusEnum.AGV_TakeFinish);
+                        break;
+                    case nameof(AGVStatusEnum.PICKER_SEND):
+                        if (task == null) throw new Exception($"鏈壘鍒版枡绠便�恵agvUpdateDTO.ContainerCode}銆戜换鍔�");
+                        _taskService.TaskCompleted(task.TaskNum);
+                        break;
+                    case nameof(AGVStatusEnum.WAITFEEDBACK):
+                        //AGV鏀捐
+                        List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x=>x.StationType==StationTypeEnum.StationType_OnlyInbound.ObjToInt());
+                        if (!stationMangers.Select(x=>x.StationCode).Contains(agvUpdateDTO.CurrentPosition))
+                        {
+                            WebResponseContent responseContent = _taskService.AgvTaskFlow(agvUpdateDTO.MissionCode);
+                            if (!responseContent.Status) throw new Exception($"{responseContent.Message}");
+                        }
+                        break;
+                    default:
+                        break;
+                }
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// AGV浠诲姟璇锋眰
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost, HttpGet, Route("WorkRequest"), AllowAnonymous]
+        public AgvTaskReqContent WorkRequest([FromBody] AgvTaskRequestDTO agvTaskRequestDTO)
+        {
+            AgvTaskReqContent content = new AgvTaskReqContent();
+            try
+            {
+                //鑾峰彇浠诲姟
+                Dt_Task? taskExist = _taskRepository.QueryFirst(x=>x.PalletCode==agvTaskRequestDTO.ContainerCode) ?? throw new Exception($"鏈壘鍒版枡绠眥agvTaskRequestDTO.ContainerCode}浠诲姟");
+                //鑾峰彇绔欏彴
+                Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == agvTaskRequestDTO.PositionId) ?? throw new Exception($"鏈壘鍒皗agvTaskRequestDTO.PositionId}绔欏彴浣嶇疆");
+                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode) ?? throw new Exception($"鏈壘鍒板搴旇澶噞stationManger.StationDeviceCode}");
 
-        
+                OtherDevice commonConveyorLine = (OtherDevice)device;
+
+                if (stationManger.StationType==StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
+                {
+                    short IsPut = commonConveyorLine.Communicator.Read<short>("0");
+                    if (IsPut != 256) throw new Exception($"{agvTaskRequestDTO.PositionId}绂佹鏀剧");
+                }
+                else
+                {
+                    short IsTake = commonConveyorLine.Communicator.Read<short>("11");
+                    if (IsTake != 256) throw new Exception($"{agvTaskRequestDTO.PositionId}绂佹鍙栫");
+                }
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// AGV浣滀笟瀹屾垚
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost, HttpGet, Route("WorkFinish"), AllowAnonymous]
+        public AgvTaskReqContent WorkFinish([FromBody] AgvTaskRequestDTO agvTaskRequestDTO)
+        {
+            AgvTaskReqContent content = new AgvTaskReqContent();
+            try
+            {
+                //鑾峰彇绔欏彴
+                Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == agvTaskRequestDTO.PositionId) ?? throw new Exception($"鏈壘鍒皗agvTaskRequestDTO.PositionId}绔欏彴浣嶇疆");
+                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode) ?? throw new Exception($"鏈壘鍒板搴旇澶噞stationManger.StationDeviceCode}");
+
+                OtherDevice commonConveyorLine = (OtherDevice)device;
+
+                if (stationManger.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
+                {
+                    commonConveyorLine.Communicator.Write("21", (short)256);
+                }
+                else
+                {
+                    commonConveyorLine.Communicator.Write("23", (short)256);
+                }
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                if (ex.Message.Contains("鏁版嵁鍐欏叆锛屽湴鍧�锛氥��23銆戯紝鍐欏叆鐨勬暟鎹細銆�256銆�") || ex.Message.Contains("鏁版嵁鍐欏叆锛屽湴鍧�锛氥��21銆戯紝鍐欏叆鐨勬暟鎹細銆�256銆�"))
+                {
+                    content.OK();
+                }
+                else
+                {
+                    content.Error(ex.Message);
+                }
+            }
+            return content;
+        }
     }
 }

--
Gitblit v1.9.3