@@ -56,15 +56,19 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity> | |||||
@Override | @Override | ||||
protected List<DefaultEntity> filterData() { | protected List<DefaultEntity> filterData() { | ||||
Set<Long> setId = ModelProjectCache.getInstance().getDependsPrjIds(prj_id); | |||||
if (setId.isEmpty()) return new ArrayList<>(); | |||||
String sqlPrjId = CommUtil.getSqlInIds(setId); | |||||
EntityDao<ModelCatalog> dao = DbEngine.getInstance().findDao(ModelCatalog.ENTITY_NAME); | EntityDao<ModelCatalog> dao = DbEngine.getInstance().findDao(ModelCatalog.ENTITY_NAME); | ||||
String text = "%" + params.readString("text") + "%"; | String text = "%" + params.readString("text") + "%"; | ||||
List<ModelCatalog> list = dao.queryWhere(" mc_prj_id=? and (mc_name like ? or mc_code like ?) order by mc_name", prj_id, text, text); | |||||
List<ModelCatalog> list = dao.queryWhere(" mc_prj_id in (" + sqlPrjId + ") and (mc_name like ? or mc_code like ?) order by mc_name", text, text); | |||||
List<DefaultEntity> listRet = new ArrayList<>(list); | List<DefaultEntity> listRet = new ArrayList<>(list); | ||||
switch (type) { | switch (type) { | ||||
case TYPE_TABLE: | case TYPE_TABLE: | ||||
EntityDao<ModelTable> tabledao = DbEngine.getInstance().findDao(ModelTable.class); | EntityDao<ModelTable> tabledao = DbEngine.getInstance().findDao(ModelTable.class); | ||||
List<ModelTable> l = tabledao.queryWhere(" tb_prj_id=? and (tb_name like ? or tb_title like ?) order by tb_name", prj_id, text, text); | |||||
List<ModelTable> l = tabledao.queryWhere(" tb_prj_id in (" + sqlPrjId + ") and (tb_name like ? or tb_title like ?) order by tb_name", text, text); | |||||
listRet.addAll(l); | listRet.addAll(l); | ||||
break; | break; | ||||
case TYPE_PAGE: | case TYPE_PAGE: | ||||
@@ -74,13 +78,13 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity> | |||||
List<ModelForm> lf; | List<ModelForm> lf; | ||||
switch (type) { | switch (type) { | ||||
case TYPE_PAGE: | case TYPE_PAGE: | ||||
lf = formdao.queryWhere(" mf_prj_id=? and mf_type<>? and (mf_name like ? or mf_title like ?) order by tb_name", prj_id, SwEnum.FormType.WIDGET.value, text, text); | |||||
lf = formdao.queryWhere(" mf_prj_id in (" + sqlPrjId + ") and mf_type<>? and (mf_name like ? or mf_title like ?) order by tb_name", SwEnum.FormType.WIDGET.value, text, text); | |||||
break; | break; | ||||
case TYPE_WIDGET: | case TYPE_WIDGET: | ||||
lf = formdao.queryWhere(" mf_prj_id=? and mf_type=? and (mf_name like ? or mf_title like ?) order by tb_name", prj_id, SwEnum.FormType.WIDGET.value, text, text); | |||||
lf = formdao.queryWhere(" mf_prj_id in (" + sqlPrjId + ") and mf_type=? and (mf_name like ? or mf_title like ?) order by tb_name", SwEnum.FormType.WIDGET.value, text, text); | |||||
break; | break; | ||||
default: | default: | ||||
lf = formdao.queryWhere(" mf_prj_id=? and (mf_name like ? or mf_title like ?) order by tb_name", prj_id, text, text); | |||||
lf = formdao.queryWhere(" mf_prj_id in (" + sqlPrjId + ") and (mf_name like ? or mf_title like ?) order by tb_name", text, text); | |||||
} | } | ||||
listRet.addAll(lf); | listRet.addAll(lf); | ||||
} | } | ||||
@@ -4,10 +4,7 @@ import cc.smtweb.framework.core.common.SwConsts; | |||||
import cc.smtweb.framework.core.db.vo.ModelCatalog; | import cc.smtweb.framework.core.db.vo.ModelCatalog; | ||||
import cc.smtweb.framework.core.mvc.service.TreeHelper; | import cc.smtweb.framework.core.mvc.service.TreeHelper; | ||||
import java.util.ArrayList; | |||||
import java.util.Collection; | |||||
import java.util.Comparator; | |||||
import java.util.List; | |||||
import java.util.*; | |||||
/** | /** | ||||
* Created by Akmm at 2022/3/25 10:47 | * Created by Akmm at 2022/3/25 10:47 | ||||
@@ -24,9 +21,16 @@ public class ModelCatalogTreeHelper extends TreeHelper<ModelCatalog> { | |||||
if (id > 0) { | if (id > 0) { | ||||
return getChildren(id, comparator); | return getChildren(id, comparator); | ||||
} | } | ||||
Collection<ModelCatalog> set = cache.getListByKey(CACHE_KEY, prj_id + SwConsts.SPLIT_CHAR + SwConsts.DEF_ROOT_ID); | |||||
Set<Long> setId = ModelProjectCache.getInstance().getDependsPrjIds(prj_id); | |||||
if (setId.isEmpty()) return new ArrayList<>(); | |||||
Set<ModelCatalog> set = new HashSet<>(); | |||||
List<ModelCatalog> list = set == null ? new ArrayList<>() : new ArrayList<>(set); | |||||
for (long prjId: setId) { | |||||
Collection<ModelCatalog> st = cache.getListByKey(CACHE_KEY, prjId + SwConsts.SPLIT_CHAR + SwConsts.DEF_ROOT_ID); | |||||
if (st != null) set.addAll(st); | |||||
} | |||||
List<ModelCatalog> list = new ArrayList<>(set); | |||||
if (comparator != null) | if (comparator != null) | ||||
list.sort(comparator); | list.sort(comparator); | ||||
return list; | return list; | ||||
@@ -6,8 +6,12 @@ import cc.smtweb.framework.core.cache.CacheManager; | |||||
import cc.smtweb.framework.core.db.DbEngine; | import cc.smtweb.framework.core.db.DbEngine; | ||||
import cc.smtweb.framework.core.db.EntityDao; | import cc.smtweb.framework.core.db.EntityDao; | ||||
import cc.smtweb.framework.core.db.vo.ModelProject; | import cc.smtweb.framework.core.db.vo.ModelProject; | ||||
import cc.smtweb.framework.core.util.NumberUtil; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import java.util.HashSet; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Set; | |||||
/** | /** | ||||
* Created by Akmm at 2022/1/12 18:34 | * Created by Akmm at 2022/1/12 18:34 | ||||
@@ -45,4 +49,26 @@ public class ModelProjectCache extends AbstractCache<ModelProject> { | |||||
ModelProject bean = getByModule(module); | ModelProject bean = getByModule(module); | ||||
return bean !=null ? String.valueOf(bean.getId()): ""; | return bean !=null ? String.valueOf(bean.getId()): ""; | ||||
} | } | ||||
//找当前项目及其依赖项目的id集合,递归 | |||||
public Set<Long> getDependsPrjIds(long id) { | |||||
Set<Long> set = new HashSet<>(); | |||||
addPrjId(set, id); | |||||
return set; | |||||
} | |||||
//递归增加 | |||||
private void addPrjId(Set<Long> set, long id) { | |||||
if (set.contains(id)) return; | |||||
ModelProject bean = get(id); | |||||
if (bean == null) return; | |||||
set.add(id); | |||||
if (StringUtils.isEmpty(bean.getDepends())) return; | |||||
String[] dps = bean.getDepends().split(","); | |||||
for (String s: dps) { | |||||
s = s.trim(); | |||||
if (StringUtils.isEmpty(s)) return; | |||||
addPrjId(set, NumberUtil.getLongIgnoreErr(s)); | |||||
} | |||||
} | |||||
} | } |
@@ -2,8 +2,10 @@ package cc.smtweb.system.bpm.web.design.db; | |||||
import cc.smtweb.framework.core.db.vo.ModelTable; | import cc.smtweb.framework.core.db.vo.ModelTable; | ||||
import cc.smtweb.framework.core.mvc.service.DefaultComboHandler; | import cc.smtweb.framework.core.mvc.service.DefaultComboHandler; | ||||
import cc.smtweb.framework.core.util.CommUtil; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Set; | |||||
/** | /** | ||||
* Created by Akmm at 2022/3/22 19:25 | * Created by Akmm at 2022/3/22 19:25 | ||||
@@ -18,8 +20,10 @@ public class ModelTableComboHandler extends DefaultComboHandler<ModelTable> { | |||||
super.buildCondition(sql, args); | super.buildCondition(sql, args); | ||||
long prj_id = params.readLong("prj_id"); | long prj_id = params.readLong("prj_id"); | ||||
if (prj_id > 0) { | if (prj_id > 0) { | ||||
sql.append(" and tb_prj_id=?"); | |||||
args.add(prj_id); | |||||
Set<Long> setId = ModelProjectCache.getInstance().getDependsPrjIds(prj_id); | |||||
if (!setId.isEmpty()) { | |||||
sql.append(" and tb_prj_id in (").append(CommUtil.getSqlInIds(setId)).append(")"); | |||||
} | |||||
} | } | ||||
long db_id = params.readLong("db_id"); | long db_id = params.readLong("db_id"); | ||||