From 3c7658b4fff5cfba50105357eb3723dcbcea5c6a Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 27 十二月 2024 18:38:24 +0800
Subject: [PATCH] AGV接口逻辑

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGVController.cs |  139 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 134 insertions(+), 5 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGVController.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGVController.cs"
index bf814b7..0cf13a6 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGVController.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGVController.cs"
@@ -1,8 +1,14 @@
 锘縰sing Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using WIDESEA_DTO.Agv;
+using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Enums;
+using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_IBasicInfoRepository;
+using WIDESEAWCS_ITaskInfoRepository;
+using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_Tasks;
@@ -14,13 +20,121 @@
     public class AGVController : ControllerBase
     {
         private readonly IStationMangerRepository _stationMangerRepository;
+        private readonly ITaskService _taskService;
+        private readonly ITaskRepository _taskRepository;
 
-        public AGVController(IStationMangerRepository stationMangerRepository)
+        public AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository)
         {
             _stationMangerRepository = stationMangerRepository;
+            _taskService = taskService;
+            _taskRepository = taskRepository;
+        }
+        /// <summary>
+        /// 瀹夊叏淇″彿鐢宠 AGV-WCS
+        /// </summary>
+        /// <param name="secureApplyModel"></param>
+        /// <returns></returns>
+        [HttpPost, HttpGet, Route("AgvSecureApply"), AllowAnonymous]
+        public AgvResponseContent AgvSecureApply([FromBody] AgvSecureApplyDTO secureApplyModel)
+        {
+            AgvResponseContent agvResponseContent = new AgvResponseContent();
+            agvResponseContent.ReqCode = secureApplyModel.ReqCode;
+            try
+            {
+                var task = _taskRepository.QueryFirst(x => secureApplyModel.TaskCode.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);
+                }
+                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 ? "鎴愬姛" : "澶辫触";
+            }
+            catch (Exception ex)
+            {
+                agvResponseContent.Code = "1";
+                agvResponseContent.Message = ex.Message;
+            }
+            return agvResponseContent;
+            //return _taskService.AgvSecureApply(secureApplyModel);
+        }
+        /// <summary>
+        /// AGV浠诲姟鏇存柊/瀹屾垚
+        /// </summary>
+        /// <param name="agvUpdateModel"></param>
+        /// <returns></returns>
+        [HttpPost, HttpGet, Route("AgvCallback"), AllowAnonymous]
+        public AgvResponseContent AgvUpdateTask([FromBody] AgvUpdateDTO agvUpdateModel)
+        {
+            AgvResponseContent agvResponseContent = new AgvResponseContent();
+            try
+            {
+                if (agvUpdateModel == null) throw new Exception("鏈幏鍙栧埌璇锋眰鍙傛暟");
+                agvResponseContent.ReqCode = agvUpdateModel.ReqCode;
+                var task = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode.ObjToInt() == x.TaskNum);
+                if (task == null) throw new Exception("鏈壘鍒颁换鍔�");
+                switch (agvUpdateModel.Method)
+                {
+                    case "start":
+                        break;
+                    case "outbin"://鍑哄簱鏍规嵁杩欎釜淇″彿鍒ゆ柇鍙栬揣瀹屾垚
+                        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.鑷姩瀹屾垚);
+                            agvResponseContent.Code = up ? "0" : "1";
+                            agvResponseContent.Message = up ? "鎴愬姛" : "澶辫触";
+                            return agvResponseContent;
+                        }
+                        break;
+                    case "end"://鍏ュ簱鏍规嵁杩欎釜淇″彿鍒ゆ柇鏀捐揣瀹屾垚
+                        if (task.TaskType != TaskTypeEnum.Outbound.ObjToInt())
+                        {
+                            var content = PutFinish(task.CurrentAddress);
+                            if (!content.Status) throw new Exception(content.Message);
+                            task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
+                            var up = _taskRepository.UpdateData(task);
+                            agvResponseContent.Code = up ? "0" : "1";
+                            agvResponseContent.Message = up ? "鎴愬姛" : "澶辫触";
+                            return agvResponseContent;
+                        }
+                        break;
+                    case "cancel":
+                        task.TaskState = TaskStatusEnum.Cancel.ObjToInt();
+                        _taskRepository.UpdateData(task);
+                        break;
+                    default:
+                        throw new Exception($"鏈畾涔夋柟娉曞悕銆恵agvUpdateModel.Method}銆�");
+                }
+                agvResponseContent.Code = "0";
+                agvResponseContent.Message = "鎴愬姛";
+            }
+            catch (Exception ex)
+            {
+                agvResponseContent.Code = "1";
+                agvResponseContent.Message = ex.Message;
+            }
+            return agvResponseContent;
+            //return _taskService.AgvUpdateTask(agvUpdateModel);
         }
 
-        [HttpPost, HttpGet, Route("PutRequest"), AllowAnonymous]
+        /// <summary>
+        /// 鏀捐揣璇锋眰
+        /// </summary>
+        /// <param name="code"></param>
+        /// <param name="palletType"></param>
+        /// <returns></returns>
+        //[HttpPost, HttpGet, Route("PutRequest"), AllowAnonymous]
         public WebResponseContent PutRequest(string code, int palletType)
         {
             try
@@ -65,7 +179,12 @@
             }
         }
 
-        [HttpPost, HttpGet, Route("PutFinish"), AllowAnonymous]
+        //[HttpPost, HttpGet, Route("PutFinish"), AllowAnonymous]
+        /// <summary>
+        /// 鏀捐揣瀹屾垚
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
         public WebResponseContent PutFinish(string code)
         {
             try
@@ -92,7 +211,12 @@
             }
         }
 
-        [HttpPost, HttpGet, Route("TakeRequest"), AllowAnonymous]
+        //[HttpPost, HttpGet, Route("TakeRequest"), AllowAnonymous]
+        /// <summary>
+        /// 鍙栬揣璇锋眰
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
         public WebResponseContent TakeRequest(string code)
         {
             try
@@ -136,7 +260,12 @@
             }
         }
 
-        [HttpPost, HttpGet, Route("TakeFinish"), AllowAnonymous]
+        //[HttpPost, HttpGet, Route("TakeFinish"), AllowAnonymous]
+        /// <summary>
+        /// 鍙栬揣瀹屾垚
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
         public WebResponseContent TakeFinish(string code)
         {
             try

--
Gitblit v1.9.3