查询逻辑修正

master
Alan 4 months ago
parent 4a05b3671d
commit 87ac8ad505
  1. 42
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java

@ -139,43 +139,18 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
@Override
public PageDTO<CoursesVO> 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<UmsUser>()
.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<String> 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<CoursesVO> 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<CoursesMapper, Courses> impl
default:
throw new BusinessException(ErrorCode.INVALID_ROLE);
}
populateTeacherNames(coursesVOPageDTO.getList());
return coursesVOPageDTO;
}
private PageDTO<CoursesVO> queryForTeacher(CourseQuery courseQuery, String username) {
private PageDTO<CoursesVO> queryForTeacher(CourseQuery courseQuery) {
Page<Courses> page = courseQuery.toMpPageDefaultSortByCreateTime();
Page<Courses> 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<CoursesMapper, Courses> impl
return PageDTO.of(p,CoursesVO.class);
}
private PageDTO<CoursesVO> queryForStudent(CourseQuery courseQuery, String username) {
private PageDTO<CoursesVO> queryForStudent(CourseQuery courseQuery) {
List<StudentCourses> studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper<StudentCourses>()
.eq(StudentCourses::getStudent, username));
.eq(StudentCourses::getStudent, courseQuery.getUsername()));
List<String> coursesList = studentCourses.stream()
.map(StudentCourses::getCourse)
.collect(Collectors.toList());
@ -236,7 +210,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
UmsUser umsUserTea = umsUserMapper.selectOne(new LambdaQueryWrapper<UmsUser>()
.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<UmsTeacher>()

Loading…
Cancel
Save