| | |
| | | using Microsoft.Extensions.Logging; |
| | | //using Microsoft.Extensions.Logging; |
| | | using Quartz; |
| | | using Serilog; |
| | | using WIDESEA_Core; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Common.Constants; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | using WIDESEAWCS_Common.Constants; |
| | | using WIDESEAWCS_Tasks.StackerCraneJob; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | |
| | | /// <summary> |
| | | /// 日志记录器 |
| | | /// </summary> |
| | | private readonly ILogger<CommonStackerCraneJob> _logger; |
| | | private readonly ILogger _logger; |
| | | |
| | | /// <summary> |
| | | /// 堆垛机设备编码 |
| | |
| | | ITaskRepository taskRepository, |
| | | IRouterService routerService, |
| | | HttpClientHelper httpClientHelper, |
| | | ILogger<CommonStackerCraneJob> logger) |
| | | ILogger logger) |
| | | { |
| | | _taskService = taskService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | |
| | | { |
| | | try |
| | | { |
| | | //QuartzLogger.Info($"CommonStackerCraneJob Execute:开始执行堆垛机任务调度 【{DateTime.Now.ToString("F")}】", "CommonStackerCraneJob Execute "); |
| | | // 从 JobDataMap 获取堆垛机设备参数 |
| | | bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); |
| | | if (!flag || value is not CommonStackerCrane commonStackerCrane) |
| | | { |
| | | // 参数无效,直接返回 |
| | | QuartzLogHelper.LogWarn(_logger, "Execute:参数无效", "Execute:参数无效", "CommonStackerCraneJob"); |
| | | QuartzLogHelper.LogInfo(_logger, "Execute:参数无效", "CommonStackerCraneJob"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | |
| | | |
| | | // ========== 检查是否可以发送新任务 ========== |
| | | //if (!commonStackerCrane.IsCanSendTask(commonStackerCrane.Communicator, commonStackerCrane.DeviceProDTOs, commonStackerCrane.DeviceProtocolDetailDTOs)) |
| | | if (commonStackerCrane.StackerCraneStatusValue != StackerCraneStatus.Normal ) |
| | | if (commonStackerCrane.StackerCraneStatusValue != StackerCraneStatus.Normal) |
| | | { |
| | | // 堆垛机不可用(如正在执行上一任务),直接返回 |
| | | return Task.CompletedTask; |
| | |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | |
| | | |
| | | // ========== 构建命令 ========== |
| | | // 命令构建下沉到专用构建器 |
| | | object? stackerCraneTaskCommand = _commandBuilder.ConvertToStackerCraneTaskCommand(task); |
| | | if (stackerCraneTaskCommand == null) |
| | | { |
| | | // 命令构建失败 |
| | | QuartzLogHelper.LogWarn(_logger, "Execute:命令构建失败,设备: {DeviceCode},任务号: {TaskNum}", $"命令构建失败,任务号: {task.TaskNum}", _deviceCode, _deviceCode, task.TaskNum); |
| | | QuartzLogHelper.LogInfo(_logger, $"Execute:命令构建失败,设备: {_deviceCode},任务号: {task.TaskNum}", _deviceCode); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | |
| | | commonStackerCrane.LastTaskType = task.TaskType; |
| | | _taskService.UpdateTaskStatusToNext(task.TaskNum); |
| | | |
| | | QuartzLogHelper.LogInfo(_logger, "Execute:命令发送成功,设备: {DeviceCode},任务号: {TaskNum}", $"命令发送成功,任务号: {task.TaskNum}", _deviceCode, _deviceCode, task.TaskNum); |
| | | QuartzLogHelper.LogInfo(_logger, $"Execute:命令发送成功,设备: {_deviceCode},任务号: {task.TaskNum}", _deviceCode); |
| | | } |
| | | else |
| | | { |
| | | QuartzLogHelper.LogError(_logger, "Execute:命令发送失败,设备: {DeviceCode},任务号: {TaskNum}", $"命令发送失败", _deviceCode, _deviceCode, task.TaskNum); |
| | | QuartzLogHelper.LogInfo(_logger, $"Execute:命令发送失败,设备: {_deviceCode},任务号: {task.TaskNum}", _deviceCode); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录异常 |
| | | QuartzLogHelper.LogError(_logger, ex, "Execute:执行异常,设备: {DeviceCode}", $"执行异常: {ex.Message}", _deviceCode, _deviceCode); |
| | | QuartzLogHelper.LogError(_logger, ex, $"Execute:执行异常,设备: {_deviceCode}", $"执行异常: {ex.Message}", _deviceCode, _deviceCode); |
| | | } |
| | | finally |
| | | { |
| | | QuartzLogHelper.LogInfo(_logger, $"CommonStackerCraneJob Execute:堆垛机任务调度执行完成 【{DateTime.Now.ToString("F")}】", _deviceCode); |
| | | } |
| | | |
| | | return Task.CompletedTask; |
| | |
| | | if (stackerCrane != null) |
| | | { |
| | | // 记录日志 |
| | | QuartzLogHelper.LogInfo(_logger, "CommonStackerCrane_StackerCraneTaskCompletedEventHandler:任务完成,任务号: {TaskNum}", $"任务完成,任务号: {e.TaskNum}", stackerCrane.DeviceCode, e.TaskNum); |
| | | QuartzLogHelper.LogInfo(_logger, $"CommonStackerCrane_StackerCraneTaskCompletedEventHandler:任务完成,任务号: {e.TaskNum}", stackerCrane.DeviceCode); |
| | | |
| | | // 更新任务状态为完成 |
| | | if (_taskService.StackCraneTaskCompleted(e.TaskNum).Status) |