数据集属性支持设置默认值

This commit is contained in:
datagear 2021-03-29 18:42:29 +08:00
parent 516134efe8
commit b64ab7856b
7 changed files with 77 additions and 10 deletions

View File

@ -1,7 +1,7 @@
/*
* Copyright 2018 datagear.tech
*
* Licensed under the LGPLv3 license:
* Copyright 2018 datagear.tech
*
* Licensed under the LGPLv3 license:
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
@ -26,7 +26,10 @@ public class DataSetProperty extends AbstractDataNameType implements Serializabl
private static final long serialVersionUID = 1L;
/** 展示标签 */
private String label;
private String label = null;
/** 默认值 */
private Object defaultValue = null;
public DataSetProperty()
{
@ -53,10 +56,32 @@ public class DataSetProperty extends AbstractDataNameType implements Serializabl
this.label = label;
}
/**
* 获取默认值可能为{@code null}
* <p>
* 如果数据中此属性值为{@code null}那么应该设置为此默认值
* </p>
* <p>
* 注意此默认值类型不一定是期望的数据类型应当先对其进行类型转换
* </p>
*
* @return
*/
public Object getDefaultValue()
{
return defaultValue;
}
public void setDefaultValue(Object defaultValue)
{
this.defaultValue = defaultValue;
}
@Override
public String toString()
{
return getClass().getSimpleName() + " [name=" + getName() + ", type=" + getType() + ", label=" + label + "]";
return getClass().getSimpleName() + " [name=" + getName() + ", type=" + getType() + ", label=" + label
+ ", defaultValue=" + defaultValue + "]";
}
/**

View File

@ -148,9 +148,11 @@ public abstract class AbstractDataSet extends AbstractIdentifiable implements Da
*
* @param cn
* @param rs
* @param rawData {@code Collection<Map<String, ?>>}{@code Map<String, ?>[]}{@code Map<String, ?>}{@code null}
* @param rawData
* {@code Collection<Map<String, ?>>}{@code Map<String, ?>[]}{@code Map<String, ?>}{@code null}
* @param properties
* @param dataSetOption 允许为{@code null}
* @param dataSetOption
* 允许为{@code null}
* @return {@code List<Map<String, ?>>}{@code Map<String, ?>[]}{@code Map<String, ?>}{@code null}
* @throws Throwable
*/
@ -209,9 +211,13 @@ public abstract class AbstractDataSet extends AbstractIdentifiable implements Da
int plen = properties.size();
Object[] defaultValues = new Object[plen];
Object dvPlaceholder = new Object();
Arrays.fill(defaultValues, dvPlaceholder);
for (Map<String, ?> rowRaw : rawData)
{
// 应当仅保留数据集属性对应的数据
// 应当仅保留数据集属性对应的数据因为数据集属性是允许编辑的如果用户删除了某个数据集属性表明对应的值不想被使用
Map<String, Object> row = new HashMap<>();
for (int j = 0; j < plen; j++)
@ -222,6 +228,17 @@ public abstract class AbstractDataSet extends AbstractIdentifiable implements Da
Object value = rowRaw.get(name);
value = convertToPropertyDataType(converter, value, property);
if (value == null)
{
if (defaultValues[j] == dvPlaceholder)
{
Object defaultValue = property.getDefaultValue();
defaultValues[j] = convertToPropertyDataType(converter, defaultValue, property);
}
value = defaultValues[j];
}
row.put(name, value);
}

View File

@ -780,3 +780,5 @@ PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.datagear.management
--version[2.4.0], DO NOT EDIT THIS LINE!
-----------------------------------------
--
ALTER TABLE DATAGEAR_DATA_SET_PROP ADD COLUMN PROP_DFT_VALUE VARCHAR(100);

View File

@ -106,11 +106,13 @@
<insert id="insertPropertyPO">
INSERT INTO DATAGEAR_DATA_SET_PROP
(
PROP_DS_ID, PROP_NAME, PROP_TYPE, PROP_LABEL, PROP_ORDER
PROP_DS_ID, PROP_NAME, PROP_TYPE, PROP_LABEL,
PROP_DFT_VALUE, PROP_ORDER
)
VALUES
(
#{entity.dataSetId}, #{entity.child.name}, #{entity.child.type}, #{entity.child.label, jdbcType=VARCHAR}, #{entity.order}
#{entity.dataSetId}, #{entity.child.name}, #{entity.child.type}, #{entity.child.label, jdbcType=VARCHAR},
#{entity.child.defaultValue, jdbcType=VARCHAR}, #{entity.order}
)
</insert>
@ -388,6 +390,7 @@
PROP_NAME AS ${_iq_}child.name${_iq_},
PROP_TYPE AS ${_iq_}child.type${_iq_},
PROP_LABEL AS ${_iq_}child.label${_iq_},
PROP_DFT_VALUE AS ${_iq_}child.defaultValue${_iq_},
PROP_ORDER AS ${_iq_}order${_iq_}
FROM
DATAGEAR_DATA_SET_PROP

View File

@ -732,6 +732,8 @@ dataSet.noDataSetParamDefined=没有定义参数
dataSet.DataSetProperty.name=名称
dataSet.DataSetProperty.type=类型
dataSet.DataSetProperty.label=展示名称
dataSet.DataSetProperty.defaultValue=默认值
dataSet.DataSetProperty.defaultValue.desc=当数据中没有此属性值时,将使用这个默认值
dataSet.DataSetProperty.DataType.STRING=字符串
dataSet.DataSetProperty.DataType.NUMBER=数值
dataSet.DataSetProperty.DataType.BOOLEAN=布尔值

View File

@ -732,6 +732,8 @@ dataSet.noDataSetParamDefined=No parameter defined
dataSet.DataSetProperty.name=Name
dataSet.DataSetProperty.type=Type
dataSet.DataSetProperty.label=Label
dataSet.DataSetProperty.defaultValue=Default value
dataSet.DataSetProperty.defaultValue.desc=This default value will be used if no value in data
dataSet.DataSetProperty.DataType.STRING=String
dataSet.DataSetProperty.DataType.NUMBER=Number
dataSet.DataSetProperty.DataType.BOOLEAN=Boolean

View File

@ -239,6 +239,18 @@ po.previewOptions.url = "...";
width: "8em",
defaultContent: "",
orderable: true
},
{
title: "<@spring.message code='dataSet.DataSetProperty.defaultValue' />",
data: "defaultValue",
render: function(data, type, row, meta)
{
return "<input type='text' value='"+$.escapeHtml(data)+"' class='dataSetPropertyDefaultValue input-in-table ui-widget ui-widget-content'"
+" title='<@spring.message code='dataSet.DataSetProperty.defaultValue.desc' />' />";
},
width: "6em",
defaultContent: "",
orderable: true
}
],
data: (initDataSetProperties || []),
@ -313,6 +325,10 @@ po.previewOptions.url = "...";
{
properties[i]["label"] = $(this).val();
});
po.element(".properties-table-wrapper .dataSetPropertyDefaultValue").each(function(i)
{
properties[i]["defaultValue"] = $(this).val();
});
return properties;
};