Browse Source

页面设计增加:模块,相关子页面维护

master
郑根木 2 years ago
parent
commit
6d6fa6f7ab
6 changed files with 146 additions and 24 deletions
  1. +60
    -22
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java
  2. +8
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java
  3. +7
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormCache.java
  4. +59
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java
  5. +11
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  6. +1
    -1
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java

+ 60
- 22
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java View File

@@ -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);
}
}
}
}
}

+ 8
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java View File

@@ -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);
}
}

+ 7
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormCache.java View File

@@ -22,6 +22,7 @@ public class ModelFormCache extends AbstractEntityCache<ModelForm> {
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<ModelForm> {
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<ModelForm> {
return getListByKey(mt, tableId + SwConsts.SPLIT_CHAR + type);
}

//根据模块id,找对应的页面设计
public Set<ModelForm> 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);


+ 59
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java View File

@@ -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<ModelForm> {
//自动生成的模块子页面,暂存,便于维护缓存
private List<ModelForm> listFormChild;

public ModelFormSaveHandler() {
super(ModelForm.ENTITY_NAME);
}
@@ -30,11 +37,62 @@ public class ModelFormSaveHandler extends DefaultSaveHandler<ModelForm> {
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<String> incPage = (List<String>) opts.get("incPage");
if (incPage == null || incPage.isEmpty()) return;
listFormChild = new ArrayList<>();
Set<ModelForm> setExists = ModelFormCache.getInstance().getListByModule(bean.getEntityId());
EntityDao<ModelForm> 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<ModelForm> 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");


+ 11
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java View File

@@ -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", "详情");
}

/**


+ 1
- 1
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java View File

@@ -44,7 +44,7 @@ public abstract class AbstractTreeHandler<T> extends AbstractHandler {
}

//根据bean,构建treenode
private List<SwMap> buildNodes(List<T> rows, boolean lazy) {
protected List<SwMap> buildNodes(List<T> rows, boolean lazy) {
List<SwMap> listRet = new ArrayList<>();
if (rows == null || rows.isEmpty()) {
return listRet;


Loading…
Cancel
Save