HistoryService
流程历史信息
act_hi_procinst
: 历史流程信息,,如果流程执行完了,end_time_
和 duration
不为null
// 没有执行完的
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().unfinished().list();
// 查询已经执行完成的流程信息,,, act_hi_procinst 没有endtime表示没有执行完, duration:耗时时间
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().finished().list();
// 查找所有
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().list();
for (HistoricProcessInstance historicProcessInstance : list) {
if (historicProcessInstance.getEndTime() == null){
// 没有执行完
}else {
// 执行完了
}
}
任务历史信息
List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().taskAssignee("cc").list();
List<HistoricTaskInstance> finish = historyService.createHistoricTaskInstanceQuery().taskAssignee("cc").finished().list();
List<HistoricTaskInstance> unfinish = historyService.createHistoricTaskInstanceQuery().taskAssignee("cc").unfinished().list();
// endTime 是否为null,判断是否完成
System.out.println("list.size() = " + list.size());
System.out.println("finish.size() = " + finish.size());
System.out.println("unfinish.size() = " + unfinish.size());
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().finished().list();
for (HistoricProcessInstance historicProcessInstance : list) {
// 根据 流程实例id(processInstanceId) 查找task
List<HistoricTaskInstance> taskList = historyService.createHistoricTaskInstanceQuery().processInstanceId(historicProcessInstance.getId()).finished().list();
System.out.println(taskList.size());
System.out.println("================");
}
活动历史信息
act_hi_actinst
: 活动实例: 每一个活动都在里面,,包括,起始节点,连线,终点
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().finished().list();
for (HistoricProcessInstance historicProcessInstance : list) {
List<HistoricActivityInstance> list1 = historyService.createHistoricActivityInstanceQuery()
// 流程实例id查询
.processInstanceId(historicProcessInstance.getId())
// 开始时间排序
.orderByHistoricActivityInstanceStartTime()
// 升序
.asc()
.list();
for (HistoricActivityInstance activityInstance : list1) {
System.out.println("activityInstance = " + activityInstance.getStartTime());
}
}
List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().activityType("startEvent")
.orderByHistoricActivityInstanceStartTime()
.desc()
.list();
for (HistoricActivityInstance historicActivityInstance : list) {
System.out.println(historicActivityInstance.getActivityType()+historicActivityInstance.getStartTime());
}
历史变量信息
根据流程id查找变量
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().list();
System.out.println("list.size() = " + list.size());
for (HistoricProcessInstance historicProcessInstance : list) {
List<HistoricVariableInstance> list1 = historyService.createHistoricVariableInstanceQuery().processInstanceId(historicProcessInstance.getId()).list();
for (HistoricVariableInstance historicVariableInstance : list1) {
System.out.println("historicVariableInstance = " + historicVariableInstance.getValue());
}
}
// 查找指定名字的 variable
List<HistoricVariableInstance> list1 = historyService.createHistoricVariableInstanceQuery().processInstanceId(historicProcessInstance.getId()).variableName("birthday").list();
日志历史信息
历史日志就是 上面这四个东西,,可以查找上面的四个,,act_hi_procInst
,act_hi_varinst
,act_hi_taskinst
,act_hi_actinst
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().list();
for (HistoricProcessInstance historicProcessInstance : list) {
ProcessInstanceHistoryLog processInstanceHistoryLog = historyService.createProcessInstanceHistoryLogQuery(historicProcessInstance.getId())
// HistoricData : 中包含 variable
.includeVariables()
// HistoricData 中包含 task
.includeTasks()
.singleResult();
System.out.println(processInstanceHistoryLog.getStartTime()+"---"+processInstanceHistoryLog.getId());
List<HistoricData> historicData = processInstanceHistoryLog.getHistoricData();
for (HistoricData data : historicData) {
if (data instanceof HistoricVariableInstance){
// 是 variable
HistoricVariableInstance historicVariableInstance = (HistoricVariableInstance) data;
System.out.println("historicVariableInstance = " + historicVariableInstance.getValue());
}else if (data instanceof HistoricTaskInstance){
// 是task
HistoricTaskInstance historicTaskInstance = (HistoricTaskInstance) data;
System.out.println("historicTaskInstance = " + historicTaskInstance.getName());
}
}
}
历史权限查询
查询历史流程 处理人 : act_hi_identitylink
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().list();
for (HistoricProcessInstance historicProcessInstance : list) {
// 查询 参与者,处理人 act_hi_identitylink
List<HistoricIdentityLink> links = historyService.getHistoricIdentityLinksForProcessInstance(historicProcessInstance.getId());
for (HistoricIdentityLink link : links) {
System.out.println("link.getUserId() = " + link.getUserId());
}
}
查找 指定的任务的 执行人是谁:
String taskName = "组长审批";
HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().taskName(taskName).singleResult();
// 查找 指定task的处理人
List<HistoricIdentityLink> links = historyService.getHistoricIdentityLinksForTask(task.getId());
for (HistoricIdentityLink link : links) {
System.out.println("link.getUserId() = " + link.getUserId());
}
自定义sql查询
// 查询执行完的流程的 任务信息
List<HistoricProcessInstance> list = historyService.createNativeHistoricProcessInstanceQuery().sql("").list();
for (HistoricProcessInstance historicProcessInstance : list) {
// 根据流程id ,, 查找对应的 task
List<HistoricTaskInstance> taskInstanceList = historyService.createNativeHistoricTaskInstanceQuery().sql("").parameter("", "").list();
}
历史数据记录级别
哪些历史信息会被 记录到 act_hi_xxx
表中
配置:
- None : 不存储任何历史信息
- Activity : 存储所有的 流程实例 和 活动实例
- Audit : 在 activity之上,增加了流程的历史详细信息,,
默认
就是这个act_hi_detail
: 详细信息 - Full : 在activity之上,还会存储变量的变化信息,,,就是变量: 曾经是什么。。。流程变量 变化的详细信息在
act_hi_detail
表中
配置文件: