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