master
小萌新 4 months ago
parent 8d2e3e86ba
commit b21b0fdad1
  1. 4
      src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java
  2. 2
      src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java
  3. 8
      src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java
  4. 6
      src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java
  5. 4
      src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java
  6. 2
      src/main/java/com/teaching/backend/service/chapter/IChapterService.java
  7. 43
      src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java
  8. 3
      src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java

@ -86,12 +86,12 @@ public class KnowController {
}
//删除知识点 - 章节
@PostMapping("/delete/KnowChapter")
public BaseResponse<String> deleteKnowChapter(@RequestParam String chapterId) {
public BaseResponse<String> deleteKnowChapter(@RequestParam Long chapterId) {
return knowService.deleteKnowChapter(chapterId);
}
@GetMapping("/KnowBychapterId")
public Set<Know> queryByChapterId(@RequestParam String chapterId) {
public Set<Know> queryByChapterId(@RequestParam Long chapterId) {
return knowService.queryByChapterId(chapterId);
}

@ -54,7 +54,7 @@ public BaseResponse<List<Chapter>> getCourseChapters2(@RequestParam String cours
@ApiOperation("删除章节")
@DeleteMapping("/delete/{id}")
public BaseResponse<String> dlChapter(@PathVariable String id){
public BaseResponse<String> dlChapter(@PathVariable Long id){
chapterService.deleteChapter(id);
return ResultUtils.success("删除成功");
}

@ -43,15 +43,15 @@ public interface KnowRepository extends Neo4jRepository<Know, Long> {
Boolean deleteKnowCourse(String courseId);
@Query("CREATE (n:Know {name: $name, chapterId: $chapterId,info:$info}) return count(n)")
KnowChapter createKnowChapter(String chapterId, String name, String info);
KnowChapter createKnowChapter(Long chapterId, String name, String info);
@Query("MATCH (p:Know {chapterId:$chapterId }) SET p.name = $name set p.info= $info RETURN p;")
Boolean updateKnowChapter(String chapterId, String name, String info);
Boolean updateKnowChapter(Long chapterId, String name, String info);
@Query("MATCH (p:Know {chapterId:$chapterId }) RETURN count(p);")
Boolean deleteKnowChapter(String chapterId);
Boolean deleteKnowChapter(Long chapterId);
@Query("MATCH(n:Know)-[r:FatherAndSon*]->(nn:Know) where n.chapterId = $chapterId RETURN nn")
Set<Know> queryByChapterId(String chapterId);
Set<Know> queryByChapterId(Long chapterId);
}

@ -28,11 +28,11 @@ import java.util.List;
@TableName("chapter")
public class Chapter implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ApiModelProperty(value = "创建人")
private String createBy;

@ -109,12 +109,12 @@ public class KnowService {
public BaseResponse<KnowChapter> updateKnowChapter(Chapter chapter) {
return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent()));
}
public BaseResponse<String> deleteKnowChapter(String chapterId) {
public BaseResponse<String> deleteKnowChapter(Long chapterId) {
boolean f = knowRepository.deleteKnowChapter(chapterId);
if(f)return ResultUtils.success("删除成功");
return ResultUtils.error(ErrorCode.DELETE_FAILED);
}
public Set<Know> queryByChapterId(String chapterId){
public Set<Know> queryByChapterId(Long chapterId){
Set<Know> knows = knowRepository.queryByChapterId(chapterId);
return knows;
}

@ -31,5 +31,5 @@ public interface IChapterService extends IService<Chapter> {
void saveChapter(ChapterDTO chapterDTO);
void deleteChapter(String id);
void deleteChapter(Long id);
}

@ -13,6 +13,7 @@ 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.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -168,9 +169,8 @@ 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);
chapter.setKnowledgePoints(new ArrayList<>());
chapterMap.put(String.valueOf(chapter.getId()),chapter);
}
for (Chapter chapter:chapters){
String parentId=chapter.getPid();
@ -185,6 +185,9 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
roots.add(chapter);
}
}
roots = roots.stream()
.sorted(Comparator.comparing(Chapter::getOrderNum))
.collect(Collectors.toList());
for (Chapter root : roots) {
loadKnowledgePointsRecursively(root);
@ -195,8 +198,13 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
private void loadKnowledgePointsRecursively(Chapter chapter) {
for (Chapter child : chapter.getChildren()) {
List<Chapter> sortedChildren = chapter.getChildren().stream()
.sorted(Comparator.comparing(Chapter::getOrderNum))
.collect(Collectors.toList());
chapter.setChildren(sortedChildren);
for (Chapter child : sortedChildren) {
Set<Know> knows = knowService.queryByChapterId(child.getId());
child.setKnowledgePoints(new ArrayList<>(knows));
@ -216,7 +224,18 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
if (pid == null || pid.isEmpty()) {
chapter.setPid("0");
LambdaQueryWrapper<Chapter> maxSortWrapper = new LambdaQueryWrapper<>();
maxSortWrapper.eq(Chapter::getPid, "0").orderByDesc(Chapter::getOrderNum).last("limit 1");
Chapter maxSortChapter = this.getOne(maxSortWrapper);
int newSort = 1;
if (maxSortChapter != null) {
newSort = maxSortChapter.getOrderNum() + 1;
}
chapter.setOrderNum(newSort);
chapter.setCreateTime(LocalDateTime.now());
chapter.setUpdateTime(LocalDateTime.now());
@ -228,7 +247,18 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
Chapter parentChapter = this.getById(pid);
if (parentChapter != null) {
LambdaQueryWrapper<Chapter> maxSortWrapper = new LambdaQueryWrapper<>();
maxSortWrapper.eq(Chapter::getPid,pid).orderByDesc(Chapter::getOrderNum).last("limit 1");
parentChapter.setUpdateTime(LocalDateTime.now());
Chapter maxSortChapter = this.getOne(maxSortWrapper);
int newSort = 1;
if (maxSortChapter != null) {
newSort = maxSortChapter.getOrderNum() + 1;
}
chapter.setOrderNum(newSort);
this.updateById(parentChapter);
chapter.setCreateTime(LocalDateTime.now());
@ -241,8 +271,8 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
}
@Override
public void deleteChapter(String id) {
if (id==null||id.isEmpty()){
public void deleteChapter(Long id) {
if (id==null){
throw new BusinessException(ErrorCode.PARAMS_ERROR,"请求参数不能为空");
}
LambdaQueryWrapper<Chapter>queryWrapper=new LambdaQueryWrapper<>();
@ -265,7 +295,6 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
}
this.remove(queryWrapper);
}

@ -168,9 +168,12 @@ public class CourseObjectivesServiceImpl extends ServiceImpl<CourseObjectivesMap
public List<CourseObjectivesTreeVO> queryCourseObjectivesTree(String id) {
LambdaQueryWrapper<CourseObjectives> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CourseObjectives::getCourseId, id);
CourseObjectives courseObjectives = courseObjectivesMapper.selectOne(queryWrapper);
String courseObjectivesId = courseObjectives.getId();
List<CourseObjectivesTreeVO> objectives = courseObjectivesMapper.selectTreeNodes(courseObjectivesId);
Map<String, CourseObjectivesTreeVO> map = new HashMap<>();
for (CourseObjectivesTreeVO objective : objectives) {
objective.setName(objectivesTypeMapper.selectById(objective.getType()).getTypeName());

Loading…
Cancel
Save