Activiti 7流程跳转

 /**
     * 流程跳转
     *
     * @param taskId        taskId
     * @param targetTaskKey 目标节点id
     * @throws DCCException 跳转任务异常
     * @author huikf
     * @since 2021/3/13 12:46
     */
    public void jump(String taskId, String targetTaskKey) {
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        if (task == null) {
            //确定流程是否存在和是否在流转
            throw new DCCException("该任务不存在,无法执行该操作");
        }


        //获得当前流程的活动ID
        ExecutionQuery executionQuery = runtimeService.createExecutionQuery();
        Execution execution = executionQuery.executionId(task.getExecutionId()).singleResult();
        String activityId = execution.getActivityId();
    

    //获取当前节点和目标节点的节点信息
        FlowNode currentFlowNode = getFlowNode(task.getProcessDefinitionId(), activityId);
        FlowNode targetFlowNode = getFlowNode(task.getProcessDefinitionId(), targetTaskKey);

        if (targetFlowNode == null) {
            throw new DCCException("目标节点不存在,无法执行该操作");
        }
        if (currentFlowNode.getBehavior() instanceof MultiInstanceActivityBehavior) {
            throw new DCCException("当前节点为会签节点不支持该操作");
        }

        //获取当前节点的向下流转信息并备份
        List<SequenceFlow> oldFlowNodeOutgoingFlows = currentFlowNode.getOutgoingFlows();
     


   //清空当前节点流转走向,若清空的话流程图的获取可能会出现流转线消失的情况
        //创建新的流程走向并把当前节点执行目标节点
        SequenceFlow sequenceFlow = new SequenceFlow();
        sequenceFlow.setId("newTempSequenceId");
        sequenceFlow.setSourceFlowElement(currentFlowNode);
        sequenceFlow.setTargetFlowElement(targetFlowNode);
        List<SequenceFlow> newSequenceFlows = new ArrayList<>();
        newSequenceFlows.add(sequenceFlow);
        currentFlowNode.setOutgoingFlows(newSequenceFlows);
        taskService.complete(task.getId());
        taskService.deleteTask(task.getId(), false);
        //最后恢复原来的流转走向
        currentFlowNode.setOutgoingFlows(oldFlowNodeOutgoingFlows);
    }

    /**
     * 获取流节点
     *
     * @param processDefinitionId 流程定义id
     * @param activityId          activityId
     * @return org.activiti.bpmn.model.FlowNode
     * @author huikf
     * @since 2021/3/13 12:47
     */
    private FlowNode getFlowNode(String processDefinitionId, String activityId) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
        return (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityId);
    }
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值