| | |
| | | import com.mes.task.model.TaskExecutionResult; |
| | | import com.mes.task.service.MultiDeviceTaskService; |
| | | import com.mes.task.service.TaskExecutionEngine; |
| | | import com.mes.task.service.TaskStatusNotificationService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private final DeviceGroupRelationMapper deviceGroupRelationMapper; |
| | | private final TaskStepDetailMapper taskStepDetailMapper; |
| | | private final TaskExecutionEngine taskExecutionEngine; |
| | | private final TaskStatusNotificationService notificationService; |
| | | private final ObjectMapper objectMapper; |
| | | |
| | | @Override |
| | |
| | | save(task); |
| | | |
| | | try { |
| | | // 通知任务开始 |
| | | notificationService.notifyTaskStatus(task); |
| | | |
| | | TaskExecutionResult result = taskExecutionEngine.execute(task, groupConfig, devices, parameters); |
| | | task.setStatus(result.isSuccess() ? MultiDeviceTask.Status.COMPLETED.name() : MultiDeviceTask.Status.FAILED.name()); |
| | | task.setErrorMessage(result.isSuccess() ? null : result.getMessage()); |
| | | task.setEndTime(new Date()); |
| | | task.setResultData(writeJson(result.getData())); |
| | | updateById(task); |
| | | |
| | | // 通知任务完成 |
| | | notificationService.notifyTaskStatus(task); |
| | | |
| | | return task; |
| | | } catch (Exception ex) { |
| | | log.error("多设备任务执行异常, taskId={}", task.getTaskId(), ex); |