肖洋
2024-12-10 01ba2e2affa33320ef8aca6e033248388bb8f60e
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs
@@ -3,9 +3,10 @@
using Quartz;
using System.Diagnostics.CodeAnalysis;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.HttpContextUser;
using WIDESEAWCS_DTO.MOM;
using WIDESEAWCS_IProcessRepository;
using WIDESEAWCS_ITaskInfoRepository;
@@ -17,6 +18,7 @@
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
@@ -29,17 +31,18 @@
        private readonly ITaskRepository _taskRepository;
        private readonly IProcessRepository _processRepository;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly IRouterService _routerService;
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        public CommonStackerStationCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository, IDt_StationManagerRepository stationManagerRepository)
        public CommonStackerStationCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _processRepository = processRepository;
            _stationManagerRepository = stationManagerRepository;
            _routerService = routerService;
            _cacheService = cacheService;
            _noticeService = noticeService;
        }
        public Task Execute(IJobExecutionContext context)
@@ -82,6 +85,31 @@
                            }
                        }
                    }
                    #region 调用事件总线通知前端
                    var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
                    if (tokenInfos == null || !tokenInfos.Any())
                    {
                        //throw new Exception(commonStackerCrane.DeviceName + "缓存中未找到Token缓存");
                        return Task.CompletedTask;
                    }
                    var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList();
                    var userIds = tokenInfos?.Select(x => x.UserId).ToList();
                    object obj = new
                    {
                        commonStackerCrane.StackerCraneStatusDes,
                        commonStackerCrane.StackerCraneAutoStatusDes,
                        commonStackerCrane.StackerCraneWorkStatusDes,
                        commonStackerCrane.DeviceCode,
                        commonStackerCrane.DeviceName,
                        commonStackerCrane.CurrentTaskNum,
                        commonStackerCrane.LastTaskNum,
                    };
                    _noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonStackerCrane.DeviceName, data = obj });
                    #endregion 调用事件总线通知前端
                }
            }
            catch (Exception ex)
@@ -106,7 +134,7 @@
                if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
                {
                    Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
                    _taskService.StackCraneTaskCompleted(e.TaskNum);
                    _taskService.StackCraneTaskCompletedByStation(e.TaskNum);
                    commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                }
            }
@@ -207,93 +235,55 @@
            stackerCraneTaskCommand.WorkType = 1;
            stackerCraneTaskCommand.TrayType = 0;
            stackerCraneTaskCommand.StartCommand = 1;
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            {
                List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.Roadway);
                if (routers.Count > 0)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer);
                    string[] targetCodes = task.NextAddress.Split("-");
                    if (targetCodes.Length == 3)
                    {
                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                    }
                    else
                    {
                        //数据配置错误
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"入库任务终点错误,起点:【{task.NextAddress}】");
                        return null;
                    }
                }
                else
                {
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.NextAddress}】信息,无法获取对应的堆垛机取货站台信息");
                    return null;
                }
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            string[] sourceCodes = task.SourceAddress.Split("-");
            if (sourceCodes.Length == 3)
            {
                List<Dt_Router> routers = _routerService.QueryNextRoutes(task.Roadway, task.TargetAddress);
                if (routers.Count > 0)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer);
                stackerCraneTaskCommand.StartRow = (short)(Convert.ToInt16(sourceCodes[0]) % 2 == 0 ? 2:1);
                stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
            }
            else
            {
                //数据配置错误
                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点错误,起点:【{task.CurrentAddress}】");
                return null;
            }
            string[] targetCodes = task.TargetAddress.Split("-");
            if (targetCodes.Length == 3)
            {
                //if (task.Roadway.Contains("FR"))
                //{
                //    if(task.Roadway.EndsWith("03")|| task.Roadway.EndsWith("01"))
                //    {
                    string[] sourceCodes = task.CurrentAddress.Split("-");
                    if (sourceCodes.Length == 3)
                    {
                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                    }
                    else
                    {
                        //数据配置错误
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务起点错误,起点:【{task.CurrentAddress}】");
                        return null;
                    }
                }
                else
                {
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.NextAddress}】信息,无法获取对应的堆垛机放货站台信息");
                    return null;
                }
                //        stackerCraneTaskCommand.EndRow = (short)(Convert.ToInt16(targetCodes[0]) % 2 == 0 ? 1 : 2);
                //        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                //        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                //    }
                //    else
                //    {
                //        stackerCraneTaskCommand.EndRow = (short)(Convert.ToInt16(targetCodes[0]) % 2 == 0 ? 2 : 1);
                //        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                //        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                //    }
                //}
                //else
                //{
                //}
                stackerCraneTaskCommand.EndRow = (short)(Convert.ToInt16(targetCodes[0]) % 2 == 0 ? 2 : 1);
                stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
            else
            {
                string[] targetCodes = task.NextAddress.Split("-");
                if (targetCodes.Length == 3)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务终点错误,起点:【{task.NextAddress}】");
                    return null;
                }
                string[] sourceCodes = task.CurrentAddress.Split("-");
                if (sourceCodes.Length == 3)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
                }
                //数据配置错误
                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"任务终点错误,起点:【{task.NextAddress}】");
                return null;
            }
            return stackerCraneTaskCommand;
        }