@Override
public void getNextStepList(String taskId, String processInstanceId) throws IllegalAccessException {
// taskService、repositoryService 等容器对象获取省略...
// 存储当前节点的下一环节的所有用户节点
ArrayList<UserTask> userTaskList = new ArrayList<>();
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
//获取流程定义id
String definitionId = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult().getProcessDefinitionId();
//获取bpmn对象
BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionId);
//遍历返回下一个环节所有用户节点
getNextUserTaskList(userTaskList, bpmnModel, task.getTaskDefinitionKey());
//输出
for (UserTask userTask : userTaskList) {
System.out.println("下一个节点id:" + userTask.getId() + " 下一个节点名称:" + userTask.getName()+" 下一个节点审批人:" + userTask.getAssignee()+" 下一个节点候选组:" + (userTask.getCandidateGroups()!=null?userTask.getCandidateGroups().get(0):""));
}
}
private void getNextUserTaskList(ArrayList<UserTask> userTaskList, BpmnModel bpmnModel, String currentId) {
//通过节点定义id获取当前节点
FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(currentId);
//当前节点所有输出顺序流
List<SequenceFlow> outgoingFlows = flowNode.getOutgoingFlows();
FlowElement targetFlowElement = null;
for (SequenceFlow outgoingFlow : outgoingFlows) {
// 忽略非正常流转的节点,"${pass}"为自定义的流转表达式
if (outgoingFlow.getConditionExpression() != null && !"${pass}".equals(outgoingFlow.getConditionExpression())) {
continue;
}
targetFlowElement = outgoingFlow.getTargetFlowElement();
//用户节点
if (targetFlowElement instanceof UserTask) {
userTaskList.add((UserTask) targetFlowElement);
} else if (targetFlowElement instanceof EndEvent) {
// 结束节点
}else {
// 没有找到用户节点,且下一节点不是最后一个节点,继续查找
getNextUserTaskList(userTaskList, bpmnModel, targetFlowElement.getId());
}
}
}
05-15
2192
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-08