|
|
@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.ResourceUtils; |
|
|
|
import org.springframework.util.ResourceUtils; |
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
@ -99,63 +100,68 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public String saveCourseWithObjective(CoursesDTO coursesDTO) { |
|
|
|
public String saveCourseWithObjective(CoursesDTO coursesDTO) { |
|
|
|
// String teacher = coursesDTO.getTeacher();
|
|
|
|
// 初始化并生成新的课程ID
|
|
|
|
// if (teacher == null || teacher.equals("")) {
|
|
|
|
|
|
|
|
// throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
Courses courses = new Courses(); |
|
|
|
Courses courses = new Courses(); |
|
|
|
String courseId = UUID.randomUUID().toString().replace("-", ""); |
|
|
|
String courseId = UUID.randomUUID().toString().replace("-", ""); |
|
|
|
|
|
|
|
|
|
|
|
CourseObjectives courseObjectives = new CourseObjectives(); |
|
|
|
// 拷贝属性并设置创建时间和ID
|
|
|
|
BeanUtils.copyProperties(coursesDTO, courses); |
|
|
|
BeanUtils.copyProperties(coursesDTO, courses); |
|
|
|
courses.setCreateTime(LocalDateTime.now()); |
|
|
|
courses.setCreateTime(LocalDateTime.now()); |
|
|
|
courses.setId(courseId); |
|
|
|
courses.setId(courseId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查课程代码是否已存在
|
|
|
|
String code = coursesDTO.getCode(); |
|
|
|
String code = coursesDTO.getCode(); |
|
|
|
QueryWrapper<Courses> queryWrapper = new QueryWrapper<>(); |
|
|
|
Long count = query().eq("code", code).count(); |
|
|
|
queryWrapper.eq("code", code); |
|
|
|
if (count > 0) { |
|
|
|
Long count = coursesMapper.selectCount(queryWrapper); |
|
|
|
|
|
|
|
if (count == 0) { |
|
|
|
|
|
|
|
int insert = coursesMapper.insert(courses); |
|
|
|
|
|
|
|
if (insert > 0) { |
|
|
|
|
|
|
|
Courses coursesNew = coursesMapper.selectById(courseId); |
|
|
|
|
|
|
|
courseObjectives.setCourseId(courseId); |
|
|
|
|
|
|
|
courseObjectives.setType(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue()); |
|
|
|
|
|
|
|
// courseObjectives.setName(coursesNew.getName() + "课程总体目标");
|
|
|
|
|
|
|
|
int insertTotal = courseObjectivesMapper.insert(courseObjectives); |
|
|
|
|
|
|
|
if (insertTotal>0){ |
|
|
|
|
|
|
|
CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne |
|
|
|
|
|
|
|
(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(); |
|
|
|
|
|
|
|
if (!typeId.equals(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue())){ |
|
|
|
|
|
|
|
// String typeName = objectivesType.getTypeName();
|
|
|
|
|
|
|
|
courseObjectivesF = new CourseObjectives(); |
|
|
|
|
|
|
|
courseObjectivesF.setType(typeId); |
|
|
|
|
|
|
|
// courseObjectivesF.setName(typeName);
|
|
|
|
|
|
|
|
courseObjectivesF.setPid(courseTotalObjectivesId); |
|
|
|
|
|
|
|
courseObjectivesFList.add(courseObjectivesF); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
courseObjectivesMapper.insertBatch(courseObjectivesFList); |
|
|
|
|
|
|
|
courseTotalObjectives.setHasChild(1); |
|
|
|
|
|
|
|
courseObjectivesMapper.updateById(courseTotalObjectives); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return "添加成功"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!"); |
|
|
|
throw new BusinessException(ErrorCode.OPERATION_ERROR, "这个课程已经存在了!请联系系统相关人员为您导入课程数据!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 插入课程信息
|
|
|
|
|
|
|
|
int insert = coursesMapper.insert(courses); |
|
|
|
|
|
|
|
if (insert <= 0) { |
|
|
|
|
|
|
|
throw new BusinessException(ErrorCode.OPERATION_ERROR, "课程插入失败!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 插入课程目标信息
|
|
|
|
|
|
|
|
CourseObjectives courseObjectives = new CourseObjectives(); |
|
|
|
|
|
|
|
courseObjectives.setCourseId(courseId); |
|
|
|
|
|
|
|
courseObjectives.setType(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue()); |
|
|
|
|
|
|
|
int insertTotal = courseObjectivesMapper.insert(courseObjectives); |
|
|
|
|
|
|
|
if (insertTotal <= 0) { |
|
|
|
|
|
|
|
throw new BusinessException(ErrorCode.OPERATION_ERROR, "课程目标插入失败!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取插入后的课程目标信息
|
|
|
|
|
|
|
|
CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne( |
|
|
|
|
|
|
|
new LambdaQueryWrapper<CourseObjectives>().eq(CourseObjectives::getCourseId, courseId) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
String courseTotalObjectivesId = courseTotalObjectives.getId(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取所有目标类型并插入子目标
|
|
|
|
|
|
|
|
List<ObjectivesType> objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper<>()); |
|
|
|
|
|
|
|
ArrayList<CourseObjectives> courseObjectivesFList = new ArrayList<>(); |
|
|
|
|
|
|
|
for (ObjectivesType objectivesType : objectivesTypes) { |
|
|
|
|
|
|
|
if (!objectivesType.getId().equals(CourseCode.TOTAL_OBJECTIVE_TYPE.getValue())) { |
|
|
|
|
|
|
|
CourseObjectives courseObjectivesF = new CourseObjectives(); |
|
|
|
|
|
|
|
courseObjectivesF.setType(objectivesType.getId()); |
|
|
|
|
|
|
|
courseObjectivesF.setPid(courseTotalObjectivesId); |
|
|
|
|
|
|
|
courseObjectivesFList.add(courseObjectivesF); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 批量插入子目标并更新父目标的hasChild字段
|
|
|
|
|
|
|
|
if (!courseObjectivesFList.isEmpty()) { |
|
|
|
|
|
|
|
courseObjectivesMapper.insertBatch(courseObjectivesFList); |
|
|
|
|
|
|
|
courseTotalObjectives.setHasChild(1); |
|
|
|
|
|
|
|
courseObjectivesMapper.updateById(courseTotalObjectives); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "添加成功"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public PageDTO<CoursesVO> queryCourses(CourseQuery courseQuery) { |
|
|
|
public PageDTO<CoursesVO> queryCourses(CourseQuery courseQuery) { |
|
|
|
// int roleId = Integer.parseInt(umsUserMapper.selectOne(new LambdaQueryWrapper<UmsUser>()
|
|
|
|
|
|
|
|
// .eq(UmsUser::getUsername, courseQuery.getUsername())).getRoleId());
|
|
|
|
|
|
|
|
UmsUser umsUser = umsUserMapper.selectById(courseQuery.getUserId()); |
|
|
|
UmsUser umsUser = umsUserMapper.selectById(courseQuery.getUserId()); |
|
|
|
if (umsUser == null){ |
|
|
|
if (umsUser == null){ |
|
|
|
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); |
|
|
|
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); |
|
|
@ -187,9 +193,11 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
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("FIND_IN_SET({0}, teacher)", courseQuery.getUserId()) |
|
|
|
.apply("FIND_IN_SET({0}, teacher)", courseQuery.getUserId()) |
|
|
|
.eq(courseQuery.getCategory() != null && !courseQuery.getCategory().isEmpty(), Courses::getCategory, courseQuery.getCategory()) |
|
|
|
.eq(StringUtils.hasText(courseQuery.getCategory()), Courses::getCategory, courseQuery.getCategory()) |
|
|
|
|
|
|
|
// .eq(courseQuery.getCategory() != null && !courseQuery.getCategory().isEmpty(), Courses::getCategory, courseQuery.getCategory())
|
|
|
|
.eq(courseQuery.getNature() != null && !courseQuery.getNature().isEmpty(), Courses::getNature, courseQuery.getNature()) |
|
|
|
.eq(courseQuery.getNature() != null && !courseQuery.getNature().isEmpty(), Courses::getNature, courseQuery.getNature()) |
|
|
|
.eq(courseQuery.getAssessmenttype() != null &&!courseQuery.getAssessmenttype().isEmpty(), Courses::getAssessmenttype, courseQuery.getAssessmenttype()) |
|
|
|
.eq(courseQuery.getAssessmenttype() != null &&!courseQuery.getAssessmenttype().isEmpty(), Courses::getAssessmenttype, courseQuery.getAssessmenttype()) |
|
|
|
|
|
|
|
.select(Courses::getId,Courses::getTeacher,Courses::getImg,Courses::getName,Courses::getCredit,Courses::getClasshours) |
|
|
|
.page(page); |
|
|
|
.page(page); |
|
|
|
return PageDTO.of(p,CoursesVO.class); |
|
|
|
return PageDTO.of(p,CoursesVO.class); |
|
|
|
} |
|
|
|
} |
|
|
@ -204,6 +212,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
Page<Courses> p = lambdaQuery() |
|
|
|
Page<Courses> p = lambdaQuery() |
|
|
|
.like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) |
|
|
|
.like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) |
|
|
|
.in(Courses::getId, coursesList) |
|
|
|
.in(Courses::getId, coursesList) |
|
|
|
|
|
|
|
.select(Courses::getId,Courses::getTeacher,Courses::getImg,Courses::getName,Courses::getCredit,Courses::getClasshours) |
|
|
|
.page(page); |
|
|
|
.page(page); |
|
|
|
return PageDTO.of(p, CoursesVO.class); |
|
|
|
return PageDTO.of(p, CoursesVO.class); |
|
|
|
} |
|
|
|
} |
|
|
@ -215,6 +224,7 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl |
|
|
|
.eq(courseQuery.getNature() != null && !courseQuery.getNature().isEmpty(), Courses::getNature, courseQuery.getNature()) |
|
|
|
.eq(courseQuery.getNature() != null && !courseQuery.getNature().isEmpty(), Courses::getNature, courseQuery.getNature()) |
|
|
|
.eq(courseQuery.getAssessmenttype() != null &&!courseQuery.getAssessmenttype().isEmpty(), Courses::getAssessmenttype, courseQuery.getAssessmenttype()) |
|
|
|
.eq(courseQuery.getAssessmenttype() != null &&!courseQuery.getAssessmenttype().isEmpty(), Courses::getAssessmenttype, courseQuery.getAssessmenttype()) |
|
|
|
.apply(courseQuery.getTeacher() != null && !courseQuery.getTeacher().isEmpty(), "FIND_IN_SET({0}, teacher)", courseQuery.getTeacher()) |
|
|
|
.apply(courseQuery.getTeacher() != null && !courseQuery.getTeacher().isEmpty(), "FIND_IN_SET({0}, teacher)", courseQuery.getTeacher()) |
|
|
|
|
|
|
|
.select(Courses::getId,Courses::getTeacher,Courses::getImg,Courses::getName,Courses::getCredit,Courses::getClasshours) |
|
|
|
.page(page); |
|
|
|
.page(page); |
|
|
|
return PageDTO.of(p, CoursesVO.class); |
|
|
|
return PageDTO.of(p, CoursesVO.class); |
|
|
|
} |
|
|
|
} |
|
|
|