| | |
| | | using Microsoft.Extensions.Logging; |
| | | using Quartz; |
| | | using System; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.IO; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane; |
| | | using WIDESEAWCS_Tasks.StackerCraneJob; |
| | | using WIDESEA_Core; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | using WIDESEAWCS_Tasks.StackerCraneJob; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | |
| | | { |
| | | // 从 JobDataMap 获取堆垛机设备参数 |
| | | bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); |
| | | if (!flag || value is not IStackerCrane commonStackerCrane) |
| | | if (!flag || value is not CommonStackerCrane commonStackerCrane) |
| | | { |
| | | // 参数无效,直接返回 |
| | | _logger.LogWarning("Execute:参数无效"); |
| | |
| | | |
| | | // ========== 检查堆垛机任务完成状态 ========== |
| | | commonStackerCrane.CheckStackerCraneTaskCompleted(); |
| | | _logger.LogDebug("Execute:检查任务完成状态,设备: {DeviceCode}", _deviceCode); |
| | | QuartzLogger.Debug($"检查任务完成状态,设备: {_deviceCode}", _deviceCode); |
| | | //_logger.LogDebug("Execute:检查任务完成状态,设备: {DeviceCode}", _deviceCode); |
| | | //QuartzLogger.Debug($"检查任务完成状态,设备: {_deviceCode}", _deviceCode); |
| | | |
| | | // ========== 检查是否可以发送新任务 ========== |
| | | if (!commonStackerCrane.IsCanSendTask(commonStackerCrane.Communicator, commonStackerCrane.DeviceProDTOs, commonStackerCrane.DeviceProtocolDetailDTOs)) |
| | | //if (!commonStackerCrane.IsCanSendTask(commonStackerCrane.Communicator, commonStackerCrane.DeviceProDTOs, commonStackerCrane.DeviceProtocolDetailDTOs)) |
| | | if (commonStackerCrane.StackerCraneStatusValue != StackerCraneStatus.Normal) |
| | | { |
| | | // 堆垛机不可用(如正在执行上一任务),直接返回 |
| | | _logger.LogDebug("Execute:堆垛机不可用,设备: {DeviceCode}", _deviceCode); |
| | |
| | | if (task == null) |
| | | { |
| | | // 没有可用任务 |
| | | _logger.LogDebug("Execute:没有可用任务,设备: {DeviceCode}", _deviceCode); |
| | | QuartzLogger.Debug($"没有可用任务,设备: {_deviceCode}", _deviceCode); |
| | | //_logger.LogDebug("Execute:没有可用任务,设备: {DeviceCode}", _deviceCode); |
| | | //QuartzLogger.Debug($"没有可用任务,设备: {_deviceCode}", _deviceCode); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | _logger.LogInformation("Execute:选择任务,设备: {DeviceCode},任务号: {TaskNum}", _deviceCode, task.TaskNum); |
| | | QuartzLogger.Info($"选择任务,任务号: {task.TaskNum}", _deviceCode); |
| | | //_logger.LogInformation("Execute:选择任务,设备: {DeviceCode},任务号: {TaskNum}", _deviceCode, task.TaskNum); |
| | | //QuartzLogger.Info($"选择任务,任务号: {task.TaskNum}", _deviceCode); |
| | | |
| | | // ========== 构建命令 ========== |
| | | // 命令构建下沉到专用构建器 |
| | |
| | | bool sendFlag = SendStackerCraneCommand(commonStackerCrane, stackerCraneTaskCommand); |
| | | if (sendFlag) |
| | | { |
| | | Task.Delay(1000).Wait(); |
| | | commonStackerCrane.SetValue(StackerCraneDBName.WorkAction, (short)1); |
| | | // 发送成功,更新状态 |
| | | commonStackerCrane.LastTaskType = task.TaskType; |
| | | _taskService.UpdateTaskStatusToNext(task.TaskNum); |
| | |
| | | QuartzLogger.Info($"任务完成,任务号: {e.TaskNum}", stackerCrane.DeviceCode); |
| | | |
| | | // 更新任务状态为完成 |
| | | _taskService.StackCraneTaskCompleted(e.TaskNum); |
| | | |
| | | if (_taskService.StackCraneTaskCompleted(e.TaskNum).Status) |
| | | { |
| | | // 清除堆垛机的作业指令(设置为 2,表示空闲) |
| | | stackerCrane.SetValue(StackerCraneDBName.WorkAction, 2); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发送堆垛机命令 |