wangxinhui
2025-03-31 638a684258fb4bc6adf76a1964bdf0d7f99e404f
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/³ÉÆ·²Ö/AGV_CPExtend.cs
@@ -1,4 +1,5 @@
using System;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -8,7 +9,9 @@
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.Agv;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
namespace WIDESEAWCS_Tasks
{
@@ -18,12 +21,12 @@
        {
            try
            {
                var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.New.ObjToInt() && nameof(AGV_FLJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
                var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()|| x.TaskState == TaskStatusEnum.New.ObjToInt()) && nameof(AGV_CPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
                foreach (var task in newTasks)
                {
                    try
                    {
                        if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.OutEmpty.ObjToInt() || task.TaskType == TaskTypeEnum.OutAllocate.ObjToInt())
                        if (task.TaskType == TaskTypeEnum.OutProduct.ObjToInt())
                            task.CurrentAddress = GetAGVAddress(task.CurrentAddress);
                        else
                            task.NextAddress = GetAGVAddress(task.NextAddress);
@@ -31,7 +34,7 @@
                        {
                            TaskCode = task.AgvTaskNum,
                            ReqCode = DateTime.Now.ToString("yyyyMMddHHmmss") + task.AgvTaskNum,
                            TaskTyp = task.TaskType < TaskTypeEnum.Inbound.ObjToInt() ? "FLC" : "FLR",
                            TaskTyp = task.TaskType < TaskTypeEnum.Inbound.ObjToInt() ? "CPC" : "CPR",
                            ctnrCode = task.PalletCode,
                            PositionCodePath = new List<CodePath>()
                        {
@@ -47,11 +50,11 @@
                            }
                        },
                        };
                        WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_FLSendTask);
                        if (!content.Status) throw new Exception(content.Message);
                        task.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
                        //发送AGV任务
                        WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_CPSendTask);
                        if (!content.Status)
                            throw new Exception(content.Message);
                        task.TaskState = TaskStatusEnum.AGV_Takeing.ObjToInt();
                    }
                    catch (Exception ex)
                    {
@@ -59,11 +62,104 @@
                        task.ExceptionMessage = ex.Message;
                    }
                }
                _taskService.UpdateData(newTasks);
                if (newTasks.Count>0)
                {
                    _taskService.UpdateData(newTasks);
                }
            }
            catch (Exception ex)
            {
                WriteError(nameof(AGV_FLJob), ex.Message, ex);
                WriteError(nameof(AGV_CPJob), ex.Message, ex);
            }
        }
        /// <summary>
        /// AGV取放货回调
        /// </summary>
        public void ContinueAGVTask()
        {
            try
            {
                //获取是否有安全申请中的任务
                var continueTask = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt()) && nameof(AGV_CPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).FirstOrDefault();
                if (continueTask!=null)
                {
                    //取货回调
                    if (continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                    {
                        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == continueTask.CurrentAddress || x.StationCode== continueTask.CurrentAddress);
                        if (stationManger == null)
                        {
                            throw new Exception($"未找到站台{continueTask.CurrentAddress}信息");
                        }
                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                        if (device == null)
                        {
                            throw new Exception($"未找到设备{stationManger.StationDeviceCode}信息");
                        }
                        OtherDevice otherDevice = (OtherDevice)device;
                        short canTake = otherDevice.GetValue<GroundStationDBName, short>(GroundStationDBName.R_IsCanTake, stationManger.StationCode);
                        if (canTake != 1)
                        {
                            return;
                        }
                    }
                    else//放货回调
                    {
                        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == continueTask.NextAddress);
                        if (stationManger == null)
                        {
                            throw new Exception($"未找到站台{continueTask.NextAddress}信息");
                        }
                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                        if (device == null)
                        {
                            throw new Exception($"未找到设备{stationManger.StationDeviceCode}信息");
                        }
                        OtherDevice otherDevice = (OtherDevice)device;
                        short canPut = otherDevice.GetValue<GroundStationDBName, short>(GroundStationDBName.R_IsCanPut, stationManger.StationCode);
                        if (canPut != 1)
                        {
                            return;
                        }
                    }
                    //获取调入参数
                    AGVBoxApplyPassDTO boxApplyPassDTO = new AGVBoxApplyPassDTO()
                    {
                        ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
                        ReqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        TaskCode = continueTask.AgvTaskNum
                    };
                    if (continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                    {
                        boxApplyPassDTO.Type = "1";
                    }
                    else
                    {
                        boxApplyPassDTO.Type = "2";
                    }
                    //请求料箱回调接口
                    WebResponseContent content = _taskService.AgvBoxApplyPass(boxApplyPassDTO);
                    if (content.Status && continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                    {
                        continueTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
                        _taskService.UpdateTask(continueTask, TaskStatusEnum.AGV_Executing);
                    }
                    else if (content.Status && continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                    {
                        continueTask.TaskState = TaskStatusEnum.AGV_Puting.ObjToInt();
                        _taskService.UpdateTask(continueTask, TaskStatusEnum.AGV_Puting);
                    }
                    else
                    {
                        continueTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
                        continueTask.ExceptionMessage = content.Message;
                        _taskService.UpdateTask(continueTask, TaskStatusEnum.Exception);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteError(nameof(AGV_CPJob), ex.Message, ex);
            }
        }
        /// <summary>
@@ -81,11 +177,11 @@
                var Layer = Convert.ToInt16(targetCodes[3]);
                var a = Row switch
                {
                    1 => "A1",
                    2 => "B1",
                    3 => "C1",
                    4 => "D1",
                    5 => "E1",
                    1 => "A",
                    2 => "B",
                    3 => "C",
                    4 => "D",
                    5 => "E",
                    _ => throw new Exception($"未定义的排,地址:【{Address}】"),
                };
                var b = Layer > 9 ? "" + Layer : "0" + Layer;