Browse Source

在指定sortIndex的时候不默认为0

zhouhao 6 years ago
parent
commit
2c6198b174

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

@@ -88,7 +88,9 @@ public abstract class AbstractTreeSortService<E extends TreeSortSupportEntity<PK
 
     protected void applyPath(E entity) {
         if (StringUtils.isEmpty(entity.getParentId())) {
-            entity.setSortIndex(0L);
+            if (entity.getSortIndex() == null) {
+                entity.setSortIndex(0L);
+            }
             entity.setParentId(createParentIdOnExists());
             entity.setLevel(0);
             entity.setPath(RandomUtil.randomChar(4));
@@ -100,14 +102,16 @@ public abstract class AbstractTreeSortService<E extends TreeSortSupportEntity<PK
 
         TreeSortSupportEntity<PK> parent = selectByPk(entity.getParentId());
         if (null == parent) {
-            if (entity.getSortIndex() == null)
+            if (entity.getSortIndex() == null) {
                 entity.setSortIndex(0L);
+            }
             entity.setParentId(createParentIdOnExists());
             entity.setPath(RandomUtil.randomChar(4));
             entity.setLevel(0);
         } else {
-            if (entity.getSortIndex() == null && parent.getSortIndex() != null)
+            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);
         }