diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java index 12f48bb..2031df8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java @@ -89,6 +89,7 @@ public class MaintenanceServiceImpl implements MaintenanceService { * @param ids */ @Override + @Transactional(rollbackFor = Exception.class) public void createTask(List ids) { try { //获取日常维护计划 @@ -325,36 +326,22 @@ public class MaintenanceServiceImpl implements MaintenanceService { } taskService.save(taskEntity); dataSourceTransactionManager.commit(transaction); - - OperMaintenanceTaskEntity[] finalTaskEntity = {taskEntity}; - - CompletableFuture processInstanceIdCompletableFuture = CompletableFuture.supplyAsync(() -> { - //生成工作流实例 - String processInstanceId = this.startProcess(finalPlanEntity.getProcDefId(), finalTaskEntity[0]); - return processInstanceId; - }, executor); - //启动流程 - CompletableFuture operMaintenanceTaskEntityCompletableFuture = processInstanceIdCompletableFuture.thenApplyAsync((processInstanceId) -> { - finalTaskEntity[0].setProcessInstanceId(processInstanceId); - taskService.updateById(finalTaskEntity[0]); - finalPlanEntity.setCreateTaskTime(new Date()); - maintenancePlanService.updateById(finalPlanEntity); - finalTaskEntity[0] = taskService.getById(finalTaskEntity[0].getId()); - return finalTaskEntity[0]; - }, executor); - - - CompletableFuture thennedAcceptAsync = operMaintenanceTaskEntityCompletableFuture.thenAcceptAsync((task) -> { - //推送消息 - this.pushTaskMessage(task); - }, executor); - - + String processInstanceId = this.startProcess(finalPlanEntity.getProcDefId(), taskEntity); + //推送消息 + CompletableFuture operMaintenanceTaskEntityCompletableFuture = + CompletableFuture.runAsync(() -> { + taskEntity.setProcessInstanceId(processInstanceId); + taskService.updateById(taskEntity); + finalPlanEntity.setCreateTaskTime(new Date()); + maintenancePlanService.updateById(finalPlanEntity); + OperMaintenanceTaskEntity maintenanceTask = taskService.getById(taskEntity.getId()); + //推送消息 + this.pushTaskMessage(maintenanceTask); + }, executor); //启动队列 try { - CompletableFuture.allOf(processInstanceIdCompletableFuture, operMaintenanceTaskEntityCompletableFuture, - thennedAcceptAsync).get(); + CompletableFuture.allOf(operMaintenanceTaskEntityCompletableFuture).get(); } catch (Exception e) { e.printStackTrace(); }