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 21139fe..48b2dac 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 @@ -139,43 +139,18 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public PageDTO queryCourses(CourseQuery courseQuery) { - String username = courseQuery.getUsername(); -// if (username == null || username.isEmpty()) { -// throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); -// } - int roleId = Integer.parseInt(umsUserMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsUser::getUsername, username)).getRoleId()); -// System.out.println(courseQuery.getRoleId()); -// int roleId = Integer.parseInt(courseQuery.getRoleId().get(0)); -// System.out.println(roleId); - -// int roleId = Math.toIntExact(umsAdminRoleRelation.getRoleId()); -// int roleId = 0; -// List roleIdList = courseQuery.getRoleId(); -// System.out.println(roleIdList); -// if (roleIdList != null && !roleIdList.isEmpty()) { -// Object firstElement = roleIdList.get(0); -// -// if (firstElement instanceof List) { -// List innerList = (List) firstElement; -// if (!innerList.isEmpty()) { -// roleId = Integer.parseInt((String) innerList.get(0)); -// } -// } else if (firstElement instanceof String) { -// roleId = Integer.parseInt((String) firstElement); -// } -// } + .eq(UmsUser::getUsername, courseQuery.getUsername())).getRoleId()); PageDTO coursesVOPageDTO; switch (roleId) { //教师--也是管理员--但是只能看自己的课程,有搜索功能 case 1: - coursesVOPageDTO = queryForTeacher(courseQuery, username); + coursesVOPageDTO = queryForTeacher(courseQuery); break; //学生 case 2: - coursesVOPageDTO = queryForStudent(courseQuery, username); + coursesVOPageDTO = queryForStudent(courseQuery); break; //这个对应的是以后的院系管理员 这个才能看别的教师的课程 case 3: @@ -184,16 +159,15 @@ public class CoursesServiceImpl extends ServiceImpl impl default: throw new BusinessException(ErrorCode.INVALID_ROLE); } - populateTeacherNames(coursesVOPageDTO.getList()); return coursesVOPageDTO; } - private PageDTO queryForTeacher(CourseQuery courseQuery, String username) { + private PageDTO queryForTeacher(CourseQuery courseQuery) { Page page = courseQuery.toMpPageDefaultSortByCreateTime(); Page p = lambdaQuery() .like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) - .apply("FIND_IN_SET({0}, teacher)", username) + .apply("FIND_IN_SET({0}, teacher)", courseQuery.getUsername()) .eq(courseQuery.getCategory() != null && !courseQuery.getCategory().isEmpty(), Courses::getCategory, courseQuery.getCategory()) .eq(courseQuery.getNature() != null && !courseQuery.getNature().isEmpty(), Courses::getNature, courseQuery.getNature()) .eq(courseQuery.getAssessmenttype() != null &&!courseQuery.getAssessmenttype().isEmpty(), Courses::getAssessmenttype, courseQuery.getAssessmenttype()) @@ -201,9 +175,9 @@ public class CoursesServiceImpl extends ServiceImpl impl return PageDTO.of(p,CoursesVO.class); } - private PageDTO queryForStudent(CourseQuery courseQuery, String username) { + private PageDTO queryForStudent(CourseQuery courseQuery) { List studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper() - .eq(StudentCourses::getStudent, username)); + .eq(StudentCourses::getStudent, courseQuery.getUsername())); List coursesList = studentCourses.stream() .map(StudentCourses::getCourse) .collect(Collectors.toList()); @@ -236,7 +210,7 @@ public class CoursesServiceImpl extends ServiceImpl impl UmsUser umsUserTea = umsUserMapper.selectOne(new LambdaQueryWrapper() .eq(UmsUser::getUsername, teacherId)); if (umsUserTea == null) { - throw new BusinessException(ErrorCode.OPERATION_ERROR); + throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); } // System.out.println(umsAdminTea); UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper()