wangxinhui
2025-01-10 4bc0e18b94a2bf17c1b7277910d63ef82fbe616a
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGV/CTU_AGVController .cs
copy from "\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGVController.cs" copy to "\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGV/CTU_AGVController .cs"
Îļþ´Ó ´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGVController.cs ¸´ÖÆ
@@ -17,18 +17,43 @@
{
    [Route("api/[controller]")]
    [ApiController]
    public class AGVController : ControllerBase
    public class CTU_AGVController : ControllerBase
    {
        private readonly IStationMangerRepository _stationMangerRepository;
        private readonly ITaskService _taskService;
        private readonly ITaskRepository _taskRepository;
        public AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository)
        public CTU_AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository)
        {
            _stationMangerRepository = stationMangerRepository;
            _taskService = taskService;
            _taskRepository = taskRepository;
        }
        [HttpPost, HttpGet, Route("AGVFinish"), AllowAnonymous]
        public WebResponseContent AGVFinish(string barcode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var task = _taskRepository.QueryFirst(x => x.PalletCode == barcode);
                if (task == null) throw new Exception($"未找到任务,托盘号【{barcode}】");
                AgvUpdateDTO updateDTO = new AgvUpdateDTO()
                {
                    TaskCode = task.AgvTaskNum,
                    Method = "end"
                };
                var agvResponseContent = CtuCallback(updateDTO);
                if (agvResponseContent.Code == "1") throw new Exception(agvResponseContent.Message);
                content.OK();
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        #region å®‰å…¨ä¿¡å·ç”³è¯·
        /// <summary>
        /// å®‰å…¨ä¿¡å·ç”³è¯· AGV-WCS
        /// </summary>
@@ -41,23 +66,15 @@
            agvResponseContent.ReqCode = secureApplyModel.ReqCode;
            try
            {
                var task = _taskRepository.QueryFirst(x => secureApplyModel.TaskCode== x.AgvTaskNum);
                var task = _taskRepository.QueryFirst(x => secureApplyModel.TaskCode == x.AgvTaskNum);
                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);
                    }
                    var content = PutRequest(task.NextAddress, task.PalletType);
                }
                else
                {
                    var content = PutRequest(task.NextAddress, task.PalletType);
                    if (!content.Status)
                    {
                        throw new Exception(content.Message);
                    }
                    var content = TakeRequest(task.CurrentAddress);
                }
                task.TaskState = TaskStatusEnum.AGV_WaitToExecute.ObjToInt();
                var up = _taskRepository.UpdateData(task);
@@ -72,13 +89,15 @@
            return agvResponseContent;
            //return _taskService.AgvSecureApply(secureApplyModel);
        }
        #endregion
        /// <summary>
        /// AGV任务更新/完成
        /// CtuAGV任务更新/完成
        /// </summary>
        /// <param name="agvUpdateModel"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("AgvCallback"), AllowAnonymous]
        public AgvResponseContent AgvUpdateTask([FromBody] AgvUpdateDTO agvUpdateModel)
        [HttpPost, HttpGet, Route("CtuCallback"), AllowAnonymous]
        public AgvResponseContent CtuCallback([FromBody] AgvUpdateDTO agvUpdateModel)
        {
            AgvResponseContent agvResponseContent = new AgvResponseContent();
            try
@@ -87,67 +106,11 @@
                agvResponseContent.ReqCode = agvUpdateModel.ReqCode;
                var task = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode == x.AgvTaskNum);
                if (task == null) throw new Exception($"未找到任务,任务号【{agvUpdateModel.TaskCode}】");
                switch (agvUpdateModel.Method)
                if (agvUpdateModel.Method == "end")
                {
                    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.自动完成);
                            _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);
                            if (dt_Station==null)
                            {
                                throw new Exception($"{task.NextAddress}AGV站台未定义");
                            }
                            task.CurrentAddress = dt_Station.StationCode;
                            task.NextAddress = "";
                            task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
                            task.DeviceCode = "SC01_CSJ";
                            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}】");
                    if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt()) PutFinish(task.NextAddress);
                    _taskService.TaskCompleted(task.TaskNum);
                }
                agvResponseContent.Code = "0";
                agvResponseContent.Message = "成功";
@@ -158,7 +121,6 @@
                agvResponseContent.Message = ex.Message;
            }
            return agvResponseContent;
            //return _taskService.AgvUpdateTask(agvUpdateModel);
        }
        /// <summary>
@@ -188,6 +150,7 @@
                bool canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode);
                if (canPut)
                {
                    otherDevice.SetValue(GroundStationDBName.W_PutRequest, true, stationManger.StationCode);
                    return WebResponseContent.Instance.OK();
                }
                else
@@ -271,6 +234,7 @@
                bool canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanTake, stationManger.StationCode);
                if (canPut)
                {
                    otherDevice.SetValue(GroundStationDBName.W_TakeRequest, true, stationManger.StationCode);
                    return WebResponseContent.Instance.OK();
                }
                else