肖洋
2024-12-09 ad6f399066a747aeaba987360bce9ee40227302c
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -4,7 +4,9 @@
using Quartz;
using System.Diagnostics.CodeAnalysis;
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;
@@ -16,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
@@ -28,14 +31,18 @@
        private readonly ITaskRepository _taskRepository;
        private readonly IRouterService _routerService;
        private readonly IProcessRepository _processRepository;
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository)
        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository, ICacheService cacheService, INoticeService noticeService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _routerService = routerService;
            _processRepository = processRepository;
            _cacheService = cacheService;
            _noticeService = noticeService;
        }
        public Task Execute(IJobExecutionContext context)
@@ -78,11 +85,37 @@
                            }
                        }
                    }
                    #region 调用事件总线通知前端
                    var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
                    if (tokenInfos == null || !tokenInfos.Any())
                    {
                        throw new Exception(commonStackerCrane.DeviceName + "缓存中未找到Token缓存");
                    }
                    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)
            {
                WriteError("CommonConveyorLineJob", "test", ex);
                ConsoleHelper.WriteErrorLine($"{ex.Message}");
                //Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
            }
            //WriteDebug("CommonConveyorLineJob", "test");
@@ -117,6 +150,8 @@
        private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
        {
            Dt_Task task;
            var taskRun = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting || x.TaskState == (int)TaskInStatusEnum.SC_InExecuting);
            if (taskRun != null) { return null; }
            if (commonStackerCrane.LastTaskType == null)
            {
                task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
@@ -192,7 +227,7 @@
                    if (device != null)
                    {
                        CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device;
                        if (conveyorLine.IsOccupied(task.NextAddress))//出库站台未被占用
                        if (conveyorLine.IsOccupied(task.TargetAddress))//出库站台未被占用
                        {
                            return task;
                        }