郑根木 преди 2 години
родител
ревизия
b69ce33cb0
променени са 4 файла, в които са добавени 96 реда и са изтрити 70 реда
  1. +2
    -2
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java
  2. +92
    -66
      smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java
  3. +1
    -1
      smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_form.ftl
  4. +1
    -1
      smtweb-system/sw-system-bpm/src/main/resources/static/template/model_simple.ftl

+ 2
- 2
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java Целия файл

@@ -48,8 +48,8 @@ public class CodeGenerator {
}

//页面设计的模板信息
public Collection<Map<String, Object>> getModelTemplates() {
return ((Map)mapTemplate.get(KEY_MODEL)).values();
public List<Map<String, Object>> getModelTemplates() {
return (List<Map<String, Object>>)mapTemplate.get(KEY_MODEL);
}

private void initModel(Map<String, Object> model) {


+ 92
- 66
smtweb-system/sw-system-bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java Целия файл

@@ -19,9 +19,7 @@ import cc.smtweb.system.bpm.web.design.form.define.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
* Created by Akmm at 2022/4/20 18:45
@@ -35,6 +33,7 @@ public class ModelFormHelper {
public static final String PAGE_TYPE_CARD = "card";
//分组类别-view
public static final String PAGE_TYPE_VIEW = "view";

/**
* 从缓存获取Form对象
*
@@ -126,69 +125,16 @@ 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<Map<String, Object>> groups = layout.readListMap(key);
for (Map<String, Object> 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<Map<String, Object>> fields, PageDatasets datasets, boolean isField) {
if (fields == null) return;
PageDataset dataset = null;
for (Map<String, Object> 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
* @return
*/
public static String buildSaveDataset(String jsonStr) {
PageDatasets datasets = parsePageDataset(jsonStr);
if (datasets == null || datasets.list == null) return "";
for (PageDataset dataSet: datasets.list) {
for (PageDataset dataSet : datasets.list) {
buildSaveDataSetFields(dataSet.fields);
buildSaveDataSetFields(dataSet.filters);
}
@@ -203,7 +149,7 @@ public class ModelFormHelper {
*/
public static void buildSaveDataSetFields(List<? extends PageDatasetField> fields) {
ModelTable table = null;
for (PageDatasetField field: fields) {
for (PageDatasetField field : fields) {
if (field.table <= 0) continue;
if (table == null || table.getEntityId() != field.table) {
table = ModelTableCache.getInstance().get(field.table);
@@ -213,7 +159,7 @@ public class ModelFormHelper {
if (tf == null) continue;
field.table_text = null;
if (CommUtil.isStrEquals(tf.getTitle(), field.label)) field.label = null;
if (CommUtil.isStrEquals(tf.getDataType(),field.dataType)) field.dataType = null;
if (CommUtil.isStrEquals(tf.getDataType(), field.dataType)) field.dataType = null;
if (CommUtil.isStrEquals(tf.getRemark(), field.remark)) field.remark = null;
if (CommUtil.isStrEquals(tf.getEditor(), field.editor)) field.editor = null;
}
@@ -279,7 +225,7 @@ public class ModelFormHelper {
}
}
if (!isField) {
PageDatasetFilter filter = (PageDatasetFilter)pdf;
PageDatasetFilter filter = (PageDatasetFilter) pdf;
field.put("type", filter.type);
field.put("linkDb", filter.linkDb);
field.put("linkField", filter.linkField);
@@ -297,6 +243,7 @@ public class ModelFormHelper {
public static String buildEngineModel(ModelForm form, SwMap params, UserSession us) {
return buildEngineModel(form, params, us, true);
}

public static String buildEngineModel(ModelForm form, SwMap params, UserSession us, boolean incExtra) {
PageDatasets datasets = parsePageDataset(form.getDataset());
if (datasets == null || datasets.list == null) return "";
@@ -360,11 +307,11 @@ public class ModelFormHelper {
for (Object v : widgetIds) {
long id;
if (v instanceof String) {
id = Long.parseLong((String)v);
id = Long.parseLong((String) v);
} else if (v instanceof Integer) {
id = (Integer)v;
id = (Integer) v;
} else if (v instanceof Long) {
id = (Long)v;
id = (Long) v;
} else throw new SwException("不能识别的控件Id:" + v);
ModelForm widgetForm = getFromCache(id);
if (widgetForm == null) throw new SwException("没有找到指定的控件定义!id=" + id);
@@ -390,8 +337,8 @@ public class ModelFormHelper {
List<SwMap> listRet = new ArrayList<>();
PageDatasets datasets = ModelFormHelper.parsePageDataset(bean.getDataset());
if (datasets == null || datasets.list == null) return listRet;
for (PageDataset ds: datasets.list) {
for (PageDatasetFilter filter: ds.filters) {
for (PageDataset ds : datasets.list) {
for (PageDatasetFilter filter : ds.filters) {
if (SwEnum.FilterType.INPUT.value.equals(filter.type) || SwEnum.FilterType.PARAM.value.equals(filter.type)) {
SwMap fret = new SwMap();
fret.put("name", filter.name);
@@ -406,6 +353,7 @@ public class ModelFormHelper {

/**
* 构建一些扩展属性,目前主要是eventPath
*
* @param opts
*/
public static void buildOptsEx(ModelForm bean, SwMap opts) {
@@ -418,4 +366,82 @@ public class ModelFormHelper {
}
}

/**
* 根据向导生成model
* @param form
* @param tmplId
*/
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");
//用到的自定义控件
Set<String> setWidget = new HashSet<>();
for (String key : layout.keySet()) {
List<Map<String, Object>> groups = layout.readListMap(key);
for (Map<String, Object> group : groups) {
String type = MapUtil.readString(group, "type");
switch (type) {
case PAGE_TYPE_CARD:
buildTmplFields(MapUtil.readListMap(group, "fields"), datasets, setWidget, true);
break;
case PAGE_TYPE_LIST:
buildTmplFields(MapUtil.readListMap(group, "fields"), datasets, setWidget, true);
buildTmplFields(MapUtil.readListMap(group, "cfilters"), datasets, setWidget, false);
buildTmplFields(MapUtil.readListMap(group, "sfilters"), datasets, setWidget, false);
break;
}
}
}
String widgetRef = "";
if (!setWidget.isEmpty()) {
for (String s: setWidget) {
widgetRef += ",\"" + s + "\"";
}
widgetRef = widgetRef.substring(1);
}
tmplModel.put("widgetRef", widgetRef);
form.setContent(CodeGenerator.getInstance().generate(tmplModel, tmplId));
// form.setContent(buildSaveModel(form));
}

private static void buildTmplFields(List<Map<String, Object>> fields, PageDatasets datasets, Set<String> setWidget, boolean isField) {
if (fields == null) return;
PageDataset dataset = null;
for (Map<String, Object> 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 tableId
* @param fieldName
* @return
*/
public String getFieldCtrl(long tableId, String fieldName) {
return null;
}
}

+ 1
- 1
smtweb-system/sw-system-bpm/src/main/resources/static/template/incModel/inc_form.ftl Целия файл

@@ -13,7 +13,7 @@
<#list fields as field>
{
"id": "id${newId()}",
"type": "fx-text",
"type": "${ctrl}",
"props": {
"label": "${field.label}",
"type": "text",


+ 1
- 1
smtweb-system/sw-system-bpm/src/main/resources/static/template/model_simple.ftl Целия файл

@@ -38,7 +38,7 @@
</#list>
],
"option": {
"widgetRef": [],
"widgetRef": [${widgetRef}],
"vars": []
}
}

Зареждане…
Отказ
Запис