Activiti:历史任务管理HistoryService
查询指定用户的已处理任务
@Autowired
HistoryService historyService;
/**
* select distinct RES.* from ACT_HI_TASKINST RES
* WHERE RES.ASSIGNEE_ = ? and RES.END_TIME_ is not null
* order by RES.START_TIME_ desc LIMIT ? OFFSET ?
* 查询流程变量信息 .includeProcessVariables()
* select distinct RES.*, VAR.ID_ as VAR_ID_, VAR.NAME_ as VAR_NAME_, VAR.VAR_TYPE_ as VAR_TYPE_, VAR.REV_ as VAR_REV_,
* VAR.PROC_INST_ID_ as VAR_PROC_INST_ID_, VAR.EXECUTION_ID_ as VAR_EXECUTION_ID_, VAR.TASK_ID_ as VAR_TASK_ID_,
* VAR.BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, VAR.DOUBLE_ as VAR_DOUBLE_, VAR.TEXT_ as VAR_TEXT_, VAR.TEXT2_ as VAR_TEXT2_,
* VAR.LAST_UPDATED_TIME_ as VAR_LAST_UPDATED_TIME_, VAR.LONG_ as VAR_LONG_
* from ACT_HI_TASKINST RES
* left outer join ACT_HI_VARINST VAR ON RES.PROC_INST_ID_ = VAR.EXECUTION_ID_
* and VAR.TASK_ID_ is null WHERE RES.ASSIGNEE_ = ?
* and RES.END_TIME_ is not null
* order by RES.START_TIME_ desc, VAR.LAST_UPDATED_TIME_ asc LIMIT ? OFFSET ?
*/
@Test
public void getCompleteTask() {
List<HistoricTaskInstance> taskInstances = historyService.createHistoricTaskInstanceQuery()
.taskAssignee("wsy") // 办理人
.includeProcessVariables()
.orderByTaskCreateTime()
.desc() // 任务创建时间降序
.finished()
.list();
for (HistoricTaskInstance task : taskInstances) {
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.getProcessDefinitionId());
System.out.print(",流程实例id: " +task.getProcessInstanceId());
System.out.println(",业务id: " +task.getBusinessKey());
System.out.println("流程变量: " +task.getProcessVariables());
}
}
查询流程实例的办理历史节点信息
@Autowired
HistoryService historyService;
/**
* select RES.* from ACT_HI_ACTINST RES WHERE RES.PROC_INST_ID_ = ? order by START_TIME_ asc LIMIT ? OFFSET ?
*/
@Test
public void historyInfo() {
//获取查询对象
HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery();
//开始查询 流程实例id
List<HistoricActivityInstance> list = query.processInstanceId("972f8cfc-b825-11ed-b29c-38f3abe10e1d")
.orderByHistoricActivityInstanceStartTime()
.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.println("任务办理人: " + hi.getAssignee());
}
}
查询已结束的流程实例
@Autowired
HistoryService historyService;
/**
* select distinct RES.* , DEF.KEY_ as PROC_DEF_KEY_, DEF.NAME_ as PROC_DEF_NAME_, DEF.VERSION_ as PROC_DEF_VERSION_,
* DEF.DEPLOYMENT_ID_ as DEPLOYMENT_ID_
* from ACT_HI_PROCINST RES
* left outer join ACT_RE_PROCDEF DEF on RES.PROC_DEF_ID_ = DEF.ID_
* WHERE RES.END_TIME_ is not NULL
* order by RES.END_TIME_ desc LIMIT ? OFFSET ?
*/
@Test
public void getProcInstListFinish() {
List<HistoricProcessInstance> historics = historyService.createHistoricProcessInstanceQuery()
.orderByProcessInstanceEndTime()
.desc()
.finished()
.list();
for (HistoricProcessInstance historic : historics) {
System.out.print("流程实例id:"+historic.getId());
System.out.print(",流程实例名称:"+historic.getName());
System.out.print(",流程标识key:"+historic.getProcessDefinitionKey());
System.out.print(",流程定义版本号:"+historic.getProcessDefinitionVersion());
System.out.print(",业务id:"+historic.getBusinessKey());
System.out.print(",流程发起人:"+historic.getStartUserId());
System.out.print(",开始时间:"+historic.getStartTime());
System.out.print(",结束时间:"+historic.getEndTime());
System.out.println("删除原因详情:"+historic.getDeleteReason());
}
}