From b64ab7856be92522f8070713279fba3d09ffe66b Mon Sep 17 00:00:00 2001 From: datagear Date: Mon, 29 Mar 2021 18:42:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datagear/analysis/DataSetProperty.java | 35 ++++++++++++++++--- .../analysis/support/AbstractDataSet.java | 23 ++++++++++-- .../org/datagear/management/ddl/datagear.sql | 2 ++ .../management/mapper/DataSetEntityMapper.xml | 7 ++-- .../org/datagear/web/i18n/message.properties | 2 ++ .../datagear/web/i18n/message_en.properties | 2 ++ .../dataSet/include/dataSet_form_js.ftl | 16 +++++++++ 7 files changed, 77 insertions(+), 10 deletions(-) diff --git a/datagear-analysis/src/main/java/org/datagear/analysis/DataSetProperty.java b/datagear-analysis/src/main/java/org/datagear/analysis/DataSetProperty.java index cbd5b7b7..29530f98 100644 --- a/datagear-analysis/src/main/java/org/datagear/analysis/DataSetProperty.java +++ b/datagear-analysis/src/main/java/org/datagear/analysis/DataSetProperty.java @@ -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}。 + *

+ * 如果数据中此属性值为{@code null},那么应该设置为此默认值。 + *

+ *

+ * 注意:此默认值类型不一定是期望的数据类型,应当先对其进行类型转换。 + *

+ * + * @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 + "]"; } /** diff --git a/datagear-analysis/src/main/java/org/datagear/analysis/support/AbstractDataSet.java b/datagear-analysis/src/main/java/org/datagear/analysis/support/AbstractDataSet.java index 3ee2690c..7589da9c 100644 --- a/datagear-analysis/src/main/java/org/datagear/analysis/support/AbstractDataSet.java +++ b/datagear-analysis/src/main/java/org/datagear/analysis/support/AbstractDataSet.java @@ -148,9 +148,11 @@ public abstract class AbstractDataSet extends AbstractIdentifiable implements Da * * @param cn * @param rs - * @param rawData {@code Collection>}、{@code Map[]}、{@code Map}、{@code null} + * @param rawData + * {@code Collection>}、{@code Map[]}、{@code Map}、{@code null} * @param properties - * @param dataSetOption 允许为{@code null} + * @param dataSetOption + * 允许为{@code null} * @return {@code List>}、{@code Map[]}、{@code Map}、{@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 rowRaw : rawData) { - // 应当仅保留数据集属性对应的数据 + // 应当仅保留数据集属性对应的数据,因为数据集属性是允许编辑的,如果用户删除了某个数据集属性,表明对应的值不想被使用 Map 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); } diff --git a/datagear-management/src/main/resources/org/datagear/management/ddl/datagear.sql b/datagear-management/src/main/resources/org/datagear/management/ddl/datagear.sql index f10cc7b8..2647f1a3 100644 --- a/datagear-management/src/main/resources/org/datagear/management/ddl/datagear.sql +++ b/datagear-management/src/main/resources/org/datagear/management/ddl/datagear.sql @@ -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); diff --git a/datagear-management/src/main/resources/org/datagear/management/mapper/DataSetEntityMapper.xml b/datagear-management/src/main/resources/org/datagear/management/mapper/DataSetEntityMapper.xml index df08fdbe..eac469a2 100644 --- a/datagear-management/src/main/resources/org/datagear/management/mapper/DataSetEntityMapper.xml +++ b/datagear-management/src/main/resources/org/datagear/management/mapper/DataSetEntityMapper.xml @@ -106,11 +106,13 @@ 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} ) @@ -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 diff --git a/datagear-web/src/main/resources/org/datagear/web/i18n/message.properties b/datagear-web/src/main/resources/org/datagear/web/i18n/message.properties index a5e9e64d..6d4d6647 100644 --- a/datagear-web/src/main/resources/org/datagear/web/i18n/message.properties +++ b/datagear-web/src/main/resources/org/datagear/web/i18n/message.properties @@ -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=布尔值 diff --git a/datagear-web/src/main/resources/org/datagear/web/i18n/message_en.properties b/datagear-web/src/main/resources/org/datagear/web/i18n/message_en.properties index da70a065..510b644f 100644 --- a/datagear-web/src/main/resources/org/datagear/web/i18n/message_en.properties +++ b/datagear-web/src/main/resources/org/datagear/web/i18n/message_en.properties @@ -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 diff --git a/datagear-web/src/main/resources/org/datagear/web/templates/analysis/dataSet/include/dataSet_form_js.ftl b/datagear-web/src/main/resources/org/datagear/web/templates/analysis/dataSet/include/dataSet_form_js.ftl index 0733f2cf..1ac5a1bd 100644 --- a/datagear-web/src/main/resources/org/datagear/web/templates/analysis/dataSet/include/dataSet_form_js.ftl +++ b/datagear-web/src/main/resources/org/datagear/web/templates/analysis/dataSet/include/dataSet_form_js.ftl @@ -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 "' />"; + }, + 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; };