|
|
@@ -5,6 +5,9 @@ import cc.smtweb.framework.core.common.SwMap; |
|
|
|
import cc.smtweb.framework.core.cache.AbstractCache; |
|
|
|
import cc.smtweb.framework.core.cache.CacheManager; |
|
|
|
import cc.smtweb.framework.core.common.SwEnum; |
|
|
|
import cc.smtweb.framework.core.db.cache.ModelTableCache; |
|
|
|
import cc.smtweb.framework.core.db.vo.ModelField; |
|
|
|
import cc.smtweb.framework.core.db.vo.ModelTable; |
|
|
|
import cc.smtweb.framework.core.mvc.variable.SwVariableFactory; |
|
|
|
import cc.smtweb.framework.core.session.UserSession; |
|
|
|
import cc.smtweb.framework.core.util.CommUtil; |
|
|
@@ -52,7 +55,7 @@ public class ModelFormHelper { |
|
|
|
PageDataSet[] list = JsonUtil.parse(jsonStr, PageDataSet[].class); |
|
|
|
Map<String, PageDataSet> map = new LinkedHashMap<>(list.length); |
|
|
|
for (PageDataSet ds : list) { |
|
|
|
map.put(ds.name, ds); |
|
|
|
map.put(ds.id, ds); |
|
|
|
ds.resetFields(); |
|
|
|
} |
|
|
|
return map; |
|
|
@@ -121,43 +124,83 @@ public class ModelFormHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 保存的数据集,删除掉一些不必要的字段信息 |
|
|
|
* @param jsonStr |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static String buildSaveDataset(String jsonStr) { |
|
|
|
Map<String, PageDataSet> map = parsePageDataset(jsonStr); |
|
|
|
if (map == null) return null; |
|
|
|
try { |
|
|
|
return buildSaveDataset(map.values()); |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
throw new SwException(e); |
|
|
|
for (PageDataSet dataSet: map.values()) { |
|
|
|
buildSaveDataSetFields(dataSet.fields); |
|
|
|
buildSaveDataSetFields(dataSet.filters); |
|
|
|
} |
|
|
|
return JsonUtil.encodeString(map.values()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构建待保存的数据集 |
|
|
|
* |
|
|
|
* @param datasets |
|
|
|
* @return |
|
|
|
* @throws JsonProcessingException |
|
|
|
*/ |
|
|
|
public static String buildSaveDataset(Collection<PageDataSet> datasets) throws JsonProcessingException { |
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
FilterProvider filters = new SimpleFilterProvider().addFilter("datasetField", new SimpleBeanPropertyFilter() { |
|
|
|
private final String includes = "name,label,field,table"; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected boolean include(PropertyWriter writer) { |
|
|
|
return includes.contains(writer.getName()); |
|
|
|
public static void buildSaveDataSetFields(List<? extends PageDatasetField> fields) { |
|
|
|
ModelTable table = null; |
|
|
|
for (PageDatasetField field: fields) { |
|
|
|
if (field.table <= 0) continue; |
|
|
|
if (table == null || table.getEntityId() != field.table) { |
|
|
|
table = ModelTableCache.getInstance().get(field.table); |
|
|
|
} |
|
|
|
}).addFilter("datasetFilter", new SimpleBeanPropertyFilter() { |
|
|
|
private final String includes = ",name,label,field,table,dataType,type,linkDb,linkField,value"; |
|
|
|
if (table == null) continue; |
|
|
|
ModelField tf = table.findFieldByName(field.field); |
|
|
|
if (tf == null) continue; |
|
|
|
if (CommUtil.isStrEquals(tf.getTitle(), field.label)) field.label = 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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构建请求的数据集,补充表定义信息 |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @throws JsonProcessingException |
|
|
|
*/ |
|
|
|
public static String buildReqDataset(String jsonStr) { |
|
|
|
Map<String, PageDataSet> map = parsePageDataset(jsonStr); |
|
|
|
if (map == null) return ""; |
|
|
|
for (PageDataSet dataSet: map.values()) { |
|
|
|
buildReqDataSetFields(dataSet.fields); |
|
|
|
buildReqDataSetFields(dataSet.filters); |
|
|
|
} |
|
|
|
return JsonUtil.encodeString(map.values()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected boolean include(PropertyWriter writer) { |
|
|
|
return includes.contains("," + writer.getName()); |
|
|
|
/** |
|
|
|
* 构建请求的数据集,补充表定义信息 |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @throws JsonProcessingException |
|
|
|
*/ |
|
|
|
public static void buildReqDataSetFields(List<? extends PageDatasetField> fields) { |
|
|
|
ModelTable table = null; |
|
|
|
for (PageDatasetField field: fields) { |
|
|
|
if (field.table <= 0) continue; |
|
|
|
if (table == null || table.getEntityId() != field.table) { |
|
|
|
table = ModelTableCache.getInstance().get(field.table); |
|
|
|
} |
|
|
|
}); |
|
|
|
return mapper.writer(filters).writeValueAsString(datasets); |
|
|
|
if (table == null) continue; |
|
|
|
ModelField tf = table.findFieldByName(field.field); |
|
|
|
if (tf == null) continue; |
|
|
|
if (StringUtils.isEmpty(field.label)) field.label = tf.getTitle(); |
|
|
|
if (StringUtils.isEmpty(field.dataType)) field.dataType = tf.getDataType(); |
|
|
|
if (StringUtils.isEmpty(field.remark)) field.remark = tf.getRemark(); |
|
|
|
if (StringUtils.isEmpty(field.editor)) field.editor = tf.getEditor(); |
|
|
|
field.notNull = tf.getNotNull(); |
|
|
|
field.link = tf.getLink(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|