查询指定用户的已处理任务
@Autowired
HistoryService historyService;
/**
* 查询当前用户的已处理任务
*/
@Test
public void findCompleteTask() {
//办理人(当前用户)
String assignee = "wj1";
List<HistoricTaskInstance> taskList = historyService.createHistoricTaskInstanceQuery()
.taskAssignee(assignee) // 办理人
.orderByTaskCreateTime().desc()
.finished() // 任务已办理
.list();
for (HistoricTaskInstance task : taskList) {
System.out.print("任务ID:" + task.getId());
System.out.print(",任务名称:" + task.getName());
System.out.print(",任务的开始时间:" + task.getStartTime());
System.out.print(",任务的结束时间:" + task.getEndTime());
System.out.print(",任务的办理人:" + task.getAssignee());
System.out.print(",流程实例ID:" + task.getProcessInstanceId());
System.out.print(",流程定义ID:" + task.getProcessDefinitionId());
System.out.println(",业务唯一标识:" + task.getBusinessKey());
}
}
查询流程实例办理历史信息
/**
* 查询流程实例办理历史信息
*/
@Test
public void historyInfo() {
// 获取历史节点查询对象 ACT_HI_ACTINST 表
HistoricActivityInstanceQuery query =
historyService.createHistoricActivityInstanceQuery();
// 实例 id
String processInstanceId = "1ef2b3df-cc1e-11ec-9116-28d0ea3dce6b";
List<HistoricActivityInstance> list = query.processInstanceId(processInstanceId)
.orderByHistoricActivityInstanceStartTime().asc() // 根据开始时间排序 asc 升序
.list();
for (HistoricActivityInstance hi : list) {
System.out.print("流程定义ID: " + hi.getProcessDefinitionId());
System.out.print(",流程实例ID: " + hi.getProcessInstanceId());
System.out.print(",节点ID: " + hi.getActivityId());
System.out.print(",节点名称: " + hi.getActivityName());
System.out.print(",任务办理人:" + hi.getAssignee());
System.out.print(",开始时间:" + hi.getStartTime());
System.out.println("结束时间:" + hi.getEndTime());
}
}
查询已结束的流程实例
/**
* 查询已结束的流程实例
*/
@Test
public void getProcInstListFinish() {
List<HistoricProcessInstance> instanceList =
historyService.createHistoricProcessInstanceQuery()
.orderByProcessInstanceEndTime()
.desc()
.finished()
.list();
for (HistoricProcessInstance instance : instanceList) {
System.out.print("流程实例id:" + instance.getId());
System.out.print(",流程实例名称:"+instance.getName());
System.out.print(",流程唯一key:"+instance.getProcessDefinitionKey());
System.out.print(",流程定义版本号:"+instance.getProcessDefinitionVersion());
System.out.print(",流程发起人:"+instance.getStartUserId());
System.out.print(",业务唯一标识:"+instance.getBusinessKey());
System.out.print(",开始时间:"+instance.getStartTime() );
System.out.print(",结束时间:"+instance.getEndTime() );
System.out.println(",原因详情:"+instance.getDeleteReason());
}
}
删除已结束流程实例历史记录
/**
* 删除已结束的流程实例
* ACT_HI_DETAIL
* ACT_HI_VARINST
* ACT_HI_TASKINST
* ACT_HI_PROCINST
* ACT_HI_ACTINST
* ACT_HI_IDENTITYLINK
* ACT_HI_COMMENT
*/
@Test
public void deleteFinishProcInst() {
String procInstId = "1ef2b3df-cc1e-11ec-9116-28d0ea3dce6b";
// 1. 查询流程实例是否已结束
HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(procInstId)
.finished()
.singleResult();
if(instance == null) {
System.out.println("流程实例未结束或不存在");
return;
}
// 2. 删除已结束流程实例(如果实例未结束,会抛出异常)
historyService.deleteHistoricProcessInstance(procInstId);
}