flowable实现多实例节点的自由跳转

简介: 最近弃用activiti,改用flowable,发现在实现多节点实例自由跳转时,有很大区别。自由跳转整理如下:import org.flowable.

最近弃用activiti,改用flowable,发现在实现多节点实例自由跳转时,有很大区别。
自由跳转整理如下:


import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.Process;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.FlowableEngineAgenda;
import org.flowable.engine.impl.cmd.NeedsActiveTaskCmd;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

import java.util.List;
import java.util.Map;


/**
 * @description: 自由跳转流程
 * @author: starmark
 * @create: 2018-10-13 09:22
 **/
public class ActJumpTaskCmd extends NeedsActiveTaskCmd<Boolean> {

    protected String processId;//执行实例id
    protected String targetNodeId;//目标节点
    protected Map<String, Object> formData;//变量
    protected String operationCode;
    public ActJumpTaskCmd(String taskId,   String processId, String targetNodeId, Map<String, Object> formData,String operationCode) {
        super(taskId);
        this.processId = processId;
        this.targetNodeId = targetNodeId;
        this.formData = formData;
        this.operationCode=operationCode;
    }


    @Override
    protected Boolean execute(CommandContext commandContext, TaskEntity task) {
        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
        ExecutionEntity rootExecution=  executionEntityManager.findChildExecutionsByParentExecutionId(processId).get(0);


        CommandContextUtil.getTaskService().deleteTask(task, true);

        List<ExecutionEntity> executionEntityList= executionEntityManager.findChildExecutionsByParentExecutionId(rootExecution.getId());
        for(ExecutionEntity executionEntity:executionEntityList){
            List<ExecutionEntity> executionEntityList2= executionEntityManager.findChildExecutionsByParentExecutionId(executionEntity.getId());

            for(ExecutionEntity executionEntity2:executionEntityList2){
                CommandContextUtil.getTaskService().deleteTasksByExecutionId(executionEntity2.getId());
                executionEntityManager.deleteChildExecutions(executionEntity2,"delete",true);
                executionEntityManager.delete(executionEntity2);
                CommandContextUtil.getVariableService().deleteVariablesByExecutionId(executionEntity2.getId());
            }
            CommandContextUtil.getTaskService().deleteTasksByExecutionId(executionEntity.getId());
            executionEntityManager.deleteChildExecutions(executionEntity,"delete",true);
            executionEntityManager.delete(executionEntity);
            CommandContextUtil.getVariableService().deleteVariablesByExecutionId(executionEntity.getId());
        }




        Process process = ProcessDefinitionUtil.getProcess(rootExecution.getProcessDefinitionId());
        FlowElement targetFlowElement = process.getFlowElement(targetNodeId);
        rootExecution.setCurrentFlowElement(targetFlowElement);
        FlowableEngineAgenda agenda = CommandContextUtil.getAgenda();
        agenda.planContinueProcessInCompensation(rootExecution);

        return true;
    }


}

看完代码,我们再说说过程,流程实例的驱动主要是靠表act_ru_execution来驱动的。前后跳转主要操作以下步骤:

  • 清除相关任务(act_ru_task)
  • 清除局部变量(act_ru_variable),注意是局部变量
  • 清除轨迹(act_ru_execution)
  • 保留act_ru_execution到只剩下两条记录再往下驱动流程.
    注意:activti自由跳转也是同样的道理.
    有朋友私信我,说我的代码不支持并行分支的驳回,这个确实是这样。
    但并行分支的驳回有两种。
  1. 分支内的驳回,即驳回前有多少条分支,驳回后还是有多少条分支,研究一下act_ru_execution,看清哪些数据再处理
  2. 分支外的驳回,即原来有5条分支,可能驳回后只有一条。这样的话,还是删除掉act_ru_execution到只剩下两条记录即可.
    后续有空,我再考虑这两种驳回吧!
相关文章
|
域名解析 Kubernetes Java
图文详述Nacos配置中心使用:应用间配置共享、扩展配置文件加载优先级、新老版本差异
图文详述Nacos配置中心使用:应用间配置共享、扩展配置文件加载优先级、新老版本差异
3949 1
图文详述Nacos配置中心使用:应用间配置共享、扩展配置文件加载优先级、新老版本差异
|
4月前
|
前端开发
基于jeecgboot的flowable流程支持退回到发起人节点表单修改功能
基于jeecgboot的flowable流程支持退回到发起人节点表单修改功能
471 0
|
1月前
|
缓存 前端开发
ProFlow 流程编辑器框架问题之创建一个自定义节点如何解决
ProFlow 流程编辑器框架问题之创建一个自定义节点如何解决
25 1
|
1月前
|
前端开发 算法
ProFlow 流程编辑器框架问题之FlowView 组件中添加节点和边缘数据如何解决
ProFlow 流程编辑器框架问题之FlowView 组件中添加节点和边缘数据如何解决
37 0
|
4月前
|
前端开发
基于jeecgboot的flowable流程增加节点自动跳过功能
基于jeecgboot的flowable流程增加节点自动跳过功能
272 2
|
4月前
|
移动开发 前端开发
flowable流程跳转或退回到网关上的用户节点后流程走不下去了
flowable流程跳转或退回到网关上的用户节点后流程走不下去了
197 2
|
4月前
|
移动开发 前端开发 数据库
ruoyi-nbcio 基于flowable规则的多重并发网关的任意跳转
ruoyi-nbcio 基于flowable规则的多重并发网关的任意跳转
114 0
|
4月前
|
前端开发
基于jeecgboot的flowable增加流程节点抄送功能
基于jeecgboot的flowable增加流程节点抄送功能
430 0
|
4月前
|
移动开发 前端开发
flowable多对并发网关跳转的分析
flowable多对并发网关跳转的分析
70 0
|
11月前
|
供应链
如何取消 SAP ALE 中已经配置的跨系统主数据验证
如何取消 SAP ALE 中已经配置的跨系统主数据验证