|
|
@ -74,12 +74,12 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp |
|
|
private void injectPaperSetCount(List<ClassicCategoryDTO> nodes, Map<Long, Integer> countMap) { |
|
|
private void injectPaperSetCount(List<ClassicCategoryDTO> nodes, Map<Long, Integer> countMap) { |
|
|
for (ClassicCategoryDTO node : nodes) { |
|
|
for (ClassicCategoryDTO node : nodes) { |
|
|
if (node.getChildrenList() != null && !node.getChildrenList().isEmpty()) { |
|
|
if (node.getChildrenList() != null && !node.getChildrenList().isEmpty()) { |
|
|
// 一级分类:先递归处理子节点,再累加
|
|
|
// 一级分类:先递归处理子节点,再累加自身及子节点
|
|
|
injectPaperSetCount(node.getChildrenList(), countMap); |
|
|
injectPaperSetCount(node.getChildrenList(), countMap); |
|
|
int sum = node.getChildrenList().stream() |
|
|
int sum = node.getChildrenList().stream() |
|
|
.mapToInt(c -> c.getPaperSetCount() != null ? c.getPaperSetCount() : 0) |
|
|
.mapToInt(c -> c.getPaperSetCount() != null ? c.getPaperSetCount() : 0) |
|
|
.sum(); |
|
|
.sum(); |
|
|
node.setPaperSetCount(sum); |
|
|
node.setPaperSetCount(sum + countMap.getOrDefault(node.getId(), 0)); |
|
|
} else { |
|
|
} else { |
|
|
// 二级分类:直接取统计值
|
|
|
// 二级分类:直接取统计值
|
|
|
node.setPaperSetCount(countMap.getOrDefault(node.getId(), 0)); |
|
|
node.setPaperSetCount(countMap.getOrDefault(node.getId(), 0)); |
|
|
|