首页 > 解决方案 > Activiti - 结束进程实例结束的结束事件的名称

问题描述

我想获取我的流程实例结束的结束事件的名称。我正在使用 Activiti 版本 7(activit 的 spring boot starter)。有人可以帮忙吗?

标签: springactiviti

解决方案


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

您可以使用 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=activity和更新应用程序属性spring.activiti.dbHistoryUsed=true


推荐阅读