diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 28fa366..4768bd4 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -66,7 +66,7 @@ public class CoursesController { @ApiOperation("查询课程列表") - @ValidateParams({"username"}) + @ValidateParams({"userId"}) @GetMapping("/page") // @PostMapping("/page") public BaseResponse> getCourses(CourseQuery courseQuery){ diff --git a/src/main/java/com/teaching/backend/model/query/CourseQuery.java b/src/main/java/com/teaching/backend/model/query/CourseQuery.java index a8901a3..b8d1e73 100644 --- a/src/main/java/com/teaching/backend/model/query/CourseQuery.java +++ b/src/main/java/com/teaching/backend/model/query/CourseQuery.java @@ -15,8 +15,8 @@ public class CourseQuery extends PageQuery { @ApiModelProperty("课程名称关键字") private String name; - @ApiModelProperty(value = "用户的username",required = true) - private String username; + @ApiModelProperty(value = "用户的userId",required = true) + private String userId; // @ApiModelProperty(value = "用户的角色id",required = true) // private List roleId; 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 07efd11..ebc2af3 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 @@ -140,10 +140,14 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public PageDTO queryCourses(CourseQuery courseQuery) { - int roleId = Integer.parseInt(umsUserMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsUser::getUsername, courseQuery.getUsername())).getRoleId()); +// int roleId = Integer.parseInt(umsUserMapper.selectOne(new LambdaQueryWrapper() +// .eq(UmsUser::getUsername, courseQuery.getUsername())).getRoleId()); + UmsUser umsUser = umsUserMapper.selectById(courseQuery.getUserId()); + if (umsUser == null){ + throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); + } + int roleId = Integer.parseInt(umsUser.getRoleId()); PageDTO coursesVOPageDTO; - switch (roleId) { //教师--也是管理员--但是只能看自己的课程,有搜索功能 case 1: @@ -168,7 +172,7 @@ public class CoursesServiceImpl extends ServiceImpl impl Page page = courseQuery.toMpPageDefaultSortByCreateTime(); Page p = lambdaQuery() .like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) - .apply("FIND_IN_SET({0}, teacher)", courseQuery.getUsername()) + .apply("FIND_IN_SET({0}, teacher)", courseQuery.getUserId()) .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()) @@ -178,11 +182,10 @@ public class CoursesServiceImpl extends ServiceImpl impl private PageDTO queryForStudent(CourseQuery courseQuery) { List studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper() - .eq(StudentCourses::getStudent, courseQuery.getUsername())); + .eq(StudentCourses::getStudent, courseQuery.getUserId())); List coursesList = studentCourses.stream() .map(StudentCourses::getCourse) .collect(Collectors.toList()); - Page page = courseQuery.toMpPageDefaultSortByCreateTime(); Page p = lambdaQuery() .like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) @@ -190,7 +193,6 @@ public class CoursesServiceImpl extends ServiceImpl impl .page(page); return PageDTO.of(p, CoursesVO.class); } - private PageDTO queryForAdmin(CourseQuery courseQuery) { Page page = courseQuery.toMpPageDefaultSortByCreateTime(); Page p = lambdaQuery() @@ -206,17 +208,16 @@ public class CoursesServiceImpl extends ServiceImpl impl private void populateTeacherNames(List courseList) { for (CoursesVO coursesVO : courseList) { List teacherNameList = new ArrayList<>(); - String[] teacherIds = coursesVO.getTeacher().split(","); - for (String teacherId : teacherIds) { - UmsUser umsUserTea = umsUserMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsUser::getUsername, teacherId)); - if (umsUserTea == null) { - throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); - } + String[] teacherUserIds = coursesVO.getTeacher().split(","); + for (String teacherId : teacherUserIds) { +// UmsUser umsUserTea = umsUserMapper.selectOne(new LambdaQueryWrapper() +// .eq(UmsUser::getUsername, teacherId)); +// if (umsUserTea == null) { +// throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); +// } // System.out.println(umsAdminTea); UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsTeacher::getUserId, umsUserTea.getId())); -// System.out.println(umsTeacher); + .eq(UmsTeacher::getUserId,teacherId)); if (umsTeacher == null){ throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java index 7b83c8a..4a92433 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java @@ -84,12 +84,12 @@ public class StudentCoursesServiceImpl extends ServiceImpl queryCourses(CourseQuery courseQuery) { - String username = courseQuery.getUsername(); - if (username == null || username.equals("")) { + String userId = courseQuery.getUserId(); + if (userId == null || userId.equals("")) { throw new BusinessException(ErrorCode.STUDENT_NOT_EXIT); } List studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper() - .eq(StudentCourses::getStudent, username)); + .eq(StudentCourses::getStudent, userId)); List coursesList = studentCourses.stream() .map(StudentCourses::getCourse) .collect(Collectors.toList());