郑根木 2 лет назад
Родитель
Сommit
132aa2d869
6 измененных файлов: 66 добавлений и 20 удалений
  1. +2
    -1
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java
  2. +23
    -8
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java
  3. +2
    -2
      smtweb-framework/sw-framework-core/src/main/resources/config/demo.json
  4. +2
    -2
      smtweb-framework/sw-framework-core/target/classes/config/demo.json
  5. +3
    -7
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelCatalogTreeHandler.java
  6. +34
    -0
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelCatalogTreeHelper.java

+ 2
- 1
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java Просмотреть файл

@@ -10,5 +10,6 @@ public interface SwConsts {
String KEY_PARENT_ID = "pr";
//级次码、字符串连接符
String SPLIT_CHAR = "-";

//默认根节点
String DEF_ROOT_ID = "-1";
}

+ 23
- 8
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java Просмотреть файл

@@ -12,31 +12,46 @@ import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.db.vo.ModelField;
import cc.smtweb.framework.core.db.vo.ModelTable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
* Created by Akmm at 2022/3/17 19:56
*/
public class TreeHelper<T extends DefaultEntity> {
private static Map<String, TreeHelper> mapInstance;
static {
mapInstance = new ConcurrentHashMap<>();
}
private String tableName;

private ModelTable table;
private AbstractCache<T> cache;
protected AbstractCache<T> cache;
private EntityDao<T> dao;

private String fieldParent;
private String fieldLevelCode;

//todo 待扩展,进缓存
public static TreeHelper getTreeHelper(String tableName) {
return new TreeHelper(tableName);
return mapInstance.computeIfAbsent(tableName, k-> new TreeHelper(tableName));
}

public static TreeHelper getTreeHelper(String tableName, Class<? extends TreeHelper> clazz) {
TreeHelper helper = mapInstance.get(tableName);
if (helper == null) {
try {
helper = clazz.newInstance();
mapInstance.put(tableName, helper);
} catch (Exception e) {
throw new SwException(e);
}
}
return helper;
}

//先禁止外部创建
private TreeHelper(String tableName) {
protected TreeHelper(String tableName) {
this.tableName = tableName;
table = ModelTableCache.getInstance().getByName(tableName);
cache = CacheManager.getIntance().getCache(tableName);


+ 2
- 2
smtweb-framework/sw-framework-core/src/main/resources/config/demo.json Просмотреть файл

@@ -103,8 +103,8 @@
},
{
"name": "prj",
"title": "按目",
"fields": "mc_prj_id",
"title": "按目",
"fields": "mc_prj_id,mc_parent_id",
"type": "L"
}
]

+ 2
- 2
smtweb-framework/sw-framework-core/target/classes/config/demo.json Просмотреть файл

@@ -103,8 +103,8 @@
},
{
"name": "prj",
"title": "按目",
"fields": "mc_prj_id",
"title": "按目",
"fields": "mc_prj_id,mc_parent_id",
"type": "L"
}
]

+ 3
- 7
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelCatalogTreeHandler.java Просмотреть файл

@@ -26,14 +26,14 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<Object> {
private long prj_id;//所属项目
private int type;//查询类型:0-目录;1-表定义;2-页面定义

private TreeHelper<ModelCatalog> mcTreeHelper = null;
private ModelCatalogTreeHelper mcTreeHelper = null;

@Override
public void init(SwMap params, UserSession us) {
super.init(params, us);
type = params.readInt("type");
prj_id = params.readLong("prj_id");
mcTreeHelper = (TreeHelper<ModelCatalog>) TreeHelper.getTreeHelper(ModelCatalog.ENTITY_NAME);
mcTreeHelper = (ModelCatalogTreeHelper) TreeHelper.getTreeHelper(ModelCatalog.ENTITY_NAME, ModelCatalogTreeHelper.class);
}

@Override
@@ -69,11 +69,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<Object> {
protected List<Object> getChildren(long id) {
List<Object> listRet = new ArrayList<>();
List<ModelCatalog> list;
if (id > 0) {
list = mcTreeHelper.getChildren(id, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName()));
} else {
list = mcTreeHelper.getChildren(-1, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName()));
}
list = mcTreeHelper.getChildren(id, prj_id, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName()));

listRet.addAll(list);



+ 34
- 0
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/table/ModelCatalogTreeHelper.java Просмотреть файл

@@ -0,0 +1,34 @@
package cc.smtweb.system.bpm.web.design.table;

import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.db.vo.ModelCatalog;
import cc.smtweb.framework.core.mvc.service.TreeHelper;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;

/**
* Created by Akmm at 2022/3/25 10:47
*/
public class ModelCatalogTreeHelper extends TreeHelper<ModelCatalog> {
//按项目的缓存key,确保此表缓存配置:prj:prjid_parentid
private final static String CACHE_KEY = "prj";

public ModelCatalogTreeHelper() {
super(ModelCatalog.ENTITY_NAME);
}

public List<ModelCatalog> getChildren(long id, long prj_id, Comparator<ModelCatalog> comparator) {
if (id > 0) {
return getChildren(id, comparator);
}
Collection<ModelCatalog> set = cache.getListByKey(CACHE_KEY, prj_id + SwConsts.SPLIT_CHAR + SwConsts.DEF_ROOT_ID);

List<ModelCatalog> list = set == null ? new ArrayList<>() : new ArrayList<>(set);
if (comparator != null)
list.sort(comparator);
return list;
}
}

Загрузка…
Отмена
Сохранить