根据流程实例ID和流程任务ID获取所有任务节点
需要processInstanceId和taskId
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
ProcessInstance processInstance = query.processInstanceId(processInstanceId).singleResult();
//查询当前实例ID
String processDefinitionId = processInstance.getProcessDefinitionId();
//查询当前节点任务对象
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
String taskDefinitionKey = task.getTaskDefinitionKey();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
Process process = bpmnModel.getProcesses().get(0);
//获取所有普通任务节点
List<UserTask> UserTaskList = process.findFlowElementsOfType(UserTask.class);
for(UserTask userTask:UserTaskList){
//获取当前任务节点Id
String id = userTask.getId();
if(id.equals(taskDefinitionKey)){
//获取当前任务节点的所有出线信息
List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
for(SequenceFlow sequenceFlow:outgoingFlows){
//获取出线连接的目标节点
FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement();
//获取到了下一个节点的Id
String nextId = targetFlowElement.getId();
List<UserTask> UserTaskLists = process.findFlowElementsOfType(UserTask.class);
//再次遍历所有普通任务节点
for(UserTask userTasks:UserTaskLists) {
//获取任务节点Id
String flowId = userTasks.getId();
//如果遍历的某个任务节点Id等于下一个节点的Id
if (flowId.equals(nextId)) {
//获取下一个任务节点的执行人
String assignee = userTasks.getAssignee();
.....
}
}
}
}
}