diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java index 6ec3335..144316d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java @@ -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 private ModelCatalogTreeHelper mcTreeHelper = null; + //模块子页面,暂存 + private Map> mapFormChild = new HashMap<>(); + @Override public void init(SwMap params, UserSession us) { super.init(params, us); @@ -54,7 +56,6 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler @Override protected List filterData() { - EntityDao dao = DbEngine.getInstance().findDao(ModelCatalog.ENTITY_NAME); String text = "%" + params.readString("text") + "%"; List 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 case TYPE_FORM: EntityDao formdao = DbEngine.getInstance().findDao(ModelForm.class); List 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 listRet, List lf){ + for (ModelForm mf: lf) { + if (mf.getParent() > 0) { + List ch = mapFormChild.computeIfAbsent(mf.getParent(), k -> new ArrayList<>()); + ch.add(mf); + } else { + listRet.add(mf); + } + } + } + @Override protected List getChildren(long id) { List list = mcTreeHelper.getChildren(id, prj_id, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName())); @@ -106,13 +126,14 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler /** * 去掉没有叶子的空目录 + * * @param list * @return */ private List cleanEmpty(List list) { if (list.isEmpty()) return new ArrayList<>(list); List 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 if (!listRet.isEmpty()) return true; List 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 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 } if (bean instanceof ModelForm) { - return ((ModelForm)bean).getTitle(); + return ((ModelForm) bean).getTitle(); } return null; } @@ -194,7 +223,16 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler } 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 lf = mapFormChild.get(form.getEntityId()); + if (lf != null && !lf.isEmpty()) { + List list = buildNodes(lf, true); + node.put("children", list); + } + } } } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java index 8c6f51d..ff126bd 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java @@ -207,4 +207,12 @@ public class ModelForm extends DefaultEntity { public void setRemark(String mfRemark) { put("mf_remark", mfRemark); } + + public long getParent() { + return getLong("mf_parent"); + } + + public void setParent(long mf_parent) { + put("mf_parent", mf_parent); + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormCache.java index 77c01fd..d01b054 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormCache.java @@ -22,6 +22,7 @@ public class ModelFormCache extends AbstractEntityCache { private final static String mp = "prj"; private final static String mc = "c"; private final static String mt = "t"; + private final static String ms = "s"; public static ModelFormCache getInstance() { return CacheManager.getIntance().getCache(ModelFormCache.class); @@ -31,6 +32,7 @@ public class ModelFormCache extends AbstractEntityCache { regMap(mk, k-> k.getName().toUpperCase()); regList(mp, k-> String.valueOf(k.getPrjId())); regList(mc, k-> String.valueOf(k.getMcId())); + regList(ms, k-> String.valueOf(k.getParent())); regList(mt, k-> k.getMasterTableId() + SwConsts.SPLIT_CHAR + k.getType()); // regList(mf, k-> k.get); } @@ -79,6 +81,11 @@ public class ModelFormCache extends AbstractEntityCache { return getListByKey(mt, tableId + SwConsts.SPLIT_CHAR + type); } + //根据模块id,找对应的页面设计 + public Set getListByModule(long parent) { + return getListByKey(mt, String.valueOf(parent)); + } + public String getText(long id) { ModelForm form = get(id); return form != null ? form.getTitle() : String.valueOf(id); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java index 6ccfab9..f0da389 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java @@ -15,11 +15,18 @@ import cc.smtweb.framework.core.mvc.service.DefaultSaveHandler; import cc.smtweb.framework.core.util.JsonUtil; import org.apache.commons.lang3.StringUtils; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + /** * Created by Akmm at 2022/5/9 17:05 * 页面定义保存,注意不要覆盖content和dataset */ public class ModelFormSaveHandler extends DefaultSaveHandler { + //自动生成的模块子页面,暂存,便于维护缓存 + private List listFormChild; + public ModelFormSaveHandler() { super(ModelForm.ENTITY_NAME); } @@ -30,11 +37,62 @@ public class ModelFormSaveHandler extends DefaultSaveHandler { if (opts != null) { opts.remove(ModelFormHelper.KEY_EVENT_PATH); bean.setOption(JsonUtil.encodeString(opts)); + if (bean.getType() == SwEnum.FormType.MODULE.value) { + addChildPage(opts); + } } - dao.updateEntityEx(bean, "mf_content", "mf_dataset", "mf_tmpl"); } + //自动增加子页面 + private void addChildPage(SwMap opts) { + List incPage = (List) opts.get("incPage"); + if (incPage == null || incPage.isEmpty()) return; + listFormChild = new ArrayList<>(); + Set setExists = ModelFormCache.getInstance().getListByModule(bean.getEntityId()); + EntityDao dao = DbEngine.getInstance().findDao(ModelForm.class); + for (String type: incPage) { + String name = bean.getName() + "_" + type; + if (existsPage(setExists, name)) continue; + ModelForm page = new ModelForm(); + page.getData().putAll(bean.getData()); + page.setId(DbEngine.getInstance().nextId()); + page.setOption("{}"); + page.setName(name); + page.setTitle(bean.getTitle() + "_" + SwEnum.PageType.instance.getName(type)); + listFormChild.add(page); + dao.updateEntityEx(page, "mf_content", "mf_dataset", "mf_tmpl"); + } + } + + @Override + protected void saveSuccess() { + ModelFormCache.getInstance().put(bean); + if (listFormChild == null) { + for (ModelForm page: listFormChild) { + ModelFormCache.getInstance().put(page); + } + } + } + + @Override + protected void saveFailed() { + ModelFormCache.getInstance().reset(bean); + if (listFormChild == null) { + for (ModelForm page: listFormChild) { + ModelFormCache.getInstance().reset(page); + } + } + } + + //已经存在的,不管了 + private boolean existsPage(Set setExists, String name) { + for (ModelForm form: setExists) { + if (name.equalsIgnoreCase(form.getName())) return true; + } + return false; + } + public R saveDataset() { long id = params.readLong("id"); String data = params.readString("data"); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java index 505c53a..2811750 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java @@ -212,6 +212,17 @@ public interface SwEnum { public static IntEnumBean PAGE = instance.addEnum(0, "页面"); public static IntEnumBean WIDGET = instance.addEnum(1, "控件"); + public static IntEnumBean MODULE = instance.addEnum(2, "模块"); + } + + /** + * 子页面类型:::列表/编辑/详情 + */ + class PageType extends StrEnum { + public static PageType instance = new PageType(); + public static StrEnumBean PAGE = instance.addEnum("list", "列表"); + public static StrEnumBean WIDGET = instance.addEnum("card", "编辑"); + public static StrEnumBean MODULE = instance.addEnum("view", "详情"); } /** diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java index 4828d8f..4d42543 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java @@ -44,7 +44,7 @@ public abstract class AbstractTreeHandler extends AbstractHandler { } //根据bean,构建treenode - private List buildNodes(List rows, boolean lazy) { + protected List buildNodes(List rows, boolean lazy) { List listRet = new ArrayList<>(); if (rows == null || rows.isEmpty()) { return listRet;