|
|
@ -32,9 +32,12 @@ import com.teaching.backend.model.query.CourseQuery; |
|
|
|
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; |
|
|
|
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; |
|
|
|
import com.teaching.backend.model.vo.courses.CoursesVO; |
|
|
|
import com.teaching.backend.model.vo.courses.CoursesVO; |
|
|
|
import com.teaching.backend.model.vo.courses.PersonalCenterStudentListVO; |
|
|
|
import com.teaching.backend.model.vo.courses.PersonalCenterStudentListVO; |
|
|
|
|
|
|
|
import com.teaching.backend.model.vo.message.CourseUserInfVO; |
|
|
|
|
|
|
|
import com.teaching.backend.model.vo.message.UserReadMessageTimeVO; |
|
|
|
import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO; |
|
|
|
import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO; |
|
|
|
import com.teaching.backend.service.courses.ICoursesService; |
|
|
|
import com.teaching.backend.service.courses.ICoursesService; |
|
|
|
import com.teaching.backend.utils.CourseCode; |
|
|
|
import com.teaching.backend.utils.CourseCode; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.poi.xwpf.usermodel.*; |
|
|
|
import org.apache.poi.xwpf.usermodel.*; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -62,6 +65,7 @@ import static com.teaching.backend.constant.RoleConstants.TEACHER_ROLE; |
|
|
|
* @since 2024-05-30 |
|
|
|
* @since 2024-05-30 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> implements ICoursesService { |
|
|
|
public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> implements ICoursesService { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
@ -382,7 +386,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
List<StudentCourses> studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); |
|
|
|
List<StudentCourses> studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); |
|
|
|
List<CourseLearningRecord> courseLearningRecordList = new ArrayList<>(); |
|
|
|
List<CourseLearningRecord> courseLearningRecordList = new ArrayList<>(); |
|
|
|
for (StudentCourses studentUsername : studentUsernames) { |
|
|
|
for (StudentCourses studentUsername : studentUsernames) { |
|
|
|
CourseLearningRecord courseLearningRecord = courseLearningRecordMapper.selectNewRecord(studentUsername.getStudent()); |
|
|
|
CourseLearningRecord courseLearningRecord = courseLearningRecordMapper.selectNewRecord(String.valueOf(studentUsername.getStudent())); |
|
|
|
courseLearningRecordList.add(courseLearningRecord); |
|
|
|
courseLearningRecordList.add(courseLearningRecord); |
|
|
|
} |
|
|
|
} |
|
|
|
courseLearningRecordList = courseLearningRecordList.stream().sorted(Comparator.comparing(CourseLearningRecord::getTimes).reversed()).collect(Collectors.toList()); |
|
|
|
courseLearningRecordList = courseLearningRecordList.stream().sorted(Comparator.comparing(CourseLearningRecord::getTimes).reversed()).collect(Collectors.toList()); |
|
|
@ -396,6 +400,8 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
throw new BusinessException(400,"只有老师才有此功能"); |
|
|
|
throw new BusinessException(400,"只有老师才有此功能"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<CoursesVO> getPagePageSize(int page, int pageSize) { |
|
|
|
public List<CoursesVO> getPagePageSize(int page, int pageSize) { |
|
|
|
int startIndex = (page-1) * pageSize; |
|
|
|
int startIndex = (page-1) * pageSize; |
|
|
@ -610,6 +616,155 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
document.write(outputStream); |
|
|
|
document.write(outputStream); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public List<CourseUserInfVO> getUserInfByCourse(Long userId) { |
|
|
|
|
|
|
|
UmsUser umsUser = umsUserMapper.selectById(userId); |
|
|
|
|
|
|
|
if (umsUser == null){ |
|
|
|
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int roleId = Integer.parseInt(umsUser.getRoleId()); |
|
|
|
|
|
|
|
List<CourseUserInfVO> courseUserInfVO; |
|
|
|
|
|
|
|
switch (roleId) { |
|
|
|
|
|
|
|
//教师
|
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
courseUserInfVO = queryCourseUserForTeacher(userId); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
//学生
|
|
|
|
|
|
|
|
case 2: |
|
|
|
|
|
|
|
courseUserInfVO = queryCourseUserForStudent(userId); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new BusinessException(ErrorCode.INVALID_ROLE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return courseUserInfVO; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<CourseUserInfVO> courseUserInfVOS = new ArrayList<>(); |
|
|
|
|
|
|
|
for (Courses courses : teacherCoursesInf) { |
|
|
|
|
|
|
|
CourseUserInfVO courseUserInfVO = new CourseUserInfVO(); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); // 在循环中创建新对象
|
|
|
|
|
|
|
|
userReadMessageTimeVO.setId(studentId); |
|
|
|
|
|
|
|
userReadMessageTimeVO.setReceiverName(umsStudent.getName()); |
|
|
|
|
|
|
|
userReadMessageTimeVOS.add(userReadMessageTimeVO); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 为每个教师创建一个新的 UserReadMessageTimeVO 对象
|
|
|
|
|
|
|
|
String[] teacherUserIds = courses.getTeacher().split(","); |
|
|
|
|
|
|
|
for (String teacherId : teacherUserIds) { |
|
|
|
|
|
|
|
UmsTeacher umsTeacher = umsTeacherMapper.selectOne( |
|
|
|
|
|
|
|
new LambdaQueryWrapper<UmsTeacher>() |
|
|
|
|
|
|
|
.eq(UmsTeacher::getUserId, teacherId) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
if (umsTeacher == null) { |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
courseUserInfVOS.add(courseUserInfVO); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return courseUserInfVOS; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<CourseUserInfVO> queryCourseUserForStudent(Long userId) { |
|
|
|
|
|
|
|
// 查询学生所参与的所有课程
|
|
|
|
|
|
|
|
List<StudentCourses> studentCoursesList = studentCoursesMapper.selectList( |
|
|
|
|
|
|
|
new LambdaQueryWrapper<StudentCourses>() |
|
|
|
|
|
|
|
.eq(StudentCourses::getStudent, userId) |
|
|
|
|
|
|
|
.select(StudentCourses::getCourse) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<CourseUserInfVO> courseUserInfVOS = new ArrayList<>(); |
|
|
|
|
|
|
|
for (StudentCourses studentCourse : studentCoursesList) { |
|
|
|
|
|
|
|
CourseUserInfVO courseUserInfVO = new CourseUserInfVO(); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
courseUserInfVOS.add(courseUserInfVO); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return courseUserInfVOS; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|