ソースを参照

优化:树型表加字段level

master
郑根木 2年前
コミット
1a84c06e5b
3個のファイルの変更22行の追加6行の削除
  1. +2
    -1
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  2. +10
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelTable.java
  3. +10
    -5
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java

+ 2
- 1
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java ファイルの表示

@@ -39,7 +39,8 @@ public interface SwEnum {
public static FieldTypeBean NAME = instance.addEnum(3, "名称字段", DataType.NAME.value,1);
public static FieldTypeBean PARENT_ID = instance.addEnum(4, "父ID", DataType.ID.value);
public static FieldTypeBean LEVEL_CODE = instance.addEnum(5, "级次码", DataType.CODE.value);
public static FieldTypeBean ORDER = instance.addEnum(6, "排序字段", "");
public static FieldTypeBean LEVEL = instance.addEnum(6, "级次", DataType.SHORT.value);
// public static FieldTypeBean ORDER = instance.addEnum(6, "排序字段", "");
public static FieldTypeBean CREATE_USER = instance.addEnum(7, "创建人", DataType.ID.value);
public static FieldTypeBean CREATE_TIME = instance.addEnum(8, "创建时间", DataType.DATETIME.value);
public static FieldTypeBean UPDATE_USER = instance.addEnum(9, "更新人", DataType.ID.value);


+ 10
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelTable.java ファイルの表示

@@ -231,6 +231,16 @@ public class ModelTable extends DefaultEntity {
return null;
}

public String findFieldNameByType(int type) {
for (ModelField value : fields) {
if (type == value.getFieldType()) {
return value.getName();
}
}

return null;
}

public ModelField findIdField() {
ModelIndex index = findPrimaryIndex();
if (index != null) {


+ 10
- 5
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java ファイルの表示

@@ -31,6 +31,7 @@ public class TreeHelper<T extends DefaultEntity> {
private EntityDao<T> dao;

private String fieldParent;
private String fieldLevel;
private String fieldLevelCode;


@@ -58,16 +59,19 @@ public class TreeHelper<T extends DefaultEntity> {
cache = CacheManager.getIntance().getCache(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) {
return bean.getLong(fieldParent);
}

public long getLevel(T bean) {
return bean.getLong(fieldLevel);
}

public String getLevelCode(T bean) {
return bean.getStr(fieldLevelCode);
}
@@ -119,7 +123,8 @@ public class TreeHelper<T extends DefaultEntity> {
T parent = cache.get(getParentId(bean));
if (parent != null) {
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);
}
Collection<T> children = getChildren(bean);


読み込み中…
キャンセル
保存