diff --git a/src/main/java/com/teaching/backend/common/ErrorCode.java b/src/main/java/com/teaching/backend/common/ErrorCode.java index f166ba9..5ae2725 100644 --- a/src/main/java/com/teaching/backend/common/ErrorCode.java +++ b/src/main/java/com/teaching/backend/common/ErrorCode.java @@ -19,6 +19,8 @@ public enum ErrorCode { COURSES_NOT_EXIT(40007, "缺少课程信息"), CONTENT_NOT_EXIT(40008, "内容id不存在"), KNOWS_EXIT(40009, "该项下面存在关联的知识点"), + INVALID_ROLE(400010, "角色不存在"), + NOT_LOGIN_ERROR(40100, "未登录"), NO_AUTH_ERROR(40101, "无权限"), NOT_FOUND_ERROR(40400, "请求数据不存在"), 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 16ca638..73947c2 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -30,7 +30,7 @@ import java.util.*; * @author zjh * @since 2024-05-30 */ -@Api(tags = "教师管理课程接口") +@Api(tags = "课程管理接口") @RestController @RequestMapping("/coursesteacher") public class CoursesController { diff --git a/src/main/java/com/teaching/backend/controller/courses/StudentCoursesController.java b/src/main/java/com/teaching/backend/controller/courses/StudentCoursesController.java index a59d349..92e9d5c 100644 --- a/src/main/java/com/teaching/backend/controller/courses/StudentCoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/StudentCoursesController.java @@ -39,11 +39,5 @@ public class StudentCoursesController { return ResultUtils.success(data); } - @ApiOperation("查询课程列表") - @GetMapping("/page") - public BaseResponse> getCourses(CourseQuery courseQuery){ - PageDTO coursesList = studentCoursesService.queryCourses(courseQuery); - return ResultUtils.success(coursesList); - } } diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index 2737450..ad37b32 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -37,5 +37,4 @@ public interface ICoursesService extends IService { void down(HttpServletResponse response, String id) throws Exception; - void populateTeacherNames(List courseList); } 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 5aad33f..9a2d9ab 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 @@ -10,19 +10,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.common.ErrorCode; import com.teaching.backend.exception.BusinessException; -import com.teaching.backend.mapper.courses.CourseObjectivesMapper; -import com.teaching.backend.mapper.courses.CoursesMapper; -import com.teaching.backend.mapper.courses.ObjectiveContentsMapper; -import com.teaching.backend.mapper.courses.ObjectivesTypeMapper; +import com.teaching.backend.mapper.courses.*; import com.teaching.backend.mapper.umsAdmin.UmsAdminMapper; import com.teaching.backend.mapper.umsAdmin.UmsAdminRoleRelationMapper; import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.dto.courses.PageDTO; -import com.teaching.backend.model.entity.courses.CourseObjectives; -import com.teaching.backend.model.entity.courses.Courses; -import com.teaching.backend.model.entity.courses.ObjectiveContents; -import com.teaching.backend.model.entity.courses.ObjectivesType; +import com.teaching.backend.model.entity.courses.*; import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; import com.teaching.backend.model.entity.umsAdmin.UmsAdminRoleRelation; import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; @@ -75,6 +69,8 @@ public class CoursesServiceImpl extends ServiceImpl impl UmsTeacherMapper umsTeacherMapper; @Autowired UmsAdminRoleRelationMapper umsAdminRoleRelationMapper; + @Autowired + StudentCoursesMapper studentCoursesMapper; @Override @@ -142,26 +138,64 @@ public class CoursesServiceImpl extends ServiceImpl impl UmsAdminRoleRelation umsAdminRoleRelation = umsAdminRoleRelationMapper.selectOne(new LambdaQueryWrapper() .eq(UmsAdminRoleRelation::getAdminId, umsAdmin.getId())); - // Determine if the user is a teacher - boolean isTeacher = umsAdminRoleRelation.getRoleId() == CourseCode.TEACHER_ROLE_ID.getValue(); + int roleId = Math.toIntExact(umsAdminRoleRelation.getRoleId()); + PageDTO coursesVOPageDTO; + + switch (roleId) { + case 1: + coursesVOPageDTO = queryForTeacher(courseQuery, username); + break; + case 2: + coursesVOPageDTO = queryForStudent(courseQuery, username); + break; + case 3: + coursesVOPageDTO = queryForAdmin(courseQuery); + break; + default: + throw new BusinessException(ErrorCode.INVALID_ROLE); + } + + populateTeacherNames(coursesVOPageDTO.getList()); + return coursesVOPageDTO; + } + private PageDTO queryForTeacher(CourseQuery courseQuery, String username) { Page page = courseQuery.toMpPageDefaultSortByCreateTime(); Page p = lambdaQuery() .like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) - .apply(isTeacher, "FIND_IN_SET({0}, teacher)", username) - .eq(!isTeacher && courseQuery.getCategory() != null, Courses::getCategory, courseQuery.getCategory()) - .eq(!isTeacher && courseQuery.getNature() != null, Courses::getNature, courseQuery.getNature()) - .eq(!isTeacher && courseQuery.getAssessmenttype() != null, Courses::getAssessmenttype, courseQuery.getAssessmenttype()) - .apply(!isTeacher && courseQuery.getTeacher() != null && !courseQuery.getTeacher().isEmpty(), "FIND_IN_SET({0}, teacher)", courseQuery.getTeacher()) + .apply("FIND_IN_SET({0}, teacher)", username) .page(page); + return PageDTO.of(p, CoursesVO.class); + } - PageDTO coursesVOPageDTO = PageDTO.of(p, CoursesVO.class); - populateTeacherNames(coursesVOPageDTO.getList()); + private PageDTO queryForStudent(CourseQuery courseQuery, String username) { + List studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper() + .eq(StudentCourses::getStudent, username)); + List coursesList = studentCourses.stream() + .map(StudentCourses::getCourse) + .collect(Collectors.toList()); - return coursesVOPageDTO; + Page page = courseQuery.toMpPageDefaultSortByCreateTime(); + Page p = lambdaQuery() + .like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) + .in(Courses::getId, coursesList) + .page(page); + return PageDTO.of(p, CoursesVO.class); + } + + private PageDTO queryForAdmin(CourseQuery courseQuery) { + Page page = courseQuery.toMpPageDefaultSortByCreateTime(); + Page p = lambdaQuery() + .like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) + .eq(courseQuery.getCategory() != null, Courses::getCategory, courseQuery.getCategory()) + .eq(courseQuery.getNature() != null, Courses::getNature, courseQuery.getNature()) + .eq(courseQuery.getAssessmenttype() != null, Courses::getAssessmenttype, courseQuery.getAssessmenttype()) + .apply(courseQuery.getTeacher() != null && !courseQuery.getTeacher().isEmpty(), "FIND_IN_SET({0}, teacher)", courseQuery.getTeacher()) + .page(page); + return PageDTO.of(p, CoursesVO.class); } - public void populateTeacherNames(List courseList) { + private void populateTeacherNames(List courseList) { for (CoursesVO coursesVO : courseList) { List teacherNameList = new ArrayList<>(); String[] teacherIds = coursesVO.getTeacher().split(","); @@ -179,6 +213,7 @@ public class CoursesServiceImpl extends ServiceImpl impl } } + @Override public void deleteBatchByIds(String id) { if(id==null){ diff --git a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java index 2dac173..3f1f99f 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java @@ -54,7 +54,6 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl queryCourses(CourseQuery courseQuery) { String username = courseQuery.getUsername(); @@ -110,7 +111,7 @@ public class StudentCoursesServiceImpl extends ServiceImpl coursesVOPageDTO = PageDTO.of(p, CoursesVO.class); - coursesService.populateTeacherNames(coursesVOPageDTO.getList()); +// coursesService.populateTeacherNames(coursesVOPageDTO.getList()); return coursesVOPageDTO; }