From b844ce8f6f24d5b27de7313990be3ed9254d7100 Mon Sep 17 00:00:00 2001 From: zhenggm Date: Wed, 8 Jun 2022 20:11:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=94=9F=E6=88=90model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/smtweb/framework/core/common/SwMap.java | 5 + .../cc/smtweb/framework/core/util/MapUtil.java | 6 + .../smtweb/system/bpm/resolver/CodeResolver.java | 145 ------------------ .../cc/smtweb/system/bpm/util/CodeGenerator.java | 170 +++++++++++++++++++++ .../system/bpm/web/design/form/ModelForm.java | 8 + .../bpm/web/design/form/ModelFormHelper.java | 62 ++++++++ .../bpm/web/design/form/ModelFormSaveHandler.java | 36 ++++- .../bpm/web/design/form/ModelFormService.java | 16 ++ .../static/template/incModel/inc_dataset.ftl | 22 +++ .../static/template/incModel/inc_filter.ftl | 74 +++++++++ .../static/template/incModel/inc_form.ftl | 31 ++++ .../static/template/incModel/inc_grid_opt.ftl | 67 ++++++++ .../main/resources/static/template/inc_filter.ftl | 74 --------- .../main/resources/static/template/inc_form.ftl | 74 --------- .../resources/static/template/inc_grid_opt.ftl | 67 -------- .../src/main/resources/static/template/index.yaml | 30 ++-- .../resources/static/template/model_simple.ftl | 44 ++++++ .../src/main/resources/static/template/simple.ftl | 107 ------------- .../cc/smtweb/system/bpm/test/ModelFormTest.java | 38 +++++ 19 files changed, 594 insertions(+), 482 deletions(-) delete mode 100644 smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/resolver/CodeResolver.java create mode 100644 smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java create mode 100644 smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_dataset.ftl create mode 100644 smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_filter.ftl create mode 100644 smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_form.ftl create mode 100644 smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_grid_opt.ftl delete mode 100644 smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_filter.ftl delete mode 100644 smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_form.ftl delete mode 100644 smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_grid_opt.ftl create mode 100644 smtweb-system/sw-system-bpm/src/main/resources/static/template/model_simple.ftl delete mode 100644 smtweb-system/sw-system-bpm/src/main/resources/static/template/simple.ftl diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwMap.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwMap.java index d0ab724..f056ac6 100644 --- a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwMap.java +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwMap.java @@ -3,6 +3,7 @@ package cc.smtweb.framework.core.common; import cc.smtweb.framework.core.util.MapUtil; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; @@ -37,6 +38,10 @@ public class SwMap extends HashMap { throw new SwException("不是合法的Map对象!" + v.getClass().getName()); } + public List> readListMap(String name) { + return MapUtil.readListMap(this, name); + } + public String readString(String name, String defaultValue) { return MapUtil.readString(this, name, defaultValue); } diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java index bcaa5f0..9b38819 100644 --- a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java @@ -212,4 +212,10 @@ public class MapUtil { return null; } + + public static List> readListMap(Map map, String name) { + Object v = map.get(name); + if (v == null) return null; + return (List>)v; + } } diff --git a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/resolver/CodeResolver.java b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/resolver/CodeResolver.java deleted file mode 100644 index 8fce711..0000000 --- a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/resolver/CodeResolver.java +++ /dev/null @@ -1,145 +0,0 @@ -package cc.smtweb.system.bpm.resolver; - -import cc.smtweb.framework.core.common.SwException; -import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.framework.core.db.DbEngine; -import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateMethodModelEx; -import freemarker.template.TemplateModelException; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * - */ -public class CodeResolver { - private static CodeResolver instance = null; - - private Configuration configuration = null; - - private final String encode = org.apache.commons.codec.CharEncoding.UTF_8; - private String templatesDir; - - protected CodeResolver() { - templatesDir = this.getClass().getResource("/static/template").getPath(); - configuration = new Configuration(Configuration.VERSION_2_3_31); - try { - configuration.setDirectoryForTemplateLoading(new File(templatesDir)); - configuration.setClassicCompatible(true); - configuration.setDefaultEncoding(encode); - configuration.setOutputEncoding(encode); - } catch (Exception e) { - e.printStackTrace(); - throw new SwException(e); - } - } - - public void create(Map model, String templateName, Writer writer) { - try { - Template template = configuration.getTemplate(templateName, encode); - template.setOutputEncoding(encode); - template.process(model, writer); - writer.close(); - } catch (Exception e) { - e.printStackTrace(); - throw new SwException(e); - } - } - - public void create(Map model, String templateName, OutputStream out) { - try { - Template template = configuration.getTemplate(templateName, StandardCharsets.UTF_8.toString()); - template.setOutputEncoding(encode); - template.process(model, new OutputStreamWriter(out, encode)); - out.close(); - } catch (Exception e) { - e.printStackTrace(); - throw new SwException(e); - } - } - - /** - * 获取单实例 - * - * @return - */ - public static CodeResolver getInstance() { - if (instance == null) { - synchronized (CodeResolver.class) { - instance = new CodeResolver(); - } - } - return instance; - } - - static class PKGenerator implements TemplateMethodModelEx { - @Override - public Object exec(List list) throws TemplateModelException { - return "asd"; -// return DbEngine.getInstance().nextId(); - } - } - - /* - {param:{pa:"aaa"}, - layout:{ - c1:[{type:"list", dataset:"ds123", fields:[{field:"", dataset:""}], cfilters:[{}]}] - } - */ - public static void main(String[] args) { - StringWriter out = new StringWriter(); - SwMap map = new SwMap(); - SwMap param = new SwMap(); - param.put("pa", "aaaaa"); - map.put("param", param); - - SwMap layout = new SwMap(); - map.put("layout", layout); - List groups = new ArrayList<>(); - layout.put("c1", groups); - - SwMap area = new SwMap(); - groups.add(area); - area.put("type", "list"); - area.put("dataset", "ds123"); - - List fields = new ArrayList<>(); - area.put("fields", fields); - SwMap field = new SwMap(); - field.put("field", "f123"); - field.put("dataset", "ds123"); - field.put("label", "字段123"); - fields.add(field); - - field = new SwMap(); - field.put("field", "f121"); - field.put("label", "字段121"); - field.put("dataset", "ds123"); - fields.add(field); - - field = new SwMap(); - field.put("field", "f122"); - field.put("label", "字段122"); - field.put("dataset", "ds123"); - fields.add(field); - - List filters = new ArrayList<>(); - area.put("cfilters", filters); - field = new SwMap(); - field.put("field", "f122"); - field.put("dataset", "ds123"); - field.put("label", "字段122"); - field.put("maxlength", 20); - filters.add(field); - - map.put("title", "thisIsATest!"); - map.put("newId", new PKGenerator()); - CodeResolver.getInstance().create(map, "simple.ftl", out); - System.out.println(out.getBuffer().toString()); - } -} diff --git a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java new file mode 100644 index 0000000..a419a46 --- /dev/null +++ b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java @@ -0,0 +1,170 @@ +package cc.smtweb.system.bpm.util; + +import cc.smtweb.framework.core.common.SwException; +import cc.smtweb.framework.core.common.SwMap; +import cc.smtweb.framework.core.db.DbEngine; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateMethodModelEx; +import freemarker.template.TemplateModelException; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * Created by Akmm at 2022/6/8 15:36 + * 模板生成代码 + */ +public class CodeGenerator { + private final static String KEY_MODEL = "model"; + private static CodeGenerator instance = null; + + private Configuration configuration = null; + + private final String encode = org.apache.commons.codec.CharEncoding.UTF_8; + //模板文件所在目录 + private String templatesDir; + + //模板信息 + private SwMap mapTemplate; + + protected CodeGenerator() { + templatesDir = this.getClass().getResource("/static/template").getPath(); + mapTemplate = YamlUtil.readValue(this.getClass().getResourceAsStream("/static/template/index.yaml"), SwMap.class); + configuration = new Configuration(Configuration.VERSION_2_3_31); + try { + configuration.setDirectoryForTemplateLoading(new File(templatesDir)); + configuration.setClassicCompatible(true); + configuration.setDefaultEncoding(encode); + configuration.setOutputEncoding(encode); + } catch (Exception e) { + e.printStackTrace(); + throw new SwException(e); + } + } + + //页面设计的模板信息 + public Collection> getModelTemplates() { + return ((Map)mapTemplate.get(KEY_MODEL)).values(); + } + + private void initModel(Map model) { + model.put("newId", new PKGenerator()); + } + + public void generate(Map model, String templateName, Writer writer) { + try { + initModel(model); + Template template = configuration.getTemplate(templateName, encode); + template.setOutputEncoding(encode); + template.process(model, writer); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + throw new SwException(e); + } + } + + public void generate(Map model, String templateName, OutputStream out) { + try { + initModel(model); + Template template = configuration.getTemplate(templateName, StandardCharsets.UTF_8.toString()); + template.setOutputEncoding(encode); + template.process(model, new OutputStreamWriter(out, encode)); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + throw new SwException(e); + } + } + + public String generate(Map model, String templateName) { + StringWriter out = new StringWriter(); + generate(model, templateName + ".ftl", out); + return out.getBuffer().toString(); + } + + /** + * 获取单实例 + * + * @return + */ + public static CodeGenerator getInstance() { + if (instance == null) { + synchronized (CodeGenerator.class) { + instance = new CodeGenerator(); + } + } + return instance; + } + + static class PKGenerator implements TemplateMethodModelEx { + @Override + public Object exec(List list) throws TemplateModelException { + return DbEngine.getInstance().nextId(); +// return DbEngine.getInstance().nextId(); + } + } + + /* + {param:{pa:"aaa"}, + layout:{ + c1:[{type:"list", dataset:"ds123", fields:[{field:"", dataset:""}], cfilters:[{}]}] + } + */ + public static void main(String[] args) { + StringWriter out = new StringWriter(); + SwMap map = new SwMap(); + SwMap param = new SwMap(); + param.put("pa", "aaaaa"); + map.put("param", param); + + SwMap layout = new SwMap(); + map.put("layout", layout); + List groups = new ArrayList<>(); + layout.put("c1", groups); + + SwMap area = new SwMap(); + groups.add(area); + area.put("type", "list"); + area.put("dataset", "ds123"); + + List fields = new ArrayList<>(); + area.put("fields", fields); + SwMap field = new SwMap(); + field.put("field", "f123"); + field.put("dataset", "ds123"); + field.put("label", "字段123"); + fields.add(field); + + field = new SwMap(); + field.put("field", "f121"); + field.put("label", "字段121"); + field.put("dataset", "ds123"); + fields.add(field); + + field = new SwMap(); + field.put("field", "f122"); + field.put("label", "字段122"); + field.put("dataset", "ds123"); + fields.add(field); + + List filters = new ArrayList<>(); + area.put("cfilters", filters); + field = new SwMap(); + field.put("field", "f122"); + field.put("dataset", "ds123"); + field.put("label", "字段122"); + field.put("maxlength", 20); + filters.add(field); + + map.put("title", "thisIsATest!"); + map.put("newId", new PKGenerator()); + CodeGenerator.getInstance().generate(map, "model_simple.ftl", out); + System.out.println(out.getBuffer().toString()); + } +} diff --git a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java index 1dccd2d..000f082 100644 --- a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java +++ b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java @@ -86,6 +86,14 @@ public class ModelForm extends DefaultEntity { put("mf_option", mf_option); } + public String getTmpl() { + return getStr("mf_tmpl"); + } + + public void setTmpl(String mf_tmpl) { + put("mf_tmpl", mf_tmpl); + } + public String getDataset() { return getStr("mf_dataset"); } diff --git a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java index 7d0485a..9538d66 100644 --- a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java +++ b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java @@ -12,6 +12,7 @@ import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.JsonUtil; import cc.smtweb.framework.core.util.MapUtil; +import cc.smtweb.system.bpm.util.CodeGenerator; import cc.smtweb.system.bpm.web.design.db.ModelCatalogCache; import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; import cc.smtweb.system.bpm.web.design.form.define.*; @@ -28,6 +29,12 @@ import java.util.Map; */ public class ModelFormHelper { public static final String KEY_EVENT_PATH = "eventPath"; + //分组类别-list + public static final String PAGE_TYPE_LIST = "list"; + //分组类别-card + public static final String PAGE_TYPE_CARD = "card"; + //分组类别-view + public static final String PAGE_TYPE_VIEW = "view"; /** * 从缓存获取Form对象 * @@ -119,6 +126,60 @@ public class ModelFormHelper { } } + public static void buildSaveModelByTmpl(ModelForm form, String tmplId) { + PageDatasets datasets = parsePageDataset(form.getDataset()); + SwMap tmplModel = JsonUtil.parse(form.getTmpl(), SwMap.class); + tmplModel.put("title", form.getTitle()); + tmplModel.put("datasets", parsePageDataset(form.getDataset())); + SwMap layout = tmplModel.readMap("layout"); + for (String key: layout.keySet()) { + List> groups = layout.readListMap(key); + for (Map group: groups) { + String type = MapUtil.readString(group, "type"); + switch (type) { + case PAGE_TYPE_CARD: + buildTmplFields(MapUtil.readListMap(group, "fields"), datasets, true); + break; + case PAGE_TYPE_LIST: + buildTmplFields(MapUtil.readListMap(group, "fields"), datasets, true); + buildTmplFields(MapUtil.readListMap(group, "cfilters"), datasets, false); + buildTmplFields(MapUtil.readListMap(group, "sfilters"), datasets, false); + break; + } + } + } + + form.setContent(CodeGenerator.getInstance().generate(tmplModel, tmplId)); +// form.setContent(buildSaveModel(form)); + } + + private static void buildTmplFields(List> fields, PageDatasets datasets, boolean isField) { + if (fields == null) return; + PageDataset dataset = null; + for (Map field: fields) { + final String dsId = MapUtil.readString(field, "dataset"); + if (dataset == null || !dataset.id.equals(dsId)) { + dataset = datasets.findById(dsId); + if (dataset == null) throw new SwException("没有找到指定数据集:" + dsId); + } + String fn = MapUtil.readString(field, "field"); + PageDatasetField pdf; + if (!isField) { + pdf = dataset.getFilter(fn); + } else { + pdf = dataset.getField(fn); + if (pdf == null) pdf = dataset.getFilter(fn); + } + if (pdf == null) throw new SwException("model[" + dsId + "]未找到定义的数据集字段(" + fn + "),无法解析!"); + field.put("label", pdf.label); + field.put("required", pdf.isFieldNotNull()); + final SwEnum.DataTypeBean dtb = SwEnum.DataType.instance.getByValue(pdf.dataType); + if (dtb != null && dtb.dataLength > 0) { + field.put("maxlength", dtb.dataLength); + } + } + } + /** * 保存的数据集,删除掉一些不必要的字段信息 * @param jsonStr @@ -356,4 +417,5 @@ public class ModelFormHelper { opts.put(KEY_EVENT_PATH, ep + "." + bean.getName()); } } + } diff --git a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java index 8900b26..195889c 100644 --- a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java +++ b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormSaveHandler.java @@ -31,7 +31,7 @@ public class ModelFormSaveHandler extends DefaultSaveHandler { bean.setOption(JsonUtil.encodeString(opts)); } - dao.updateEntityEx(bean, "mf_content", "mf_dataset"); + dao.updateEntityEx(bean, "mf_content", "mf_dataset", "mf_tmpl"); } public R saveDataset() { @@ -98,4 +98,38 @@ public class ModelFormSaveHandler extends DefaultSaveHandler { }); return R.success(); } + + public R saveModelByTmpl() { + long id = params.readLong("pageId"); + String templateId = params.readString("templateId"); + String data = params.readString("data"); + bean = loadComp(id); + if (StringUtils.isEmpty(data)) { + throw new SwException("没有待保存的数据!"); + } + bean.setTmpl(data); + ModelFormHelper.buildSaveModelByTmpl(bean, templateId); + DbEngine.getInstance().doTrans(new AbsDbWorker() { + @Override + public void work() { + EntityDao dao = DbEngine.getInstance().findDao(tableName); + + ModelTable table = ModelTableCache.getInstance().getByName(tableName); + ModelField field = table.findFieldByType(SwEnum.FieldType.UPDATE_USER.value); + if (field != null) bean.put(field.getName(), us.getUserId()); + dao.updateEntity(bean, "mf_content", "mf_tmpl"); + } + + @Override + public void doAfterDbCommit() { + saveSuccess(); + } + + @Override + public void doAfterDbRollback() { + saveFailed(); + } + }); + return R.success(ModelFormHelper.buildReqModel(bean)); + } } diff --git a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java index 5b2bdb6..0d7b232 100644 --- a/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java +++ b/smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java @@ -12,6 +12,7 @@ import cc.smtweb.framework.core.mvc.service.DefaultDelHandler; import cc.smtweb.framework.core.mvc.service.DefaultListHandler; import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.framework.core.util.SqlUtil; +import cc.smtweb.system.bpm.util.CodeGenerator; import org.apache.commons.lang3.StringUtils; import java.sql.ResultSetMetaData; @@ -69,6 +70,16 @@ public class ModelFormService extends AbstractCompService { } } + //根据模板保存页面定义 + public R saveModelByTmpl(@SwBody SwMap params, UserSession us) { + try { + ModelFormSaveHandler handler = (ModelFormSaveHandler) getHandler(params, us, TYPE_SAVE); + return handler.saveModelByTmpl(); + } catch (Exception e) { + return R.error("操作失败!", e); + } + } + //加载页面模型 public R loadModel(@SwBody SwMap params, UserSession us) { try { @@ -126,4 +137,9 @@ public class ModelFormService extends AbstractCompService { return R.error("操作失败!", e); } } + + //加载模板定义 + public R loadTmpls(@SwBody SwMap params, UserSession us) { + return R.success(CodeGenerator.getInstance().getModelTemplates()); + } } diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_dataset.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_dataset.ftl new file mode 100644 index 0000000..d1e84cc --- /dev/null +++ b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_dataset.ftl @@ -0,0 +1,22 @@ +{ + "dataset": "${dataset.id}", + "label": "${dataset.label}", + "fields": [ + <#list fields as field> + { + "id": "${field.id}", + "field": "${field.field}" + }, + + ], + "filters": [ + <#list filters as field> + { + "id": "${field.id}", + "field": "${field.field}" + "required": ${field.required}, + "type": "input" + }, + + ] + }, \ No newline at end of file diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_filter.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_filter.ftl new file mode 100644 index 0000000..9dda2bb --- /dev/null +++ b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_filter.ftl @@ -0,0 +1,74 @@ +<#assign fields = group.cfilters> + { + "id": "${newId()}", + "type": "fx-form-panel", + "shape": "panel", + "props": { + "paddingY": 5, + "paddingX": 10, + "size": "35", + "colNum": 2 + }, + "children": [ +<#list fields as filter> + { + "id": "id${newId()}", + "type": "fx-text", + "props": { + "label": "${filter.label}", + "type": "text", + "maxlength": ${filter.maxlength}, + "placeholder": "请输入查询内容", + "labelWidth": 100, + "dataset": "${filter.dataset}", + "field": "${filter.field}", + "name": "${filter.name}" + }, + "events": {} + }, + + { + "id": "id${newId()}", + "type": "fx-button-group", + "props": { + "menus": [] + }, + "slots": { + "default": [ + { + "type": "fx-button", + "props": { + "label": "查询", + "leftIcon": "history-query", + "type": "primary", + "action": "button:search", + "dataset": "${group.dataset}" + }, + "id": "id${newId()}" + }, + { + "type": "fx-button", + "props": { + "label": "重置", + "type": "danger", + "action": "button:reset", + "leftIcon": "figma-reset-instance" + }, + "id": "id${newId()}" + }, + { + "id": "id${newId()}", + "type": "fx-button", + "props": { + "label": "新增", + "type": "success", + "leftIcon": "shield-add", + "action": "button:add", + "dataset": "${group.dataset}" + } + } + ] + } + } + ] + }, \ No newline at end of file diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_form.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_form.ftl new file mode 100644 index 0000000..bba01dc --- /dev/null +++ b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_form.ftl @@ -0,0 +1,31 @@ +<#assign fields = group.fields> + { + "shape": "panel", + "id": "form_panel", + "type": "fx-form-panel", + "props": { + "colNum": 2, + "paddingX": 5, + "paddingY": 5, + "size": "0" + }, + "children": [ +<#list fields as field> + { + "id": "id${newId()}", + "type": "fx-text", + "props": { + "label": "${field.label}", + "type": "text", + "maxlength": ${field.maxlength}, + "placeholder": "请输入内容", + "labelWidth": 100, + "dataset": "${field.dataset}", + "field": "${field.field}", + "name": "${field.name}" + }, + "events": {} + }, + + ] + } \ No newline at end of file diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_grid_opt.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_grid_opt.ftl new file mode 100644 index 0000000..491933f --- /dev/null +++ b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_grid_opt.ftl @@ -0,0 +1,67 @@ +{ + "shape": "panel", + "id": "form_panel", + "type": "fx-form-panel", + "props": { + "colNum": 0, + "paddingX": 5, + "paddingY": 5, + "align": "full" + }, + "children": [ + { + "id": "id${newId()}", + "type": "fx-table", + "props": { + "label": "表格", + "border": true, + "stripe": true, + "showHeader": true, + "fit": true, + "dataset": "${group.dataset}", + "actionWidth": 120 + }, + "slots": { +<#assign fields = group.fields> + "default": [ +<#list fields as col> + { + "id": "id${newId()}", + "type": "fx-table-column", + "props": { + "field": "${col.field}", + "label": "${col.label}" + } + }, + + ], + "button": [ + { + "type": "fx-button", + "props": { + "label": "编", + "type": "text", + "leftIcon": "edit", + "action": "button:edit", + "linkType": "dialog", + "dataset": "${group.dataset}" + }, + "id": "id1813718bf36" + }, + { + "type": "fx-button", + "props": { + "label": "删", + "type": "text", + "leftIcon": "delete", + "action": "button:del", + "dataset": "${group.dataset}" + }, + "id": "id${newId()}" + } + ] + }, + "events": {} + } + ] + } \ No newline at end of file diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_filter.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_filter.ftl deleted file mode 100644 index 0b7c720..0000000 --- a/smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_filter.ftl +++ /dev/null @@ -1,74 +0,0 @@ -<#assign fields = group.cfilters> -<#list fields as filter> - { - "id": "${newId()}", - "type": "fx-form-panel", - "shape": "panel", - "props": { - "paddingY": 5, - "paddingX": 10, - "size": "35", - "colNum": 2 - }, - "children": [ - { - "id": "id${newId()}", - "type": "fx-text", - "props": { - "label": "${filter.label}", - "type": "text", - "maxlength": ${filter.maxlength}, - "placeholder": "请输入查询内容", - "labelWidth": 100, - "dataset": "${filter.dataset}", - "field": "${filter.field}", - "name": "${filter.name}" - }, - "events": {} - } -, - { - "id": "id${newId()}", - "type": "fx-button-group", - "props": { - "menus": [] - }, - "slots": { - "default": [ - { - "type": "fx-button", - "props": { - "label": "查询", - "leftIcon": "history-query", - "type": "primary", - "action": "button:search", - "dataset": "${group.dataset}" - }, - "id": "id${newId()}" - }, - { - "type": "fx-button", - "props": { - "label": "重置", - "type": "danger", - "action": "button:reset", - "leftIcon": "figma-reset-instance" - }, - "id": "id${newId()}" - }, - { - "id": "id${newId()}", - "type": "fx-button", - "props": { - "label": "新增", - "type": "success", - "leftIcon": "shield-add", - "action": "button:add", - "dataset": "${group.dataset}" - } - } - ] - } - } - ] - }, \ No newline at end of file diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_form.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_form.ftl deleted file mode 100644 index 61e4cfd..0000000 --- a/smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_form.ftl +++ /dev/null @@ -1,74 +0,0 @@ -<#assign fields = group.cfilters> -<#list fields as filter> - { - "shape": "panel", - "id": "form_panel", - "type": "fx-form-panel", - "props": { - "colNum": 2, - "paddingX": 5, - "paddingY": 5, - "size": "0" - }, - "children": [ - { - "id": "id1813718bf71", - "type": "fx-text", - "props": { - "label": "编码", - "type": "text", - "maxlength": 50, - "placeholder": "请输入内容", - "labelWidth": 100, - "dataset": "ds_1813718bf61", - "field": "id_1813718bf67", - "name": "pt_code" - }, - "events": {} - }, - { - "id": "id1813718bf74", - "type": "fx-label", - "props": { - "label": "标签", - "labelWidth": 100 - } - }, - { - "id": "id1813718bf77", - "type": "fx-text", - "props": { - "label": "名称", - "type": "text", - "maxlength": 50, - "placeholder": "请输入内容", - "labelWidth": 100, - "dataset": "ds_1813718bf61", - "field": "id_1813718bf68", - "name": "pt_name" - }, - "events": {} - }, - { - "id": "id1813718bf7a", - "type": "fx-label", - "props": { - "label": "标签", - "labelWidth": 100 - } - }, - { - "id": "id1813718bf9b", - "type": "fx-select", - "props": { - "label": "行政区划", - "clearable": true, - "labelWidth": 100, - "dataset": "ds_1813718bf61", - "field": "id_1813718bf66", - "name": "pt_area_id" - }, - "events": {} - } - ] - } \ No newline at end of file diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_grid_opt.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_grid_opt.ftl deleted file mode 100644 index 66cced0..0000000 --- a/smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_grid_opt.ftl +++ /dev/null @@ -1,67 +0,0 @@ -{ - "shape": "panel", - "id": "form_panel", - "type": "fx-form-panel", - "props": { - "colNum": 0, - "paddingX": 5, - "paddingY": 5, - "align": "full" - }, - "children": [ - { - "id": "id${newId()}", - "type": "fx-table", - "props": { - "label": "表格", - "border": true, - "stripe": true, - "showHeader": true, - "fit": true, - "dataset": "${group.dataset}", - "actionWidth": 120 - }, - "slots": { -<#assign fields = group.fields> - "default": [ -<#list fields as col> - { - "id": "id${newId()}", - "type": "fx-table-column", - "props": { - "field": "${col.field}", - "label": "${col.label}" - } - } - - ], - "button": [ - { - "type": "fx-button", - "props": { - "label": "编", - "type": "text", - "leftIcon": "edit", - "action": "button:edit", - "linkType": "dialog", - "dataset": "${group.dataset}" - }, - "id": "id1813718bf36" - }, - { - "type": "fx-button", - "props": { - "label": "删", - "type": "text", - "leftIcon": "delete", - "action": "button:del", - "dataset": "${group.dataset}" - }, - "id": "id${newId()}" - } - ] - }, - "events": {} - } - ] - } \ No newline at end of file diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/index.yaml b/smtweb-system/sw-system-bpm/src/main/resources/static/template/index.yaml index 5d0c736..1b79b63 100644 --- a/smtweb-system/sw-system-bpm/src/main/resources/static/template/index.yaml +++ b/smtweb-system/sw-system-bpm/src/main/resources/static/template/index.yaml @@ -1,14 +1,16 @@ -simple: - label: 简单页面 - type: list/scard/ccard -# 布局 - layout: - c1: - name: '客户区' - type: 'list' - hasGroup: false -# 变量 - param: - p1: - name: '' - type: 'ds/...' +model: + - + name: 'model_simple' + label: '简单页面' + # 布局 + layout: + - + name: 'c1' + label: '客户区' + type: 'list' + hasGroup: false + # 变量 + param: + - + name: 'p1' + type: 'ds/...' diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/model_simple.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/model_simple.ftl new file mode 100644 index 0000000..6b66639 --- /dev/null +++ b/smtweb-system/sw-system-bpm/src/main/resources/static/template/model_simple.ftl @@ -0,0 +1,44 @@ +{ + "form": [ + { + "page": { + "id": "p${newId()}", + "type": "fx-page", + "props": { + "title": "${title}", + "key": "${newId()}" + } + }, + "graph": { + "shape": "panel", + "id": "root_panel", + "type": "fx-split-panel", + "props": { + "horizontal": false, + "shadow": "never" + }, + "children": [ +<#list layout.c1 as group> + <#if (group.type == "list")> + <#if (group.cfilters?size>0)> + <#include "incModel/inc_filter.ftl"/> + + <#include "incModel/inc_grid_opt.ftl"/> + <#elseif (group.type == "card")> + <#include "incModel/inc_form.ftl"/> + + + ] + } + } + ], + "model": [ +<#list datasets as dataset> + <#include "incModel/inc_dataset.ftl"/> + + ], + "option": { + "widgetRef": [], + "vars": [] + } +} \ No newline at end of file diff --git a/smtweb-system/sw-system-bpm/src/main/resources/static/template/simple.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/simple.ftl deleted file mode 100644 index 2e01861..0000000 --- a/smtweb-system/sw-system-bpm/src/main/resources/static/template/simple.ftl +++ /dev/null @@ -1,107 +0,0 @@ -{ - "form": [ - { - "page": { - "id": "p${newId()}", - "type": "fx-page", - "props": { - "title": "${title}", - "key": "${newId()}" - } - }, - "graph": { - "shape": "panel", - "id": "root_panel", - "type": "fx-split-panel", - "props": { - "horizontal": false, - "shadow": "never" - }, - "children": [ -<#list layout.c1 as group> - <#if (group.cfilters?size>0)> - <#include "inc_filter.ftl"/> - -<#include "inc_grid_opt.ftl"/> - - ] - } - } - ], - "model": [ - { - "dataset": "ds_1813718bf0c", - "label": "机构列表", - "fields": [ - { - "id": "id_1813718bf0e", - "field": "pt_id" - }, - { - "id": "id_1813718bf0f", - "field": "pt_parent_id" - }, - { - "id": "id_1813718bf10", - "field": "pt_level_code" - }, - { - "id": "id_1813718bf11", - "field": "pt_area_id" - }, - { - "id": "id_1813718bf12", - "field": "pt_code" - }, - { - "id": "id_1813718bf13", - "field": "pt_name" - }, - { - "id": "id_1813718bf14", - "field": "pt_type" - }, - { - "id": "id_1813718bf15", - "field": "pt_statu" - }, - { - "id": "id_1813718bf16", - "field": "pt_linker" - }, - { - "id": "id_1813718bf17", - "field": "pt_tel" - }, - { - "id": "id_1813718bf18", - "field": "pt_addr" - }, - { - "id": "id_1813718bf19", - "field": "pt_lon" - }, - { - "id": "id_1813718bf1a", - "field": "pt_lat" - }, - { - "id": "id_1813718bf1b", - "field": "pt_remark" - } - ], - "filters": [ - { - "id": "id_1813718bf21", - "field": "pt_code", - "required": false, - "type": "input" - } - ] - } - ], - "option": { - "widgetRef": [], - "vars": [] - } -} \ No newline at end of file diff --git a/smtweb-system/sw-system-bpm/src/test/java/cc/smtweb/system/bpm/test/ModelFormTest.java b/smtweb-system/sw-system-bpm/src/test/java/cc/smtweb/system/bpm/test/ModelFormTest.java index b610f43..5c1c24d 100644 --- a/smtweb-system/sw-system-bpm/src/test/java/cc/smtweb/system/bpm/test/ModelFormTest.java +++ b/smtweb-system/sw-system-bpm/src/test/java/cc/smtweb/system/bpm/test/ModelFormTest.java @@ -3,6 +3,8 @@ package cc.smtweb.system.bpm.test; import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.system.bpm.spring.BpmApplication; +import cc.smtweb.system.bpm.web.design.form.ModelForm; +import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; import org.junit.Test; import org.junit.runner.RunWith; @@ -60,4 +62,40 @@ public class ModelFormTest { R r = service.del(params, null); System.out.println(r.readSuccess()); } + + @Test + public void testBuildModelByTmpl() { + ModelForm form = new ModelForm(); + form.setTitle("测试呀"); + form.setDataset("[{\"id\":\"ds_1813718bf0c\",\"name\":\"master\",\"label\":\"机构列表\",\"type\":\"list\",\"masterTable\":\"718391823709507584\",\"masterTable_text\":\"机构表\",\"idField\":\"pt_id\",\"lazy\":false,\"canEdit\":false,\"fields\":[{\"id\":\"id_1813718bf0e\",\"table\":\"718391823709507584\",\"field\":\"pt_id\",\"name\":\"pt_id\",\"fieldType\":1,\"notNull\":1,\"link\":\"0\"},{\"id\":\"id_1813718bf0f\",\"table\":\"718391823709507584\",\"field\":\"pt_parent_id\",\"name\":\"pt_parent_id\",\"fieldType\":4,\"notNull\":0,\"link\":\"0\"},{\"id\":\"id_1813718bf10\",\"table\":\"718391823709507584\",\"field\":\"pt_level_code\",\"name\":\"pt_level_code\",\"fieldType\":5,\"notNull\":0,\"link\":\"0\"},{\"id\":\"id_1813718bf11\",\"table\":\"718391823709507584\",\"field\":\"pt_area_id\",\"name\":\"pt_area_id\",\"fieldType\":0,\"notNull\":0,\"link\":\"718410950209703936\"},{\"id\":\"id_1813718bf12\",\"table\":\"718391823709507584\",\"field\":\"pt_code\",\"name\":\"pt_code\",\"fieldType\":2,\"notNull\":1,\"link\":\"0\"},{\"id\":\"id_1813718bf13\",\"table\":\"718391823709507584\",\"field\":\"pt_name\",\"name\":\"pt_name\",\"fieldType\":3,\"notNull\":1,\"link\":\"0\"},{\"id\":\"id_1813718bf14\",\"table\":\"718391823709507584\",\"field\":\"pt_type\",\"name\":\"pt_type\",\"fieldType\":0,\"notNull\":0,\"link\":\"0\"},{\"id\":\"id_1813718bf15\",\"table\":\"718391823709507584\",\"field\":\"pt_statu\",\"name\":\"pt_statu\",\"fieldType\":0,\"notNull\":0,\"link\":\"0\"},{\"id\":\"id_1813718bf16\",\"table\":\"718391823709507584\",\"field\":\"pt_linker\",\"name\":\"pt_linker\",\"fieldType\":0,\"notNull\":0,\"link\":\"0\"},{\"id\":\"id_1813718bf17\",\"table\":\"718391823709507584\",\"field\":\"pt_tel\",\"name\":\"pt_tel\",\"fieldType\":0,\"notNull\":0,\"link\":\"0\"},{\"id\":\"id_1813718bf18\",\"table\":\"718391823709507584\",\"field\":\"pt_addr\",\"name\":\"pt_addr\",\"fieldType\":0,\"notNull\":0,\"link\":\"0\"},{\"id\":\"id_1813718bf19\",\"table\":\"718391823709507584\",\"field\":\"pt_lon\",\"name\":\"pt_lon\",\"fieldType\":0,\"notNull\":0,\"link\":\"0\"},{\"id\":\"id_1813718bf1a\",\"table\":\"718391823709507584\",\"field\":\"pt_lat\",\"name\":\"pt_lat\",\"fieldType\":0,\"notNull\":0,\"link\":\"0\"},{\"id\":\"id_1813718bf1b\",\"table\":\"718391823709507584\",\"field\":\"pt_remark\",\"name\":\"pt_remark\",\"fieldType\":0,\"notNull\":0,\"link\":\"0\"}],\"filters\":[{\"id\":\"id_1813718bf21\",\"table\":\"718391823709507584\",\"field\":\"pt_name\",\"name\":\"pt_code\",\"fieldType\":3,\"notNull\":1,\"link\":\"0\",\"type\":\"input\",\"sqlName\":\"pt_name\",\"required\":false}],\"data\":[],\"dynCond\":{\"opt\":\"or\",\"children\":[{\"param\":\"pt_code\",\"opt\":\"like\"},{\"param\":\"pt_code\",\"opt\":\"like\"}]},\"sortFields\":[{\"field\":\"pt_code\",\"type\":\"asc\"}]}]"); + form.setTmpl("{\n" + + " \"param\": {\n" + + " \"p1\": \"pp1\"\n" + + " },\n" + + " \"layout\": {\n" + + " \"c1\": [\n" + + " {\n" + + " \"name\": \"group2\",\n" + + " \"label\": \"分组2\",\n" + + " \"type\": \"list\",\n" + + " \"dataset\": \"ds_1813718bf0c\",\n" + + " \"fields\": [\n" + + " {\n" + + " \"field\": \"pt_parent_id\",\n" + + " \"dataset\": \"ds_1813718bf0c\"\n" + + " }\n" + + " ],\n" + + " \"cfilters\": [\n" + + " {\n" + + " \"field\": \"pt_code\",\n" + + " \"dataset\": \"ds_1813718bf0c\"\n" + + " }\n" + + " ]\n" + + " }\n" + + " ]\n" + + " }\n" + + " }"); + ModelFormHelper.buildSaveModelByTmpl(form, "model_simple"); + System.out.println(form.getContent()); + } }