@@ -5,8 +5,11 @@ import cc.smtweb.framework.core.cache.CacheManager; | |||||
import cc.smtweb.framework.core.common.SwConsts; | import cc.smtweb.framework.core.common.SwConsts; | ||||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | import cc.smtweb.framework.core.db.cache.ModelTableCache; | ||||
import cc.smtweb.framework.core.db.impl.DatabaseUtil; | import cc.smtweb.framework.core.db.impl.DatabaseUtil; | ||||
import cc.smtweb.framework.core.db.vo.ModelCatalog; | |||||
import cc.smtweb.framework.core.mvc.service.TreeHelper; | |||||
import cc.smtweb.framework.core.systask.TaskStartEvent; | import cc.smtweb.framework.core.systask.TaskStartEvent; | ||||
import cc.smtweb.framework.core.systask.WebStartedEvent; | import cc.smtweb.framework.core.systask.WebStartedEvent; | ||||
import cc.smtweb.system.bpm.web.design.db.ModelCatalogTreeHelper; | |||||
import org.springframework.boot.context.event.ApplicationStartedEvent; | import org.springframework.boot.context.event.ApplicationStartedEvent; | ||||
import org.springframework.context.ApplicationListener; | import org.springframework.context.ApplicationListener; | ||||
import org.springframework.context.event.EventListener; | import org.springframework.context.event.EventListener; | ||||
@@ -26,5 +29,7 @@ public class BpmStartedListener implements ApplicationListener<ApplicationStarte | |||||
new DatabaseUtil(true, false).checkDb(); | new DatabaseUtil(true, false).checkDb(); | ||||
//初始化缓存 | //初始化缓存 | ||||
CacheManager.getIntance().init(); | CacheManager.getIntance().init(); | ||||
TreeHelper.regTreeHelper(ModelCatalog.ENTITY_NAME, ModelCatalogTreeHelper.class); | |||||
} | } | ||||
} | } |
@@ -48,7 +48,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity> | |||||
prj_id = params.readLong("prj_id"); | prj_id = params.readLong("prj_id"); | ||||
exc_empty = params.readBool("exc_empty"); | exc_empty = params.readBool("exc_empty"); | ||||
exc_depend = params.readBool("exc_depend"); | exc_depend = params.readBool("exc_depend"); | ||||
mcTreeHelper = (ModelCatalogTreeHelper) TreeHelper.getTreeHelper(ModelCatalog.ENTITY_NAME, ModelCatalogTreeHelper.class); | |||||
mcTreeHelper = (ModelCatalogTreeHelper) TreeHelper.getTreeHelper(ModelCatalog.ENTITY_NAME); | |||||
} | } | ||||
@Override | @Override | ||||
@@ -18,7 +18,7 @@ public class ModelCatalogTreeHelper extends TreeHelper<ModelCatalog> { | |||||
} | } | ||||
public List<ModelCatalog> getChildren(long id, long prj_id,boolean exc_depend, Comparator<ModelCatalog> comparator) { | public List<ModelCatalog> getChildren(long id, long prj_id,boolean exc_depend, Comparator<ModelCatalog> comparator) { | ||||
if (id > 0) { | |||||
if (id > 0L) { | |||||
return getChildren(id, comparator); | return getChildren(id, comparator); | ||||
} | } | ||||
Set<Long> setId = exc_depend ? new HashSet<>(Arrays.asList(prj_id)) : ModelProjectCache.getInstance().getDependsPrjIds(prj_id); | Set<Long> setId = exc_depend ? new HashSet<>(Arrays.asList(prj_id)) : ModelProjectCache.getInstance().getDependsPrjIds(prj_id); | ||||
@@ -20,8 +20,10 @@ import java.util.concurrent.ConcurrentHashMap; | |||||
* Created by Akmm at 2022/3/17 19:56 | * Created by Akmm at 2022/3/17 19:56 | ||||
*/ | */ | ||||
public class TreeHelper<T extends DefaultEntity> { | public class TreeHelper<T extends DefaultEntity> { | ||||
private static Map<String, Class<? extends TreeHelper>> mapDef; | |||||
private static Map<String, TreeHelper> mapInstance; | private static Map<String, TreeHelper> mapInstance; | ||||
static { | static { | ||||
mapDef = new HashMap<>(); | |||||
mapInstance = new ConcurrentHashMap<>(); | mapInstance = new ConcurrentHashMap<>(); | ||||
} | } | ||||
private String tableName; | private String tableName; | ||||
@@ -36,20 +38,24 @@ public class TreeHelper<T extends DefaultEntity> { | |||||
public static TreeHelper getTreeHelper(String tableName) { | public static TreeHelper getTreeHelper(String 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) { | |||||
TreeHelper bean = mapInstance.get(tableName); | |||||
if (bean != null) return bean; | |||||
Class<? extends TreeHelper> clazz = mapDef.get(tableName); | |||||
if (clazz == null) { | |||||
bean = new TreeHelper(tableName); | |||||
} else { | |||||
try { | try { | ||||
helper = clazz.newInstance(); | |||||
mapInstance.put(tableName, helper); | |||||
bean = clazz.newInstance(); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
throw new SwException(e); | throw new SwException(e); | ||||
} | } | ||||
} | } | ||||
return helper; | |||||
mapInstance.put(tableName, bean); | |||||
return bean; | |||||
} | |||||
public static void regTreeHelper(String tableName, Class<? extends TreeHelper> clazz) { | |||||
mapDef.put(tableName, clazz); | |||||
} | } | ||||
//先禁止外部创建 | //先禁止外部创建 | ||||