|
|
@ -41,30 +41,26 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp |
|
|
ClassicCategoryDTO::getParentId, |
|
|
ClassicCategoryDTO::getParentId, |
|
|
ClassicCategoryDTO::setChildrenList); |
|
|
ClassicCategoryDTO::setChildrenList); |
|
|
|
|
|
|
|
|
// 3. 查询所有套题组(只查必要字段),同时用于统计数量和填充列表
|
|
|
// 3. 查询套题组,统计数量和分组
|
|
|
List<ClassicPaperSetEntity> allPaperSets = classicPaperSetBaseService.lambdaQuery() |
|
|
List<ClassicPaperSetEntity> allPaperSets = classicPaperSetBaseService.lambdaQuery() |
|
|
.select(ClassicPaperSetEntity::getClassicCategoryId, ClassicPaperSetEntity::getId, ClassicPaperSetEntity::getName) |
|
|
.select(ClassicPaperSetEntity::getClassicCategoryId, ClassicPaperSetEntity::getId, ClassicPaperSetEntity::getName) |
|
|
.orderByDesc(ClassicPaperSetEntity::getId) |
|
|
.orderByDesc(ClassicPaperSetEntity::getId).list(); |
|
|
.list(); |
|
|
|
|
|
Map<Long, Integer> countMap = new HashMap<>(); |
|
|
Map<Long, Integer> countMap = new HashMap<>(); |
|
|
|
|
|
Map<Long, List<ClassicPaperSetDTO>> paperSetMap = Boolean.TRUE.equals(withPaperSet) ? new HashMap<>() : null; |
|
|
for (ClassicPaperSetEntity set : allPaperSets) { |
|
|
for (ClassicPaperSetEntity set : allPaperSets) { |
|
|
Long catId = set.getClassicCategoryId(); |
|
|
Long catId = set.getClassicCategoryId(); |
|
|
if (catId != null) { |
|
|
if (catId == null) continue; |
|
|
countMap.merge(catId, 1, Integer::sum); |
|
|
countMap.merge(catId, 1, Integer::sum); |
|
|
|
|
|
if (paperSetMap != null) { |
|
|
|
|
|
//按分类ID分组套题组
|
|
|
|
|
|
paperSetMap.computeIfAbsent(catId, k -> new ArrayList<>()).add(set.toDTO(ClassicPaperSetDTO::new)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 4. 注入 paperSetCount 到树节点
|
|
|
// 4. 注入 paperSetCount 到树节点
|
|
|
injectPaperSetCount(tree, countMap); |
|
|
injectPaperSetCount(tree, countMap); |
|
|
|
|
|
if (paperSetMap != null){ |
|
|
if (Boolean.TRUE.equals(withPaperSet)) { |
|
|
// 5. 注入套题组到二级分类
|
|
|
// 5. 按分类ID分组套题组
|
|
|
|
|
|
Map<Long, List<ClassicPaperSetDTO>> paperSetMap = allPaperSets.stream() |
|
|
|
|
|
.filter(s -> s.getClassicCategoryId() != null) |
|
|
|
|
|
.map(s -> s.toDTO(ClassicPaperSetDTO::new)) |
|
|
|
|
|
.collect(Collectors.groupingBy(ClassicPaperSetDTO::getClassicCategoryId)); |
|
|
|
|
|
|
|
|
|
|
|
// 6. 注入套题组到二级分类
|
|
|
|
|
|
injectPaperList(tree, paperSetMap); |
|
|
injectPaperList(tree, paperSetMap); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|