原来查询方法includeProcessVariables查询var会耗用大量时间遍历,act_ru_variable
HistoricTaskInstanceQuery histTaskQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished() .includeProcessVariables().orderByHistoricTaskInstanceEndTime().desc();
优化,不查询includeProcessVariables
HistoricTaskInstanceQuery histTaskQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished().orderByHistoricTaskInstanceEndTime().desc();
然后在遍历中只一个title
HistoricVariableInstance vars = historyService.createHistoricVariableInstanceQuery().processInstanceId(histTask.getProcessInstanceId())//创建一个历史的流程变量查询 .variableName("title").singleResult();
for (HistoricTaskInstance histTask : histList) { Map<String, Object> mapJson = new Hashtable<String, Object>(); HistoricVariableInstance vars = historyService.createHistoricVariableInstanceQuery().processInstanceId(histTask.getProcessInstanceId())//创建一个历史的流程变量查询 .variableName("title").singleResult(); if(vars != null){ mapJson.put("title", vars.getValue()); } Act e = new Act(); e.setHistTask(histTask); e.setVars(mapJson); //e.setVars(histTask.getProcessVariables()); // e.setTaskVars(histTask.getTaskLocalVariables()); // System.out.println(histTask.getId()+" = "+histTask.getProcessVariables() + " ========== " + histTask.getTaskLocalVariables()); e.setProcDef(ProcessDefCache.get(histTask.getProcessDefinitionId())); // e.setProcIns(runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult()); // e.setProcExecUrl(ActUtils.getProcExeUrl(task.getProcessDefinitionId())); e.setStatus("finish"); page.getList().add(e); }