|
|
@ -10,19 +10,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.teaching.backend.common.ErrorCode; |
|
|
|
import com.teaching.backend.common.ErrorCode; |
|
|
|
import com.teaching.backend.exception.BusinessException; |
|
|
|
import com.teaching.backend.exception.BusinessException; |
|
|
|
import com.teaching.backend.mapper.courses.CourseObjectivesMapper; |
|
|
|
import com.teaching.backend.mapper.courses.*; |
|
|
|
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.umsAdmin.UmsAdminMapper; |
|
|
|
import com.teaching.backend.mapper.umsAdmin.UmsAdminMapper; |
|
|
|
import com.teaching.backend.mapper.umsAdmin.UmsAdminRoleRelationMapper; |
|
|
|
import com.teaching.backend.mapper.umsAdmin.UmsAdminRoleRelationMapper; |
|
|
|
import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; |
|
|
|
import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; |
|
|
|
import com.teaching.backend.model.dto.courses.CoursesDTO; |
|
|
|
import com.teaching.backend.model.dto.courses.CoursesDTO; |
|
|
|
import com.teaching.backend.model.dto.courses.PageDTO; |
|
|
|
import com.teaching.backend.model.dto.courses.PageDTO; |
|
|
|
import com.teaching.backend.model.entity.courses.CourseObjectives; |
|
|
|
import com.teaching.backend.model.entity.courses.*; |
|
|
|
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.umsAdmin.UmsAdmin; |
|
|
|
import com.teaching.backend.model.entity.umsAdmin.UmsAdmin; |
|
|
|
import com.teaching.backend.model.entity.umsAdmin.UmsAdminRoleRelation; |
|
|
|
import com.teaching.backend.model.entity.umsAdmin.UmsAdminRoleRelation; |
|
|
|
import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; |
|
|
|
import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; |
|
|
@ -75,6 +69,8 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
UmsTeacherMapper umsTeacherMapper; |
|
|
|
UmsTeacherMapper umsTeacherMapper; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
UmsAdminRoleRelationMapper umsAdminRoleRelationMapper; |
|
|
|
UmsAdminRoleRelationMapper umsAdminRoleRelationMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
StudentCoursesMapper studentCoursesMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -142,26 +138,64 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
UmsAdminRoleRelation umsAdminRoleRelation = umsAdminRoleRelationMapper.selectOne(new LambdaQueryWrapper<UmsAdminRoleRelation>() |
|
|
|
UmsAdminRoleRelation umsAdminRoleRelation = umsAdminRoleRelationMapper.selectOne(new LambdaQueryWrapper<UmsAdminRoleRelation>() |
|
|
|
.eq(UmsAdminRoleRelation::getAdminId, umsAdmin.getId())); |
|
|
|
.eq(UmsAdminRoleRelation::getAdminId, umsAdmin.getId())); |
|
|
|
|
|
|
|
|
|
|
|
// Determine if the user is a teacher
|
|
|
|
int roleId = Math.toIntExact(umsAdminRoleRelation.getRoleId()); |
|
|
|
boolean isTeacher = umsAdminRoleRelation.getRoleId() == CourseCode.TEACHER_ROLE_ID.getValue(); |
|
|
|
PageDTO<CoursesVO> 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<CoursesVO> queryForTeacher(CourseQuery courseQuery, String username) { |
|
|
|
Page<Courses> page = courseQuery.toMpPageDefaultSortByCreateTime(); |
|
|
|
Page<Courses> page = courseQuery.toMpPageDefaultSortByCreateTime(); |
|
|
|
Page<Courses> p = lambdaQuery() |
|
|
|
Page<Courses> p = lambdaQuery() |
|
|
|
.like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) |
|
|
|
.like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) |
|
|
|
.apply(isTeacher, "FIND_IN_SET({0}, teacher)", username) |
|
|
|
.apply("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()) |
|
|
|
|
|
|
|
.page(page); |
|
|
|
.page(page); |
|
|
|
|
|
|
|
return PageDTO.of(p, CoursesVO.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PageDTO<CoursesVO> coursesVOPageDTO = PageDTO.of(p, CoursesVO.class); |
|
|
|
private PageDTO<CoursesVO> queryForStudent(CourseQuery courseQuery, String username) { |
|
|
|
populateTeacherNames(coursesVOPageDTO.getList()); |
|
|
|
List<StudentCourses> studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper<StudentCourses>() |
|
|
|
|
|
|
|
.eq(StudentCourses::getStudent, username)); |
|
|
|
|
|
|
|
List<String> coursesList = studentCourses.stream() |
|
|
|
|
|
|
|
.map(StudentCourses::getCourse) |
|
|
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
return coursesVOPageDTO; |
|
|
|
Page<Courses> page = courseQuery.toMpPageDefaultSortByCreateTime(); |
|
|
|
|
|
|
|
Page<Courses> p = lambdaQuery() |
|
|
|
|
|
|
|
.like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) |
|
|
|
|
|
|
|
.in(Courses::getId, coursesList) |
|
|
|
|
|
|
|
.page(page); |
|
|
|
|
|
|
|
return PageDTO.of(p, CoursesVO.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PageDTO<CoursesVO> queryForAdmin(CourseQuery courseQuery) { |
|
|
|
|
|
|
|
Page<Courses> page = courseQuery.toMpPageDefaultSortByCreateTime(); |
|
|
|
|
|
|
|
Page<Courses> 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<CoursesVO> courseList) { |
|
|
|
private void populateTeacherNames(List<CoursesVO> courseList) { |
|
|
|
for (CoursesVO coursesVO : courseList) { |
|
|
|
for (CoursesVO coursesVO : courseList) { |
|
|
|
List<String> teacherNameList = new ArrayList<>(); |
|
|
|
List<String> teacherNameList = new ArrayList<>(); |
|
|
|
String[] teacherIds = coursesVO.getTeacher().split(","); |
|
|
|
String[] teacherIds = coursesVO.getTeacher().split(","); |
|
|
@ -179,6 +213,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void deleteBatchByIds(String id) { |
|
|
|
public void deleteBatchByIds(String id) { |
|
|
|
if(id==null){ |
|
|
|
if(id==null){ |
|
|
|