在审批该节点之前,查询该节点的下一级审批节点的信息。
直接上代码:
public FlowElement getNextUserFlowElement(String processInstanceId){
Task task=taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
if (task==null){
throw new ServiceException("流程未启动或已执行完成");
}
// 取得已提交的任务
HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery()
.taskId(task.getId()).singleResult();
// 取得正在流转的流程实例,若已完成则为null
//getRuntimeProcessInstance是自己封装的获取流程实例的方法
ProcessInstance processInstance =getRuntimeProcessInstance(historicTaskInstance.getProcessInstanceId());
//每个流程实例只有一个executionId
//获得流程定义
ProcessDefinition processDefinition=repositoryService.getProcessDefinition(historicTaskInstance.getProcessDefinitionId());
//获得当前流程的活动ID
ExecutionQuery executionQuery =runtimeService.createExecutionQuery();
Execution execution =executionQuery.executionId(historicTaskInstance.getExecutionId()).singleResult();
String activityId=execution.getActivityId();
UserTask userTask =null;
while (true){
//根据活动节点获取当前的组件信息
FlowNode flowNode =getFlowNode(processDefinition.getId(),activityId);
//获取该流程组件的之后/之前的组件信息
List<SequenceFlow> sequenceFlowListOutGoing=flowNode.getOutgoingFlows();
// List<SequenceFlow> sequenceFlowListIncoming=flowNode.getIncomingFlows();
//获取的下个节点不一定是userTask的任务节点,所以要判断是否是任务节点
//sequenceFlowListOutGoing数量可能大于1,可以自己做判断,此处只取第一个
FlowElement flowElement =sequenceFlowListOutGoing.get(0).getTargetFlowElement();
if (flowElement instanceof UserTask){
userTask =(UserTask)flowElement;
System.out.println("获取该任务节点的审批信息...");
break;
}else {
//下一节点不是任务userTask的任务节点,所以要获取再下一个节点的信息,直到获取到userTask任务节点信息
String flowElementId=flowElement.getId();
activityId=flowElementId;
continue;
}
}
}
//根据活动节点和流程定义ID获取该活动节点的组件信息
public FlowNode getFlowNode(String processDefinitionId,String activityId){
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
FlowNode flowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityId);
return flowNode;
}
此种方法只适合当前审批节点和下一级审批节点间只有一条流程线的情况,若有多条线,则需要根据el表达式做相应的判断。
PS:很久之前看到的帖子,当时只看了一遍,之后根据印象慢慢写的,原文地址忘记了。。