Ruoyi-Flowable(7.x版本)后端学习

学习ing.......

学习ing.......

学习ing.......

Flowable的表结构

必看:
Repository Tables | Flowable Enterprise Documentation
【Flowable】Flowable自动生成的数据库表的含义_flowable 自动创建表-CSDN博客
https://www.cnblogs.com/mjtabu/p/15982321.html
flowable数据表详解_flowable数据库表-CSDN博客
https://www.phpsdk.cn/plug/news/show.html?id=26587
flowable+springboot的使用_springboot flowable-CSDN博客
选看(版本较低,仅供参考):
activiti工作流数据库表详细说明_act_hi_procinst-CSDN博客
Activiti 数据库表结构 | 开发文档
略有价值 -> flowable38张表含义说明_flowable表说明-CSDN博客
flowable 表结构说明 - 简书
https://blog.51cto.com/u_15222067/5275645#page_top

🔔 提示:
  • 低版本和高版本的Flowable表会有所区别
  • 目前以Ruoyi-Flowable项目的6.8.0版本为主(稳定,可升级)
  • 6.8.0升级至7.0.0后,维持原有表可以正常使用

表名称结构(共三部分)

Flowable实战(二):表结构以及变量表单介绍_flowable 表单-CSDN博客

格式:xxx_xxx_**

第一部分:

  • ACT_(Activiti所需要关注的表)
  • FLW_(Flowable所需要关注的表)

例如:

以ACT_APP_APPDEF 和 FLW_CHANNEL_DEFINITION为例子。

  • ACT代表的Activiti 毕竟是同一批人另起的炉灶,另一方面遵循的都是BPMN还要考虑到兼容人家,方便客户转移过来。
  • ACT_APP_APPDEF看字面意思是应用定义表。
  • FLW估计就是Flowable的自己的时缩写。
  • FLW_CHANNEL_DEFINITION这个的意思是,Flowable支持JMS、Kafka和RabbitMQ源和目标,但也可以使用其他适配器类型进行扩展。部署通道定义时,新定义将插入到FLW_CHANNEL_DEFINITION表中,表明翻译过来Flowable的渠道定义。

第二部分:

说明表用途的两字符标示符,服务API的命名也大略符合这个规则。

RE表示流程定义和流程静态资源 (图片,规则,等等)。
RU表示流程实例,任务,变量,异步任务等运行中的数据。
HI表示历史数据,比如历史流程实例, 变量,任务等等。
CO表示连接
APP表示应用
GE 表示通用数据
......待补充
......待补充
......待补充

例如:

  • ACT_RE_:RE代表repository。带有这个前缀的表包含“静态”信息,例如流程定义与流程资源(图片、规则等)。
  • ACT_RU_:RU代表runtime。这些表存储运行时信息,例如流程实例(process instance)、用户任务(user task)、变量(variable)、作业(job)等。Flowable只在流程实例运行中保存运行时数据,并在流程实例结束时删除记录。这样保证运行时表小和快。
  • ACT_HI_:HI代表history。这些表存储历史数据,例如已完成的流程实例、变量、任务等。
  • ACT_GE_:GE代表general。通用数据。在多处使用。
  • ACT_ID_:ID代表identity 。组织机构,用户记录,流程中使用到的用户和组。这些表包含标识的信息,如用户,用户组,等等。
  • ACT_CMMN_:CMMN流程引擎数据
  • ACT_DMN_:DMN流程引擎
  • ACT_EVT_LOG_:事件日志
  • ACT_FO_:表单引擎数据
  • ACT_ID_:存储与用户身份相关数据
  • ACT_PRODEF_INFO_:流程定义的信息

第三部分:

基于第二部分,延伸的具体含义,此处略。

表清单

...待补充

...待补充

...待补充

关键字

hi:历史

case:案例

plan:计划

decision:决策

evt:事件

log:日志

form:表单

task:任务

procinst:流程实例

taskinst:任务实例

...待补充

...待补充

...待补充

Flowable的启动依赖与自动建表

官方文档: Spring Boot · Flowable Open Source Documentation
中文手册: Flowable BPMN 用户手册 (v 6.5.0-SNAPSHOT)
相关概念: 简述 BPMN && CMMN && DMN 协议区别以及应用场景 - 知乎
🔔 提示:
  • 选择不同的starter依赖,所需要用的以及自动创建的表也是不一样的
  • mysql的自动建表可能要加nullCatalogMeansCurrent=null
  • 其中,flowable-spring-boot-starter是最全的,推荐使用这个
  • flowable-spring-boot-starter-process是纯流程,也可以考虑
  • 目前以Ruoyi-Flowable的6.8.0版本为基础进行升级,不自动创建
<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-spring-boot-starter</artifactId>
    <version>7.0.0</version>
</dependency>

官网原文:

Starter

Description

flowable-spring-boot-starter-cmmn

Contains the dependencies for booting the CMMN Engine in Standalone mode

flowable-spring-boot-starter-cmmn-rest

Contains the dependencies for booting the CMMN Engine in Standalone mode and starts its REST API

flowable-spring-boot-starter-dmn

Contains the dependencies for booting the DMN Engine in Standalone mode

flowable-spring-boot-starter-dmn-rest

Contains the dependencies for booting the DMN Engine in Standalone mode and starts its REST API

flowable-spring-boot-starter-process

Contains the dependencies for booting the Process Engine in Standalone mode

flowable-spring-boot-starter-process-rest

Contains the dependencies for booting the Process Engine in Standalone mode and starts its REST API

flowable-spring-boot-starter

Contains the dependencies for booting all Flowable Engines (Process, CMMN, DMN, and IDM)

flowable-spring-boot-starter-rest

Contains the dependencies for booting all Flowable Engines and their respective REST API

flowable-spring-boot-starter-actuator

Contains the required dependencies for Spring Boot

中文手册:

Flowable 的Spring配置

官方文档: Spring Boot · Flowable Open Source Documentation
中文手册: Flowable BPMN 用户手册 (v 6.5.0-SNAPSHOT)
环境配置: https://www.cnblogs.com/xwbz/p/9858174.html
# flowable相关表
flowable:
  # true 会对数据库中所有表进行更新操作。如果表不存在,则自动创建(建议开发时使用)
  database-schema-update: false
  # 关闭定时任务JOB
  async-executor-activate: false

Flowable的Api调用

(必看)flowable工作流所有业务概念: https://www.phpsdk.cn/plug/news/show.html?id=26587
(必看) flowable+springboot的使用_springboot flowable-CSDN博客
基础教程: flowable - 知乎
实战教程: https://www.cnblogs.com/xwbz/p/9858174.html
官方文档: Spring Boot · Flowable Open Source Documentation
中文手册: Flowable BPMN 用户手册 (v 6.5.0-SNAPSHOT)
简介: flowable简介-CSDN博客

总入口点是ProcessEngine;

使用ProcessEngine,可以获得各种提供工作流/BPM方法的服务。

ProcessEngine与服务对象都是线程安全的,因此可以在服务器中保存并共用同一个引用。

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); // spring的项目可以直接导入pom依赖,然后@Autowired导入使用

RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
ManagementService managementService = processEngine.getManagementService();
IdentityService identityService = processEngine.getIdentityService();
HistoryService historyService = processEngine.getHistoryService();
FormService formService = processEngine.getFormService();
DynamicBpmnService dynamicBpmnService = processEngine.getDynamicBpmnService();

FormService

表单数据的管理。

是可选服务,也就是说Flowable没有它也能很好地运行,而不必牺牲任何功能。这个服务引入了开始表单(start form)与任务表单(task form)的概念。 开始表单是在流程实例启动前显示的表单,而任务表单是用户完成任务时显示的表单。Flowable可以在BPMN 2.0流程定义中定义这些表单。表单服务通过简单的方式暴露这些数据。再次重申,表单不一定要嵌入流程定义,因此这个服务是可选的。

formService.getStartFormKey() 获取表单key
formService.getRenderedStartForm()查询表单json(无数据)

RepositoryService

提供了在编辑和发布审批流程的api。主要是模型管理和流程定义的业务api。

这个服务提供了管理与控制部署(deployments)与流程定义(process definitions)的操作:

  • 查询引擎现有的部署与流程定义。
  • 暂停或激活部署中的某些流程,或整个部署。暂停意味着不能再对它进行操作,激活刚好相反,重新使它可以操作。
  • 获取各种资源,比如部署中保存的文件,或者引擎自动生成的流程图。
  • 获取POJO版本的流程定义。它可以用Java而不是XML的方式查看流程。
1.提供了带条件的查询模型流程定义的api
repositoryService.createXXXQuery()
例如:
repositoryService.createModelQuery().list() 模型查询
repositoryService.createProcessDefinitionQuery().list() 流程定义查询

repositoryService.createXXXXQuery().XXXKey(XXX) (查询该key是否存在)

2.提供一大波模型与流程定义的通用方法
模型相关
repositoryService.getModel() (获取模型)
repositoryService.saveModel() (保存模型)
repositoryService.deleteModel() (删除模型)
repositoryService.createDeployment().deploy(); (部署模型)
repositoryService.getModelEditorSource() (获得模型JSON数据的UTF8字符串)
repositoryService.getModelEditorSourceExtra() (获取PNG格式图像)

3.流程定义相关
repositoryService.getProcessDefinition(ProcessDefinitionId); 获取流程定义具体信息
repositoryService.activateProcessDefinitionById() 激活流程定义
repositoryService.suspendProcessDefinitionById() 挂起流程定义
repositoryService.deleteDeployment() 删除流程定义
repositoryService.getProcessDiagram()获取流程定义图片流
repositoryService.getResourceAsStream()获取流程定义xml流
repositoryService.getBpmnModel(pde.getId()) 获取bpmn对象(当前进行到的那个节点的流程图使用)

4.流程定义授权相关
repositoryService.getIdentityLinksForProcessDefinition() 流程定义授权列表
repositoryService.addCandidateStarterGroup()新增组流程授权
repositoryService.addCandidateStarterUser()新增用户流程授权
repositoryService.deleteCandidateStarterGroup() 删除组流程授权
repositoryService.deleteCandidateStarterUser() 删除用户流程授权

RuntimeService

处理正在运行的流程。

runtimeService.createProcessInstanceBuilder().start() 发起流程
runtimeService.deleteProcessInstance() 删除正在运行的流程
runtimeService.suspendProcessInstanceById() 挂起流程定义
runtimeService.activateProcessInstanceById() 激活流程实例
runtimeService.getVariables(processInstanceId); 获取表单中填写的值
runtimeService.getActiveActivityIds(processInstanceId)获取以进行的流程图节点 (当前进行到的那个节点的流程图使用)

runtimeService.createChangeActivityStateBuilder().moveExecutionsToSingleActivityId(executionIds, endId).changeState(); 终止流程

HistoryService

在用户发起审批后,会生成流程实例。historyService为处理流程实例的api,但是其中包括了已经完成的和未完成的流程实例。

如果处理正在运行的流程实例,请使用runtimeService。

暴露Flowable引擎收集的所有历史数据。当执行流程时,引擎会保存许多数据(可配置),例如流程实例启动时间、谁在执行哪个任务、完成任务花费的事件、每个流程实例的执行路径,等等。这个服务主要提供查询这些数据的能力

historyService.createHistoricProcessInstanceQuery().list() 查询流程实例列表(历史流程,包括未完成的)
historyService.createHistoricProcessInstanceQuery().list().foreach().getValue() 可以获取历史中表单的信息
historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); 根据id查询流程实例
historyService.deleteHistoricProcessInstance() 删除历史流程
historyService.deleteHistoricTaskInstance(taskid); 删除任务实例
historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list() 流程实例节点列表 (当前进行到的那个节点的流程图使用)

TaskService

对流程实例的各个节点的审批处理。

流转的节点审批
taskService.createTaskQuery().list() 待办任务列表
taskService.createTaskQuery().taskId(taskId).singleResult(); 待办任务详情
taskService.saveTask(task); 修改任务
taskService.setAssignee() 设置审批人
taskService.addComment() 设置审批备注
taskService.complete() 完成当前审批
taskService.getProcessInstanceComments(processInstanceId); 查看任务详情(也就是都经过哪些人的审批,意见是什么)
taskService.delegateTask(taskId, delegater); 委派任务
taskService.claim(taskId, userId);认领任务
taskService.unclaim(taskId); 取消认领
taskService.complete(taskId, completeVariables); 完成任务

任务授权
taskService.addGroupIdentityLink()新增组任务授权
taskService.addUserIdentityLink() 新增人员任务授权
taskService.deleteGroupIdentityLink() 删除组任务授权
taskService.deleteUserIdentityLink() 删除人员任务授权

ManagementService

主要是执行自定义命令。

managementService.executeCommand(new classA()) 执行classA的内部方法

在自定义的方法中可以使用以下方法获取repositoryService。

ProcessEngineConfiguration processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
RepositoryService repositoryService = processEngineConfiguration.getRepositoryService();

也可以获取流程定义方法集合 。

ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
ProcessDefinitionEntityManager processDefinitionEntityManager =
processEngineConfiguration.getProcessDefinitionEntityManager();
如findById/findLatestProcessDefinitionByKey/findLatestProcessDefinitionByKeyAndTenantId等。

IdentityService

用于身份信息获取和保存,这里主要是获取身份信息。

用于管理(创建,更新,删除,查询……)组与用户。请注意,Flowable实际上在运行时并不做任何用户检查。例如任务可以分派给任何用户,而引擎并不会验证系统中是否存在该用户。这是因为Flowable有时要与LDAP、Active Directory等服务结合使用

identityService.createUserQuery().userId(userId).singleResult(); 获取审批用户的具体信息
identityService.createGroupQuery().groupId(groupId).singleResult(); 获取审批组的具体信息

DynamicBpmnService

可用于修改流程定义中的部分内容,而不需要重新部署它。例如可以修改流程定义中一个用户任务的办理人设置,或者修改一个服务任务中的类名。

Ruoyi-Flowable 源码分析

开源仓库: RuoYi-flowable: 基于RuoYi-vue + flowable 6.x 的工作流管理平台,提供流程管理、流程监控和任务调度等功能。具有易于集成、高度可定制和扩展性强的特点。
整合教程: 若依(RuoYi-Vue)+Flowable工作流前后端整合教程_若依flowable-CSDN博客
他人总结: flowable数据表数据流转总结_flowable工作流 表流转-CSDN博客

知识点整理

flowable工作流引擎-表act_re_procdef 的 id 是如何生成的? - JAVA_Blog - OSCHINA - 中文开源技术交流社区
flowable工作流引擎-自定义权限管理 - JAVA_Blog - OSCHINA - 中文开源技术交流社区
我也没想到 Springboot + Flowable 开发工作流会这么简单 - 程序员小富的个人空间 - OSCHINA - 中文开源技术交流社区

类解析

FlowDefinitionController 工作流程定义

  • list 流程定义列表
  • importFile 导入流程文件
  • readXml 读取xml文件
  • readImage 读取图片文件
  • save 保存流程设计器内的xml文件
  • start 发起流程
  • updateState 激活或挂起流程定义
  • delete 删除流程
  • userList 指定流程办理人员列表
  • roleList 指定流程办理组列表
  • expList 指定流程达式列表

FlowInstanceController 工作流流程实例管理

  • startById 根据流程定义id启动流程实例
  • updateState 激活或挂起流程实例
  • stopProcessInstance 结束流程实例
  • delete 删除流程实例

FlowTaskController 工作流流程任务管理

  • myProcess 我发起的流程
  • stopProcess 取消申请
  • revokeProcess 撤回流程
  • todoList 获取待办列表
  • finishedList 获取已办任务
  • flowRecord 流程历史流转记录
  • flowFormData 流程初始化表单
  • processVariables 获取流程变量
  • complete 审批任务
  • taskReject 驳回任务
  • taskReturn 退回任务
  • findReturnTaskList 获取所有可回退的节点
  • delete 删除任务
  • claim 认领/签收任务
  • unClaim 取消认领/签收任务
  • delegate 委派任务
  • resolveTask 任务归还
  • assign 转办任务
  • addMultiInstanceExecution 多实例加签
  • deleteMultiInstanceExecution 多实例减签
  • getNextFlowNode 获取下一节点
  • getNextFlowNodeByStart 流程发起时获取下一节点
  • genProcessDiagram 生成流程图
  • getFlowViewer 获取流程执行节点
  • flowXmlAndNode 流程节点信息
  • flowTaskForm 流程节点表单

SysFormController 流程表单管理

  • list 查询流程表单列表
  • formList 查询流程表单列表(不分页)
  • export 导出流程表单列表
  • getInfo 获取流程表单详细信息
  • add 新增流程表单
  • edit 修改流程表单
  • remove 删除流程表单
  • addDeployForm 挂载流程表单

FlowServiceFactory 引擎注入封装

  • RepositoryService 提供对流程定义和部署存储库的访问权限的服务。
  • RuntimeService
  • IdentityService
  • TaskService
  • HistoryService
  • ManagementService 用于流程引擎的管理和维护操作的服务。这些操作通常不会在工作流驱动的应用程序中使用,而是在例如操作控制台中使用。
  • ProcessEngine 提供对公开BPM和工作流操作的所有服务的访问。通常,最终用户应用程序中只需要一个中央ProcessEngine实例。构建ProcessEngine是通过ProcessEngineConfiguration实例完成的,并且是应该避免昂贵的操作。为此,建议将其存储在静态字段或JNDI位置(或类似位置)。这是一个线程安全的对象,所以没有什么特别的需要采取预防措施。

FlowableConfig 流程引擎配置

FindNextNodeUtil 查找下一节点或任务

流程操作解析

流程部署

工作流----第二章-----部署_setprocessdefinitioncategory-CSDN博客
💡 注意:

流程节点挂载的表单是根据以key的方式存在bpmn流程节点里的

📌需要关注的表:

  • act_re_deployment 部署单元信息
  • act_re_procdef 已部署的流程定义
  • act_ge_bytearray 流程bpmn文件存放

📌调用接口:

  • flowable/definition/save(每次编辑,都会新增一个版本)

📌调用Flowable API:

// 部署模型
Deployment deploy = repositoryService.createDeployment().addInputStream(name + BPMN_FILE_SUFFIX, in).name(name).category(category).deploy();
// 流程定义查询
ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();
// 给定义好的流程设置分类
repositoryService.setProcessDefinitionCategory(definition.getId(), category);

流程查看

📌需要关注的表:

  • act_re_deployment 部署单元信息
  • act_re_procdef 已部署的流程定义(版本信息)
  • act_ge_bytearray 流程bpmn文件存放

📌调用接口:

  • flowable/definition/readXml/{deployId}

📌调用Flowable API:

// 流程定义查询
ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deployId).singleResult();
// 获取流程定义xml流
InputStream inputStream = repositoryService.getResourceAsStream(definition.getDeploymentId(), definition.getResourceName());

流程删除

📌需要关注的表:

  • act_re_deployment 部署单元信息
  • act_re_procdef 已部署的流程定义(版本信息)
  • act_ge_bytearray 流程bpmn文件存放

📌调用接口:

  • flowable/definition/{deployIds} 删除流程

📌调用Flowable API:

// 删除流程定义
repositoryService.deleteDeployment(deployId, true);

流程启动(=创建流程实例=提交申请)

📌需要关注的表:

  • act_re_deployment 部署单元信息
  • act_re_procdef 已部署的流程定义
  • act_ge_bytearray 流程bpmn文件存放
  • act_ru_variable 存储流程变量
  • act_ru_execution 存储流程执行情况
  • act_ru_task 存储流程任务
  • act_hi_procinst
  • act_hi_taskinst
  • act_hi_varinst 历史变量
💡ru_(runtime)表只在流程运行中保存数据,流程完成或取消后数据将被删除!

📌调用接口:

  • flowable/definition/list 查看流程
  • flowable/task/flowFormData 查看挂载表单
  • flowable/task/nextFlowNodeByStart 流程发起时获取下一节点
  • flowable/definition/start/{procDefId}

📌调用Flowable Api:

// 查询流程定义
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(flowTaskVo.getDeploymentId()).singleResult();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).latestVersion().singleResult();
// 设置流程发起人Id到流程中
identityService.setAuthenticatedUserId(sysUser.getUserId().toString());
// 发起流程
runtimeService.startProcessInstanceById(procDefId, variables);

任务查看

📌需要关注的表:

  • act_re_deployment 部署单元信息
  • act_re_procdef 已部署的流程定义
  • act_ge_bytearray 流程bpmn文件存放
  • act_ru_variable 存储流程变量
  • act_ru_execution 存储流程执行情况
  • act_ru_task 存储流程任务
  • act_hi_procinst
  • act_hi_taskinst
  • act_hi_varinst 历史变量

📌调用接口:

  • flowable/task/myProcess 我发起的流程
  • flowable/task/processVariables/{taskId} 获取流程变量(包含了子节点表单)
  • flowable/task/flowTaskForm 流程节点表单(包含了主表单和子节点表单)
  • flowable/task/flowRecord 流程历史流转记录
  • flowable/task/flowXmlAndNode 流程节点信息

📌调用Flowable Api:

// 仅选择由给定用户启动的历史流程实例
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().startedBy(userId.toString()).orderByProcessInstanceStartTime().desc();
// 获取流程定义具体信息
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(hisIns.getProcessDefinitionId()).singleResult();
// 查询待办任务列表
List<Task> taskList = taskService.createTaskQuery().processInstanceId(hisIns.getId()).list();
// 根据流程定义id获取bpmn对象(当前进行到的那个节点的流程图使用)
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
// 根据流程实例id获取全部历史节点活动实例,即已经走过的节点历史,数据采用开始时间升序
List<HistoricTaskInstance> historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(hisIns.getId()).orderByHistoricTaskInstanceEndTime().desc().list();
// 获取历史任务实例(包含变量)
HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().finished().taskId(taskId).singleResult();
Map<String, Object> variables = taskService.getVariables(taskId);
List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().processInstanceId(procInsId).orderByHistoricActivityInstanceStartTime().desc().list();
List<HistoricIdentityLink> linksForTask = historyService.getHistoricIdentityLinksForTask(histIns.getTaskId());
List<Comment> commentList = taskService.getProcessInstanceComments(histIns.getProcessInstanceId());

待办任务列表查看

📌调用接口:

  • flowable/task/todoList 获取待办列表

📌调用Flowable Api:

// 查询自己的任务
TaskQuery taskQuery = taskService.createTaskQuery()
                .active()
                .includeProcessVariables()
                .taskCandidateGroupIn(sysUser.getRoles().stream().map(role -> role.getRoleId().toString()).collect(Collectors.toList()))
                .taskCandidateOrAssigned(sysUser.getUserId().toString())
                .orderByTaskCreateTime().desc();
 // 流程定义信息
            ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
                    .processDefinitionId(task.getProcessDefinitionId())
                    .singleResult();
 // 流程发起人信息
            HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
                    .processInstanceId(task.getProcessInstanceId())
                    .singleResult();
            SysUser startUser = sysUserService.selectUserById(Long.parseLong(historicProcessInstance.getStartUserId()));

任务审批/完成(包含流转表单)

Flowable进阶学习(八)动态表单;外置表单(JSON表单、HTML表单及踩坑记录);任务回退(串行任务、并行任务、子流程回退)_flowable 表单-CSDN博客

“完成任务”在现实中,这通常意味着由用户提交一个表单。表单中的数据作为流程变量传递。

📌需要关注的表:

  • 流程走完后就会把act_ru_variable,act_ru_task,act_ru_execution里面的数据都会没有了
  • act_hi_actinst里面会有历史记录
  • act_hi_varinst存储历史变量,里面也会存储完成时添加的变量

📌调用接口:

  • flowable/task/complete

【formData】貌似没有用上......

📌调用Flowable Api:

Task task = taskService.createTaskQuery().taskId(taskVo.getTaskId()).singleResult();
        if (Objects.isNull(task)) {
            return AjaxResult.error("任务不存在");
        }
        if (DelegationState.PENDING.equals(task.getDelegationState())) {
            taskService.addComment(taskVo.getTaskId(), taskVo.getInstanceId(), FlowComment.DELEGATE.getType(), taskVo.getComment());
            taskService.resolveTask(taskVo.getTaskId(), taskVo.getVariables());
        } else {
            taskService.addComment(taskVo.getTaskId(), taskVo.getInstanceId(), FlowComment.NORMAL.getType(), taskVo.getComment());
            Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
            taskService.setAssignee(taskVo.getTaskId(), userId.toString());
            taskService.complete(taskVo.getTaskId(), taskVo.getVariables());
        }

taskVo:

{
    "returnTaskShow": false,
    "delegateTaskShow": false,
    "defaultTaskShow": true,
    "comment": "同意",
    "procInsId": "10088",
    "instanceId": "10088",
    "deployId": "10084",
    "taskId": "10100",
    "procDefId": "",
    "targetKey": "",
    "variables": {
        "fields": [{
                "__config__": {
                    "label": "用餐评价",
                    "showLabel": true,
                    "tag": "el-input",
                    "tagIcon": "textarea",
                    "required": true,
                    "layout": "colFormItem",
                    "span": 24,
                    "regList": [{
                        "required": true,
                        "message": "请输入多行文本用餐评价",
                        "trigger": "blur"
                    }],
                    "changeTag": true,
                    "document": "https://element.eleme.cn/#/zh-CN/component/input",
                    "formId": 101,
                    "renderKey": "1011702261605840",
                    "defaultValue": "12312"
                },
                "type": "textarea",
                "placeholder": "请输入多行文本用餐评价",
                "autosize": {
                    "minRows": 4,
                    "maxRows": 4
                },
                "style": {
                    "width": "100%"
                },
                "show-word-limit": false,
                "readonly": false,
                "disabled": true,
                "__vModel__": "field101"
            },
            {
                "__config__": {
                    "label": "评分",
                    "tag": "el-rate",
                    "tagIcon": "rate",
                    "defaultValue": 5,
                    "span": 24,
                    "showLabel": true,
                    "layout": "colFormItem",
                    "required": true,
                    "regList": [{
                        "required": true,
                        "message": "评分不能为空",
                        "trigger": "change"
                    }],
                    "changeTag": true,
                    "document": "https://element.eleme.cn/#/zh-CN/component/rate",
                    "formId": 102,
                    "renderKey": "1021702261611457"
                },
                "style": {},
                "max": 5,
                "allow-half": false,
                "show-text": false,
                "show-score": false,
                "disabled": true,
                "__vModel__": "field102"
            },
            {
                "__config__": {
                    "label": "请假标题",
                    "showLabel": true,
                    "changeTag": true,
                    "tag": "el-input",
                    "tagIcon": "input",
                    "required": true,
                    "layout": "colFormItem",
                    "span": 24,
                    "document": "https://element.eleme.cn/#/zh-CN/component/input",
                    "regList": [],
                    "formId": 101,
                    "renderKey": "1011650592466703"
                },
                "__slot__": {
                    "prepend": "",
                    "append": ""
                },
                "placeholder": "请输入请假标题",
                "style": {
                    "width": "100%"
                },
                "clearable": true,
                "prefix-icon": "",
                "suffix-icon": "",
                "show-word-limit": false,
                "readonly": false,
                "disabled": false,
                "__vModel__": "field101"
            },
            {
                "__config__": {
                    "label": "请假天数",
                    "showLabel": true,
                    "changeTag": true,
                    "tag": "el-input",
                    "tagIcon": "input",
                    "required": true,
                    "layout": "colFormItem",
                    "span": 24,
                    "document": "https://element.eleme.cn/#/zh-CN/component/input",
                    "regList": [],
                    "formId": 101,
                    "renderKey": "1011646362752852"
                },
                "__slot__": {
                    "prepend": "",
                    "append": ""
                },
                "placeholder": "请输入请假天数",
                "style": {
                    "width": "100%"
                },
                "clearable": true,
                "prefix-icon": "",
                "suffix-icon": "",
                "show-word-limit": false,
                "readonly": false,
                "disabled": false,
                "__vModel__": "day"
            },
            {
                "__config__": {
                    "label": "请假备注",
                    "showLabel": true,
                    "tag": "el-input",
                    "tagIcon": "textarea",
                    "required": true,
                    "layout": "colFormItem",
                    "span": 24,
                    "regList": [],
                    "changeTag": true,
                    "document": "https://element.eleme.cn/#/zh-CN/component/input",
                    "formId": 102,
                    "renderKey": "1021650592469692"
                },
                "type": "textarea",
                "placeholder": "请输入请假备注",
                "autosize": {
                    "minRows": 4,
                    "maxRows": 4
                },
                "style": {
                    "width": "100%"
                },
                "show-word-limit": false,
                "readonly": false,
                "disabled": false,
                "__vModel__": "field102"
            }
        ],
        "formRef": "elForm",
        "formModel": "formData",
        "size": "medium",
        "labelPosition": "right",
        "labelWidth": 100,
        "formRules": "rules",
        "gutter": 15,
        "disabled": false,
        "span": 24,
        "formBtns": true,
        "unFocusedComponentBorder": false,
        "field101": "节点表单标题111",
        "field102": "112233",
        "day": "11",
        "variables": {
            "fields": [{
                    "__config__": {
                        "label": "用餐评价",
                        "showLabel": true,
                        "tag": "el-input",
                        "tagIcon": "textarea",
                        "required": true,
                        "layout": "colFormItem",
                        "span": 24,
                        "regList": [{
                                "required": true,
                                "message": "请输入多行文本用餐评价",
                                "trigger": "blur"
                            },
                            {
                                "required": true,
                                "message": "请输入多行文本用餐评价",
                                "trigger": "blur"
                            }
                        ],
                        "changeTag": true,
                        "document": "https://element.eleme.cn/#/zh-CN/component/input",
                        "formId": 101,
                        "renderKey": "1011702261605840",
                        "defaultValue": "12312"
                    },
                    "type": "textarea",
                    "placeholder": "请输入多行文本用餐评价",
                    "autosize": {
                        "minRows": 4,
                        "maxRows": 4
                    },
                    "style": {
                        "width": "100%"
                    },
                    "show-word-limit": false,
                    "readonly": false,
                    "disabled": true,
                    "__vModel__": "field101"
                },
                {
                    "__config__": {
                        "label": "评分",
                        "tag": "el-rate",
                        "tagIcon": "rate",
                        "defaultValue": 5,
                        "span": 24,
                        "showLabel": true,
                        "layout": "colFormItem",
                        "required": true,
                        "regList": [{
                                "required": true,
                                "message": "评分不能为空",
                                "trigger": "change"
                            },
                            {
                                "required": true,
                                "message": "评分不能为空",
                                "trigger": "change"
                            }
                        ],
                        "changeTag": true,
                        "document": "https://element.eleme.cn/#/zh-CN/component/rate",
                        "formId": 102,
                        "renderKey": "1021702261611457"
                    },
                    "style": {},
                    "max": 5,
                    "allow-half": false,
                    "show-text": false,
                    "show-score": false,
                    "disabled": true,
                    "__vModel__": "field102"
                },
                {
                    "__config__": {
                        "label": "请假标题",
                        "showLabel": true,
                        "changeTag": true,
                        "tag": "el-input",
                        "tagIcon": "input",
                        "required": true,
                        "layout": "colFormItem",
                        "span": 24,
                        "document": "https://element.eleme.cn/#/zh-CN/component/input",
                        "regList": [{
                            "required": true,
                            "message": "请输入请假标题",
                            "trigger": "blur"
                        }],
                        "formId": 101,
                        "renderKey": "1011650592466703",
                        "defaultValue": "节点表单标题111"
                    },
                    "__slot__": {
                        "prepend": "",
                        "append": ""
                    },
                    "placeholder": "请输入请假标题",
                    "style": {
                        "width": "100%"
                    },
                    "clearable": true,
                    "prefix-icon": "",
                    "suffix-icon": "",
                    "show-word-limit": false,
                    "readonly": false,
                    "disabled": false,
                    "__vModel__": "field101"
                },
                {
                    "__config__": {
                        "label": "请假天数",
                        "showLabel": true,
                        "changeTag": true,
                        "tag": "el-input",
                        "tagIcon": "input",
                        "required": true,
                        "layout": "colFormItem",
                        "span": 24,
                        "document": "https://element.eleme.cn/#/zh-CN/component/input",
                        "regList": [{
                            "required": true,
                            "message": "请输入请假天数",
                            "trigger": "blur"
                        }],
                        "formId": 101,
                        "renderKey": "1011646362752852",
                        "defaultValue": "11"
                    },
                    "__slot__": {
                        "prepend": "",
                        "append": ""
                    },
                    "placeholder": "请输入请假天数",
                    "style": {
                        "width": "100%"
                    },
                    "clearable": true,
                    "prefix-icon": "",
                    "suffix-icon": "",
                    "show-word-limit": false,
                    "readonly": false,
                    "disabled": false,
                    "__vModel__": "day"
                },
                {
                    "__config__": {
                        "label": "请假备注",
                        "showLabel": true,
                        "tag": "el-input",
                        "tagIcon": "textarea",
                        "required": true,
                        "layout": "colFormItem",
                        "span": 24,
                        "regList": [{
                            "required": true,
                            "message": "请输入请假备注",
                            "trigger": "blur"
                        }],
                        "changeTag": true,
                        "document": "https://element.eleme.cn/#/zh-CN/component/input",
                        "formId": 102,
                        "renderKey": "1021650592469692",
                        "defaultValue": "112233"
                    },
                    "type": "textarea",
                    "placeholder": "请输入请假备注",
                    "autosize": {
                        "minRows": 4,
                        "maxRows": 4
                    },
                    "style": {
                        "width": "100%"
                    },
                    "show-word-limit": false,
                    "readonly": false,
                    "disabled": false,
                    "__vModel__": "field102"
                }
            ],
            "formRef": "elForm",
            "formModel": "formData",
            "size": "medium",
            "labelPosition": "right",
            "labelWidth": 100,
            "formRules": "rules",
            "gutter": 15,
            "disabled": true,
            "span": 24,
            "formBtns": false,
            "unFocusedComponentBorder": false
        }
    },
    "executionId": "10096",
    "formData": {
        "formData": {
            "fields": [{
                    "__config__": {
                        "label": "用餐评价",
                        "showLabel": true,
                        "tag": "el-input",
                        "tagIcon": "textarea",
                        "required": true,
                        "layout": "colFormItem",
                        "span": 24,
                        "regList": [{
                                "required": true,
                                "message": "请输入多行文本用餐评价",
                                "trigger": "blur"
                            },
                            {
                                "required": true,
                                "message": "请输入多行文本用餐评价",
                                "trigger": "blur"
                            }
                        ],
                        "changeTag": true,
                        "document": "https://element.eleme.cn/#/zh-CN/component/input",
                        "formId": 101,
                        "renderKey": "1011702261605840",
                        "defaultValue": "12312"
                    },
                    "type": "textarea",
                    "placeholder": "请输入多行文本用餐评价",
                    "autosize": {
                        "minRows": 4,
                        "maxRows": 4
                    },
                    "style": {
                        "width": "100%"
                    },
                    "show-word-limit": false,
                    "readonly": false,
                    "disabled": true,
                    "__vModel__": "field101"
                },
                {
                    "__config__": {
                        "label": "评分",
                        "tag": "el-rate",
                        "tagIcon": "rate",
                        "defaultValue": 5,
                        "span": 24,
                        "showLabel": true,
                        "layout": "colFormItem",
                        "required": true,
                        "regList": [{
                                "required": true,
                                "message": "评分不能为空",
                                "trigger": "change"
                            },
                            {
                                "required": true,
                                "message": "评分不能为空",
                                "trigger": "change"
                            }
                        ],
                        "changeTag": true,
                        "document": "https://element.eleme.cn/#/zh-CN/component/rate",
                        "formId": 102,
                        "renderKey": "1021702261611457"
                    },
                    "style": {},
                    "max": 5,
                    "allow-half": false,
                    "show-text": false,
                    "show-score": false,
                    "disabled": true,
                    "__vModel__": "field102"
                },
                {
                    "__config__": {
                        "label": "请假标题",
                        "showLabel": true,
                        "changeTag": true,
                        "tag": "el-input",
                        "tagIcon": "input",
                        "required": true,
                        "layout": "colFormItem",
                        "span": 24,
                        "document": "https://element.eleme.cn/#/zh-CN/component/input",
                        "regList": [{
                            "required": true,
                            "message": "请输入请假标题",
                            "trigger": "blur"
                        }],
                        "formId": 101,
                        "renderKey": "1011650592466703",
                        "defaultValue": "节点表单标题111"
                    },
                    "__slot__": {
                        "prepend": "",
                        "append": ""
                    },
                    "placeholder": "请输入请假标题",
                    "style": {
                        "width": "100%"
                    },
                    "clearable": true,
                    "prefix-icon": "",
                    "suffix-icon": "",
                    "show-word-limit": false,
                    "readonly": false,
                    "disabled": false,
                    "__vModel__": "field101"
                },
                {
                    "__config__": {
                        "label": "请假天数",
                        "showLabel": true,
                        "changeTag": true,
                        "tag": "el-input",
                        "tagIcon": "input",
                        "required": true,
                        "layout": "colFormItem",
                        "span": 24,
                        "document": "https://element.eleme.cn/#/zh-CN/component/input",
                        "regList": [{
                            "required": true,
                            "message": "请输入请假天数",
                            "trigger": "blur"
                        }],
                        "formId": 101,
                        "renderKey": "1011646362752852",
                        "defaultValue": "11"
                    },
                    "__slot__": {
                        "prepend": "",
                        "append": ""
                    },
                    "placeholder": "请输入请假天数",
                    "style": {
                        "width": "100%"
                    },
                    "clearable": true,
                    "prefix-icon": "",
                    "suffix-icon": "",
                    "show-word-limit": false,
                    "readonly": false,
                    "disabled": false,
                    "__vModel__": "day"
                },
                {
                    "__config__": {
                        "label": "请假备注",
                        "showLabel": true,
                        "tag": "el-input",
                        "tagIcon": "textarea",
                        "required": true,
                        "layout": "colFormItem",
                        "span": 24,
                        "regList": [{
                            "required": true,
                            "message": "请输入请假备注",
                            "trigger": "blur"
                        }],
                        "changeTag": true,
                        "document": "https://element.eleme.cn/#/zh-CN/component/input",
                        "formId": 102,
                        "renderKey": "1021650592469692",
                        "defaultValue": "112233"
                    },
                    "type": "textarea",
                    "placeholder": "请输入请假备注",
                    "autosize": {
                        "minRows": 4,
                        "maxRows": 4
                    },
                    "style": {
                        "width": "100%"
                    },
                    "show-word-limit": false,
                    "readonly": false,
                    "disabled": false,
                    "__vModel__": "field102"
                }
            ],
            "formRef": "elForm",
            "formModel": "formData",
            "size": "medium",
            "labelPosition": "right",
            "labelWidth": 100,
            "formRules": "rules",
            "gutter": 15,
            "disabled": true,
            "span": 24,
            "formBtns": false,
            "unFocusedComponentBorder": false
        },
        "valData": {
            "field101": "节点表单标题111",
            "field102": "112233",
            "day": "11"
        }
    }
}

任务驳回

📌需要关注的表:

  • act_ru_task 存储流程任务
  • act_hi_taskinst

📌调用接口:

  • flowable/task/reject

📌调用Flowable Api:

runtimeService.createChangeActivityStateBuilder() .processInstanceId(task.getProcessInstanceId()).moveActivityIdsToSingleActivityId(currentIds, targetIds.get(0)).changeState();

任务退回

📌调用接口:

  • flowable/task/return

任务委派

📌调用接口:

  • flowable/task/delegateTask

任务归还

📌调用接口:

  • flowable/task/resolveTask

任务转办

📌调用接口:

  • flowable/task/assignTask

取消申请

目前实现方式: 直接将当前流程变更为已完成

📌调用接口:

  • flowable/task/stopProcess

流程绑定主要表单

📌需要关注的表:

  • sys_form 流程表单
  • act_re_deployment 部署单元信息
  • sys_deploy_form 流程表单关联详情

📌调用接口:

  • /flowable/form/addDeployForm 挂载流程表单

📌实现场景:

  1. 进入流程定义页面
  2. 在流程列表上点击【配置主表单】按钮
  3. 选择一个表单进行挂载

Flowable名词附录

流程定义

流程实例

表单

部署流程

启动流程

流程变量

排他网关

并行网关

部署流程定义

接下来我们构建一个非常简单的请假流程,Flowable引擎需要流程定义为BPMN 2.0格式,这是一个业界广泛接受的XML标准。 在Flowable术语中,我们将其称为一个**流程定义(process definition)「。一个流程定义可以启动多个」流程实例(process instance)**。流程定义可以看做是重复执行流程的蓝图。 在这个例子中,流程定义定义了请假的各个步骤,而一个流程实例对应某个雇员提出的一个请假申请。

BPMN 2.0存储为XML,并包含可视化的部分:使用标准方式定义了每个步骤类型(人工任务,自动服务调用,等等)如何呈现,以及如何互相连接。这样BPMN 2.0标准使技术人员与业务人员能用双方都能理解的方式交流业务流程。

我们要使用的流程定义为:

流程定义说明:

我们假定启动流程需要提供一些信息,例如雇员名字、请假时长以及说明。当然,这些可以单独建模为流程中的第一步。 但是如果将它们作为流程的“输入信息”,就能保证只有在实际请求时才会建立一个流程实例。否则(将提交作为流程的第一步),用户可能在提交之前改变主意并取消,但流程实例已经创建了。 在某些场景中,就可能影响重要的指标(例如启动了多少申请,但还未完成),取决于业务目标。

左侧的圆圈叫做**启动事件(start event)**。这是一个流程实例的起点。

第一个矩形是一个**用户任务(user task)**。这是流程中用户操作的步骤。在这个例子中,经理需要批准或驳回申请

取决于经理的决定,「排他网关(exclusive gateway)」 (带叉的菱形)会将流程实例路由至批准或驳回路径

如果批准,则需要将申请注册至某个外部系统,并跟着另一个用户任务,将经理的决定通知给申请人。当然也可以改为发送邮件。

如果驳回,则为雇员发送一封邮件通知他。

一般来说,这样的流程定义使用可视化建模工具建立,如Flowable Designer(Eclipse)或Flowable Web Modeler(Web应用)。但在这里我们直接撰写XML,以熟悉BPMN 2.0及其概念。

与上面展示的流程图对应的BPMN 2.0 XML在下面显示。请注意这只包含了“流程部分”。如果使用图形化建模工具,实际的XML文件还将包含“可视化部分”,用于描述图形信息,如流程定义中各个元素的坐标(所有的图形化信息包含在XML的BPMNDiagram标签中,作为definitions标签的子元素)。

  • 28
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值