栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

activiti实现跳转节点的方法

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

activiti实现跳转节点的方法

1.通过代码实现,即获取到当前节点,然后退回到已走过的指定节点。代码如下:

@RequestMapping("/returnNode")
    public String returnNode(String taskId) {
        // 取得当前任务.当前任务节点
        HistoricTaskInstance currTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
        // 取得所有历史任务按时间降序排序
        List hisInstances = historyService.createHistoricTaskInstanceQuery().processInstanceId(currTask.getProcessInstanceId()).orderByTaskCreateTime().desc().list();
        if(ObjectUtils.isEmpty(hisInstances)||hisInstances.size()<2){
            return "fail";
        }
        //目的节点
        HistoricTaskInstance lastTask = null;
        //所有目的节点的历史记录
        List commitList = historyService.createHistoricTaskInstanceQuery().processInstanceId(currTask.getProcessInstanceId()).taskName("one").orderByTaskCreateTime().asc().list();
        lastTask=commitList.get(0);
        if (null==lastTask){
            return "fail";
        }
        // 目的节点的taskId
        String lastTaskId = lastTask.getId();
        // 目的节点的executionId
        String lastExecutionId = lastTask.getExecutionId();
        //目的节点对应的流程定义ID
        String processDefinitionId = lastTask.getProcessDefinitionId();
        //对应的流程图文件
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
        String lastActivityId = null;
        //获取所有和目的节点任务名一样的已完成的历史记录
        List finishedList = historyService.createHistoricActivityInstanceQuery().executionId(lastExecutionId).finished().list();
        for (HistoricActivityInstance f: finishedList){
            if(lastTaskId.equals(f.getTaskId())){
                lastActivityId=f.getActivityId();
                break;
            }
        }
        FlowNode lastFlowNode = (FlowNode)bpmnModel.getMainProcess().getFlowElement(lastActivityId);
// 取得当前节点的信息
        // 当前节点的executionId
        String curExecutionId = currTask.getExecutionId();
        Execution execution = runtimeService.createExecutionQuery().executionId(curExecutionId).singleResult();
        String curActivityId = execution.getActivityId();
        FlowNode curFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(curActivityId);
        //记录当前节点的原活动方向
        List oriSequenceFlows = new ArrayList<>();
        oriSequenceFlows.addAll(curFlowNode.getOutgoingFlows());
        //清理活动方向
        curFlowNode.getOutgoingFlows().clear();
        //建立新方向
        List newSequenceFlowList = new ArrayList<>();
        SequenceFlow newSequenceFlow = new SequenceFlow();
        newSequenceFlow.setId("newSequenceFlowId");
        newSequenceFlow.setSourceFlowElement(curFlowNode);
        newSequenceFlow.setTargetFlowElement(lastFlowNode);
        newSequenceFlowList.add(newSequenceFlow);
        curFlowNode.setOutgoingFlows(newSequenceFlowList);
        // 完成任务
        taskService.complete(taskId);
        return "成功";
    }

对应的流程图如下:

上述代码可以实现从two节点退回到one节点

2.通过排他网关实现,流程图如下:

通过设置two节点完成时的参数确定流程图是退回到one节点还是结束。 

注意,方法一不会自动删除流程中的参数,需要手动删除,如果通过网关退回,可以实现退回后之前的流程变量自动被删除。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/305956.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号