From 395d4b00786e20c0c731799a4874d8fc2de4d7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 20 Aug 2024 11:30:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/courses/ICoursesService.java | 2 +- .../impl/courses/CoursesServiceImpl.java | 31 ++++++++++--------- .../umsAdmin/UmsStudentManageServiceImpl.java | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index e08a348..5f3d7d5 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -54,7 +54,7 @@ public interface ICoursesService extends IService { List queryStudentList(String userId); LinkedHashSet queryTeacherByStudentLearningRecordList(String userId); - LinkedHashSet queryTeacherByStudentList(String userId); + List queryTeacherByStudentList(String userId); List getUserInfByCourse(Long userId); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index ee9f974..f6d9ba7 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -407,25 +407,28 @@ public class CoursesServiceImpl extends ServiceImpl impl } @Override - public LinkedHashSet queryTeacherByStudentList(String userId) { + public List queryTeacherByStudentList(String userId) { String roleId = umsUserMapper.getByIdRoleId(userId); CourseQuery courseQuery = new CourseQuery(); courseQuery.setUserId(userId); - LinkedHashSet umsStudentManageList = new LinkedHashSet<>(); if (roleId.equals("1")){ - PageDTO queryCourses = queryCourses(courseQuery); + PageDTO queryCourses = queryForTeacher(courseQuery); List coursesList = queryCourses.getList(); - List courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList()); - for (String courseId : courseIds) { - List studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); - for (StudentCourses studentUsername : studentUsernames) { - UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(String.valueOf(studentUsername.getStudent())); - if (umsStudentManage != null){ - umsStudentManageList.add(umsStudentManage); - } - } - } - return umsStudentManageList; + + // 首先,收集所有需要查询的学生ID + Set studentIds = coursesList.stream() + .map(CoursesVO::getId) + .flatMap(courseId -> studentCoursesMapper.selectBatchSomeStudent(courseId).stream() + .map(StudentCourses::getStudent)) // 假设getStudent返回Long类型 + .collect(Collectors.toSet()); // 使用Set去重 + + // 然后,一次性查询所有学生信息 + List umsStudentManageLists = studentIds.stream() + .map(studentId -> umsStudentManageMapper.queryStudent(String.valueOf(studentId))) // 假设queryStudent接受Long类型参数 + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + return umsStudentManageLists; } throw new BusinessException(400,"只有老师才有此功能"); } diff --git a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java index c8b5c32..2d4b5c2 100644 --- a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java @@ -54,7 +54,7 @@ public class UmsStudentManageServiceImpl extends ServiceImpl pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO) { - LinkedHashSet umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getUserId()); + List umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getUserId()); //总记录数 int totalCount = umsStudentManages.size();