将知识添加进子章节

master
小萌新 4 months ago
parent fa9571e2c5
commit 414b11ac24
  1. 34
      src/main/java/com/teaching/backend/controller/courses/CoursesController.java
  2. 4
      src/main/java/com/teaching/backend/controller/courses/CoursesController2.java
  3. 9
      src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java
  4. 13
      src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
  5. 29
      src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java

@ -44,21 +44,37 @@ public class CoursesController {
// @ApiOperation("网站首页")
// @GetMapping("/index")
// public BaseResponse<Map<String,Object>> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
// List<CoursesVO> coursesVo = coursesService.getPagePageSize(page, pageSize);
//// System.out.println(coursesVo);
// long totalcount = coursesService.count();
// long toatlPages = (int) Math.ceil((double)totalcount / pageSize);
// Map<String,Object> objectMap = new HashMap<>();
// objectMap.put("content",coursesVo);
// objectMap.put("totalcount", totalcount);
// objectMap.put("totalPages", toatlPages);
// objectMap.put("currentPage", page);
// return ResultUtils.success(objectMap);
// }
@ApiOperation("网站首页")
@GetMapping("/index")
public BaseResponse<Map<String,Object>> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
List<CoursesVO> coursesVo = coursesService.getPagePageSize(page, pageSize);
// System.out.println(coursesVo);
long totalcount = coursesService.count();
long toatlPages = (int) Math.ceil((double)totalcount / pageSize);
Map<String,Object> objectMap = new HashMap<>();
objectMap.put("content",coursesVo);
objectMap.put("totalcount", totalcount);
objectMap.put("totalPages", toatlPages);
objectMap.put("currentPage", page);
Map<String, Object> result = coursesService.getPagePageSize2(page, pageSize);
// 将结果放入新的Map对象中返回
Map<String, Object> objectMap = new HashMap<>();
objectMap.put("content", result.get("courses"));
objectMap.put("totalcount", result.get("totalcount"));
objectMap.put("totalPages", result.get("totalPages"));
objectMap.put("currentPage", result.get("currentPage"));
return ResultUtils.success(objectMap);
}
@ApiOperation("新增课程--同步新增课程的总体目标并同时添加所有的分项目标")
@ValidateParams({"teacher","img", "category", "nature","name","code","credit","classhours","assessmenttype","assessmentway"}) // 需要校验的参数
@PostMapping("/addcourse")

@ -6,7 +6,6 @@
//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.entity.resource.CourseResources;
//import com.teaching.backend.model.entity.courses.Courses;
//import com.teaching.backend.service.courses.ICoursesService;
//import io.swagger.annotations.ApiOperation;
@ -32,8 +31,6 @@
//public class CoursesController2 {
// @Autowired
// ICoursesService coursesService;
// @Autowired
// ResourcesRelationshipService resourcesRelationshipService;
//
// @ApiOperation("网站首页2")
// @GetMapping("/index2")
@ -78,6 +75,7 @@
// return ResultUtils.success(relatedResources);
// }
//
//
// }
//
//

@ -1,14 +1,10 @@
package com.teaching.backend.model.dto.chapter;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.xml.soap.Text;
import java.io.Serializable;
import java.time.LocalDateTime;
@ -74,11 +70,6 @@ public class ChapterDTO implements Serializable {
@ApiModelProperty(value = "周次")
private String zc;
@ApiModelProperty(value = "资源")
private String ziyuan;
@ApiModelProperty(value = "资源文件")
private String zywj;
@ApiModelProperty(value = "内部序号显示")
private String numshow;

@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import com.teaching.backend.model.entity.KnowGraph.Know;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -80,12 +80,6 @@ public class Chapter implements Serializable {
@ApiModelProperty(value = "周次")
private String zc;
@ApiModelProperty(value = "资源")
private String ziyuan;
@ApiModelProperty(value = "资源文件")
private String zywj;
@ApiModelProperty(value = "内部序号显示")
private String numshow;
@ -93,4 +87,9 @@ public class Chapter implements Serializable {
@TableField(exist = false)
private List<Chapter> children; // 用于存储子章节
@ApiModelProperty(value = "知识点")
@TableField(exist = false)
private List<Know> knowledgePoints; // 用于存储章节下的知识点
}

@ -8,8 +8,10 @@ import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.chapter.ChapterMapper;
import com.teaching.backend.model.dto.chapter.ChapterDTO;
import com.teaching.backend.model.entity.KnowGraph.Know;
import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.vo.chapter.ChapterVo;
import com.teaching.backend.service.KnowGraph.KnowService;
import com.teaching.backend.service.chapter.IChapterService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,6 +33,8 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
// private int count=0;
List<Chapter> list=new ArrayList<>();
@Autowired
private KnowService knowService;
@Override
public String updateNumShow(Chapter chapter) {
@ -155,7 +159,6 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
@Override
public List<Chapter> getChapterTree(String courseId) {
List<Chapter> chapters=baseMapper.selectSectionsByCourseId(courseId);
Map<String,Chapter> chapterMap=new HashMap<>();
@ -165,6 +168,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
for (Chapter chapter:chapters){
chapter.setChildren(new ArrayList<>());
chapter.setKnowledgePoints(new ArrayList<>()); // 初始化知识点列表
chapterMap.put(chapter.getId(),chapter);
}
@ -182,9 +186,23 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
}
}
return roots;
for (Chapter root : roots) {
loadKnowledgePointsRecursively(root);
}
return roots;
}
private void loadKnowledgePointsRecursively(Chapter chapter) {
for (Chapter child : chapter.getChildren()) {
Set<Know> knows = knowService.queryByChapterId(child.getId());
child.setKnowledgePoints(new ArrayList<>(knows));
loadKnowledgePointsRecursively(child);
}
}
@Override
public void saveChapter(ChapterDTO chapterDTO) {
@ -235,9 +253,16 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
lambdaQueryWrapper.eq(Chapter::getPid,id);
Long count= this.count(lambdaQueryWrapper);
if (count>0){
throw new BusinessException(ErrorCode.OPERATION_ERROR,"存在子章节,无法删除");
}
Set<Know> knows = knowService.queryByChapterId(id);
if (!knows.isEmpty()) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "子章节下存在知识点,无法删除");
}
this.remove(queryWrapper);

Loading…
Cancel
Save