activiti7 流程撤回的两种实现思路

13 篇文章 0 订阅
一、使用BpmnModel
/**
* @param processInstanceBusinessKey BUSINESS_KEY_
* @param userName 当前用户
**/
public void rollBackToAssignWoekFlow(String processInstanceBusinessKey, String userName){
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(processInstanceBusinessKey).singleResult();
        if(processInstance == null) {
            throw new CustomException("撤回失败,失败原因:未查到流程信息!");
        }

        String processInstanceId = processInstance.getProcessInstanceId();

        //获取流程模型
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
        if (null == bpmnModel) {
            throw new CustomException("撤回失败,失败原因:未查到流程信息!");
        }

        Process process = bpmnModel.getProcesses().get(0);

        // 当前待办的任务(激活的任务)
        org.activiti.engine.task.Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).active().singleResult();

        // 获取当前节点
        FlowNode currentFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(task.getTaskDefinitionKey());
        // List<SequenceFlow> outgoingFlows1 = currentFlowNode.getOutgoingFlows();

        // 退回的目标节点(当前用户已办理的最新节点)
        List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId)
                .taskAssignee(userName).orderByHistoricTaskInstanceEndTime().desc().list();
        HistoricTaskInstance historicTaskInstance = list.get(0);
        FlowNode targetFlowNode = (FlowNode) process.getFlowElement(historicTaskInstance.getTaskDefinitionKey());

        // 动态创建从当前任务节点到目标节点的连线
        SequenceFlow sequenceFlow4 = genarateSequenceFlow("test001","test-name",currentFlowNode,targetFlowNode,null,process);
        // currentFlowNode.getOutgoingFlows().clear();
        List<SequenceFlow> oldOutgoingFlows = currentFlowNode.getOutgoingFlows();
        // 将当前节点的向外连线设置成创建的连线
        currentFlowNode.setOutgoingFlows(List.of(sequenceFlow4));
        task.setAssignee(userName);
        taskService.complete(task.getId());    // 完成任务
        currentFlowNode.setOutgoingFlows(oldOutgoingFlows);    // 完成任务后将原来的连线设置回当前任务节点
    }
二、使用流程图设计撤回

在设计bpmn流程图时添加一个排他网关,使用表达式控制流程撤回(想到于退回功能)。
在这里插入图片描述

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值