helongyang
13 小时以前 dc06f58d8ed537555fd529551180f43a0586ec3f
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/AGV/CTU_AGVController .cs
@@ -14,6 +14,7 @@
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_Tasks;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using static Dm.net.buffer.ByteArrayBuffer;
namespace WIDESEAWCS_Server.Controllers
@@ -114,13 +115,14 @@
                }
                if (task.PalletCode!= agvCallbackBox.ContainerCode)
                {
                    string Address = task.CurrentAddress switch
                    string Address = task?.CurrentAddress switch
                    {
                        "5206" => "5105",
                        "5212" => "5111",
                        "5218" => "5117",
                        "8005" => "8001",
                        "5135" => "5236",
                        _ => throw new Exception("未找到地址信息"),
                    };
                    AgvCTUCancelDTO agvCTUCancel=new AgvCTUCancelDTO()
                    {
@@ -171,11 +173,7 @@
            {
                if (agvUpdateModel == null) throw new Exception("未获取到请求参数");
                agvResponseContent.ReqCode = agvUpdateModel.ReqCode;
                var task = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode == x.AgvTaskNum);
                //是否存在输送线体待AGV搬运任务
                var taskExecutes = _taskRepository.QueryData(x => x.NextAddress == task.CurrentAddress && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.TaskType == TaskTypeEnum.InProduct.ObjToInt());
                if (task == null) throw new Exception($"未找到任务,任务号【{agvUpdateModel.TaskCode}】");
                var task = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode == x.AgvTaskNum) ?? throw new Exception($"未找到任务,任务号【{agvUpdateModel.TaskCode}】");
                switch (agvUpdateModel.Method.ToUpper())
                {
                    case "END":
@@ -188,27 +186,16 @@
                        //更改成品入库AGV取货任务状态
                        if (task.TaskType == TaskTypeEnum.InProduct.ObjToInt() || task.TaskType == TaskTypeEnum.InProductBack.ObjToInt())
                        {
                            //for (int i = 0; i < 100; i++)
                            //{
                            //    task.TaskState = TaskStatusEnum.AGV_WaitToExecute.ObjToInt();
                            //    task.Remark = task.TaskState.ToString();
                            //    _taskRepository.UpdateData(task);
                            //    var taskOk = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode == x.AgvTaskNum);
                            //    if (taskOk.TaskState==TaskStatusEnum.AGV_WaitToExecute.ObjToInt() || taskOk.Remark.Contains("320"))
                            //    {
                            //        agvResponseContent.Code = "0";
                            //        agvResponseContent.Message = ""+i;
                            //        break;
                            //    }
                            //}
                            //是否存在输送线体待AGV搬运任务
                            var taskExecutes = _taskRepository.QueryData(x => x.NextAddress == task.CurrentAddress && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.TaskType == TaskTypeEnum.InProduct.ObjToInt());
                            if (taskExecutes.Count > 0)
                            {
                                string address = task.CurrentAddress switch
                                {
                                    "5206" => "5105",
                                    "5212" => "5111",
                                    "5218" => "5117",
                                    "5218" => "5117"
                                };
                                //调用AGV预调度接口
                                AgvScheduleTaskDTO agvScheduleTask = new AgvScheduleTaskDTO()
@@ -268,7 +255,8 @@
                                WebResponseContent content = _taskService.AgvBoxApplyPass(boxApplyPassDTO);
                                if (content.Status && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                                {
                                    _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing);
                                    task.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
                                    _taskRepository.UpdateData(task);
                                }
                                else
                                {
@@ -283,13 +271,84 @@
                                _taskRepository.UpdateData(task);
                            }
                        }
                        else //更改辅料取货
                        {
                            //是否存在输送线体待AGV搬运任务
                            var taskExecutesFL = _taskRepository.QueryData(x => x.TaskState == TaskStatusEnum.New.ObjToInt() && x.DeviceCode == "AGV_FL" && !string.IsNullOrEmpty(x.DeviceCode));
                            if (taskExecutesFL.Count > 0)
                            {
                                //调用AGV预调度接口
                                AgvScheduleTaskDTO agvScheduleTask = new AgvScheduleTaskDTO()
                                {
                                    PositionCode = "8001",
                                    NextTask = "60",
                                    UseableLayers = "1",
                                    CacheCount = "1",
                                    Update = "0",
                                    AgvTyp = "10",
                                    PreTaskQty = "1",
                                    ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
                                    ReqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                };
                                WebResponseContent contentFL = _taskService.AgvPreScheduleTask(agvScheduleTask);
                                if (!contentFL.Status)
                                {
                                    agvResponseContent.Code = "1";
                                    agvResponseContent.Message = contentFL.Message;
                                    return agvResponseContent;
                                }
                            }
                            else //线体无任务
                            {
                                //调用AGV预调度接口
                                AgvScheduleTaskDTO agvScheduleTask = new AgvScheduleTaskDTO()
                                {
                                    PositionCode = "8001",
                                    NextTask = "15",
                                    UseableLayers = "1",
                                    CacheCount = "1",
                                    Update = "0",
                                    AgvTyp = "10",
                                    PreTaskQty = "1",
                                    ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
                                    ReqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                };
                                WebResponseContent contentFL = _taskService.AgvPreScheduleTask(agvScheduleTask);
                                if (!contentFL.Status)
                                {
                                    agvResponseContent.Code = "1";
                                    agvResponseContent.Message = contentFL.Message;
                                    return agvResponseContent;
                                }
                            }
                            //获取调入参数
                            AGVBoxApplyPassDTO boxApplyPassDTO = new AGVBoxApplyPassDTO()
                            {
                                ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
                                ReqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                TaskCode = task.AgvTaskNum
                            };
                            boxApplyPassDTO.Type = "1";
                            //请求料箱回调接口
                            WebResponseContent content = _taskService.AgvBoxApplyPass(boxApplyPassDTO);
                            if (content.Status && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                            {
                                task.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
                                _taskRepository.UpdateData(task);
                            }
                            else
                            {
                                task.ExceptionMessage = content.Message;
                                _taskService.UpdateTask(task, TaskStatusEnum.Exception);
                            }
                        }
                        break;
                    case "APPLYFROMAGV":
                        //更改成品出AGV放货任务状态
                        if (task.TaskType == TaskTypeEnum.OutProduct.ObjToInt())
                        {
                        //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())
@@ -299,7 +358,8 @@
                        }
                        else if(task.TaskType == TaskTypeEnum.OutProduct.ObjToInt())
                        {
                            _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing);
                            task.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
                            _taskRepository.UpdateData(task);
                        }
                        break;
                    default:
@@ -374,7 +434,7 @@
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("PutFinish"), AllowAnonymous]
        public WebResponseContent PutFinish(string code)
        public WebResponseContent PutFinish(string code,string barCode="",string taskNum="")
        {
            try
            {
@@ -390,8 +450,15 @@
                }
                OtherDevice otherDevice = (OtherDevice)device;
                if (!barCode.IsNullOrEmpty() && !taskNum.IsNullOrEmpty())
                {
                    otherDevice.SetValue(W_ConveyorLineFLDB.Barcode, barCode, stationManger.StationCode);
                    Thread.Sleep(500);
                    otherDevice.SetValue(W_ConveyorLineFLDB.TaskNum, taskNum, stationManger.StationCode);
                    Thread.Sleep(500);
                }
                otherDevice.SetValue(GroundStationDBName.W_PutFinish, true, stationManger.StationCode);
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)