Flowable 实现【选择下一步流程审核人】

原理:

  1. 在流程表单数据正式提交审核前,将流程表单数据 formData 及流程执行实例 ExecutionEntity 传递给接口
  2. 接口在流程定义取得当前节点信息并循环查找出线 SequenceFlow 还需要注意遇到网关时应该怎样处理
  3. 使用变量执行出线 SequenceFlow 条件(类似完成提交任务操作)
  4. 找出第一个用户任务UserTask 根据这个UserTask中信息,我们就能拿到流程审核人了
  5. 最重要的一点,在第三点中使用变量去执行条件的时候,变量会被持久化至数据库中,所以我们一定要在事务中进行操作,操作完成后回滚清空当前事务,避免数据紊乱

项目完整源码链接

以下是全部代码,此逻辑仅供参考

1package com.nutzfw.core.plugin.flowable.cmd; 2 3import org.apache.commons.collections.CollectionUtils; 4import org.flowable.bpmn.model.*; 5import org.flowable.common.engine.impl.interceptor.Command; 6import org.flowable.common.engine.impl.interceptor.CommandContext; 7import org.flowable.engine.impl.persistence.entity.ExecutionEntity; 8import org.flowable.engine.impl.util.condition.ConditionUtil; 9 10import java.util.List; 11import java.util.Map; 12 13/** 14 * @author huchuc@vip.qq.com 15 * @date: 2019/7/9 16 * 使用示例,一定要放到事务中,否则变量会入库,导致数据紊乱 17 * try { 18 * Trans.begin(); 19 * UserTask userTask = managementService.executeCommand(new FindNextUserTaskNodeCmd(execution, bpmnModel, vars)); 20 * System.out.println(userTask.getId()); 21 * } finally { 22 * Trans.clear(true); 23 * } 24 */ 25public class FindNextUserTaskNodeCmd implements Command<UserTask> { 26 27 private final ExecutionEntity execution; 28 private final BpmnModel bpmnModel; 29 private Map<String, Object> vars; 30 /** 31 * 返回下一用户节点 32 */ 33 private UserTask nextUserTask; 34 35 /** 36 * @param execution 当前执行实例 37 * @param bpmnModel 当前执行实例的模型 38 * @param vars 参与计算流程条件的变量 39 */ 40 public FindNextUserTaskNodeCmd(ExecutionEntity execution, BpmnModel bpmnModel, Map<String, Object> vars) { 41 this.execution = execution; 42 this.bpmnModel = bpmnModel; 43 this.vars = vars; 44 } 45 46 /** 47 * @param execution 当前执行实例 48 * @param bpmnModel 当前执行实例的模型 49 */ 50 public FindNextUserTaskNodeCmd(ExecutionEntity execution, BpmnModel bpmnModel) { 51 this.execution = execution; 52 this.bpmnModel = bpmnModel; 53 } 54 55 @Override 56 public UserTask execute(CommandContext commandContext) { 57 execution.setVariables(vars); 58 FlowElement currentNode = bpmnModel.getFlowElement(execution.getActivityId()); 59 List<SequenceFlow> outgoingFlows = ((FlowNode) currentNode).getOutgoingFlows(); 60 if (CollectionUtils.isNotEmpty(outgoingFlows)) { 61 this.findNextUserTaskNode(outgoingFlows, execution); 62 } 63 return nextUserTask; 64 } 65 66 67 void findNextUserTaskNode(List<SequenceFlow> outgoingFlows, ExecutionEntity execution) { 68 sw: 69 for (SequenceFlow outgoingFlow : outgoingFlows) { 70 if (ConditionUtil.hasTrueCondition(outgoingFlow, execution)) { 71 if (outgoingFlow.getTargetFlowElement() instanceof ExclusiveGateway) { 72 //只有排他网关才继续 73 ExclusiveGateway exclusiveGateway = (ExclusiveGateway) outgoingFlow.getTargetFlowElement(); 74 findNextUserTaskNode(exclusiveGateway.getOutgoingFlows(), execution); 75 } else if (outgoingFlow.getTargetFlowElement() instanceof UserTask) { 76 nextUserTask = (UserTask) outgoingFlow.getTargetFlowElement(); 77 //找到第一个符合条件的userTask就跳出循环 78 break sw; 79 } 80 } 81 } 82 } 83}
点赞
收藏

评论区

加载中...

相关推荐

Git学习

已有项目添加到Git操作流程:1.在一个目录下执行gitinit,会将当前目录创建为git仓库gitinit2.执行gitadd.把当前目录下所有文件添加到仓库gitadd.3.把添加的文件提交到本地仓库gitcommitm'Firstcommit'4.添加remote及验证remote。

Java Activiti6.0 spring5 SSM 工作流引擎 审批流程 java项目框架

1.模型管理:web在线流程设计器、预览流程xml、导出xml、部署流程2.流程管理:导入导出流程资源文件、查看流程图、根据流程实例反射出流程模型、激活挂起3.运行中流程:查看流程信息、当前任务节点、当前流程图、作废暂停流程、指派待办人4.历史的流程:查看流程信息、流程用时、流程状态、查看任务发起人信息5.待办任务:查看本人个人任务以及

Flowable论坛提问记录

1\.ExclusiveGateway之后的SequenceFlow同时配置了skipexpress和conditionexpression,流程如何走?https://forum.flowable.org/t/questionaboutskipexpressionofsequenceflowoutgoingfromexc

Activiti的流程配置

在使用activiti做流程引擎的时候,某些节点的执行人是固定的,但是有些节点的执行人不是固定的,为了进一步的简化用户操作,我们可以将固定执行人的任务节点预先配置好,这样在启动流程的时候用户配置的节点就会进一步的得到简化。废话不多说,数据库的表结构如下:!(https://static.oschina.net/uploads/space/2016

JEPLUS工作流之判断流程——JEPLUS软件快速开发平台

JEPLUS工作流之判断流程判断流程就是可以在流程过程根据一定得条件来判断,当达到某一个条件时执行后面得流程,当达成另外一个条件时执行另外得流程。一、效果展示!image.png(http://www.jestq.com/JE/data/upload/ckeditor/201807/153128952135201

Flask 【第十篇】自定义Form组件

一、wtforms源码流程1、实例化流程分析源码流程1.执行type的__call__方法,读取字段到静态字段cls._unbound_fields中;meta类读取到cls._wtforms_meta中2.执行构造方法a.循环cls.