Flowable获取节点信息

15 篇文章 0 订阅

1、传入当前任务ID,和当前任务的一个选择条件值(测试后发现传入任何值都行)

/**
     * 下一节点名称
     * @param taskId 流程id
     * @return
     */
    public void findFlowNode(String taskId, Object approved) { // taskId:任务ID,approved:任意选择条件
        //当前任务信息
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        //ProcessInstanceId流程实例
        String processlnstanceld = task.getProcessInstanceId();
        Map<String, Object> data = new HashMap<>();
        data.put("approved", approved);
        //获取流程发布工的信息
        String definitionld = runtimeService.createProcessInstanceQuery().processInstanceId(processlnstanceld).singleResult().getProcessDefinitionId();        //获取bpm(模型)对象
        BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionld);
        //传节点定义key获取当前节点
        FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey());
        // 获取本节点的Id和Name
        System.out.println("当前节点Id" + flowNode.getId());
        System.out.println("当前节点名称" + flowNode.getName());
        //输出连线
        List<SequenceFlow> outgoingFlows = flowNode.getOutgoingFlows();
        //遍历返回下一个节点信息
        for (SequenceFlow outgoingFlow : outgoingFlows) {
            //类型自己判断(获取下个节点是网关还是节点)
            FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement();
            //下个是节点
            if(targetFlowElement instanceof UserTask) {
                // 判断是否是会签
                UserTask userTask = (UserTask) targetFlowElement;
                if (userTask.getBehavior() instanceof ParallelMultiInstanceBehavior) {
                    ParallelMultiInstanceBehavior behavior = (ParallelMultiInstanceBehavior) userTask.getBehavior();
                    if (behavior != null && behavior.getCollectionExpression() != null) {
						System.out.println("当前节点是会签");
                    }
                }else {
                    System.out.println("当前节点不是会签");
                }
                if (approvalFlowNodeDto.getBehaviorFlag()) { // 下个节点是会签
                	// 会签的候选用户Key
                    String assignees =((UserTask) targetFlowElement).getAssignee();;
					System.out.println("获取会签的id");
					String nextCandidateUsers = (((UserTask) targetFlowElement).getLoopCharacteristics().getInputDataItem());
					System.out.println("获取会签的collection,候选人List",nextCandidateUsers);
                } else { // 下个节点不是会签
                    String candidateUserses = ((UserTask) targetFlowElement).getCandidateUsers().get(0);
                    System.out.println("获取用户节点的candidateUsers,候选人",candidateUserses);
                    String candidateUsers = candidateUserses.substring(candidateUserses.indexOf("{")+1, candidateUserses.indexOf("}"));
                    System.out.println("查询出的值是${submitUser},截取获取用户节点的candidateUsers,候选人",candidateUsers);
                }
                System.out.println("下一节点: id=" + targetFlowElement.getId() + ",name=" + targetFlowElement.getName());
            }else if(targetFlowElement instanceof ExclusiveGateway){// 下个节点是网关(调用下面的方法)
                setExclusiveGateway(targetFlowElement,data);
            }
        }
    }

2、网关节点的方法

/**
     * 获取排他网关分支名称、分支表达式、下一级任务节点
     * @param flowElement
     * @param data
     */
    private void setExclusiveGateway(FlowElement flowElement,Map data){
    	// 获取所有网关分支
        List<SequenceFlow> targetFlows=((ExclusiveGateway)flowElement).getOutgoingFlows();
        // 循环每个网关分支
        for(SequenceFlow sequenceFlow : targetFlows){
            // 获取下一个网关和节点数据
            FlowElement targetFlowElement=sequenceFlow.getTargetFlowElement();
            // 网关数据不为空
            if (org.apache.commons.lang.StringUtils.isNotBlank(sequenceFlow.getConditionExpression())) {
                //计算连接线上的表达式
                Object result = managementService.executeCommand(new ExpressionEvaluateUtil(sequenceFlow.getConditionExpression(), data));
                System.out.println("排他网关中线条: id=" + sequenceFlow.getId() + ",name=" + sequenceFlow.getName()+",result="+result+",ConditionExpression="+sequenceFlow.getConditionExpression());
                // 获取网关判断条件
                String conditionExpression = null;
                if (sequenceFlow.getConditionExpression() != null) {
                    conditionExpression = sequenceFlow.getConditionExpression().substring(sequenceFlow.getConditionExpression().indexOf("==")+2,
                            sequenceFlow.getConditionExpression().indexOf("}"));
                }
                System.out.println("截取后的选择条件: id=" + conditionExpression);
            }
            // 网关的下个节点是用户节点
            if(targetFlowElement instanceof UserTask){
                // 判断是否是会签
                UserTask userTask = (UserTask) targetFlowElement;
                if (userTask.getBehavior() instanceof ParallelMultiInstanceBehavior) {
                    ParallelMultiInstanceBehavior behavior = (ParallelMultiInstanceBehavior) userTask.getBehavior();
                    if (behavior != null && behavior.getCollectionExpression() != null) {
                        System.out.println("当前节点是会签");
                    }
                }else {
                    System.out.println("当前节点不是会签");
                }
                System.out.println("排他网关的下一节点是UserTask: id=" + targetFlowElement.getId() + ",name=" + targetFlowElement.getName());
                System.out.println("排他网关的下一节点CandidateUsers候选者"+ ((UserTask) targetFlowElement).getCandidateUsers());
                if (BehaviorFlag()----自己去前边判断) { // 会签的候选用户Key
                	// 判断会签用户的用户提交人的List
                    MultiInstanceLoopCharacteristics a = (((UserTask) targetFlowElement).getLoopCharacteristics());
                    // "获取会签的collection,候选人List"
                    String = nextCandidateUsers(((UserTask) targetFlowElement).getLoopCharacteristics().getInputDataItem());
                } else { //不是会签
                	// 获取用户的候选人
                    String candidateUserses = ((UserTask) targetFlowElement).getCandidateUsers().get(0);
                    // 截取候选人的值
                    String candidateUsers = candidateUserses.substring(candidateUserses.indexOf("{")+1, candidateUserses.indexOf("}"));
                }
            }else if(targetFlowElement instanceof EndEvent){
                System.out.println("排他网关的下一节点是EndEvent: 结束节点");
            }else if(targetFlowElement instanceof ServiceTask){
                System.out.println("排他网关的下一节点是ServiceTask: 内部方法");
            }else if(targetFlowElement instanceof ExclusiveGateway){
                setExclusiveGateway(targetFlowElement,data);
            }else if(targetFlowElement instanceof SubProcess){
                System.out.println("排他网关的下一节点是SubProcess: 内部子流程");
            }
        }
    }
  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值