diff --git a/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java b/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java index cead419..9e72bf0 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java @@ -14,7 +14,6 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.time.LocalDateTime; import java.util.List; /** @@ -25,7 +24,7 @@ import java.util.List; * @author zjh * @since 2024-05-31 */ -@Api(tags = "项目目标管理接口") +@Api(tags = "课程目标管理接口") @RestController @RequestMapping("/course_objectives") public class CourseObjectivesController { @@ -62,7 +61,6 @@ public class CourseObjectivesController { String pid = courseObjectivesDTO.getPid(); CourseObjectives courseObjectives = courseObjectivesMapper.selectById(pid); BeanUtil.copyProperties(courseObjectivesDTO, courseObjectives); - courseObjectives.setUpdateTime(LocalDateTime.now()); courseObjectivesService.updateById(courseObjectives); return ResultUtils.success("编辑成功"); } 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 4206336..0efc084 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -49,10 +49,10 @@ public class CoursesController { return ResultUtils.success(objectMap); } - @ApiOperation("新增课程--同步新增课程的总体目标") + @ApiOperation("新增课程--同步新增课程的总体目标并同时添加所有的分项目标") @PostMapping("/addcourse") - public BaseResponse saveCourse(@RequestBody CoursesDTO coursesDTO, @RequestParam String teacherId){ - String data = coursesService.saveCourseWithObjective(coursesDTO, teacherId); + public BaseResponse saveCourse(@RequestBody CoursesDTO coursesDTO){ + String data = coursesService.saveCourseWithObjective(coursesDTO); return ResultUtils.success(data); } @@ -76,10 +76,7 @@ public class CoursesController { @ApiOperation("根据id修改课程") @PutMapping public BaseResponse editCourse(@RequestBody CoursesDTO coursesDTO){ - String courseId = coursesDTO.getId(); - Courses course = coursesService.getById(courseId); - BeanUtil.copyProperties(coursesDTO, course); - coursesService.updateById(course); + coursesService.updateCourse(coursesDTO); return ResultUtils.success("编辑成功"); } diff --git a/src/main/java/com/teaching/backend/model/dto/courses/CourseObjectivesDTO.java b/src/main/java/com/teaching/backend/model/dto/courses/CourseObjectivesDTO.java index 4b1129f..9341142 100644 --- a/src/main/java/com/teaching/backend/model/dto/courses/CourseObjectivesDTO.java +++ b/src/main/java/com/teaching/backend/model/dto/courses/CourseObjectivesDTO.java @@ -26,7 +26,7 @@ public class CourseObjectivesDTO implements Serializable { * 分项目标类型 思政 知识、素质、价值 */ @ApiModelProperty(value = "分项目标类型",required = true) - private String type; + private Integer type; /** * 父节点 */ diff --git a/src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java b/src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java index e0848a0..b037c6d 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/CourseObjectives.java @@ -33,24 +33,17 @@ public class CourseObjectives implements Serializable { @TableId(value = "id", type = IdType.ASSIGN_UUID) private String id; - @ApiModelProperty(value = "创建日期") - private LocalDateTime createTime; - - - @ApiModelProperty(value = "更新日期") - private LocalDateTime updateTime; - @ApiModelProperty(value = "父级节点") private String pid; @ApiModelProperty(value = "是否有子节点") - private String hasChild; + private Integer hasChild; @ApiModelProperty(value = "目标名称") private String name; @ApiModelProperty(value = "目标类型") - private String type; + private Integer type; @ApiModelProperty(value = "课程id") diff --git a/src/main/java/com/teaching/backend/model/entity/courses/Courses.java b/src/main/java/com/teaching/backend/model/entity/courses/Courses.java index bb23b59..a3459c6 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/Courses.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/Courses.java @@ -139,5 +139,10 @@ public class Courses implements Serializable { */ private String description; + /** + *课程状态 + */ + private int status; + } diff --git a/src/main/java/com/teaching/backend/model/entity/courses/ObjectivesType.java b/src/main/java/com/teaching/backend/model/entity/courses/ObjectivesType.java index decfc66..62ffcf5 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/ObjectivesType.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/ObjectivesType.java @@ -27,9 +27,9 @@ public class ObjectivesType implements Serializable { private static final long serialVersionUID = 1L; - @TableId(value = "id", type = IdType.ASSIGN_UUID) - @ApiModelProperty(value = "类型编码,不用输入,使用雪花算法生成") - private String id; + @TableId(value = "id", type = IdType.AUTO) + @ApiModelProperty(value = "类型编码,不用输入,使用自动生成") + private Integer id; @ApiModelProperty(value = "类型名称",required = true) private String typeName; diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index f1ea1ee..08d48a6 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -21,7 +21,7 @@ import java.util.List; */ public interface ICoursesService extends IService { - String saveCourseWithObjective(CoursesDTO coursesDTO, String teacherId); + String saveCourseWithObjective(CoursesDTO coursesDTO); PageDTO queryCourses(CourseQuery courseQuery, String teacherId); @@ -31,4 +31,6 @@ public interface ICoursesService extends IService { int countHours(String id); List getPagePageSize(int page, int pageSize); + + void updateCourse(CoursesDTO coursesDTO); } 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 bdec642..e268549 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 @@ -12,8 +12,12 @@ import com.teaching.backend.model.entity.courses.CourseObjectives; import com.teaching.backend.model.entity.courses.ObjectiveContents; import com.teaching.backend.model.vo.CourseObjectivesTreeVO; import com.teaching.backend.service.courses.ICourseObjectivesService; +import com.teaching.backend.utils.CourseCode; +import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; @@ -39,37 +43,46 @@ public class CourseObjectivesServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper + Long count = courseObjectivesMapper.selectCount(new LambdaQueryWrapper() .eq(CourseObjectives::getPid, pid) - .eq(CourseObjectives::getType, type); - Long count = courseObjectivesMapper.selectCount(queryWrapper); - if (count>0){ + .eq(CourseObjectives::getType, type)); + if (count==CourseCode.OBJECTIVE_EXIT.getValue()){ throw new BusinessException(ErrorCode.CONTENT_EXISTS,"该类型的目标已存在,禁止重复添加!"); } - //往表里面写分项目标 - CourseObjectives courseObjectivesNew = new CourseObjectives(); - BeanUtil.copyProperties(courseObjectivesDTO,courseObjectivesNew); - courseObjectivesNew.setCreateTime(LocalDateTime.now()); + if (type!=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); - //插入数据以后要把总体目标那边的haschild改成1 - CourseObjectives courseObjectivesOld = courseObjectivesMapper.selectById(pid); - courseObjectivesOld.setUpdateTime(LocalDateTime.now()); - 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) { + Long count = courseObjectivesMapper.selectCount(new LambdaQueryWrapper() + .eq(CourseObjectives::getPid, courseObjectivesDTO.getPid()) + .eq(CourseObjectives::getType, CourseCode.SI_ZHENG_TYPE.getValue())); + return count; } /** @@ -82,21 +95,20 @@ public class CourseObjectivesServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(CourseObjectives::getPid, pid); - Long count1 = courseObjectivesMapper.selectCount(queryWrapper); - if (count1==1){ - Long count2 = getCount(id); - if (count2==0) + Long countSZ = courseObjectivesMapper.selectCount(queryWrapper); + if (countSZ==CourseCode.SI_ZHENG_EXIT.getValue()){ + Long countContentsSZ = getCount(id); + if (countContentsSZ<(CourseCode.CONTENT_EXIT.getValue())) { // 删除操作和更新父目标状态 deleteObjectiveAndUpdateParent(id, pid); @@ -112,8 +124,8 @@ public class CourseObjectivesServiceImpl extends ServiceImpl @@ -46,17 +50,16 @@ public class CoursesServiceImpl extends ServiceImpl impl CourseObjectivesMapper courseObjectivesMapper; @Autowired ObjectiveContentsMapper objectiveContentsMapper; + @Autowired + ObjectivesTypeMapper objectivesTypeMapper; + @Override @Transactional - public String saveCourseWithObjective(CoursesDTO coursesDTO, String teacherId) { + public String saveCourseWithObjective(CoursesDTO coursesDTO) { Courses courses = new Courses(); CourseObjectives courseObjectives = new CourseObjectives(); BeanUtils.copyProperties(coursesDTO, courses); -// List teacherIds = new ArrayList<>(); -// teacherIds.add(teacherId); -// courses.setTeacher(String.valueOf(teacherIds)); - courses.setTeacher(teacherId); courses.setCreateTime(LocalDateTime.now()); String code = coursesDTO.getCode(); QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -65,11 +68,28 @@ public class CoursesServiceImpl extends ServiceImpl impl if (count == 0) { int insert = coursesMapper.insert(courses); if (insert > 0) { - Courses courses1 = coursesMapper.selectOne(queryWrapper); - courseObjectives.setCourseId(courses1.getId()); - courseObjectives.setCreateTime(courses1.getCreateTime()); - courseObjectives.setName(courses1.getName() + "课程总体目标"); - courseObjectivesMapper.insert(courseObjectives); + Courses coursesNew = coursesMapper.selectOne(queryWrapper); + courseObjectives.setCourseId(coursesNew.getId()); + courseObjectives.setName(coursesNew.getName() + "课程总体目标"); +// courseObjectives.setHasChild(1); + int insertTotal = courseObjectivesMapper.insert(courseObjectives); + if (insertTotal>0){ + CourseObjectives courseTotalObjectives = courseObjectivesMapper.selectOne + (new LambdaQueryWrapper().eq(CourseObjectives::getCourseId, coursesNew.getId())); + String courseTotalObjectivesId = courseTotalObjectives.getId(); + List objectivesTypes = objectivesTypeMapper.selectList(new LambdaQueryWrapper()); + for (ObjectivesType objectivesType : objectivesTypes) { + Integer typeId = objectivesType.getId(); + String typeName = objectivesType.getTypeName(); + CourseObjectives courseObjectivesF = new CourseObjectives(); + courseObjectivesF.setType(typeId); + courseObjectivesF.setName(typeName); + courseObjectivesF.setPid(courseTotalObjectivesId); + courseObjectivesMapper.insert(courseObjectivesF); + } + courseTotalObjectives.setHasChild(1); + courseObjectivesMapper.updateById(courseTotalObjectives); + } } return "添加成功"; } else { @@ -97,79 +117,54 @@ public class CoursesServiceImpl extends ServiceImpl impl } @Override -// @Transactional public void deleteBatchByIds(String id) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(CourseObjectives::getCourseId, id); - CourseObjectives courseObjectives = courseObjectivesMapper.selectOne(queryWrapper); + CourseObjectives courseObjectives= courseObjectivesMapper.selectOne + (new LambdaQueryWrapper().eq(CourseObjectives::getCourseId, id)); String objectivesId = courseObjectives.getId(); - LambdaQueryWrapper queryWrapper2 = new LambdaQueryWrapper().eq(ObjectiveContents::getObjectiveId, objectivesId); - Long count = objectiveContentsMapper.selectCount(queryWrapper2); - if (courseObjectives.getHasChild().equals("1")) { - throw new BusinessException(ErrorCode.CONTENT_EXISTS, "该课程已有分项目标,禁止删除"); - } - if (!count.equals(0)){ - throw new BusinessException(ErrorCode.CONTENT_EXISTS, "总目标下面还有内容,禁止删除"); + List courseObjectivesTreeVOList = courseObjectivesMapper.selectTreeNodes(objectivesId); + int contents = 0; + List objectiveIds = new ArrayList<>(); + for (CourseObjectivesTreeVO courseObjectivesTreeVO : courseObjectivesTreeVOList) { + String objectiveId = courseObjectivesTreeVO.getId(); + objectiveIds.add(objectiveId); + Long content = objectiveContentsMapper + .selectCount(new LambdaQueryWrapper().eq(ObjectiveContents::getObjectiveId, objectiveId)); + contents+=content; } - else { + if (contents==0){ coursesMapper.deleteById(id); - courseObjectivesMapper.deleteById(courseObjectives.getId()); + courseObjectivesMapper.deleteBatchIds(objectiveIds); + } + else{ + throw new BusinessException(ErrorCode.CONTENT_EXISTS, "该课程的目标下面还有内容,请把相关内容清空后再来删除课程"); } } - @Override - public List getPagePageSize(int page, int pageSize) { - int startIndex = (page-1) * pageSize; - List list = coursesMapper.getItemsByPage(startIndex, pageSize); -// List list = coursesMapper.selectList(null); - List coursesVo = BeanUtil.copyToList(list, CoursesVO.class); - coursesVo = coursesVo.stream().map((item) -> { - - item.setTotalHours(countHours(item.getId())); - item.setTotalchapter(100); - item.setTotalKnow(100); -// if (StringUtils.isBlank(item.getName()) || -// StringUtils.isBlank(item.getDescription()) ){ -// throw new BusinessException(ErrorCode.OPERATION_ERROR,"数据格式有问题,请修改"); -// } - return item; - }).collect(Collectors.toList()); - return coursesVo; - + public int countHours(String id) { + return 0; } @Override - public int countHours(String id) { - Courses courses = coursesMapper.selectById(id); - - Integer classhours = 0; - Integer theoryhours = 0; - Integer practicehours = 0; - Integer experimenthours = 0; - Integer otherhours = 0; - if (courses.getClasshours() != null) { - classhours = courses.getClasshours(); - } - - if (courses.getTheoryhours() != null) { - theoryhours = courses.getTheoryhours(); - } - - if (courses.getPracticehours() != null) { - practicehours = courses.getPracticehours(); - } - - if (courses.getExperimenthours() != null) { - experimenthours = courses.getExperimenthours(); - } + public List getPagePageSize(int page, int pageSize) { + return null; + } - if (courses.getOtherhours() != null) { - otherhours = courses.getOtherhours(); + /** + * 修改课程信息 + * @param coursesDTO + */ + public void updateCourse(CoursesDTO coursesDTO) { + String courseId = coursesDTO.getId(); + Courses course = coursesMapper.selectById(courseId); + if (course.getStatus()==CourseCode.COURSE_UODATING.getValue()){ + throw new BusinessException(ErrorCode.SYSTEM_ERROR,"课程正在修改中,请等待修改完成后再进行操作"); } - int total = classhours + theoryhours + practicehours + experimenthours + otherhours; - - return total; - + course.setStatus(CourseCode.COURSE_UODATING.getValue()); + coursesMapper.updateById(course); + BeanUtil.copyProperties(coursesDTO, course); + course.setStatus(0); + coursesMapper.updateById(course); } diff --git a/src/main/java/com/teaching/backend/utils/CourseCode.java b/src/main/java/com/teaching/backend/utils/CourseCode.java new file mode 100644 index 0000000..30dd812 --- /dev/null +++ b/src/main/java/com/teaching/backend/utils/CourseCode.java @@ -0,0 +1,37 @@ +package com.teaching.backend.utils; + +public enum CourseCode { + HAS_CHILD(1, "存在子节点"), + + OBJECTIVE_EXIT(1,"目标存在"), + CONTENT_EXIT(1, "存在内容"), + SI_ZHENG_TYPE(1, "思政目标类型"), + SI_ZHENG_EXIT(1, "思政目标存在"), + COURSE_UODATING(1, "课程正在修改中"); + + + /** + * 状态码 + */ + private final int value; + + /** + * 信息 + */ + private final String message; + + CourseCode(int value, String message) { + this.value = value; + this.message = message; + } + + public int getValue() { + return value; + } + + public String getMessage() { + return message; + } + + +} diff --git a/src/main/resources/mapper/CourseObjectivesMapper.xml b/src/main/resources/mapper/CourseObjectivesMapper.xml index 429a2e3..347ebec 100644 --- a/src/main/resources/mapper/CourseObjectivesMapper.xml +++ b/src/main/resources/mapper/CourseObjectivesMapper.xml @@ -4,7 +4,6 @@