|
|
|
@ -52,6 +52,7 @@ import java.io.File; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.function.Function; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
import static com.teaching.backend.constant.RoleConstants.TEACHER_ROLE; |
|
|
|
@ -640,57 +641,76 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<CourseUserInfVO> queryCourseUserForTeacher(Long userId) { |
|
|
|
|
// 查询所有与该教师相关的课程
|
|
|
|
|
List<Courses> teacherCoursesInf = coursesMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<Courses>() |
|
|
|
|
// 1. 获取该教师负责的所有课程
|
|
|
|
|
List<Courses> teacherCoursesInf = coursesMapper.selectList(new LambdaQueryWrapper<Courses>() |
|
|
|
|
.apply("FIND_IN_SET({0}, teacher)", userId) |
|
|
|
|
.select(Courses::getId, Courses::getTeacher) |
|
|
|
|
.select(Courses::getId, Courses::getTeacher, Courses::getName) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 2. 提取所有课程的ID
|
|
|
|
|
Set<String> courseIds = teacherCoursesInf.stream() |
|
|
|
|
.map(Courses::getId) |
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
// 3. 批量查询所有课程的学生ID
|
|
|
|
|
List<StudentCourses> studentCourses = studentCoursesMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<StudentCourses>().in(StudentCourses::getCourse, courseIds) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 4. 获取所有的学生ID
|
|
|
|
|
Set<Long> studentIds = studentCourses.stream() |
|
|
|
|
.map(StudentCourses::getStudent) |
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
// 5. 批量查询所有学生的信息
|
|
|
|
|
List<UmsStudent> students = umsStudentMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<UmsStudent>().in(UmsStudent::getUserId, studentIds) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 6. 将学生信息缓存到Map中,Key为学生ID
|
|
|
|
|
Map<Long, UmsStudent> studentMap = students.stream() |
|
|
|
|
.collect(Collectors.toMap(UmsStudent::getUserId, Function.identity())); |
|
|
|
|
|
|
|
|
|
// 7. 处理教师信息并构建返回结果
|
|
|
|
|
List<CourseUserInfVO> courseUserInfVOS = new ArrayList<>(); |
|
|
|
|
for (Courses courses : teacherCoursesInf) { |
|
|
|
|
for (Courses course : teacherCoursesInf) { |
|
|
|
|
CourseUserInfVO courseUserInfVO = new CourseUserInfVO(); |
|
|
|
|
courseUserInfVO.setCourseId(course.getId()); |
|
|
|
|
courseUserInfVO.setCourseName(course.getName()); |
|
|
|
|
|
|
|
|
|
List<UserReadMessageTimeVO> userReadMessageTimeVOS = new ArrayList<>(); |
|
|
|
|
courseUserInfVO.setCourseId(courses.getId()); |
|
|
|
|
|
|
|
|
|
// 查询与课程相关的所有学生
|
|
|
|
|
List<Long> studentIds = studentCoursesMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<>(StudentCourses.class) |
|
|
|
|
.eq(StudentCourses::getCourse, courses.getId()) |
|
|
|
|
).stream().map(StudentCourses::getStudent).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
// 为每个学生创建一个新的 UserReadMessageTimeVO 对象
|
|
|
|
|
for (Long studentId : studentIds) { |
|
|
|
|
UmsStudent umsStudent = umsStudentMapper.selectOne( |
|
|
|
|
new LambdaQueryWrapper<>(UmsStudent.class) |
|
|
|
|
.eq(UmsStudent::getUserId, studentId) |
|
|
|
|
.select(UmsStudent::getName) |
|
|
|
|
); |
|
|
|
|
if (umsStudent == null) { |
|
|
|
|
log.error("用户不存在: {}",studentId); |
|
|
|
|
|
|
|
|
|
// 添加学生信息
|
|
|
|
|
for (StudentCourses sc : studentCourses) { |
|
|
|
|
if (sc.getCourse().equals(course.getId())) { |
|
|
|
|
UmsStudent student = studentMap.get(sc.getStudent()); // 类型转换
|
|
|
|
|
if (student != null) { |
|
|
|
|
UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); |
|
|
|
|
userReadMessageTimeVO.setId(student.getUserId()); |
|
|
|
|
userReadMessageTimeVO.setReceiverName(student.getName()); |
|
|
|
|
userReadMessageTimeVOS.add(userReadMessageTimeVO); |
|
|
|
|
} else { |
|
|
|
|
log.error("学生不存在: {}", sc.getStudent()); |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); |
|
|
|
|
} |
|
|
|
|
UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); // 在循环中创建新对象
|
|
|
|
|
userReadMessageTimeVO.setId(studentId); |
|
|
|
|
userReadMessageTimeVO.setReceiverName(umsStudent.getName()); |
|
|
|
|
userReadMessageTimeVOS.add(userReadMessageTimeVO); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 为每个教师创建一个新的 UserReadMessageTimeVO 对象
|
|
|
|
|
String[] teacherUserIds = courses.getTeacher().split(","); |
|
|
|
|
// 添加教师信息
|
|
|
|
|
String[] teacherUserIds = course.getTeacher().split(","); |
|
|
|
|
for (String teacherId : teacherUserIds) { |
|
|
|
|
UmsTeacher umsTeacher = umsTeacherMapper.selectOne( |
|
|
|
|
new LambdaQueryWrapper<UmsTeacher>() |
|
|
|
|
.eq(UmsTeacher::getUserId, teacherId) |
|
|
|
|
new LambdaQueryWrapper<UmsTeacher>().eq(UmsTeacher::getUserId, teacherId) |
|
|
|
|
); |
|
|
|
|
if (umsTeacher == null) { |
|
|
|
|
log.error("教师不存在: {}",teacherId); |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); |
|
|
|
|
} |
|
|
|
|
UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); // 在循环中创建新对象
|
|
|
|
|
if (umsTeacher != null) { |
|
|
|
|
UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); |
|
|
|
|
userReadMessageTimeVO.setId(umsTeacher.getUserId()); |
|
|
|
|
userReadMessageTimeVO.setReceiverName(umsTeacher.getName()); |
|
|
|
|
userReadMessageTimeVOS.add(userReadMessageTimeVO); |
|
|
|
|
} else { |
|
|
|
|
log.error("教师不存在: {}", teacherId); |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
courseUserInfVO.setUsersInf(userReadMessageTimeVOS); |
|
|
|
@ -700,64 +720,94 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<CourseUserInfVO> queryCourseUserForStudent(Long userId) { |
|
|
|
|
// 查询学生所参与的所有课程
|
|
|
|
|
List<StudentCourses> studentCoursesList = studentCoursesMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<StudentCourses>() |
|
|
|
|
.eq(StudentCourses::getStudent, userId) |
|
|
|
|
.select(StudentCourses::getCourse) |
|
|
|
|
// 1. 获取学生参与的所有课程
|
|
|
|
|
List<StudentCourses> studentCourses = studentCoursesMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<StudentCourses>().eq(StudentCourses::getStudent, userId) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 2. 提取所有课程的ID
|
|
|
|
|
Set<String> courseIds = studentCourses.stream() |
|
|
|
|
.map(StudentCourses::getCourse) |
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
// 3. 批量查询所有课程的信息
|
|
|
|
|
List<Courses> coursesList = coursesMapper.selectBatchIds(courseIds); |
|
|
|
|
|
|
|
|
|
// 4. 获取所有的教师ID
|
|
|
|
|
Set<Long> teacherIds = coursesList.stream() |
|
|
|
|
.flatMap(course -> Arrays.stream(course.getTeacher().split(","))) |
|
|
|
|
.map(Long::parseLong) |
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
// 5. 批量查询所有教师的信息
|
|
|
|
|
List<UmsTeacher> teachers = umsTeacherMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<UmsTeacher>().in(UmsTeacher::getUserId, teacherIds) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 6. 将教师信息缓存到Map中,Key为教师ID
|
|
|
|
|
Map<Long, UmsTeacher> teacherMap = teachers.stream() |
|
|
|
|
.collect(Collectors.toMap(UmsTeacher::getUserId, Function.identity())); |
|
|
|
|
|
|
|
|
|
// 7. 批量查询所有课程的学生信息
|
|
|
|
|
List<StudentCourses> allStudentCourses = studentCoursesMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<StudentCourses>().in(StudentCourses::getCourse, courseIds) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 8. 提取所有学生的ID
|
|
|
|
|
Set<Long> allStudentIds = allStudentCourses.stream() |
|
|
|
|
.map(StudentCourses::getStudent) |
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
// 9. 批量查询所有学生的信息
|
|
|
|
|
List<UmsStudent> students = umsStudentMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<UmsStudent>().in(UmsStudent::getUserId, allStudentIds) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 10. 将学生信息缓存到Map中,Key为学生ID
|
|
|
|
|
Map<Long, UmsStudent> studentMap = students.stream() |
|
|
|
|
.collect(Collectors.toMap(UmsStudent::getUserId, Function.identity())); |
|
|
|
|
|
|
|
|
|
// 11. 处理课程信息并构建返回结果
|
|
|
|
|
List<CourseUserInfVO> courseUserInfVOS = new ArrayList<>(); |
|
|
|
|
for (StudentCourses studentCourse : studentCoursesList) { |
|
|
|
|
for (Courses course : coursesList) { |
|
|
|
|
CourseUserInfVO courseUserInfVO = new CourseUserInfVO(); |
|
|
|
|
courseUserInfVO.setCourseId(course.getId()); |
|
|
|
|
courseUserInfVO.setCourseName(course.getName()); |
|
|
|
|
|
|
|
|
|
List<UserReadMessageTimeVO> userReadMessageTimeVOS = new ArrayList<>(); |
|
|
|
|
courseUserInfVO.setCourseId(studentCourse.getCourse()); |
|
|
|
|
|
|
|
|
|
// 查询与课程相关的所有学生
|
|
|
|
|
List<Long> studentIds = studentCoursesMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<>(StudentCourses.class) |
|
|
|
|
.eq(StudentCourses::getCourse, studentCourse.getCourse()) |
|
|
|
|
).stream().map(StudentCourses::getStudent).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
// 为每个学生创建一个新的 UserReadMessageTimeVO 对象
|
|
|
|
|
for (Long studentId : studentIds) { |
|
|
|
|
UmsStudent umsStudent = umsStudentMapper.selectOne( |
|
|
|
|
new LambdaQueryWrapper<>(UmsStudent.class) |
|
|
|
|
.eq(UmsStudent::getUserId, studentId) |
|
|
|
|
.select(UmsStudent::getName) |
|
|
|
|
); |
|
|
|
|
if (umsStudent == null) { |
|
|
|
|
log.error("用户不存在: {}", studentId); |
|
|
|
|
|
|
|
|
|
// 添加教师信息
|
|
|
|
|
String[] courseTeacherIds = course.getTeacher().split(","); |
|
|
|
|
for (String teacherId : courseTeacherIds) { |
|
|
|
|
UmsTeacher umsTeacher = teacherMap.get(Long.valueOf(teacherId)); |
|
|
|
|
if (umsTeacher != null) { |
|
|
|
|
UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); |
|
|
|
|
userReadMessageTimeVO.setId(umsTeacher.getUserId()); |
|
|
|
|
userReadMessageTimeVO.setReceiverName(umsTeacher.getName()); |
|
|
|
|
userReadMessageTimeVOS.add(userReadMessageTimeVO); |
|
|
|
|
} else { |
|
|
|
|
log.error("教师不存在: {}", teacherId); |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); |
|
|
|
|
} |
|
|
|
|
UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); // 在循环中创建新对象
|
|
|
|
|
userReadMessageTimeVO.setId(studentId); |
|
|
|
|
userReadMessageTimeVO.setReceiverName(umsStudent.getName()); |
|
|
|
|
userReadMessageTimeVOS.add(userReadMessageTimeVO); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询与课程相关的所有教师
|
|
|
|
|
Courses course = coursesMapper.selectById(studentCourse.getCourse()); |
|
|
|
|
if (course != null) { |
|
|
|
|
String[] teacherUserIds = course.getTeacher().split(","); |
|
|
|
|
for (String teacherId : teacherUserIds) { |
|
|
|
|
UmsTeacher umsTeacher = umsTeacherMapper.selectOne( |
|
|
|
|
new LambdaQueryWrapper<UmsTeacher>() |
|
|
|
|
.eq(UmsTeacher::getUserId, teacherId) |
|
|
|
|
); |
|
|
|
|
if (umsTeacher == null) { |
|
|
|
|
log.error("教师不存在: {}", teacherId); |
|
|
|
|
// 添加学生信息
|
|
|
|
|
for (StudentCourses sc : allStudentCourses) { |
|
|
|
|
if (sc.getCourse().equals(course.getId())) { |
|
|
|
|
UmsStudent student = studentMap.get(sc.getStudent()); // 类型转换
|
|
|
|
|
if (student != null) { |
|
|
|
|
UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); |
|
|
|
|
userReadMessageTimeVO.setId(student.getUserId()); |
|
|
|
|
userReadMessageTimeVO.setReceiverName(student.getName()); |
|
|
|
|
userReadMessageTimeVOS.add(userReadMessageTimeVO); |
|
|
|
|
} else { |
|
|
|
|
log.error("学生不存在: {}", sc.getStudent()); |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); |
|
|
|
|
} |
|
|
|
|
UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); // 在循环中创建新对象
|
|
|
|
|
userReadMessageTimeVO.setId(umsTeacher.getUserId()); |
|
|
|
|
userReadMessageTimeVO.setReceiverName(umsTeacher.getName()); |
|
|
|
|
userReadMessageTimeVOS.add(userReadMessageTimeVO); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
log.error("课程不存在: {}", studentCourse.getCourse()); |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_COURSE_NOTEXISTS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
courseUserInfVO.setUsersInf(userReadMessageTimeVOS); |
|
|
|
@ -766,6 +816,8 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
return courseUserInfVOS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|