mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-05 12:23:29 +08:00
优化默认parentId
This commit is contained in:
@@ -54,13 +54,23 @@ public abstract class AbstractTreeSortService<E extends TreeSortSupportEntity<PK
|
||||
return createQuery().where(TreeSupportEntity.parentId, parentId).noPaging().list();
|
||||
}
|
||||
|
||||
//当父节点不存在时,创建parentId
|
||||
@SuppressWarnings("unchecked")
|
||||
protected PK createParentIdOnExists() {
|
||||
if (getPrimaryKeyType() == String.class) {
|
||||
return (PK) "-1";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void applyPath(E entity) {
|
||||
if (!StringUtils.isEmpty(entity.getParentId())) return;
|
||||
if (!StringUtils.isEmpty(entity.getPath())) return;
|
||||
|
||||
TreeSortSupportEntity<PK> parent = selectByPk(entity.getParentId());
|
||||
if (null == parent) {
|
||||
entity.setParentId(null);
|
||||
entity.setParentId(createParentIdOnExists());
|
||||
entity.setPath(RandomUtil.randomChar(4));
|
||||
} else {
|
||||
entity.setPath(parent.getPath() + "-" + RandomUtil.randomChar(4));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user