activiti 表结构讲解

可能你在苦恼这个问题,由于在跟踪已结束流程的时候须要获取流程办理中设置的变量值(能够分析每一个节点办理的详细状态),今天咱们就来探索一下如何实现。 html

1.Activiti表结构设计

Activiti的表结构设计分为两种类型:运行时(ACT_RU)、历史(ACT_HI)。 spring

1.1 运行时变量

全部运行时的变量都保存在表:ACT_RU_VARIABLE中,这些变量能够在启动流程、完成任务、动态添加的方式插入到数据库,以便流程在处理中能够根据变量的值决定流程的走向。 数据库

1.2 历史变量呢?

为何没有ACT_HI_VARIABLE这张表呢? 性能

我在开始的时候也是苦恼为何没有这张表,致使在跟踪历史流程信息的时候不能获取变量。 ui

2.了解历史级别

Activit默认提供了4中历史级别: spa

  • none: 不保存任何历史记录,能够提升系统性能; 设计

  • activity:保存全部的流程实例、任务、活动信息; orm

  • audit:也是Activiti的默认级别,保存全部的流程实例、任务、活动、表单属性; htm

  • full: 最完整的历史记录,除了包含audit级别的信息以外还能保存详细,例如:流程变量。 ci

对于几种级别根据对功能的要求选择,若是须要往后跟踪详细能够开启full

3.配置历史级别

3.1 在XML中配置

在引擎BeanprocessEngineConfiguration中配置:

?
1
2
3
<beanid="processEngineConfiguration"class="org.activiti.spring.SpringProcessEngineConfiguration">
    <propertyname="history"value="full">
</property></bean>

3.2 动态配置

?
1
2
3
4
ProcessEngine processEngine = ProcessEngineConfiguration
  .createProcessEngineConfigurationFromResourceDefault()
  .setHistory(ProcessEngineConfiguration.HISTORY_FULL)
  .buildProcessEngine();

4.读取历史变量

如今再重启你的应用,启动流程或者在任务complete以后查看ACT_HI_DETAIL表的数据已经记录了。

开始full历史级别后保存的历史信息

4.1 Java代码-5.10版本以前

?
1
2
3
4
5
6
List<historicdetail> list = historyService.createHistoricDetailQuery().processInstanceId(processInstance.getId()).list();
for(HistoricDetail historicDetail : list) {
    HistoricVariableUpdate variable = (HistoricVariableUpdate) historicDetail;
    System.out.println("variable: "+ variable.getVariableName() +" = "+ variable.getValue());
}
</historicdetail>

4.2 Java代码-5.11版本以后

5.11版本在变量保存方面作了变更,单首创建了一张表ACT_HI_VARINST保存变量,能够经过下面的代码读取变量。参见:Activiti 5.11发布

5.11添加的表ACT_HI_VARINST

?
1
2
3
4
5
List<historicvariableinstance> list = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
for(HistoricVariableInstance variableInstance : list) {
  System.out.println("variable: "+ variable.getVariableName() +" = "+ variable.getValue());
}
</historicvariableinstance>

5.只读取表单字段

?
1
2
3
4
5
6
List<historicdetail> formProperties = historyService.createHistoricDetailQuery().processInstanceId(processInstance.getId()).formProperties().list();
for(HistoricDetail historicDetail : formProperties) {
  HistoricFormProperty field = (HistoricFormProperty) historicDetail;
  System.out.println("field id: "+ field.getPropertyId() +", value: "+ field.getPropertyValue());
}
</historicdetail>
相关文章
相关标签/搜索