ModelAndView mav = new ModelAndView("/form/finished-list", Collections.singletonMap("processType", processType));
Page<HistoricProcessInstance> page = new Page<HistoricProcessInstance>(PageUtil.PAGE_SIZE);
int[] pageParams = PageUtil.init(page, request);
if (!StringUtils.equals(processType, "all")) {
HistoricProcessInstanceQuery leaveDynamicQuery = historyService.createHistoricProcessInstanceQuery()
.processDefinitionKey("leave-dynamic-from").finished().orderByProcessInstanceEndTime().desc();
List<HistoricProcessInstance> list = leaveDynamicQuery.listPage(pageParams[0], pageParams[1]);
HistoricProcessInstanceQuery dispatchQuery = historyService.createHistoricProcessInstanceQuery()
.processDefinitionKey("dispatch").finished().orderByProcessInstanceEndTime().desc();
List<HistoricProcessInstance> list2 = dispatchQuery.listPage(pageParams[0], pageParams[1]);
HistoricProcessInstanceQuery leaveJpaQuery = historyService.createHistoricProcessInstanceQuery()
.processDefinitionKey("leave-jpa").finished().orderByProcessInstanceEndTime().desc();
List<HistoricProcessInstance> list3 = leaveJpaQuery.listPage(pageParams[0], pageParams[1]);
list.addAll(list2);
list.addAll(list3);
page.setResult(list);
page.setTotalCount(leaveDynamicQuery.count() + dispatchQuery.count());
} else {
HistoricProcessInstanceQuery dynamicQuery = historyService.createHistoricProcessInstanceQuery()
.finished().orderByProcessInstanceEndTime().desc();
List<HistoricProcessInstance> list = dynamicQuery.listPage(pageParams[0], pageParams[1]);
page.setResult(list);
page.setTotalCount(dynamicQuery.count());
}
mav.addObject("page", page);
return mav;
}