文章目录
- 流程挂起与激活
- 流程实例挂起与激活
- 启动、处理、结束流程的原理
- 一、启动流程的原理
- 启动一个流程实例时涉及到的表及表结构:
- ACT_RU_EXECUTION 运行时流程执行实例
- ACT_RU_IDENTITYLINK 运行时用户关系信息
- ACT_RU_TASK 运行时任务表
- ACT_RU_VARIABLE 运行时变量表
- 二、处理流程的原理及相关表变动
- 三、流程结束的原理以及相关表变动
- ACT_HI_PROCINST:历史流程实例表
- ACT_HI_TASKINST:历史任务实例表(流程节点)
- ACT_HI_VARINST:历史流程变量表
- ACT_HI_IDENTITYLINK:历史用户关系表
- ACT_HI_ACTINST:历史活动实例表(流程定义相关)
流程挂起与激活
部署的流程其默认状态为激活状态,若暂时不想使用该定义的流程,则可以进行挂起操作。流程定义为挂起状态时,该流程定义将不允许启动新的流程实例。且当前该流程定义下的流程实例全部挂起暂停执行。
/**
* 测试流程挂起与激活
*/
@Test
public void test_Suspended(){
RepositoryService repositoryService = processEngine.getRepositoryService();
// 获取对应的流程定义信息
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionId("MyProcess:1:6").singleResult();
// 获取当前流程定义的状态信息
System.out.println("processDefinition.isSuspended() = " + processDefinition.isSuspended());
if(processDefinition.isSuspended()){
// 当前流程挂起,进行激活
repositoryService.activateProcessDefinitionById(processDefinition.getId());
System.out.println("激活流程===> " + processDefinition.getName() );
}else {
// 当前流程激活,进行挂起
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
System.out.println("挂起流程===> " + processDefinition.getName() );
}
}
/**
* 测试启动流程
* 当流程挂起的时候,执行启动流程操作会报错
* org.flowable.engine.common.api.FlowableException: Cannot start process instance. Process definition MyProcess (id = MyProcess:1:6) is suspended
*/
@Test
public void test_runProcess(){
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceById("MyProcess:1:6");
System.out.println("processInstance.getActivityId() = " + processInstance.getActivityId());
}
流程实例挂起与激活
启动、处理、结束流程的原理
一、启动流程的原理
当我们启动了一个流程实例后,会在ACT_RU_*对应的表结构中操作,运行时实例涉及的表结构共10张:
- ACT_RU_DEADLETTER_JOB 正在运行的任务表
- ACT_RU_EVENT_SUBSCR 运行时事件
- ACT_RU_EXECUTION 运行时流程执行实例
- ACT_RU_HISTORY_JOB 历史作业表
- ACT_RU_IDENTITYLINK 运行时用户关系信息
- ACT_RU_JOB运行时作业表
- ACT_RU_SUSPENDED_JOB 暂停作业表
- ACT_RU_TASK 运行时任务表
- ACT_RU_TIMERJOB定时作业表
- ACT_RU_VARIABLE 运行时变是表
启动一个流程实例时涉及到的表及表结构:
ACT_RU_EXECUTION 运行时流程执行实例
ID_ |REV_|PROC_INST_ID_|BUSINESS_KEY_|PARENT_ID_|PROC_DEF_ID_ |SUPER_EXEC_|ROOT_PROC_INST_ID_|ACT_ID_ |IS_ACTIVE_|IS_CONCURRENT_|IS_SCOPE_|IS_EVENT_SCOPE_|IS_MI_ROOT_|SUSPENSION_STATE_|CACHED_ENT_STATE_|TENANT_ID_|NAME_|START_ACT_ID_|START_TIME_ |START_USER_ID_|LOCK_TIME_|IS_COUNT_ENABLED_|EVT_SUBSCR_COUNT_|TASK_COUNT_|JOB_COUNT_|TIMER_JOB_COUNT_|SUSP_JOB_COUNT_|DEADLETTER_JOB_COUNT_|VAR_COUNT_|ID_LINK_COUNT_|CALLBACK_ID_|CALLBACK_TYPE_|
-----+----+-------------+-------------+----------+---------------+-----------+------------------+----------------------------------------+----------+--------------+---------+---------------+-----------+-----------------+-----------------+----------+-----+-------------+-----------------------+--------------+----------+-----------------+-----------------+-----------+----------+----------------+---------------+---------------------+----------+--------------+------------+--------------+
10001| 1|10001 |qj1002 | |MyHolidayUI:1:7| |10001 | | 1| 0| 1| 0| 0| 1| |whx | |startEvent1 |2023-01-19 12:58:59.447| | | 1| 0| 0| 0| 0| 0| 0| 0| 0| | |
10005| 1|10001 | |10001 |MyHolidayUI:1:7| |10001 |sid-78EFF658-A003-460A-950A-764DC53C913F| 1| 0| 0| 0| 0| 1| |whx | | | 2023-01-19 12:58:59.49| | | 1| 0| 1| 0| 0| 0| 0| 0| 0| | |
ACT_RU_IDENTITYLINK 运行时用户关系信息
ID_ |REV_|GROUP_ID_|TYPE_ |USER_ID_|TASK_ID_|PROC_INST_ID_|PROC_DEF_ID_|SCOPE_ID_|SCOPE_TYPE_|SCOPE_DEFINITION_ID_|
-----+----+---------+-----------+--------+--------+-------------+------------+---------+-----------+--------------------+
10010| 1| |participant|whx | |10001 | | | | |
-- 其中 TYPE_字段的类型来自类:org.flowable.identitylink.service.IdentityLinkType
assignee指派人、candidate候选人、owner所有人、starter启动人、participant参与人
ACT_RU_TASK 运行时任务表
ID_ |REV_|EXECUTION_ID_|PROC_INST_ID_|PROC_DEF_ID_ |TASK_DEF_ID_|SCOPE_ID_|SUB_SCOPE_ID_|SCOPE_TYPE_|SCOPE_DEFINITION_ID_|NAME_ |PARENT_TASK_ID_父任务ID|DESCRIPTION_|TASK_DEF_KEY_ |OWNER_|ASSIGNEE_指派|DELEGATION_委托|PRIORITY_|CREATE_TIME_ |DUE_DATE_|CATEGORY_|SUSPENSION_STATE_是是否挂起|TENANT_ID_租户id|FORM_KEY_表单key|CLAIM_TIME_|IS_COUNT_ENABLED_|VAR_COUNT_|ID_LINK_COUNT_|SUB_TASK_COUNT_|
-----+----+-------------+-------------+---------------+------------+---------+-------------+-----------+--------------------+------+---------------+------------+----------------------------------------+------+---------+-----------+---------+-----------------------+---------+---------+-----------------+----------+---------+-----------+-----------------+----------+--------------+---------------+
10008| 1|10005 |10001 |MyHolidayUI:1:7| | | | | |提交请假申请| | |sid-78EFF658-A003-460A-950A-764DC53C913F| |whx | | 50|2023-01-19 12:58:59.495| | | 1|whx | | | 1| 0| 0| 0|
ACT_RU_VARIABLE 运行时变量表
二、处理流程的原理及相关表变动
/**
* 带参的流程完成
* act_ru_task表记录的是当前流程实例所运行的节点。即待办任务
*/
@Test
public void test_runCompleteWithParams() {
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery()
.processInstanceId("10001").taskAssignee("whx").singleResult();
Map<String, Object> processVariables = task.getProcessVariables();
processVariables.forEach((k, v) -> {
System.out.println(k + "~" + v);
});
processVariables.put("approved", true);
processVariables.put("nrOfHolliday", 7);
taskService.complete(task.getId(), processVariables);
}
- ACT_RU_EXECUTION 运行时流程执行实例(不会做修改)
- ACT_RU_IDENTITYLINK 运行时用户关系信息(会新增一条处理记录)
- ACT_RU_TASK 运行时任务表(删除已完成的任务,新增待办)
ID_ |REV_|EXECUTION_ID_|PROC_INST_ID_|PROC_DEF_ID_ |TASK_DEF_ID_|SCOPE_ID_|SUB_SCOPE_ID_|SCOPE_TYPE_|SCOPE_DEFINITION_ID_|NAME_ |PARENT_TASK_ID_|DESCRIPTION_|TASK_DEF_KEY_ |OWNER_|ASSIGNEE_|DELEGATION_|PRIORITY_|CREATE_TIME_ |DUE_DATE_|CATEGORY_|SUSPENSION_STATE_|TENANT_ID_|FORM_KEY_|CLAIM_TIME_|IS_COUNT_ENABLED_|VAR_COUNT_|ID_LINK_COUNT_|SUB_TASK_COUNT_| -----+----+-------------+-------------+---------------+------------+---------+-------------+-----------+--------------------+------+---------------+------------+----------------------------------------+------+---------+-----------+---------+-----------------------+---------+---------+-----------------+----------+---------+-----------+-----------------+----------+--------------+---------------+ 12503| 1|10005 |10001 |MyHolidayUI:1:7| | | | | |领导审批 | | |sid-2C6EBB59-7020-4067-B7F6-03A1F2494C5D| |huathy | | 50|2023-01-20 14:41:56.644| | | 1|whx | | | 1| 0| 0| 0|
- ACT_RU_VARIABLE 运行时变量表(流程变量的更新)
三、流程结束的原理以及相关表变动
当一个流程完成处理的时候,会删除上述的四张运行时表ACT_RU_。中当前流程的数据,并转入历史表中。ACT_HI_。
所涉及到的表结构:
ACT_HI_PROCINST:历史流程实例表
ID_ |REV_|PROC_INST_ID_|BUSINESS_KEY_|PROC_DEF_ID_ |START_TIME_ |END_TIME_ |DURATION_|START_USER_ID_|START_ACT_ID_|END_ACT_ID_ |SUPER_PROCESS_INSTANCE_ID_|DELETE_REASON_|TENANT_ID_|NAME_|CALLBACK_ID_|CALLBACK_TYPE_|
-----+----+-------------+-------------+---------------+-----------------------+-----------------------+---------+--------------+-------------+----------------------------------------+--------------------------+--------------+----------+-----+------------+--------------+
10001| 2|10001 |qj1002 |MyHolidayUI:1:7|2023-01-19 12:58:59.447|2023-01-21 06:02:51.449|147832002| |startEvent1 |sid-BFA54F29-3329-4DA5-9F55-AF278B5508EC| | |whx | | | |
ACT_HI_TASKINST:历史任务实例表(流程节点)
ID_ |REV_|PROC_DEF_ID_ |TASK_DEF_ID_|TASK_DEF_KEY_ |PROC_INST_ID_|EXECUTION_ID_|SCOPE_ID_|SUB_SCOPE_ID_|SCOPE_TYPE_|SCOPE_DEFINITION_ID_|NAME_ |PARENT_TASK_ID_|DESCRIPTION_|OWNER_|ASSIGNEE_|START_TIME_ |CLAIM_TIME_|END_TIME_ |DURATION_|DELETE_REASON_|PRIORITY_|DUE_DATE_|FORM_KEY_|CATEGORY_|TENANT_ID_|LAST_UPDATED_TIME_ |
-----+----+---------------+------------+----------------------------------------+-------------+-------------+---------+-------------+-----------+--------------------+------+---------------+------------+------+---------+-----------------------+-----------+-----------------------+---------+--------------+---------+---------+---------+---------+----------+-----------------------+
10008| 2|MyHolidayUI:1:7| |sid-78EFF658-A003-460A-950A-764DC53C913F|10001 |10005 | | | | |提交请假申请| | | |whx |2023-01-19 12:58:59.515| |2023-01-20 14:41:56.625| 92577110| | 50| | | |whx |2023-01-20 14:41:56.625|
12503| 2|MyHolidayUI:1:7| |sid-2C6EBB59-7020-4067-B7F6-03A1F2494C5D|10001 |10005 | | | | |领导审批 | | | |huathy |2023-01-20 14:41:56.658| | 2023-01-21 06:02:51.33| 55254672| | 50| | | |whx | 2023-01-21 06:02:51.33|
ACT_HI_VARINST:历史流程变量表
ACT_HI_IDENTITYLINK:历史用户关系表
ACT_HI_ACTINST:历史活动实例表(流程定义相关)
D_ |REV_|PROC_DEF_ID_ |PROC_INST_ID_|EXECUTION_ID_|ACT_ID_ |TASK_ID_|CALL_PROC_INST_ID_|ACT_NAME_|ACT_TYPE_ |ASSIGNEE_|START_TIME_ |END_TIME_ |DURATION_|DELETE_REASON_|TENANT_ID_|
----+----+---------------+-------------+-------------+----------------------------------------+--------+------------------+---------+----------+---------+-----------------------+-----------------------+---------+--------------+----------+
0006| 1|MyHolidayUI:1:7|10001 |10005 |startEvent1 | | | |startEvent| |2023-01-19 12:58:59.491|2023-01-19 12:58:59.492| 1| |whx |
0007| 2|MyHolidayUI:1:7|10001 |10005 |sid-78EFF658-A003-460A-950A-764DC53C913F|10008 | |提交请假申请 |userTask |whx |2023-01-19 12:58:59.495|2023-01-20 14:41:56.639| 92577144| |whx |
2502| 2|MyHolidayUI:1:7|10001 |10005 |sid-2C6EBB59-7020-4067-B7F6-03A1F2494C5D|12503 | |领导审批 |userTask |huathy |2023-01-20 14:41:56.644|2023-01-21 06:02:51.375| 55254731| |whx |
5001| 1|MyHolidayUI:1:7|10001 |10005 |sid-BFA54F29-3329-4DA5-9F55-AF278B5508EC| | | |endEvent | |2023-01-21 06:02:51.408|2023-01-21 06:02:51.411| 3| |whx |