From a1909f59cde7253d6ca57cff59a5f82ea344a406 Mon Sep 17 00:00:00 2001 From: junjie Date: Thu, 2 Dec 2021 17:54:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=95=B0=E6=8D=AE=E9=9B=86):=20=E5=85=B3?= =?UTF-8?q?=E8=81=94=E6=95=B0=E6=8D=AE=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 38 ++++++++++--------- .../resources/i18n/messages_en_US.properties | 3 +- .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 3 +- frontend/src/views/dataset/add/AddUnion.vue | 4 +- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index e904ea5769..ce119736ac 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -1083,9 +1083,7 @@ public class DataSetTableService { DEException.throwException(Translator.get("i18n_custom_ds_delete") + String.format(":table id [%s]", tableId)); } List fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField()); - if (CollectionUtils.isEmpty(fields)) { - DEException.throwException(Translator.get("i18n_cst_ds_tb_or_field_deleted") + String.format(":table id [%s]", tableId)); - } + String[] array = fields.stream().map(f -> table + "." + f.getDataeaseName() + " AS " + DorisTableUtils.dorisFieldName(tableId + "_" + f.getDataeaseName())).toArray(String[]::new); checkedInfo.put(table, array); checkedFields.addAll(fields); @@ -1103,7 +1101,7 @@ public class DataSetTableService { Map.Entry next = iterator.next(); field.append(StringUtils.join(next.getValue(), ",")).append(","); } - String f = field.substring(0, field.length() - 1); + String f = subPrefixSuffixChar(field.toString()); // join StringBuilder join = new StringBuilder(); for (UnionParamDTO unionParamDTO : unionList) { @@ -1134,13 +1132,13 @@ public class DataSetTableService { } } if (StringUtils.isEmpty(f)) { - DEException.throwException(Translator.get("i18n_custom_ds_delete")); + DEException.throwException(Translator.get("i18n_union_ds_no_checked")); } sql = MessageFormat.format("SELECT {0} FROM {1}", f, DorisTableUtils.dorisName(union.get(0).getCurrentDs().getId())) + join.toString(); } else { String f = StringUtils.join(checkedInfo.get(DorisTableUtils.dorisName(union.get(0).getCurrentDs().getId())), ","); if (StringUtils.isEmpty(f)) { - throw new RuntimeException(Translator.get("i18n_custom_ds_delete")); + throw new RuntimeException(Translator.get("i18n_union_ds_no_checked")); } sql = MessageFormat.format("SELECT {0} FROM {1}", f, DorisTableUtils.dorisName(union.get(0).getCurrentDs().getId())); } @@ -1162,9 +1160,7 @@ public class DataSetTableService { DEException.throwException(Translator.get("i18n_custom_ds_delete") + String.format(":table id [%s]", tableId)); } List fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField()); - if (CollectionUtils.isEmpty(fields)) { - DEException.throwException(Translator.get("i18n_cst_ds_tb_or_field_deleted") + String.format(":table id [%s]", tableId)); - } + String[] array = fields.stream().map(f -> table + "." + f.getDataeaseName() + " AS " + DorisTableUtils.dorisFieldName(tableId + "_" + f.getDataeaseName())).toArray(String[]::new); checkedInfo.put(table, array); checkedFields.addAll(fields); @@ -1196,9 +1192,7 @@ public class DataSetTableService { DEException.throwException(Translator.get("i18n_custom_ds_delete") + String.format(":table id [%s]", tableId)); } List fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField()); - if (CollectionUtils.isEmpty(fields)) { - DEException.throwException(Translator.get("i18n_cst_ds_tb_or_field_deleted") + String.format(":table id [%s]", tableId)); - } + String[] array = fields.stream().map(f -> String.format(keyword, table) + "." + String.format(keyword, f.getOriginName()) + " AS " + DorisTableUtils.dorisFieldNameShort(tableId + "_" + f.getOriginName())).toArray(String[]::new); checkedInfo.put(table, array); checkedFields.addAll(fields); @@ -1216,7 +1210,7 @@ public class DataSetTableService { Map.Entry next = iterator.next(); field.append(StringUtils.join(next.getValue(), ",")).append(","); } - String f = field.substring(0, field.length() - 1); + String f = subPrefixSuffixChar(field.toString()); // join StringBuilder join = new StringBuilder(); for (UnionParamDTO unionParamDTO : unionList) { @@ -1249,13 +1243,13 @@ public class DataSetTableService { } } if (StringUtils.isEmpty(f)) { - DEException.throwException(Translator.get("i18n_custom_ds_delete")); + DEException.throwException(Translator.get("i18n_union_ds_no_checked")); } sql = MessageFormat.format("SELECT {0} FROM {1}", f, String.format(keyword, tableName)) + join.toString(); } else { String f = StringUtils.join(checkedInfo.get(tableName), ","); if (StringUtils.isEmpty(f)) { - throw new RuntimeException(Translator.get("i18n_custom_ds_delete")); + throw new RuntimeException(Translator.get("i18n_union_ds_no_checked")); } sql = MessageFormat.format("SELECT {0} FROM {1}", f, String.format(keyword, tableName)); } @@ -1266,6 +1260,16 @@ public class DataSetTableService { return map; } + private String subPrefixSuffixChar(String str) { + while (StringUtils.startsWith(str, ",")) { + str = str.substring(1, str.length()); + } + while (StringUtils.endsWith(str, ",")) { + str = str.substring(0, str.length() - 1); + } + return str; + } + // 递归计算出所有子级的checkedFields和unionParam private void getUnionSQLDatasourceJoin(List childrenDs, Map checkedInfo, List unionList, String keyword, List checkedFields) { for (int i = 0; i < childrenDs.size(); i++) { @@ -1279,9 +1283,7 @@ public class DataSetTableService { String table = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getTable(); List fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField()); - if (CollectionUtils.isEmpty(fields)) { - DEException.throwException(Translator.get("i18n_cst_ds_tb_or_field_deleted") + String.format(":table id [%s]", tableId)); - } + String[] array = fields.stream().map(f -> String.format(keyword, table) + "." + String.format(keyword, f.getOriginName()) + " AS " + DorisTableUtils.dorisFieldNameShort(tableId + "_" + f.getOriginName())).toArray(String[]::new); checkedInfo.put(table, array); checkedFields.addAll(fields); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index ab583bd2b4..59000ff479 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -289,4 +289,5 @@ i18n_Exec=Running i18n_no_trigger=The current setting does not trigger task generation. i18n_dataset_field_delete=Union field deleted,please set again and redo. i18n_es_limit=Elasticsearch version cannot be less than 6.3 -i18n_ds_error=Preview fail:Execute SQL error。Cause field、table、dataset changed,please check \ No newline at end of file +i18n_ds_error=Preview fail:Execute SQL error。Cause field、table、dataset changed,please check +i18n_union_ds_no_checked=This union dataset no checked field,please edit \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 6bafb1da79..2e749e1a5a 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -289,3 +289,4 @@ i18n_no_trigger=当前设置没有触发任务生成 i18n_dataset_field_delete=该自定义数据集有关联字段被删除,请重新确认关联关系并重做该数据集 i18n_es_limit=Elasticsearch 版本不能小于6.3 i18n_ds_error=预览数据错误:执行SQL失败。可能因相关字段、表、数据集等元素发生变更,请检查 +i18n_union_ds_no_checked=当前关联数据集,无选中字段,请重新编辑 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 4c40206670..4eab3d4c27 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -291,4 +291,5 @@ i18n_Exec=運行中 i18n_no_trigger=当前设置没有触发任务生成 當前設置沒有觸發任務生成. i18n_dataset_field_delete=該自定義數據集有關聯字段被刪除,請重新確認關聯關系並重做該數據集 i18n_es_limit=Elasticsearch 版本不能小於6.3 -i18n_ds_error=預覽數據錯誤:執行SQL失敗。可能因相關字段、表、數據集等元素發生變更,請檢查 \ No newline at end of file +i18n_ds_error=預覽數據錯誤:執行SQL失敗。可能因相關字段、表、數據集等元素發生變更,請檢查 +i18n_union_ds_no_checked=當前關聯數據集,無選中字段,請重新編輯 \ No newline at end of file diff --git a/frontend/src/views/dataset/add/AddUnion.vue b/frontend/src/views/dataset/add/AddUnion.vue index c87cb68323..39e1bb0790 100644 --- a/frontend/src/views/dataset/add/AddUnion.vue +++ b/frontend/src/views/dataset/add/AddUnion.vue @@ -310,8 +310,8 @@ export default { } .union-container{ display: flex; - width:100%; - height:400px; + width: 100%; + height: calc(100vh - 200px); overflow: auto; } .form-item{