|
|
|
@ -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; |
|
|
|
@ -359,7 +360,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<PersonalCenterStudentListVO> queryStudentList(String userId) { |
|
|
|
|
LinkedHashSet<UmsStudentManage> umsStudentManageList = queryTeacherByStudentList(userId); |
|
|
|
|
LinkedHashSet<UmsStudentManage> umsStudentManageList = queryTeacherByStudentLearningRecordList(userId); |
|
|
|
|
List<PersonalCenterStudentListVO> personalCenterStudentListVOList = new ArrayList<>(); |
|
|
|
|
PersonalCenterStudentListVO personalCenterStudentListVO = null; |
|
|
|
|
for (UmsStudentManage umsStudentManage : umsStudentManageList) { |
|
|
|
@ -373,8 +374,8 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public LinkedHashSet<UmsStudentManage> queryTeacherByStudentList(String userId) { |
|
|
|
|
String roleId = umsUserMapper.getbyIdRoleId(userId); |
|
|
|
|
public LinkedHashSet<UmsStudentManage> queryTeacherByStudentLearningRecordList(String userId) { |
|
|
|
|
String roleId = umsUserMapper.getByIdRoleId(userId); |
|
|
|
|
CourseQuery courseQuery = new CourseQuery(); |
|
|
|
|
courseQuery.setUserId(userId); |
|
|
|
|
LinkedHashSet<UmsStudentManage> umsStudentManageList = new LinkedHashSet<>(); |
|
|
|
@ -387,20 +388,44 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
List<CourseLearningRecord> courseLearningRecordList = new ArrayList<>(); |
|
|
|
|
for (StudentCourses studentUsername : studentUsernames) { |
|
|
|
|
CourseLearningRecord courseLearningRecord = courseLearningRecordMapper.selectNewRecord(String.valueOf(studentUsername.getStudent())); |
|
|
|
|
courseLearningRecordList.add(courseLearningRecord); |
|
|
|
|
} |
|
|
|
|
courseLearningRecordList = courseLearningRecordList.stream().sorted(Comparator.comparing(CourseLearningRecord::getTimes).reversed()).collect(Collectors.toList()); |
|
|
|
|
for (CourseLearningRecord courseLearningRecord : courseLearningRecordList) { |
|
|
|
|
UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(courseLearningRecord.getUserId()); |
|
|
|
|
umsStudentManageList.add(umsStudentManage); |
|
|
|
|
if (courseLearningRecord != null){ |
|
|
|
|
courseLearningRecordList.add(courseLearningRecord); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
courseLearningRecordList = courseLearningRecordList.stream().sorted(Comparator.comparing(CourseLearningRecord::getTimes).reversed()).collect(Collectors.toList()); |
|
|
|
|
for (CourseLearningRecord courseLearningRecord : courseLearningRecordList) { |
|
|
|
|
UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(courseLearningRecord.getUserId()); |
|
|
|
|
umsStudentManageList.add(umsStudentManage); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return umsStudentManageList; |
|
|
|
|
} |
|
|
|
|
throw new BusinessException(400,"只有老师才有此功能"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public LinkedHashSet<UmsStudentManage> queryTeacherByStudentList(String userId) { |
|
|
|
|
String roleId = umsUserMapper.getByIdRoleId(userId); |
|
|
|
|
CourseQuery courseQuery = new CourseQuery(); |
|
|
|
|
courseQuery.setUserId(userId); |
|
|
|
|
LinkedHashSet<UmsStudentManage> umsStudentManageList = new LinkedHashSet<>(); |
|
|
|
|
if (roleId.equals("1")){ |
|
|
|
|
PageDTO<CoursesVO> queryCourses = queryCourses(courseQuery); |
|
|
|
|
List<CoursesVO> coursesList = queryCourses.getList(); |
|
|
|
|
List<String> courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList()); |
|
|
|
|
for (String courseId : courseIds) { |
|
|
|
|
List<StudentCourses> studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); |
|
|
|
|
for (StudentCourses studentUsername : studentUsernames) { |
|
|
|
|
UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(String.valueOf(studentUsername.getStudent())); |
|
|
|
|
if (umsStudentManage != null){ |
|
|
|
|
umsStudentManageList.add(umsStudentManage); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return umsStudentManageList; |
|
|
|
|
} |
|
|
|
|
throw new BusinessException(400,"只有老师才有此功能"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<CoursesVO> getPagePageSize(int page, int pageSize) { |
|
|
|
@ -640,57 +665,76 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<CourseUserInfVO> queryCourseUserForTeacher(Long userId) { |
|
|
|
|
// 查询所有与该教师相关的课程
|
|
|
|
|
List<Courses> teacherCoursesInf = coursesMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<Courses>() |
|
|
|
|
.apply("FIND_IN_SET({0}, teacher)", userId) |
|
|
|
|
.select(Courses::getId, Courses::getTeacher) |
|
|
|
|
// 1. 获取该教师负责的所有课程
|
|
|
|
|
List<Courses> teacherCoursesInf = coursesMapper.selectList(new LambdaQueryWrapper<Courses>() |
|
|
|
|
.apply("FIND_IN_SET({0}, teacher)", userId) |
|
|
|
|
.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); |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); |
|
|
|
|
|
|
|
|
|
// 添加学生信息
|
|
|
|
|
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); |
|
|
|
|
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(umsTeacher.getUserId()); |
|
|
|
|
userReadMessageTimeVO.setReceiverName(umsTeacher.getName()); |
|
|
|
|
userReadMessageTimeVOS.add(userReadMessageTimeVO); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
courseUserInfVO.setUsersInf(userReadMessageTimeVOS); |
|
|
|
@ -700,64 +744,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 +840,8 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
return courseUserInfVOS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|