|
|
@@ -123,6 +123,11 @@ public class SecondGoodsCategoryServiceImpl extends ServiceImpl<SecondGoodsCateg
|
|
|
|
|
|
List<SecondGoodsCategory> roots = nodes.stream()
|
|
|
.filter(n -> -1 == n.getParentId()) // 假设根节点的parentId为-1
|
|
|
+ .sorted((n1, n2) -> {
|
|
|
+ if (n1.getCategorySort() == null) return 1;
|
|
|
+ if (n2.getCategorySort() == null) return -1;
|
|
|
+ return n1.getCategorySort().compareTo(n2.getCategorySort());
|
|
|
+ })
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
for (SecondGoodsCategory root : roots) {
|
|
|
@@ -134,6 +139,11 @@ public class SecondGoodsCategoryServiceImpl extends ServiceImpl<SecondGoodsCateg
|
|
|
private void addChildrenRecursive(SecondGoodsCategory parent, Map<Integer, SecondGoodsCategory> nodeMap) {
|
|
|
List<SecondGoodsCategory> children = nodeMap.values().stream()
|
|
|
.filter(child -> child.getParentId().equals(parent.getId()))
|
|
|
+ .sorted((n1, n2) -> {
|
|
|
+ if (n1.getCategorySort() == null) return 1;
|
|
|
+ if (n2.getCategorySort() == null) return -1;
|
|
|
+ return n1.getCategorySort().compareTo(n2.getCategorySort());
|
|
|
+ })
|
|
|
.collect(Collectors.toList());
|
|
|
parent.setChildren(children);
|
|
|
children.forEach(child -> addChildrenRecursive(child, nodeMap));
|