wangxinhui
2025-04-08 dcecb039035f4b2e82e31c39b74db9402444c536
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGV/CTU_AGVController .cs
@@ -6,6 +6,7 @@
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.Agv;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
@@ -28,6 +29,29 @@
            _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 å®‰å…¨ä¿¡å·ç”³è¯·
@@ -67,7 +91,69 @@
            //return _taskService.AgvSecureApply(secureApplyModel);
        }
        #endregion
        /// <summary>
        /// æ–™ç®±åˆ¤æ–­
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("AgvCallbackBoxNo"), AllowAnonymous]
        public AgvResponseContent AgvCallbackBoxNo([FromBody] AgvCallbackBoxNoDTO agvCallbackBox)
        {
            AgvResponseContent agvResponseContent = new AgvResponseContent();
            try
            {
                var task = _taskRepository.QueryFirst(x => agvCallbackBox.TaskNo == x.AgvTaskNum);
                if (task==null)
                {
                    agvResponseContent.Code = "1";
                    agvResponseContent.Message = $"未找到任务{agvCallbackBox.TaskNo}";
                    return agvResponseContent;
                }
                if (task.PalletCode!= agvCallbackBox.ContainerCode)
                {
                    string Address = task.CurrentAddress switch
                    {
                        "5206" => "5105",
                        "5212" => "5111",
                        "5218" => "5117",
                        "8005" => "8001",
                        "5135" => "5236",
                    };
                    AgvCTUCancelDTO agvCTUCancel=new AgvCTUCancelDTO()
                    {
                        ForceCancel="1",
                        MatterArea= task.CurrentAddress,
                        TaskCode=task.AgvTaskNum,
                        ReqCode = DateTime.Now.ToString("yyyyMMddHHmmss") + task.AgvTaskNum,
                        ReqTime= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    };
                    WebResponseContent content = _taskService.AgvBoxApplyPass(agvCTUCancel);
                    //取消任务
                    if (content.Status)
                    {
                        agvResponseContent.Code = "0";
                        agvResponseContent.Message = $"取消{task.AgvTaskNum}成功";
                        task.ExceptionMessage = $"实际箱号{task.PalletCode}扫描箱{agvCallbackBox.ContainerCode}";
                        _taskService.UpdateTask(task, TaskStatusEnum.Cancel);
                    }
                    else
                    {
                        agvResponseContent.Code = "1";
                        agvResponseContent.Message = content.Message;
                    }
                }
                else
                {
                    agvResponseContent.Code = "0";
                    agvResponseContent.Message = "成功";
                }
            }
            catch (Exception ex)
            {
                agvResponseContent.Code = "1";
                agvResponseContent.Message = ex.Message;
            }
            return agvResponseContent;
        }
        /// <summary>
        /// CtuAGV任务更新/完成
        /// </summary>
@@ -84,10 +170,41 @@
                var task = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode == x.AgvTaskNum);
                if (task == null) throw new Exception($"未找到任务,任务号【{agvUpdateModel.TaskCode}】");
                if (agvUpdateModel.Method == "end")
                switch (agvUpdateModel.Method)
                {
                    if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt()) PutFinish(task.NextAddress);
                    _taskService.TaskCompleted(task.TaskNum);
                    case "end":
                        if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.OutEmpty.ObjToInt()
                            || task.TaskType == TaskTypeEnum.OutAllocate.ObjToInt() || task.TaskType == TaskTypeEnum.OutProduct.ObjToInt())
                            PutFinish(task.NextAddress);
                        _taskService.TaskCompleted(task.TaskNum);
                        break;
                    case "applyToAgv":
                        //更改成品入库AGV取货任务状态
                        if (task.TaskType == TaskTypeEnum.InProduct.ObjToInt() || task.TaskType == TaskTypeEnum.InProductBack.ObjToInt())
                        {
                            _taskService.UpdateTask(task,TaskStatusEnum.AGV_WaitToExecute);
                        }
                        break;
                    case "applyFromAgv":
                        //更改成品出AGV放货任务状态
                        if (task.TaskType == TaskTypeEnum.OutProduct.ObjToInt())
                        {
                            _taskService.UpdateTask(task, TaskStatusEnum.AGV_WaitToExecute);
                        }
                        break;
                    case "outbin":
                        if (task.TaskType == TaskTypeEnum.InProduct.ObjToInt() || task.TaskType == TaskTypeEnum.InProductBack.ObjToInt())
                        {
                            TakeFinish(task.CurrentAddress);
                            _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing);
                        }
                        else if(task.TaskType == TaskTypeEnum.OutProduct.ObjToInt())
                        {
                            _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing);
                        }
                        break;
                    default:
                        break;
                }
                agvResponseContent.Code = "0";
                agvResponseContent.Message = "成功";