diff --git a/src/main/java/com/teaching/backend/common/ErrorCode.java b/src/main/java/com/teaching/backend/common/ErrorCode.java
index 4b2a66e..95830fb 100644
--- a/src/main/java/com/teaching/backend/common/ErrorCode.java
+++ b/src/main/java/com/teaching/backend/common/ErrorCode.java
@@ -18,7 +18,7 @@ public enum ErrorCode {
STUDENT_NOT_EXIT(40006, "缺少学生信息"),
COURSES_NOT_EXIT(40007, "缺少课程信息"),
CONTENT_NOT_EXIT(40008, "内容id不存在"),
- KNOWS_EXIT(40009, "该项下面存在关联的知识点"),
+ KNOWS_EXIT(40009, "该项下面存在关联的知识点,请在删除关联的知识点后再来操作!"),
INVALID_ROLE(400010, "角色不存在"),
NOT_LOGIN_ERROR(40100, "未登录"),
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 07fb7f2..8840c0c 100644
--- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java
+++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java
@@ -3,19 +3,14 @@ package com.teaching.backend.controller.courses;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.CommonResult;
-import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.common.ResultUtils;
-import com.teaching.backend.exception.BusinessException;
-
import com.teaching.backend.filter.ValidateParams;
import com.teaching.backend.model.dto.courses.CoursesDTO;
import com.teaching.backend.model.dto.courses.PageDTO;
-
import com.teaching.backend.model.entity.courses.Courses;
import com.teaching.backend.model.entity.umsAdmin.UmsStudent;
import com.teaching.backend.model.query.CourseQuery;
import com.teaching.backend.model.vo.courses.CoursesVO;
-import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO;
import com.teaching.backend.service.courses.ICoursesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -24,7 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
-import java.util.*;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
/**
*
@@ -87,7 +84,6 @@ public class CoursesController {
@ApiOperation("查询课程列表")
@ValidateParams({"userId"})
@GetMapping("/page")
-// @PostMapping("/page")
public BaseResponse> getCourses(CourseQuery courseQuery){
PageDTO coursesList = coursesService.queryCourses(courseQuery);
return ResultUtils.success(coursesList);
@@ -97,9 +93,6 @@ public class CoursesController {
@ValidateParams({"id"})
@GetMapping("/{id}")
public BaseResponse getByIdCourse(@PathVariable String id){
- if(id==null){
- throw new BusinessException(ErrorCode.PARAMS_ERROR,"课程id为空");
- }
Courses course = coursesService.getById(id);
CoursesDTO coursesDTO = new CoursesDTO();
BeanUtils.copyProperties(course,coursesDTO);
@@ -114,16 +107,12 @@ public class CoursesController {
return ResultUtils.success("编辑成功");
}
- //TODO:删除功能暂未完善,数据缺失
- // 暂时发现有个漏洞 就是目标关联的有知识点的时候还是可以直接删除
- // (当有内容的时候本来就是得先删除内容--关联也有知识点 所以内容下面的不用校验 )
@ApiOperation("根据id删除课程")
@ValidateParams({"id"})
@DeleteMapping("/{id}")
public BaseResponse deleteCourses(@PathVariable String id){
coursesService.deleteBatchByIds(id);
-// coursesService.removeBatchByIds(ids);
return ResultUtils.success("删除成功");
}
diff --git a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java
index 17a9462..cbe1c5e 100644
--- a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java
+++ b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java
@@ -39,7 +39,6 @@ public class ObjectiveContentsController {
@ValidateParams({"id"})
@DeleteMapping("/{id}")
public BaseResponse deleteContent(@PathVariable String id){
-// objectiveContentsService.removeById(id);
String data = objectiveContentsService.deleteById(id);
return ResultUtils.success(data);
}
diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
index f5682e6..435f710 100644
--- a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
+++ b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
@@ -25,6 +25,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_HAS_NO_CHILD;
+
/**
*
* 服务实现类
@@ -54,33 +56,33 @@ public class CourseObjectivesServiceImpl extends ServiceImpl()
.eq(CourseObjectives::getPid, pid)
.eq(CourseObjectives::getType, type));
+
if (count==CourseCode.OBJECTIVE_EXIT.getValue()){
throw new BusinessException(ErrorCode.CONTENT_EXISTS,"该类型的目标已存在,禁止重复添加!");
}
- if (type!=CourseCode.SI_ZHENG_TYPE.getValue()){
+
+ if (!type.equals(CourseCode.SI_ZHENG_TYPE.getValue())){
Long sz = SZ_EXIT(courseObjectivesDTO);
if (sz!=CourseCode.SI_ZHENG_EXIT.getValue()){
throw new BusinessException(ErrorCode.PARAMS_ILLEGAL,"请在添加完思政目标以后再添加此类型目标!");
}
}
- courseObjectivesMapper.insert(courseObjectivesNew);
+ //插入新的课程目标
+ int insert = courseObjectivesMapper.insert(courseObjectivesNew);
+ //插入数据以后要把总体目标那边的haschild改成1
+ if (insert>0){
+ CourseObjectives courseObjectivesOld = courseObjectivesMapper.selectById(pid);
+ if (courseObjectivesOld.getHasChild() == TOTAL_OBJECTIVE_HAS_NO_CHILD.getValue()) {
+ courseObjectivesOld.setHasChild(1);
+ courseObjectivesMapper.updateById(courseObjectivesOld);
+ }
+ }
return "添加成功";
-
- //往表里面写分项目标
-// courseObjectivesMapper.insert(courseObjectivesNew);
-// //插入数据以后要把总体目标那边的haschild改成1
-// CourseObjectives courseObjectivesOld = courseObjectivesMapper.selectById(pid);
-// courseObjectivesOld.setHasChild(1);
-// courseObjectivesMapper.updateById(courseObjectivesOld);
}
private Long SZ_EXIT(CourseObjectivesDTO courseObjectivesDTO) {
@@ -110,7 +112,7 @@ public class CourseObjectivesServiceImpl extends ServiceImpl()
.eq(ObjectiveContentKnow::getObjectiveOrContent, id));
if(count > CourseCode.KNOWS_EXIT.getValue()){
@@ -121,9 +123,9 @@ public class CourseObjectivesServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CourseObjectives::getPid, pid);
Long countSZ = courseObjectivesMapper.selectCount(queryWrapper);
- if (countSZ==CourseCode.SI_ZHENG_EXIT.getValue()){
+ if (countSZ.equals(CourseCode.SI_ZHENG_EXIT.getValue())){
Long countContentsSZ = getCount(id);
- if (countContentsSZ<(CourseCode.CONTENT_EXIT.getValue()))
+ if (countContentsSZ == (CourseCode.CONTENT_EXIT.getValue()))
{
// 删除操作和更新父目标状态
deleteObjectiveAndUpdateParent(id, pid);
@@ -140,7 +142,7 @@ public class CourseObjectivesServiceImpl extends ServiceImpl impl
@Override
@Transactional
public String saveCourseWithObjective(CoursesDTO coursesDTO) {
-// String teacher = coursesDTO.getTeacher();
-// if (teacher == null || teacher.equals("")) {
-// throw new BusinessException(ErrorCode.USERNAME_NOT_EXIT);
-// }
+ // 初始化并生成新的课程ID
Courses courses = new Courses();
String courseId = UUID.randomUUID().toString().replace("-", "");
- CourseObjectives courseObjectives = new CourseObjectives();
+ // 拷贝属性并设置创建时间和ID
BeanUtils.copyProperties(coursesDTO, courses);
courses.setCreateTime(LocalDateTime.now());
courses.setId(courseId);
+
+ // 检查课程代码是否已存在
String code = coursesDTO.getCode();
- QueryWrapper queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("code", code);
- 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().eq(CourseObjectives::getCourseId, courseId));
- String courseTotalObjectivesId = courseTotalObjectives.getId();
- List objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper());
- ArrayList 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 {
+ Long count = query().eq("code", code).count();
+ if (count > 0) {
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().eq(CourseObjectives::getCourseId, courseId)
+ );
+ String courseTotalObjectivesId = courseTotalObjectives.getId();
+
+ // 获取所有目标类型并插入子目标
+ List objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper<>());
+ ArrayList 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
public PageDTO queryCourses(CourseQuery courseQuery) {
-// int roleId = Integer.parseInt(umsUserMapper.selectOne(new LambdaQueryWrapper()
-// .eq(UmsUser::getUsername, courseQuery.getUsername())).getRoleId());
UmsUser umsUser = umsUserMapper.selectById(courseQuery.getUserId());
if (umsUser == null){
throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS);
@@ -187,9 +193,11 @@ public class CoursesServiceImpl extends ServiceImpl impl
Page p = lambdaQuery()
.like(courseQuery.getName() != null, Courses::getName, courseQuery.getName())
.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.getAssessmenttype() != null &&!courseQuery.getAssessmenttype().isEmpty(), Courses::getAssessmenttype, courseQuery.getAssessmenttype())
+ .select(Courses::getId,Courses::getTeacher,Courses::getImg,Courses::getName,Courses::getCredit,Courses::getClasshours)
.page(page);
return PageDTO.of(p,CoursesVO.class);
}
@@ -204,6 +212,7 @@ public class CoursesServiceImpl extends ServiceImpl impl
Page p = lambdaQuery()
.like(courseQuery.getName() != null, Courses::getName, courseQuery.getName())
.in(Courses::getId, coursesList)
+ .select(Courses::getId,Courses::getTeacher,Courses::getImg,Courses::getName,Courses::getCredit,Courses::getClasshours)
.page(page);
return PageDTO.of(p, CoursesVO.class);
}
@@ -215,6 +224,7 @@ public class CoursesServiceImpl extends ServiceImpl impl
.eq(courseQuery.getNature() != null && !courseQuery.getNature().isEmpty(), Courses::getNature, courseQuery.getNature())
.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())
+ .select(Courses::getId,Courses::getTeacher,Courses::getImg,Courses::getName,Courses::getCredit,Courses::getClasshours)
.page(page);
return PageDTO.of(p, CoursesVO.class);
}
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 f62b99a..13720df 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
@@ -18,6 +18,7 @@ import com.teaching.backend.service.courses.IObjectiveContentKnowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -71,7 +72,6 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl objectiveContentKnows = objectiveContentKnowMapper.selectList(
new LambdaQueryWrapper()
.eq(ObjectiveContentKnow::getObjectiveOrContent, objectiveOrContentId));
@@ -105,16 +100,16 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl objectiveContents = objectiveContentsMapper.selectList(
- new LambdaQueryWrapper()
+ List objectiveContents = objectiveContentsMapper.selectList(new LambdaQueryWrapper()
.eq(ObjectiveContents::getObjectiveId, objectiveOrContentId));
// 如果存在分项目标内容,处理并计算每个内容的相关数据
- if (objectiveContents != null && !objectiveContents.isEmpty()) {
+ if (!CollectionUtils.isEmpty(objectiveContents)) {
List contentKnowVOs = objectiveContents.stream()
.map(content -> createObjectiveContentKnowVO(content.getId(), objectiveContentKnowMapper.selectList(
new LambdaQueryWrapper()
@@ -123,10 +118,10 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl {
- BigDecimal contentPercentage = calculatePercentage(contentKnowVO.getKnowsTime(), classhours);
- contentKnowVO.setPersent(contentPercentage + "%");
- });
+// contentKnowVOs.forEach(contentKnowVO -> {
+// BigDecimal contentPercentage = calculatePercentage(contentKnowVO.getKnowsTime(), classhours);
+// contentKnowVO.setPersent(contentPercentage + "%");
+// });
// 设置内容的知识点数据
objectiveContentKnowVO.setContentKnowsData(contentKnowVOs);
@@ -168,6 +163,4 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl0 ? "删除成功!" : "删除失败!";
+ return delete > 0 ? "删除成功!" : "删除失败!";
}
}
diff --git a/src/main/java/com/teaching/backend/utils/CourseCode.java b/src/main/java/com/teaching/backend/utils/CourseCode.java
index d736cd4..b7b2465 100644
--- a/src/main/java/com/teaching/backend/utils/CourseCode.java
+++ b/src/main/java/com/teaching/backend/utils/CourseCode.java
@@ -4,14 +4,14 @@ public enum CourseCode {
HAS_CHILD(1, "存在子节点"),
OBJECTIVE_EXIT(1,"目标存在"),
- CONTENT_EXIT(1, "存在内容"),
+ CONTENT_EXIT(0, "不存在内容"),
SI_ZHENG_TYPE(1, "思政目标类型"),
SI_ZHENG_EXIT(1, "思政目标存在"),
KNOWS_EXIT(0, "存在关联的知识点"),
TEACHER_ROLE_ID(1, "教师的角色id是1"),
TOTAL_OBJECTIVE_TYPE(0, "课程总目标"),
-
+ TOTAL_OBJECTIVE_HAS_NO_CHILD(0, "课程总目标下面没有分项目标"),
Total_EXIT(0, "课程总目标"),
COURSE_UPDATING(1, "课程正在修改中");