Browse Source

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

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

33
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<String> ids) {
try {
//获取日常维护计划
@ -325,36 +326,22 @@ public class MaintenanceServiceImpl implements MaintenanceService {
}
taskService.save(taskEntity);
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) -> {
finalTaskEntity[0].setProcessInstanceId(processInstanceId);
taskService.updateById(finalTaskEntity[0]);
String processInstanceId = this.startProcess(finalPlanEntity.getProcDefId(), taskEntity);
//推送消息
CompletableFuture<Void> operMaintenanceTaskEntityCompletableFuture =
CompletableFuture.runAsync(() -> {
taskEntity.setProcessInstanceId(processInstanceId);
taskService.updateById(taskEntity);
finalPlanEntity.setCreateTaskTime(new Date());
maintenancePlanService.updateById(finalPlanEntity);
finalTaskEntity[0] = taskService.getById(finalTaskEntity[0].getId());
return finalTaskEntity[0];
}, executor);
CompletableFuture<Void> thennedAcceptAsync = operMaintenanceTaskEntityCompletableFuture.thenAcceptAsync((task) -> {
OperMaintenanceTaskEntity maintenanceTask = taskService.getById(taskEntity.getId());
//推送消息
this.pushTaskMessage(task);
this.pushTaskMessage(maintenanceTask);
}, executor);
//启动队列
try {
CompletableFuture.allOf(processInstanceIdCompletableFuture, operMaintenanceTaskEntityCompletableFuture,
thennedAcceptAsync).get();
CompletableFuture.allOf(operMaintenanceTaskEntityCompletableFuture).get();
} catch (Exception e) {
e.printStackTrace();
}

Loading…
Cancel
Save