flowable 中流程变量都放在act_ru_variable,act_hi_varinst中
act_ru_variable 存放得是正在运行的流程变量,正在运行的指的是(PROC_INST_ID_ )流程实例正在运行
act_hi_varinst 存放的是已经运行完成的流程变量,运行完成指的是流程实例已经运行完成,在代码中怎么知道流程实例运行,之后会说到监听器...
设置流程变量:
/**
*@Author cf
*@Description 设置流程变量
*@Date 10:14 2019/4/17
* proInstanceId 流程实例id 为哪条流程实例设置流程变量
*value 设置为流程变量的值\
* key 设置为流程变量的key(获取也是根据这个key获取)
**/
public void setVariable(String proInstanceId,String key, Object value) {
//设置流程变量
runtimeService.setVariable(proInstanceId, key, value);
}
获取流程变量
public Object getVariable (String key, String processInstanceId) {
Object variable = runtimeService.getVariable(processInstanceId, key);
return variable;
}
获取历史流程变量
/**
*@Author cf
*@Description 获取历史流程变量
*@Date 10:18 2019/4/17
*@Param [processInstanceId, key]
* processInstanceId 流程实例id
* key 键
*@return java.lang.Object
**/
public Object getHisVariable(String processInstanceId,String key) {
Object variable = null;
List<HistoricVariableInstance> list = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
for (int i = 0; i < list.size(); i++) {
HistoricVariableInstance historicVariableInstance = list.get(i);
if (historicVariableInstance.getVariableName().equals(key)) {
variable = historicVariableInstance.getValue();
}
}
return variable;
}
注意:
1.只要在act_ru_*表中存在,那么在act_hi_*表中一定会存在,反之,不一定会存在.
2.key名相同,值会被覆盖.例:比如说key为"save-key",值为1,第二次存入"save-key",值为2,之后的值一直都会是2