|
|
|
@ -3,6 +3,7 @@ package com.teaching.backend.service.impl.courses; |
|
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.word.WordExportUtil; |
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import cn.hutool.core.lang.UUID; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
@ -14,6 +15,7 @@ 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.UmsAdminRoleRelationMapper; |
|
|
|
|
import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; |
|
|
|
|
import com.teaching.backend.model.dto.courses.CoursesDTO; |
|
|
|
|
import com.teaching.backend.model.dto.courses.PageDTO; |
|
|
|
@ -22,6 +24,7 @@ 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.UmsAdminRoleRelation; |
|
|
|
|
import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; |
|
|
|
|
import com.teaching.backend.model.query.CourseQuery; |
|
|
|
|
import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; |
|
|
|
@ -66,6 +69,8 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
UmsAdminMapper umsAdminMapper; |
|
|
|
|
@Autowired |
|
|
|
|
UmsTeacherMapper umsTeacherMapper; |
|
|
|
|
@Autowired |
|
|
|
|
UmsAdminRoleRelationMapper umsAdminRoleRelationMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -73,12 +78,15 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
public String saveCourseWithObjective(CoursesDTO coursesDTO) { |
|
|
|
|
String teacher = coursesDTO.getTeacher(); |
|
|
|
|
if (teacher == null || teacher.equals("")) { |
|
|
|
|
throw new BusinessException(ErrorCode.TEACHER_NOT_EXIT); |
|
|
|
|
throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); |
|
|
|
|
} |
|
|
|
|
Courses courses = new Courses(); |
|
|
|
|
String courseId = UUID.randomUUID().toString().replace("-", ""); |
|
|
|
|
|
|
|
|
|
CourseObjectives courseObjectives = new CourseObjectives(); |
|
|
|
|
BeanUtils.copyProperties(coursesDTO, courses); |
|
|
|
|
courses.setCreateTime(LocalDateTime.now()); |
|
|
|
|
courses.setId(courseId); |
|
|
|
|
String code = coursesDTO.getCode(); |
|
|
|
|
QueryWrapper<Courses> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("code", code); |
|
|
|
@ -86,24 +94,27 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
if (count == 0) { |
|
|
|
|
int insert = coursesMapper.insert(courses); |
|
|
|
|
if (insert > 0) { |
|
|
|
|
Courses coursesNew = coursesMapper.selectOne(queryWrapper); |
|
|
|
|
courseObjectives.setCourseId(coursesNew.getId()); |
|
|
|
|
Courses coursesNew = coursesMapper.selectById(courseId); |
|
|
|
|
courseObjectives.setCourseId(courseId); |
|
|
|
|
courseObjectives.setName(coursesNew.getName() + "课程总体目标"); |
|
|
|
|
int insertTotal = courseObjectivesMapper.insert(courseObjectives); |
|
|
|
|
if (insertTotal>0){ |
|
|
|
|
CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne |
|
|
|
|
(new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, coursesNew.getId())); |
|
|
|
|
(new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, courseId)); |
|
|
|
|
String courseTotalObjectivesId = courseTotalObjectives.getId(); |
|
|
|
|
List<ObjectivesType> objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper<ObjectivesType>()); |
|
|
|
|
ArrayList<CourseObjectives> courseObjectivesFList = new ArrayList<>(); |
|
|
|
|
CourseObjectives courseObjectivesF = null; |
|
|
|
|
for (ObjectivesType objectivesType : objectivesTypes) { |
|
|
|
|
Integer typeId = objectivesType.getId(); |
|
|
|
|
String typeName = objectivesType.getTypeName(); |
|
|
|
|
CourseObjectives courseObjectivesF = new CourseObjectives(); |
|
|
|
|
courseObjectivesF = new CourseObjectives(); |
|
|
|
|
courseObjectivesF.setType(typeId); |
|
|
|
|
courseObjectivesF.setName(typeName); |
|
|
|
|
courseObjectivesF.setPid(courseTotalObjectivesId); |
|
|
|
|
courseObjectivesMapper.insert(courseObjectivesF); |
|
|
|
|
courseObjectivesFList.add(courseObjectivesF); |
|
|
|
|
} |
|
|
|
|
courseObjectivesMapper.insertBatch(courseObjectivesFList); |
|
|
|
|
courseTotalObjectives.setHasChild(1); |
|
|
|
|
courseObjectivesMapper.updateById(courseTotalObjectives); |
|
|
|
|
} |
|
|
|
@ -118,42 +129,50 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
|
@Override |
|
|
|
|
public PageDTO<CoursesVO> queryCourses(CourseQuery courseQuery) { |
|
|
|
|
String username = courseQuery.getUsername(); |
|
|
|
|
if (username==null || username.equals("")){ |
|
|
|
|
throw new BusinessException(ErrorCode.TEACHER_NOT_EXIT); |
|
|
|
|
if (username == null || username.isEmpty()) { |
|
|
|
|
throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT); |
|
|
|
|
} |
|
|
|
|
//要搜索的课程名字
|
|
|
|
|
String name = courseQuery.getName(); |
|
|
|
|
// 1.1构建分页条件
|
|
|
|
|
|
|
|
|
|
UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper<UmsAdmin>() |
|
|
|
|
.eq(UmsAdmin::getUsername, username)); |
|
|
|
|
UmsAdminRoleRelation umsAdminRoleRelation = umsAdminRoleRelationMapper.selectOne(new LambdaQueryWrapper<UmsAdminRoleRelation>() |
|
|
|
|
.eq(UmsAdminRoleRelation::getAdminId, umsAdmin.getId())); |
|
|
|
|
|
|
|
|
|
// Determine if the user is a teacher
|
|
|
|
|
boolean isTeacher = umsAdminRoleRelation.getRoleId() == CourseCode.TEACHER_ROLE_ID.getValue(); |
|
|
|
|
|
|
|
|
|
Page<Courses> page = courseQuery.toMpPageDefaultSortByCreateTime(); |
|
|
|
|
// 2.分页查询
|
|
|
|
|
Page<Courses> p = lambdaQuery() |
|
|
|
|
.like(name != null, Courses::getName, name) |
|
|
|
|
// .eq(Courses::getTeacher,teacherId)
|
|
|
|
|
// .apply("JSON_CONTAINS(teacher, JSON_QUOTE({0}))", teacherId)
|
|
|
|
|
.apply("FIND_IN_SET({0}, teacher)", username) |
|
|
|
|
.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()) |
|
|
|
|
.page(page); |
|
|
|
|
|
|
|
|
|
PageDTO<CoursesVO> coursesVOPageDTO = PageDTO.of(p, CoursesVO.class); |
|
|
|
|
List<CoursesVO> pageDTOList = coursesVOPageDTO.getList(); |
|
|
|
|
List<String> teachers = null; |
|
|
|
|
populateTeacherNames(coursesVOPageDTO.getList()); |
|
|
|
|
|
|
|
|
|
for (CoursesVO coursesVO : pageDTOList) { |
|
|
|
|
return coursesVOPageDTO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void populateTeacherNames(List<CoursesVO> courseList) { |
|
|
|
|
for (CoursesVO coursesVO : courseList) { |
|
|
|
|
List<String> teacherNameList = new ArrayList<>(); |
|
|
|
|
String teacherIds = coursesVO.getTeacher(); |
|
|
|
|
teachers = new ArrayList<>(Arrays.asList(teacherIds.split(","))); |
|
|
|
|
for (String teacher : teachers) { |
|
|
|
|
UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper<UmsAdmin>(). |
|
|
|
|
eq(UmsAdmin::getUsername, teacher)); |
|
|
|
|
if (umsAdmin==null){ |
|
|
|
|
String[] teacherIds = coursesVO.getTeacher().split(","); |
|
|
|
|
for (String teacherId : teacherIds) { |
|
|
|
|
UmsAdmin umsAdminTea = umsAdminMapper.selectOne(new LambdaQueryWrapper<UmsAdmin>() |
|
|
|
|
.eq(UmsAdmin::getUsername, teacherId)); |
|
|
|
|
if (umsAdminTea == null) { |
|
|
|
|
throw new BusinessException(ErrorCode.OPERATION_ERROR); |
|
|
|
|
} |
|
|
|
|
Long adminId = umsAdmin.getId(); |
|
|
|
|
UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper<UmsTeacher>() |
|
|
|
|
.eq(UmsTeacher::getUserId, adminId)); |
|
|
|
|
.eq(UmsTeacher::getUserId, umsAdminTea.getId())); |
|
|
|
|
teacherNameList.add(umsTeacher.getName()); |
|
|
|
|
} |
|
|
|
|
coursesVO.setTeacher(String.join(",", teacherNameList)); |
|
|
|
|
} |
|
|
|
|
return coursesVOPageDTO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|