Activiti-结束流程实例在其中结束的结束事件的名称

时间:2020-08-24 09:55:27

标签: spring activiti

我想获取流程实例在其中结束的结束事件的名称。我正在使用Activiti版本7(activit的春季启动启动器)。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

嗨,我也有类似的问题,我知道这有点老了,但仍然...

您可以使用HistoryService来完成流程(假设您有一些ID)

@Autowired
private HistoryService historyService;

请考虑我的代码段,该代码段实际上会由于路径结尾而结束进程

Map<String, Object> params = new HashMap<>(); // Some params

Task task = taskService.createTaskQuery()
        .processInstanceId(processId)
        .singleResult();

taskService.complete(task.getId(), params); //params optional, this ends whole process 

List<HistoricVariableInstance> allVars = historyService
        .createHistoricVariableInstanceQuery()
        .processInstanceId(navTask.getProcessId())
        .list();
//return to user all filled in forms etc.

HistoricProcessInstance historicProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(navTask.getProcessId()).singleResult();
String endId = historicProcess.getEndActivityId(); //This returns ID where your process ended

如果结束活动的ID不够,您可以进行更多挖掘:

String procDefId = historicProcess.getProcessDefinitionId()
FlowElement  flowEl = repositoryService.getBpmnModel(procDefId).getMainProcess().getFlowElements()
       .stream()
       .filter(flowElement -> flowElement.getId().equals("endId"))
       .findFirst()
       .orElseThrow(IllegalStateException::new)
flowEl.getName() //your name and other stuff you need 

最后一个要点:就我而言,历史记录并没有保留,必须使用spring.activiti.historyLevel=activityspring.activiti.dbHistoryUsed=true

更新应用程序属性。