@@ -1,5 +1,6 @@
package cc.smtweb.system.bpm.web.design.db;
import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.EntityDao;
@@ -14,9 +15,7 @@ import cc.smtweb.framework.core.util.CommUtil;
import cc.smtweb.system.bpm.web.design.form.ModelForm;
import cc.smtweb.system.bpm.web.design.form.ModelFormCache;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.*;
/**
* Created by Akmm at 2022/3/21 18:22
@@ -35,6 +34,9 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity>
private ModelCatalogTreeHelper mcTreeHelper = null;
//模块子页面,暂存
private Map<Long, List<DefaultEntity>> mapFormChild = new HashMap<>();
@Override
public void init(SwMap params, UserSession us) {
super.init(params, us);
@@ -54,7 +56,6 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity>
@Override
protected List<DefaultEntity> filterData() {
EntityDao<ModelCatalog> dao = DbEngine.getInstance().findDao(ModelCatalog.ENTITY_NAME);
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);
@@ -71,17 +72,36 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity>
case TYPE_FORM:
EntityDao<ModelForm> formdao = DbEngine.getInstance().findDao(ModelForm.class);
List<ModelForm> lf;
if (type != TYPE_FORM) {
lf = formdao.queryWhere(" mf_prj_id=? and (mf_name like ? or mf_title like ?) order by tb_name", prj_id, text, text);
} else {
//数据库type 0-页面 1-控件
lf = formdao.queryWhere(" mf_prj_id=? and mf_type=? and (mf_name like ? or mf_title like ?) order by tb_name", prj_id, type - 2, text, text);
switch (type) {
case TYPE_FORM:
lf = formdao.queryWhere(" mf_prj_id=? and (mf_name like ? or mf_title like ?) order by tb_name", prj_id, text, text);
addForm(listRet, lf);
break;
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);
addForm(listRet, lf);
break;
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);
listRet.addAll(lf);
break;
}
listRet.addAll(lf);
}
return listRet;
}
//添加页面,将模块子页面单独扔map,特殊处理
private void addForm(List<DefaultEntity> listRet, List<ModelForm> lf){
for (ModelForm mf: lf) {
if (mf.getParent() > 0) {
List<DefaultEntity> ch = mapFormChild.computeIfAbsent(mf.getParent(), k -> new ArrayList<>());
ch.add(mf);
} else {
listRet.add(mf);
}
}
}
@Override
protected List<DefaultEntity> getChildren(long id) {
List<ModelCatalog> list = mcTreeHelper.getChildren(id, prj_id, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName()));
@@ -106,13 +126,14 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity>
/**
* 去掉没有叶子的空目录
*
* @param list
* @return
*/
private List<DefaultEntity> cleanEmpty(List<ModelCatalog> list) {
if (list.isEmpty()) return new ArrayList<>(list);
List<DefaultEntity> lret = new ArrayList<>();
for (ModelCatalog mc: list) {
for (ModelCatalog mc : list) {
if (hasChildren(mc)) lret.add(mc);
}
return lret;
@@ -133,7 +154,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity>
if (!listRet.isEmpty()) return true;
List<ModelCatalog> list = mcTreeHelper.getChildren(mc.getId(), prj_id, null);
if (list == null || list.isEmpty()) return false;
for (ModelCatalog c: list) {
for (ModelCatalog c : list) {
if (hasChildren(c)) return true;
}
return false;
@@ -154,15 +175,23 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity>
return CommUtil.chineseCompare(o1.getTitle(), o2.getTitle());
});
if (set == null || set.isEmpty()) return;
if (type != TYPE_FORM) {
int pt = type - 2;
for (ModelForm form: set) {
if (form.getType() == pt) {
listRet.add(form);
switch (type) {
case TYPE_PAGE:
for (ModelForm form : set) {
if (form.getType() != SwEnum.FormType.WIDGET.value) {
listRet.add(form);
}
}
}
} else {
listRet.addAll(set);
break;
case TYPE_WIDGET:
for (ModelForm form : set) {
if (form.getType() == SwEnum.FormType.WIDGET.value) {
listRet.add(form);
}
}
break;
default:
listRet.addAll(set);
}
}
@@ -181,7 +210,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity>
}
if (bean instanceof ModelForm) {
return ((ModelForm)bean).getTitle();
return ((ModelForm) bean).getTitle();
}
return null;
}
@@ -194,7 +223,16 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity>
} else if (bean instanceof ModelTable) {
node.put("type", TYPE_TABLE);
} else if (bean instanceof ModelForm) {
node.put("type", ((ModelForm)bean).getType() + 2);
final ModelForm form = (ModelForm) bean;
node.put("type", form.getType() + 2);
//是模块,需要加子页面
if (form.getType() == SwEnum.FormType.MODULE.value) {
List<DefaultEntity> lf = mapFormChild.get(form.getEntityId());
if (lf != null && !lf.isEmpty()) {
List<SwMap> list = buildNodes(lf, true);
node.put("children", list);
}
}
}
}
}