Browse Source

退回报错

tags/24080901
PoffyZhang 1 year ago
parent
commit
740bb4fefb
1 changed files with 88 additions and 0 deletions
  1. +88
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/ProcessEndListener.java

+ 88
- 0
pmapi/src/main/java/com/ningdatech/pmapi/scheduler/listener/ProcessEndListener.java View File

@@ -0,0 +1,88 @@
package com.ningdatech.pmapi.scheduler.listener;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.pmapi.common.constant.BizConst;
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import com.ningdatech.pmapi.projectlib.model.entity.ProjectInst;
import com.ningdatech.pmapi.projectlib.service.IProjectInstService;
import com.ningdatech.pmapi.projectlib.service.IProjectService;
import com.wflow.workflow.notify.event.ProcessStartEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.HistoryService;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
* 工作流开始 结束监听 自动审批的话 会漏掉 调用状态机
*
* @author ZPF
* @return
* @since 2023/04/14 14:19
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class ProcessEndListener {
private final TaskService taskService;
private final HistoryService historyService;
private final IProjectInstService projectInstService;

private final IProjectService projectService;

private final StateMachineUtils stateMachineUtils;

@Async
@EventListener
public void onApplicationEvent(ProcessStartEvent event) {
log.info("进入工作流结束的 事件监听!{}", event.getInstCode());
String instCode = event.getInstCode();

log.info("instCode:{}", instCode);

//休息3秒
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

//1.去查找 项目实例关系表
ProjectInst projectInst = projectInstService.getOne(Wrappers.lambdaQuery(ProjectInst.class)
.eq(ProjectInst::getInstCode, instCode)
.last(BizConst.LIMIT_1));

if (Objects.isNull(projectInst)) {
return;
}

List<Task> tasks = taskService.createTaskQuery()
.processInstanceId(instCode)
.active()
.list();

List<HistoricTaskInstance> historyTasks = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(instCode)
.unfinished()
.list();

//已经没有任务了
if (CollUtil.isEmpty(tasks) && CollUtil.isEmpty(historyTasks)) {
Long projectId = projectInst.getProjectId();
Project project = projectService.getNewProject(projectId);
stateMachineUtils.pass(project);
project.setUpdateOn(LocalDateTime.now());
projectService.updateById(project);
}
}
}

Loading…
Cancel
Save