方法优化,减少调用时间
getAll直接从数据库中查出所有的数据再for循环处理;比for循环一个个的在数据库里查出数据再处理快一些。要尽量避免for循环操作数据库。
long startTime = System.currentTimeMillis();
for(String deptId : deptIds){
Double averageHours = this.yearStudentHoursPlanService.getAverageHoursByDept(year, deptId);
Person person = new Person();
person.setDeptId(deptId);
int countPerson = this.personService.getByPageCount(person);
Double sumHours = averageHours * countPerson;
sumPlanHours = sumPlanHours + sumHours;
sumPlanPerson = sumPlanPerson + countPerson;
}
long endTime = System.currentTimeMillis();
float excTime=(float)(endTime-startTime)/1000;
logger.info("===============耗时:"+ excTime+"秒==============");
===============耗时:11.906秒==============