wangxinhui
昨天 a8756c3526832332db4ef5685348d9b188c2bf2b
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/¸ÉĤ²Ö/StackerCraneJob_GM.cs
@@ -28,6 +28,8 @@
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_DTO.TaskInfo;
using AutoMapper;
using HslCommunication.WebSocket;
using WIDESEAWCS_Tasks.干膜仓;
namespace WIDESEAWCS_Tasks
{
@@ -38,13 +40,15 @@
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly ITaskRepository _taskRepository;
        public static GMReadData gMReadData = new GMReadData();
        private readonly IRouterService _routerService;
        private readonly IStationMangerRepository _stationMangerRepository;
        private readonly IRouterRepository _routerRepository;
        private readonly IMapper _mapper;
        private List<Dt_ApiInfo> apiInfos;
        private WebSocketServer _webSocketServer;
        public StackerCraneJob_GM(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IMapper mapper)
        public StackerCraneJob_GM(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IMapper mapper,WebSocketServer webSocketServer)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -54,6 +58,7 @@
            _cacheService = cacheService;
            _routerRepository = routerRepository;
            _mapper = mapper;
            _webSocketServer = webSocketServer;
            string? apiInfoStr = _cacheService.Get("apiInfos");
            if (!string.IsNullOrEmpty(apiInfoStr))
@@ -74,6 +79,7 @@
        {
            try
            {
                Thread.Sleep(2200);
                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonStackerCrane != null)
                {
@@ -110,6 +116,14 @@
                            }
                        }
                    }
                    gMReadData.R_GM_Status = ((short)commonStackerCrane.StackerCraneStatusValue);
                    gMReadData.R_GM_AutoStatus = ((short)commonStackerCrane.StackerCraneAutoStatusValue);
                    gMReadData.R_GM_WorkStatus = ((short)commonStackerCrane.StackerCraneWorkStatusValue);
                    gMReadData.R_GM_TaskNum = commonStackerCrane.CurrentTaskNum.ObjToInt();
                    gMReadData.R_GM_WorkType = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType);
                    gMReadData.R_GM_TrayType = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.TrayType);
                    string gMData = JsonConvert.SerializeObject(gMReadData);
                    _webSocketServer.PublishAllClientPayload(gMData);
                }
            }
            catch (Exception ex)
@@ -275,7 +289,6 @@
                    WriteError(commonStackerCrane.DeviceCode, $"移库接口调用错误");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库接口调用错误");
                    return null;
                }
                if (task.TaskNum == taskDTO.TaskNum)
                {
@@ -286,9 +299,18 @@
                    Dt_Task reloTask = _mapper.Map<Dt_Task>(taskDTO);
                    //判断移库货位任务是否已存在,如存在先执行
                    Dt_Task existTask = _taskService.QueryStackerExistTask(reloTask.PalletCode, reloTask.SourceAddress);
                    if (existTask != null)
                    if (existTask != null && existTask.TaskState == (int)TaskStatusEnum.SC_Execute)
                    {
                        Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => (x.StationCode == task.NextAddress || x.StackerCraneStationCode == task.NextAddress) && x.StackerCraneCode == task.DeviceCode);
                        existTask.NextAddress = stationManger.StackerCraneStationCode;
                        _taskRepository.UpdateData(existTask);
                        return existTask;
                    }
                    else if (existTask != null && existTask.TaskState != (int)TaskStatusEnum.SC_Execute)
                    {
                        WriteError(commonStackerCrane.DeviceCode, $"任务{task.TaskNum}浅货位任务{existTask.TaskNum}任务状态不为堆垛待执行");
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"任务{task.TaskNum}浅货位任务{existTask.TaskNum}任务状态不为堆垛待执行");
                        return null;
                    }
                    else
                    {
@@ -315,7 +337,7 @@
        /// <returns>如果未被占用,返回传入的任务信息,否则,返回null</returns>
        private Dt_Task? OutTaskStationIsOccupied([NotNull] Dt_Task task)
        {
            Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress && x.StackerCraneCode == task.DeviceCode);
            Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x =>( x.StationCode == task.NextAddress || x.StackerCraneStationCode==task.NextAddress )&& x.StackerCraneCode == task.DeviceCode);
            if (stationManger != null)
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);