@Author Jarrett Luo @Date 2022/10/20 17:59 @Version 1.0
| 23 | * @Version 1.0 |
| 24 | */ |
| 25 | @Slf4j |
| 26 | public class MainTask implements RunnableTask { |
| 27 | |
| 28 | private final TaskExecutor taskExecutor; |
| 29 | |
| 30 | private final TaskData taskData = new TaskData(); |
| 31 | |
| 32 | /** |
| 33 | * @Author luojiarui |
| 34 | * @Description // 初始化任务,指定一个 |
| 35 | * @Date 15:43 2022/11/13 |
| 36 | * @Param [fileDocument] |
| 37 | **/ |
| 38 | public MainTask(FileDocument fileDocument) { |
| 39 | taskData.setFileDocument(fileDocument); |
| 40 | taskData.setThumbFilePath(""); |
| 41 | taskData.setThumbFilePath(""); |
| 42 | String fileSuffix = fileDocument.getSuffix(); |
| 43 | DocType docType = DocType.getDocType(fileSuffix); |
| 44 | taskData.setDocType(docType); |
| 45 | this.taskExecutor = TaskExecutorFactory.getTaskExecutor(docType); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @Author luojiarui |
| 50 | * @Description 成功以后更新文件 |
| 51 | * @Date 18:17 2022/11/13 |
| 52 | * @Param [] |
| 53 | **/ |
| 54 | @Override |
| 55 | public void success() { |
| 56 | taskData.getFileDocument().setDocState(DocStateEnum.SUCCESS); |
| 57 | updateTaskStatus(); |
| 58 | |
| 59 | // 更新文档的数据 |
| 60 | IFileService fileService = SpringApplicationContext.getBean(IFileService.class); |
| 61 | fileService.updateFile(taskData.getFileDocument()); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void failed(Throwable throwable) { |
| 66 | log.error("解析文件报错啦", throwable); |
| 67 | String errorMsg = throwable.getMessage(); |
| 68 | taskData.getFileDocument().setDocState(DocStateEnum.FAIL); |
| 69 | taskData.getFileDocument().setErrorMsg(errorMsg +" " + throwable.getCause()); |
| 70 | updateTaskStatus(); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void run() { |
| 75 | FileDocument fileDocument = taskData.getFileDocument(); |
| 76 | if (null == taskExecutor || fileDocument == null) { |
| 77 | log.error("执行文件{}报错",fileDocument); |
| 78 | throw new TaskRunException("当前执行器初始化失败!"); |
| 79 | } |
| 80 | if (StringUtils.hasText(fileDocument.getThumbId()) || StringUtils.hasText(fileDocument.getTextFileId())) { |
| 81 | removeExistGridFs(); |
| 82 | } |
nothing calls this directly
no outgoing calls
no test coverage detected