Jelajahi Sumber

储备中班级人数改成统计

周箭河 5 tahun lalu
induk
melakukan
6a5bd3f8f4

+ 17 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupServiceImpl.java

@@ -130,18 +130,26 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
     	PageInfo<ClassGroup> pageInfo = new PageInfo<ClassGroup>(queryInfo.getPage(), queryInfo.getRows());
 		Map<String, Object> params = new HashMap<String, Object>();
 		MapUtil.populateMap(params, queryInfo);
-		
+
 		List<ClassGroup> dataList = new ArrayList<ClassGroup>();
 		int count = this.findCount(params);
 		if (count > 0) {
-			pageInfo.setTotal(count);
-			params.put("offset", pageInfo.getOffset());
-			dataList = this.getDAO().queryPage(params);
-		}
-		for (ClassGroup cg : dataList) {
-			cg.setTeacherMapperList(classGroupTeacherMapperDao.findClassGroupTeachers(cg.getId() + ""));
-			cg.setCourseScheduleList(courseScheduleDao.findCoursesByClassGroupId(cg.getId(), null));
-		}
+            pageInfo.setTotal(count);
+            params.put("offset", pageInfo.getOffset());
+            dataList = this.getDAO().queryPage(params);
+            List<Integer> classGroupIds = dataList.stream().map(ClassGroup::getId).collect(Collectors.toList());
+
+            List<Map<Integer, Integer>> classGroupStudentNumMaps = classGroupStudentMapperDao.countClassGroupsStudentNum(classGroupIds, null);
+            Map<Integer, Long> classGroupStudentNumMap = MapUtil.convertIntegerMap(classGroupStudentNumMaps);
+
+            for (ClassGroup cg : dataList) {
+                Long studentNum = classGroupStudentNumMap.get(cg.getId());
+                cg.setStudentNum(Objects.isNull(studentNum) ? 0 : studentNum.intValue());
+                cg.setTeacherMapperList(classGroupTeacherMapperDao.findClassGroupTeachers(cg.getId() + ""));
+                cg.setCourseScheduleList(courseScheduleDao.findCoursesByClassGroupId(cg.getId(), null));
+            }
+        }
+
 		pageInfo.setRows(dataList);
 		return pageInfo;
 	}