肖海南学生管理分页查询优化

master
总裁 3 months ago
parent 5c9061d8df
commit 395d4b0078
  1. 2
      src/main/java/com/teaching/backend/service/courses/ICoursesService.java
  2. 31
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  3. 2
      src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java

@ -54,7 +54,7 @@ public interface ICoursesService extends IService<Courses> {
List<PersonalCenterStudentListVO> queryStudentList(String userId); List<PersonalCenterStudentListVO> queryStudentList(String userId);
LinkedHashSet<UmsStudentManage> queryTeacherByStudentLearningRecordList(String userId); LinkedHashSet<UmsStudentManage> queryTeacherByStudentLearningRecordList(String userId);
LinkedHashSet<UmsStudentManage> queryTeacherByStudentList(String userId); List<UmsStudentManage> queryTeacherByStudentList(String userId);
List<CourseUserInfVO> getUserInfByCourse(Long userId); List<CourseUserInfVO> getUserInfByCourse(Long userId);
} }

@ -407,25 +407,28 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
} }
@Override @Override
public LinkedHashSet<UmsStudentManage> queryTeacherByStudentList(String userId) { public List<UmsStudentManage> queryTeacherByStudentList(String userId) {
String roleId = umsUserMapper.getByIdRoleId(userId); String roleId = umsUserMapper.getByIdRoleId(userId);
CourseQuery courseQuery = new CourseQuery(); CourseQuery courseQuery = new CourseQuery();
courseQuery.setUserId(userId); courseQuery.setUserId(userId);
LinkedHashSet<UmsStudentManage> umsStudentManageList = new LinkedHashSet<>();
if (roleId.equals("1")){ if (roleId.equals("1")){
PageDTO<CoursesVO> queryCourses = queryCourses(courseQuery); PageDTO<CoursesVO> queryCourses = queryForTeacher(courseQuery);
List<CoursesVO> coursesList = queryCourses.getList(); List<CoursesVO> coursesList = queryCourses.getList();
List<String> courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList());
for (String courseId : courseIds) { // 首先,收集所有需要查询的学生ID
List<StudentCourses> studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); Set<Long> studentIds = coursesList.stream()
for (StudentCourses studentUsername : studentUsernames) { .map(CoursesVO::getId)
UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(String.valueOf(studentUsername.getStudent())); .flatMap(courseId -> studentCoursesMapper.selectBatchSomeStudent(courseId).stream()
if (umsStudentManage != null){ .map(StudentCourses::getStudent)) // 假设getStudent返回Long类型
umsStudentManageList.add(umsStudentManage); .collect(Collectors.toSet()); // 使用Set去重
}
} // 然后,一次性查询所有学生信息
} List<UmsStudentManage> umsStudentManageLists = studentIds.stream()
return umsStudentManageList; .map(studentId -> umsStudentManageMapper.queryStudent(String.valueOf(studentId))) // 假设queryStudent接受Long类型参数
.filter(Objects::nonNull)
.collect(Collectors.toList());
return umsStudentManageLists;
} }
throw new BusinessException(400,"只有老师才有此功能"); throw new BusinessException(400,"只有老师才有此功能");
} }

@ -54,7 +54,7 @@ public class UmsStudentManageServiceImpl extends ServiceImpl<UmsStudentManageMap
@Override @Override
public Map<String, Object> pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO) { public Map<String, Object> pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO) {
LinkedHashSet<UmsStudentManage> umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getUserId()); List<UmsStudentManage> umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getUserId());
//总记录数 //总记录数
int totalCount = umsStudentManages.size(); int totalCount = umsStudentManages.size();

Loading…
Cancel
Save