diff --git a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java index fbc1e68..b29720e 100644 --- a/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java +++ b/src/main/java/com/teaching/backend/controller/KnowGraph/KnowController.java @@ -86,12 +86,12 @@ public class KnowController { } //删除知识点 - 章节 @PostMapping("/delete/KnowChapter") - public BaseResponse deleteKnowChapter(@RequestParam String chapterId) { + public BaseResponse deleteKnowChapter(@RequestParam Long chapterId) { return knowService.deleteKnowChapter(chapterId); } @GetMapping("/KnowBychapterId") - public Set queryByChapterId(@RequestParam String chapterId) { + public Set queryByChapterId(@RequestParam Long chapterId) { return knowService.queryByChapterId(chapterId); } diff --git a/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java b/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java index 3d29175..46e776a 100644 --- a/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java +++ b/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java @@ -54,7 +54,7 @@ public BaseResponse> getCourseChapters2(@RequestParam String cours @ApiOperation("删除章节") @DeleteMapping("/delete/{id}") - public BaseResponse dlChapter(@PathVariable String id){ + public BaseResponse dlChapter(@PathVariable Long id){ chapterService.deleteChapter(id); return ResultUtils.success("删除成功"); } diff --git a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java index 5a0664f..7483a9c 100644 --- a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java +++ b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowRepository.java @@ -43,15 +43,15 @@ public interface KnowRepository extends Neo4jRepository { 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 queryByChapterId(String chapterId); + Set queryByChapterId(Long chapterId); } diff --git a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java index 37fb576..e70465a 100644 --- a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java +++ b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java @@ -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; diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java b/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java index f18a008..4f0f1a8 100644 --- a/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java +++ b/src/main/java/com/teaching/backend/service/KnowGraph/KnowService.java @@ -109,12 +109,12 @@ public class KnowService { public BaseResponse updateKnowChapter(Chapter chapter) { return ResultUtils.success(knowRepository.createKnowChapter(chapter.getId(), chapter.getName(), chapter.getContent())); } - public BaseResponse deleteKnowChapter(String chapterId) { + public BaseResponse deleteKnowChapter(Long chapterId) { boolean f = knowRepository.deleteKnowChapter(chapterId); if(f)return ResultUtils.success("删除成功"); return ResultUtils.error(ErrorCode.DELETE_FAILED); } - public Set queryByChapterId(String chapterId){ + public Set queryByChapterId(Long chapterId){ Set knows = knowRepository.queryByChapterId(chapterId); return knows; } diff --git a/src/main/java/com/teaching/backend/service/chapter/IChapterService.java b/src/main/java/com/teaching/backend/service/chapter/IChapterService.java index e2cd18d..f867f4b 100644 --- a/src/main/java/com/teaching/backend/service/chapter/IChapterService.java +++ b/src/main/java/com/teaching/backend/service/chapter/IChapterService.java @@ -31,5 +31,5 @@ public interface IChapterService extends IService { void saveChapter(ChapterDTO chapterDTO); - void deleteChapter(String id); + void deleteChapter(Long id); } diff --git a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java index 153eb8b..7e64960 100644 --- a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java @@ -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 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 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 impl private void loadKnowledgePointsRecursively(Chapter chapter) { - for (Chapter child : chapter.getChildren()) { + List sortedChildren = chapter.getChildren().stream() + .sorted(Comparator.comparing(Chapter::getOrderNum)) + .collect(Collectors.toList()); + + chapter.setChildren(sortedChildren); + for (Chapter child : sortedChildren) { Set knows = knowService.queryByChapterId(child.getId()); child.setKnowledgePoints(new ArrayList<>(knows)); @@ -216,7 +224,18 @@ public class ChapterServiceImpl extends ServiceImpl impl if (pid == null || pid.isEmpty()) { + chapter.setPid("0"); + + LambdaQueryWrapper 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 impl Chapter parentChapter = this.getById(pid); if (parentChapter != null) { + LambdaQueryWrapper 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 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,"请求参数不能为空"); } LambdaQueryWrapperqueryWrapper=new LambdaQueryWrapper<>(); @@ -265,7 +295,6 @@ public class ChapterServiceImpl extends ServiceImpl impl } this.remove(queryWrapper); - } 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 1ebffa2..f5682e6 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 @@ -168,9 +168,12 @@ public class CourseObjectivesServiceImpl extends ServiceImpl queryCourseObjectivesTree(String id) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(CourseObjectives::getCourseId, id); + CourseObjectives courseObjectives = courseObjectivesMapper.selectOne(queryWrapper); + String courseObjectivesId = courseObjectives.getId(); List objectives = courseObjectivesMapper.selectTreeNodes(courseObjectivesId); + Map map = new HashMap<>(); for (CourseObjectivesTreeVO objective : objectives) { objective.setName(objectivesTypeMapper.selectById(objective.getType()).getTypeName());