From 52a47479748053a0488526dc790d57adb18cc66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Fri, 14 Jul 2023 11:37:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=B8=B8=E7=BB=B4=E6=8A=A4=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=94=B9=E6=88=90=E5=BC=82=E6=AD=A5=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/MaintenanceServiceImpl.java | 41 ++++++++-------------- 1 file changed, 14 insertions(+), 27 deletions(-) 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(); }