Browse Source

优化level

zhouhao 7 years ago
parent
commit
a0633a41cf

+ 3 - 0
hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractTreeSortService.java

@@ -67,6 +67,7 @@ public abstract class AbstractTreeSortService<E extends TreeSortSupportEntity<PK
         if (StringUtils.isEmpty(entity.getParentId())) {
             entity.setSortIndex(0L);
             entity.setParentId(createParentIdOnExists());
+            entity.setLevel(0);
             entity.setPath(RandomUtil.randomChar(4));
             return;
         }
@@ -80,10 +81,12 @@ public abstract class AbstractTreeSortService<E extends TreeSortSupportEntity<PK
                 entity.setSortIndex(0L);
             entity.setParentId(createParentIdOnExists());
             entity.setPath(RandomUtil.randomChar(4));
+            entity.setLevel(0);
         } else {
             if (entity.getSortIndex() == null && parent.getSortIndex() != null)
                 entity.setSortIndex(parent.getSortIndex() * 10);
             entity.setPath(parent.getPath() + "-" + RandomUtil.randomChar(4));
+            entity.setLevel(entity.getPath().split("-").length);
         }
     }