1
wangxinhui
2025-06-10 bb66bf9372783cfb1af35a5384fdc69cc9c56a9f
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/¸ÉĤ²Ö/StackerCraneJob_GM.cs
@@ -26,6 +26,8 @@
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_DTO.TaskInfo;
using AutoMapper;
namespace WIDESEAWCS_Tasks
{
@@ -39,9 +41,10 @@
        private readonly IRouterService _routerService;
        private readonly IStationMangerRepository _stationMangerRepository;
        private readonly IRouterRepository _routerRepository;
        private readonly IMapper _mapper;
        private List<Dt_ApiInfo> apiInfos;
        public StackerCraneJob_GM(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository)
        public StackerCraneJob_GM(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IMapper mapper)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -50,6 +53,7 @@
            _stationMangerRepository = stationMangerRepository;
            _cacheService = cacheService;
            _routerRepository = routerRepository;
            _mapper = mapper;
            string? apiInfoStr = _cacheService.Get("apiInfos");
            if (!string.IsNullOrEmpty(apiInfoStr))
@@ -92,9 +96,16 @@
                                    commonStackerCrane.LastTaskType = task.TaskType;
                                    task.Dispatchertime = DateTime.Now;
                                    task.ExceptionMessage = "";
                                    if (task.TaskLength<=0)
                                    {
                                        WriteInfo(commonStackerCrane.DeviceCode, $"物料长度错误{task.TaskLength}");
                                        return Task.CompletedTask;
                                    }
                                    commonStackerCrane.Communicator.Write("DB105.58", (short)task.TaskLength);
                                    _taskService.UpdateTask(task, TaskStatusEnum.SC_Executing);
                                    commonStackerCrane.Communicator.Write("DB105.54", (short)1);
                                    //延时1s
                                    Thread.Sleep(1000);
                                }
                            }
                        }
@@ -214,7 +225,7 @@
                if (OutTaskStationIsOccupied(task) == null)
                {
                    bool flag = false;
                    List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList();
                    List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress, task.TaskType).Select(x => x.ChildPosi).ToList();
                    List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes);
                    foreach (var item in tasks)
                    {
@@ -237,11 +248,61 @@
                if (string.IsNullOrEmpty(url))
                {
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"未找到WMS移库判断接口");
                    WriteInfo(commonStackerCrane.DeviceCode, $"未找到WMS移库判断接口");
                    WriteError(commonStackerCrane.DeviceCode, $"未找到WMS移库判断接口");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到WMS移库判断接口");
                    return null;
                }
                HttpHelper.Post($"{url}?taskNum={task.TaskNum}&locationCode={task.NextAddress}", "");//todo è°ƒç”¨WMS任务完成方法
                string response = HttpHelper.Post($"{url}?taskNum={task.TaskNum}&locationCode={task.CurrentAddress}", "");//todo è°ƒç”¨WMS任务完成方法
                if (string.IsNullOrEmpty(response))
                {
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"移库接口调用错误");
                    WriteError(commonStackerCrane.DeviceCode, $"移库接口调用错误");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库接口调用错误");
                    return null;
                }
                WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(response);
                if (responseContent == null || !responseContent.Status)
                {
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"移库接口调用错误");
                    WriteError(commonStackerCrane.DeviceCode, $"移库接口调用错误");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库接口调用错误");
                    return null;
                }
                WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.Serialize());
                if (taskDTO == null)
                {
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"移库接口调用错误");
                    WriteError(commonStackerCrane.DeviceCode, $"移库接口调用错误");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库接口调用错误");
                    return null;
                }
                if (task.TaskNum == taskDTO.TaskNum)
                {
                    return task;
                }
                else
                {
                    Dt_Task reloTask = _mapper.Map<Dt_Task>(taskDTO);
                    //判断移库货位任务是否已存在,如存在先执行
                    Dt_Task existTask = _taskService.QueryStackerExistTask(reloTask.PalletCode, reloTask.SourceAddress);
                    if (existTask != null)
                    {
                        return existTask;
                    }
                    else
                    {
                        reloTask.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
                        reloTask.CurrentAddress = taskDTO.SourceAddress;
                        reloTask.NextAddress = taskDTO.TargetAddress;
                        reloTask.DeviceCode = task.DeviceCode;
                        reloTask.TaskType = TaskTypeEnum.Relocation.ObjToInt();
                        int taskId = _taskRepository.AddData(reloTask);
                        reloTask.TaskId = taskId;
                    }
                    return reloTask;
                }
            }
            return task;
@@ -261,7 +322,8 @@
                if (device != null)
                {
                    OtherDevice client = (OtherDevice)device;
                    if (!client.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Goods, stationManger.StationCode))//出库站台未被占用
                    bool ReadGood = client.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Goods, stationManger.StationCode);
                    if (!ReadGood)//出库站台未被占用
                    {
                        task.NextAddress = stationManger.StackerCraneStationCode;
                        _taskRepository.UpdateData(task);
@@ -295,7 +357,7 @@
            stackerCraneTaskCommand.Barcode = task.PalletCode;
            stackerCraneTaskCommand.TaskNum = task.TaskNum;
            stackerCraneTaskCommand.WorkType = 1;
            stackerCraneTaskCommand.TrayType = (Int16)task.PalletType;
            stackerCraneTaskCommand.TrayType = 0;
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            {
                string[] startCodes = task.CurrentAddress.Split("-");