|
|
|
@ -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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|