From 705a80692acfba7280becafbc7efc744600463d0 Mon Sep 17 00:00:00 2001 From: zhenggm Date: Mon, 15 Aug 2022 15:38:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9ALC=5FSINGLE=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/bpm/web/design/form/ModelFormCache.java | 2 +- .../bpm/web/design/form/ModelFormDelHandler.java | 54 ++++++++++ .../bpm/web/design/form/ModelFormSaveHandler.java | 15 ++- .../bpm/web/design/form/ModelFormService.java | 2 +- .../bpm/web/design/form/model/BaseModelWorker.java | 13 +++ .../bpm/web/design/form/model/LcSinlgeWorker.java | 6 +- .../bpm/web/design/form/model/ModelFactory.java | 5 + .../bpm/web/engine/dynPage/DynPageSaveHandler.java | 1 + .../cc/smtweb/framework/core/db/EntityDao.java | 2 +- .../core/mvc/service/DefaultDelHandler.java | 1 - .../core/mvc/service/DefaultSaveHandler.java | 1 + smtweb-framework/core/src/main/resources/demo.json | 119 ++------------------- 12 files changed, 101 insertions(+), 120 deletions(-) create mode 100644 smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormDelHandler.java 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 fa8d67b..0e2ccae 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 @@ -84,7 +84,7 @@ public class ModelFormCache extends AbstractEntityCache { //根据模块id,找对应的页面设计 public Set getListByModule(long parent) { - return getListByKey(mt, String.valueOf(parent)); + return getListByKey(ms, String.valueOf(parent)); } public String getText(long id) { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormDelHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormDelHandler.java new file mode 100644 index 0000000..dc22549 --- /dev/null +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormDelHandler.java @@ -0,0 +1,54 @@ +package cc.smtweb.system.bpm.web.design.form; + +import cc.smtweb.framework.core.db.DbEngine; +import cc.smtweb.framework.core.db.EntityDao; +import cc.smtweb.framework.core.mvc.service.DefaultDelHandler; +import cc.smtweb.framework.core.util.CommUtil; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Created by Akmm at 2022-08-15 15:00 + */ +public class ModelFormDelHandler extends DefaultDelHandler { + //被删除的id + private Set listDeled = new HashSet<>(); + public ModelFormDelHandler() { + super(ModelForm.ENTITY_NAME); + } + + @Override + protected void checkValid() { +// super.checkValid(); + } + + @Override + protected void delDb() { + EntityDao dao = DbEngine.getInstance().findDao(ModelForm.class); + listDeled = ModelFormCache.getInstance().getListByModule(id); + if (CommUtil.isEmpty(listDeled)) { + dao.deleteEntity(id); + } else { + List ids = new ArrayList<>(); + ids.add(id); + for (ModelForm form: listDeled) { + ids.add(form.getId()); + } + dao.deleteEntity(ids); + } + } + + @Override + protected void saveSuccess() { + ModelFormCache cache = ModelFormCache.getInstance(); + if (!CommUtil.isEmpty(listDeled)) { + for (ModelForm form: listDeled) { + cache.remove(form.getId()); + } + } + cache.remove(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 a910ef4..0dc8881 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 @@ -41,11 +41,16 @@ public class ModelFormSaveHandler extends DefaultSaveHandler { @Override protected void insertBean(EntityDao dao) { - super.insertBean(dao); listFormChild = new ArrayList<>(); ModelFactory.getInstance().saveForm(bean, listFormChild); + super.insertBean(dao); } + @Override + protected void checkValid() { + super.checkValid(); + DbEngine.getInstance().findDao(ModelForm.class).checkUnique(bean, "mf_prj_id", "mf_name"); + } @Override protected void saveSuccess() { @@ -132,15 +137,15 @@ public class ModelFormSaveHandler extends DefaultSaveHandler { } public R saveModelByTmpl() { - long id = params.readLong("pageId"); - String templateId = params.readString("templateId"); + String id = params.readString("pageId"); String data = params.readString("data"); - bean = loadComp(id); + bean = ModelFormHelper.getFromCache(id); if (StringUtils.isEmpty(data)) { throw new BizException("没有待保存的数据!"); } bean.setTmpl(data); - ModelFormHelper.buildSaveModelByTmpl(bean, templateId); + ModelFactory.getInstance().buildSaveModel(bean); +// ModelFormHelper.buildSaveModelByTmpl(bean, templateId); DbEngine.getInstance().doTrans(new AbsDbWorker() { @Override public void work() { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java index 1bc25e0..f3d986f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java @@ -36,7 +36,7 @@ public class ModelFormService extends AbstractCompService { case TYPE_SAVE: return new ModelFormSaveHandler(); case TYPE_DEL: - return new DefaultDelHandler(ModelForm.ENTITY_NAME); + return new ModelFormDelHandler(); case TYPE_LIST: return new DefaultListHandler(ModelForm.ENTITY_NAME); case TYPE_CODE: diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/BaseModelWorker.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/BaseModelWorker.java index 5b52ed8..91185fa 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/BaseModelWorker.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/BaseModelWorker.java @@ -18,6 +18,11 @@ import java.util.Set; * 抽象类的页面保存,供各模板继承使用 */ public class BaseModelWorker { + /** + * 模块/页面保存:opts根据模型做些个性化处理,如果是模块,需要添加子页面 + * @param bean + * @param listFormChild + */ public void saveForm(ModelForm bean, List listFormChild) { SwMap opts = bean.getOpts(); if (opts != null) { @@ -62,4 +67,12 @@ public class BaseModelWorker { return page; } + + /** + * 根据模型生成页面 + * @param bean + */ + public void buildSaveModel(ModelForm bean) { + + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcSinlgeWorker.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcSinlgeWorker.java index 1dc096b..af1c310 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcSinlgeWorker.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcSinlgeWorker.java @@ -5,6 +5,7 @@ import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.db.EntityDao; import cc.smtweb.framework.core.util.CommUtil; +import cc.smtweb.framework.core.util.JsonUtil; import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.web.design.form.ModelForm; import cc.smtweb.system.bpm.web.design.form.ModelFormCache; @@ -27,8 +28,9 @@ public class LcSinlgeWorker extends BaseModelWorker { SwMap cfgPage = new SwMap(); cfg.put(ModelFormHelper.OPT_PAGE, cfgPage); String formName = ModelFormHelper.getPageName(bean) + StringUtil.upFirst(SwEnum.PageType.LIST.value); - cfg.put(SwEnum.PageType.LIST.value, formName); - + cfgPage.put(SwEnum.PageType.LIST.value, formName); + bean.setOption(JsonUtil.encodeString(opts)); + ModelForm page; if (bean.isNew()) {//新增 page = createPage(bean, SwEnum.PageType.LIST.value); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/ModelFactory.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/ModelFactory.java index dec4924..34af617 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/ModelFactory.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/ModelFactory.java @@ -41,4 +41,9 @@ public class ModelFactory { BaseModelWorker worker = getWorker(bean); worker.saveForm(bean, listFormChild); } + + public void buildSaveModel(ModelForm bean) { + BaseModelWorker worker = getWorker(bean); + worker.buildSaveModel(bean); + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageSaveHandler.java index d067b81..7fe630e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageSaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageSaveHandler.java @@ -165,6 +165,7 @@ public class DynPageSaveHandler extends AbstractDynPageHandler { } //暂时不考虑list保存的情况 bean.getData().putAll(data); + bean.setIsNew(false); } return bean; diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java index 59381ff..bf31805 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java @@ -363,7 +363,7 @@ public class EntityDao extends AbstractEntityDao { args.add(readValue(bean, f)); sTitle += "+" + modelTable.findFieldTitle(f); } - if (jdbcEngine.isExists("select 1 from " + modelTable.getSchemaTableName() + " where " + modelTable.getIdField() + "=? " + ss, args.toArray())) + if (jdbcEngine.isExists("select 1 from " + modelTable.getSchemaTableName() + " where " + modelTable.getIdField() + " <> ? " + ss, args.toArray())) throw new BizException(sTitle.substring(1) + " 不能重复!"); } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultDelHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultDelHandler.java index de73fc3..7a45f0b 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultDelHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultDelHandler.java @@ -24,7 +24,6 @@ public class DefaultDelHandler extends AbstractDelHandl protected void checkValid() { EntityHelper.checkExists(tableName, id); // ModelTable table = ModelTableCache.getInstance().getByName(tableName); - //todo 检查外键引用的使用情况 } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java index 64ed02e..59b8ef3 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java @@ -62,6 +62,7 @@ public class DefaultSaveHandler extends AbstractSaveHan @Override protected void readFromPage() { bean.readFromMap(params); + bean.setIsNew(isNew); } @Override diff --git a/smtweb-framework/core/src/main/resources/demo.json b/smtweb-framework/core/src/main/resources/demo.json index 8234153..d16ce42 100644 --- a/smtweb-framework/core/src/main/resources/demo.json +++ b/smtweb-framework/core/src/main/resources/demo.json @@ -1,112 +1,13 @@ { - "fields": [ - { - "locked": 1, - "name": "bp_id", - "title": "主键", - "fieldType": 1, - "dataType": "id", - "null": 1, - "default": -1 - }, - { - "name": "bp_number", - "editor": "num", - "title": "第几届", - "remark": "第几届", - "dataType": "int", - "default": "", - "null": 1 - }, - { - "name": "bp_name", - "editor": "input", - "title": "届别名称", - "dataType": "name", - "default": "", - "remark": "根据第几届自动生成", - "null": 1 - }, - { - "name": "bp_start_time", - "editor": "datetime", - "title": "届别开始时间", - "dataType": "datetime", - "default": "0", - "remark": "届别开始时间", - "null": 1 - }, - { - "name": "bp_end_time", - "editor": "datetime", - "title": "届别结束时间", - "dataType": "datetime", - "default": "0", - "remark": "届别结束时间", - "null": 1 - }, - { - "name": "bp_create_uid", - "editor": "input", - "title": "创建人", - "fieldType": 7, - "dataType": "id", - "default": "", - "remark": "创建人", - "null": 1 - }, - { - "name": "bp_create_time", - "editor": "datetime", - "title": "创建时间", - "fieldType": 8, - "dataType": "datetime", - "default": "", - "remark": "创建时间", - "null": 1 - }, - { - "name": "bp_update_uid", - "editor": "input", - "title": "更新人", - "fieldType": 9, - "dataType": "id", - "default": "", - "remark": "更新人", - "null": 1 - }, - { - "name": "bp_update_time", - "editor": "datetime", - "title": "更新时间", - "fieldType": 10, - "dataType": "datetime", - "default": "", - "remark": "更新时间", - "null": 1 - }, - { - "name": "bp_state", - "editor": "combo", - "title": "状态", - "dataType": "bool", - "default": "0", - "remark": "1启用0无效", - "null": 1 - } - ], - "indexes": [ - { - "locked": 1, - "fields": "bp_id", - "type": "P" - } - ], - "caches": [ - { - "name": "n", - "fields": "bp_name", - "type": "M" + "config": { + "model": "LC_SINGLE", + "props": { + "masterTable": "2", + "masterTable_text": "目录定义" + }, + "page": { + "list": "bpm.sTestMList" } - ] + }, + "pageType": "list" } \ No newline at end of file