天天看点

activiti&flowable获取下一个节点信息

直接贴代码,不懂可说明:

/**
 * 获取下一个节点的信息测试
 */
@Test
public void testNextTasks() {

    //流程实例id
    String processInstanceId = "5b945750-81db-11e9-a576-1a73f8e23adc";

    //当前任务信息
    Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();

    //获取流程发布Id信息
    String definitionId = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult().getProcessDefinitionId();

    //获取bpm对象
    BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionId);

    //传节点定义key 获取当前节点
    FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey());

    //输出连线
    List<SequenceFlow> outgoingFlows = flowNode.getOutgoingFlows();

    //遍历返回下一个节点信息
    for (SequenceFlow outgoingFlow : outgoingFlows) {
        //类型自己判断
        FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement();
        //用户任务
        if (targetFlowElement instanceof UserTask) {
            //。。。
        }
        else if (targetFlowElement instanceof ExclusiveGateway) {
            setExclusiveGateway(targetFlowElement);
        }
    }
}


private void setExclusiveGateway(FlowElement targetFlow) {
        //排他网关,获取连线信息
        List<SequenceFlow> targetFlows = ((ExclusiveGateway) targetFlow).getOutgoingFlows();
        for (SequenceFlow sequenceFlow : targetFlows) {
            //目标节点信息
            FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement();
            if (targetFlowElement instanceof UserTask) {
                // do something
            } else if (targetFlowElement instanceof EndEvent) {
                // do something
            } else if (targetFlowElement instanceof ServiceTask) {
               // do something
            } else if (targetFlowElement instanceof ExclusiveGateway) {
                //递归寻找
                setExclusiveGateway(targetFlowElement);
            } else if (targetFlowElement instanceof SubProcess) {
               // do something
            }     
        }
    }
//获取所有节点信息:
https://blog.csdn.net/double_hll123/article/details/97111583