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/util/CodeGenerator.java similarity index 72% rename from smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/resolver/CodeResolver.java rename to smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java index 8fce711..a419a46 100644 --- 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/util/CodeGenerator.java @@ -1,4 +1,4 @@ -package cc.smtweb.system.bpm.resolver; +package cc.smtweb.system.bpm.util; import cc.smtweb.framework.core.common.SwException; import cc.smtweb.framework.core.common.SwMap; @@ -11,22 +11,30 @@ 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 CodeResolver { - private static CodeResolver instance = null; +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; - protected CodeResolver() { + //模板信息 + 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)); @@ -39,8 +47,18 @@ public class CodeResolver { } } - public void create(Map model, String templateName, Writer writer) { + //页面设计的模板信息 + 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); @@ -51,8 +69,9 @@ public class CodeResolver { } } - public void create(Map model, String templateName, OutputStream out) { + 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)); @@ -63,15 +82,21 @@ public class CodeResolver { } } + public String generate(Map model, String templateName) { + StringWriter out = new StringWriter(); + generate(model, templateName + ".ftl", out); + return out.getBuffer().toString(); + } + /** * 获取单实例 * * @return */ - public static CodeResolver getInstance() { + public static CodeGenerator getInstance() { if (instance == null) { - synchronized (CodeResolver.class) { - instance = new CodeResolver(); + synchronized (CodeGenerator.class) { + instance = new CodeGenerator(); } } return instance; @@ -80,7 +105,7 @@ public class CodeResolver { static class PKGenerator implements TemplateMethodModelEx { @Override public Object exec(List list) throws TemplateModelException { - return "asd"; + return DbEngine.getInstance().nextId(); // return DbEngine.getInstance().nextId(); } } @@ -139,7 +164,7 @@ public class CodeResolver { map.put("title", "thisIsATest!"); map.put("newId", new PKGenerator()); - CodeResolver.getInstance().create(map, "simple.ftl", out); + 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/inc_filter.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_filter.ftl similarity index 98% rename from smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_filter.ftl rename to smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_filter.ftl index 0b7c720..9dda2bb 100644 --- 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/incModel/inc_filter.ftl @@ -1,5 +1,4 @@ <#assign fields = group.cfilters> -<#list fields as filter> { "id": "${newId()}", "type": "fx-form-panel", @@ -11,6 +10,7 @@ "colNum": 2 }, "children": [ +<#list fields as filter> { "id": "id${newId()}", "type": "fx-text", @@ -25,8 +25,8 @@ "name": "${filter.name}" }, "events": {} - } -, + }, + { "id": "id${newId()}", "type": "fx-button-group", 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/inc_grid_opt.ftl b/smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_grid_opt.ftl similarity index 98% rename from smtweb-system/sw-system-bpm/src/main/resources/static/template/inc_grid_opt.ftl rename to smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_grid_opt.ftl index 66cced0..491933f 100644 --- 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/incModel/inc_grid_opt.ftl @@ -32,7 +32,7 @@ "field": "${col.field}", "label": "${col.label}" } - } + }, ], "button": [ 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/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()); + } }