Browse Source

日常维护启动改成异步线程执行修改

zhongwei
段飞宇 1 year ago
parent
commit
52a4747974
  1. 41
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java

41
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 * @param ids
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void createTask(List<String> ids) { public void createTask(List<String> ids) {
try { try {
//获取日常维护计划 //获取日常维护计划
@ -325,36 +326,22 @@ public class MaintenanceServiceImpl implements MaintenanceService {
} }
taskService.save(taskEntity); taskService.save(taskEntity);
dataSourceTransactionManager.commit(transaction); dataSourceTransactionManager.commit(transaction);
OperMaintenanceTaskEntity[] finalTaskEntity = {taskEntity};
CompletableFuture<String> processInstanceIdCompletableFuture = CompletableFuture.supplyAsync(() -> {
//生成工作流实例
String processInstanceId = this.startProcess(finalPlanEntity.getProcDefId(), finalTaskEntity[0]);
return processInstanceId;
}, executor);
//启动流程 //启动流程
CompletableFuture<OperMaintenanceTaskEntity> operMaintenanceTaskEntityCompletableFuture = processInstanceIdCompletableFuture.thenApplyAsync((processInstanceId) -> { String processInstanceId = this.startProcess(finalPlanEntity.getProcDefId(), taskEntity);
finalTaskEntity[0].setProcessInstanceId(processInstanceId); //推送消息
taskService.updateById(finalTaskEntity[0]); CompletableFuture<Void> operMaintenanceTaskEntityCompletableFuture =
finalPlanEntity.setCreateTaskTime(new Date()); CompletableFuture.runAsync(() -> {
maintenancePlanService.updateById(finalPlanEntity); taskEntity.setProcessInstanceId(processInstanceId);
finalTaskEntity[0] = taskService.getById(finalTaskEntity[0].getId()); taskService.updateById(taskEntity);
return finalTaskEntity[0]; finalPlanEntity.setCreateTaskTime(new Date());
}, executor); maintenancePlanService.updateById(finalPlanEntity);
OperMaintenanceTaskEntity maintenanceTask = taskService.getById(taskEntity.getId());
//推送消息
CompletableFuture<Void> thennedAcceptAsync = operMaintenanceTaskEntityCompletableFuture.thenAcceptAsync((task) -> { this.pushTaskMessage(maintenanceTask);
//推送消息 }, executor);
this.pushTaskMessage(task);
}, executor);
//启动队列 //启动队列
try { try {
CompletableFuture.allOf(processInstanceIdCompletableFuture, operMaintenanceTaskEntityCompletableFuture, CompletableFuture.allOf(operMaintenanceTaskEntityCompletableFuture).get();
thennedAcceptAsync).get();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

Loading…
Cancel
Save