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


    一、使用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流程图时添加一个排他网关,使用表达式控制流程撤回(想到于退回功能)。

  • 相关阅读:
    css3实现酷炫的3D盒子翻转效果
    Java源码学习:HashMap实现原理
    mac 如何显示隐藏文件和.点开头文件?
    mac 下 安装 mongodb 数据库
    WPF 自定义TextBox
    Appium+Python 安卓APP自动化测试:安装app和卸载app
    Appium+Python 安卓APP自动化测试:环境搭建与基础操作
    DataFrame利用函数或映射进行数据转换map
    TypeError: drop_duplicates() got an unexpected keyword argument 'take_last'
    DataFrame合并:合并重叠数据combine_first
  • 原文地址:https://www.cnblogs.com/yourblog/p/15948299.html
Copyright © 2020-2023  润新知