|
@@ -31,6 +31,7 @@ public class TreeHelper<T extends DefaultEntity> { |
|
|
private EntityDao<T> dao; |
|
|
private EntityDao<T> dao; |
|
|
|
|
|
|
|
|
private String fieldParent; |
|
|
private String fieldParent; |
|
|
|
|
|
private String fieldLevel; |
|
|
private String fieldLevelCode; |
|
|
private String fieldLevelCode; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -58,16 +59,19 @@ public class TreeHelper<T extends DefaultEntity> { |
|
|
cache = CacheManager.getIntance().getCache(tableName); |
|
|
cache = CacheManager.getIntance().getCache(tableName); |
|
|
dao = DbEngine.getInstance().findDao(tableName); |
|
|
dao = DbEngine.getInstance().findDao(tableName); |
|
|
|
|
|
|
|
|
ModelField field = table.findFieldByType(SwEnum.FieldType.PARENT_ID.value); |
|
|
|
|
|
fieldParent = field.getName(); |
|
|
|
|
|
field = table.findFieldByType(SwEnum.FieldType.LEVEL_CODE.value); |
|
|
|
|
|
fieldLevelCode = field.getName(); |
|
|
|
|
|
|
|
|
fieldParent = table.findFieldNameByType(SwEnum.FieldType.PARENT_ID.value); |
|
|
|
|
|
fieldLevelCode = table.findFieldNameByType(SwEnum.FieldType.LEVEL_CODE.value); |
|
|
|
|
|
fieldLevel = table.findFieldNameByType(SwEnum.FieldType.LEVEL.value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public long getParentId(T bean) { |
|
|
public long getParentId(T bean) { |
|
|
return bean.getLong(fieldParent); |
|
|
return bean.getLong(fieldParent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public long getLevel(T bean) { |
|
|
|
|
|
return bean.getLong(fieldLevel); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public String getLevelCode(T bean) { |
|
|
public String getLevelCode(T bean) { |
|
|
return bean.getStr(fieldLevelCode); |
|
|
return bean.getStr(fieldLevelCode); |
|
|
} |
|
|
} |
|
@@ -119,7 +123,8 @@ public class TreeHelper<T extends DefaultEntity> { |
|
|
T parent = cache.get(getParentId(bean)); |
|
|
T parent = cache.get(getParentId(bean)); |
|
|
if (parent != null) { |
|
|
if (parent != null) { |
|
|
bean.put(fieldLevelCode, getLevelCode(parent) + SwConsts.SPLIT_CHAR + parent.getEntityId()); |
|
|
bean.put(fieldLevelCode, getLevelCode(parent) + SwConsts.SPLIT_CHAR + parent.getEntityId()); |
|
|
dao.updateEntity(bean, fieldLevelCode); |
|
|
|
|
|
|
|
|
bean.put(fieldLevel, getLevel(parent) + 1); |
|
|
|
|
|
dao.updateEntity(bean, fieldLevelCode, fieldLevel); |
|
|
list.add(bean); |
|
|
list.add(bean); |
|
|
} |
|
|
} |
|
|
Collection<T> children = getChildren(bean); |
|
|
Collection<T> children = getChildren(bean); |
|
|