From 7cf90a2654a97e38339fa8009ebf3fed69cc8001 Mon Sep 17 00:00:00 2001 From: junjie Date: Tue, 7 Sep 2021 10:26:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=95=B0=E6=8D=AE=E9=9B=86):=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 39 +++++++++++-------- .../resources/i18n/messages_en_US.properties | 1 + .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 1 + 4 files changed, 25 insertions(+), 17 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 93e1158b4a..e52d9b4299 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -1,7 +1,6 @@ package io.dataease.service.dataset; -import com.fit2cloud.quartz.anno.QuartzScheduled; import com.google.gson.Gson; import io.dataease.base.domain.*; import io.dataease.base.mapper.*; @@ -115,9 +114,9 @@ public class DataSetTableService { } } - public void saveExcel(DataSetTableRequest datasetTable)throws Exception { + public void saveExcel(DataSetTableRequest datasetTable) throws Exception { if (StringUtils.isEmpty(datasetTable.getId())) { - if(datasetTable.isMergeSheet()){ + if (datasetTable.isMergeSheet()) { Map> map = datasetTable.getSheets().stream().collect(Collectors.groupingBy(ExcelSheetData::getFieldsMd5)); for (String s : map.keySet()) { DataSetTableRequest sheetTable = new DataSetTableRequest(); @@ -147,7 +146,7 @@ public class DataSetTableService { }); } } - }else { + } else { for (ExcelSheetData sheet : datasetTable.getSheets()) { String[] fieldArray = sheet.getFields().stream().map(TableFiled::getFieldName).toArray(String[]::new); if (checkIsRepeat(fieldArray)) { @@ -183,7 +182,7 @@ public class DataSetTableService { List oldFields = datasetTable.getSheets().get(0).getFields().stream().map(TableFiled::getRemarks).collect(Collectors.toList()); for (ExcelSheetData sheet : datasetTable.getSheets()) { //替换时, - if(datasetTable.getEditType() == 0){ + if (datasetTable.getEditType() == 0) { List newFields = sheet.getFields().stream().map(TableFiled::getRemarks).collect(Collectors.toList()); if (!oldFields.equals(newFields)) { DataEaseException.throwException(Translator.get("i18n_excel_colume_change")); @@ -240,7 +239,7 @@ public class DataSetTableService { if (datasetTable.getIsRename() == null || !datasetTable.getIsRename()) { // 更新数据和字段 if (update == 1) { - if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "sql") || StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom") ) { + if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "sql") || StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) { // 删除所有字段,重新抽象 dataSetTableFieldsService.deleteByTableId(datasetTable.getId()); saveTableField(datasetTable); @@ -251,7 +250,7 @@ public class DataSetTableService { return datasetTable; } - public void alter(DataSetTableRequest request)throws Exception { + public void alter(DataSetTableRequest request) throws Exception { checkName(request); datasetTableMapper.updateByPrimaryKeySelective(request); } @@ -804,6 +803,9 @@ public class DataSetTableService { if (StringUtils.equals(dto.getTargetTableId(), dataTableInfoCustomUnion.getTableId())) { DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId()); DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId()); + if (ObjectUtils.isEmpty(sourceField) || ObjectUtils.isEmpty(targetField)) { + DEException.throwException(Translator.get("i18n_dataset_field_delete")); + } join.append(convertUnionTypeToSQL(dto.getSourceUnionRelation())) .append(DorisTableUtils.dorisName(dto.getTargetTableId())) .append(" ON ") @@ -861,6 +863,9 @@ public class DataSetTableService { if (StringUtils.equals(dto.getTargetTableId(), dataTableInfoCustomUnion.getTableId())) { DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId()); DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId()); + if (ObjectUtils.isEmpty(sourceField) || ObjectUtils.isEmpty(targetField)) { + DEException.throwException(Translator.get("i18n_dataset_field_delete")); + } DatasetTable sourceTable = datasetTableMapper.selectByPrimaryKey(dto.getSourceTableId()); String sourceTableName = new Gson().fromJson(sourceTable.getInfo(), DataTableInfoDTO.class).getTable(); DatasetTable targetTable = datasetTableMapper.selectByPrimaryKey(dto.getTargetTableId()); @@ -901,7 +906,7 @@ public class DataSetTableService { } } - public List saveExcelTableField(String datasetTableId, List fields, boolean insert){ + public List saveExcelTableField(String datasetTableId, List fields, boolean insert) { List datasetTableFields = new ArrayList<>(); if (CollectionUtils.isNotEmpty(fields)) { for (int i = 0; i < fields.size(); i++) { @@ -920,7 +925,7 @@ public class DataSetTableService { datasetTableField.setLastSyncTime(System.currentTimeMillis()); datasetTableField.setExtField(0); datasetTableField.setGroupType(datasetTableField.getDeType() < 2 ? "d" : "q"); - if(insert){ + if (insert) { dataSetTableFieldsService.save(datasetTableField); } datasetTableFields.add(datasetTableField); @@ -1120,11 +1125,11 @@ public class DataSetTableService { .replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString()); datasourceRequest.setQuery(qp.wrapSql(sql)); List sqlFileds = new ArrayList<>(); - try{ + try { datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> { sqlFileds.add(filed); }); - }catch (Exception e){ + } catch (Exception e) { DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage()); } @@ -1137,11 +1142,11 @@ public class DataSetTableService { .replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString()); datasourceRequest.setQuery(qp.wrapSql(sql)); List sqlFileds = new ArrayList<>(); - try{ + try { datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> { sqlFileds.add(filed); }); - }catch (Exception e){ + } catch (Exception e) { DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage()); } @@ -1186,7 +1191,7 @@ public class DataSetTableService { List excelSheetDataList = parseExcel2(filename, file.getInputStream(), true); List retrunSheetDataList = new ArrayList<>(); - if (StringUtils.isNotEmpty(tableId) && editType == 1 ) { + if (StringUtils.isNotEmpty(tableId) && editType == 1) { List datasetTableFields = dataSetTableFieldsService.getFieldsByTableId(tableId); datasetTableFields.stream().filter(datasetTableField -> datasetTableField.getExtField() == 0).collect(Collectors.toList()); datasetTableFields.sort((o1, o2) -> { @@ -1210,7 +1215,7 @@ public class DataSetTableService { if (retrunSheetDataList.size() == 0) { DataEaseException.throwException(Translator.get("i18n_excel_colume_change")); } - }else { + } else { retrunSheetDataList = excelSheetDataList; } @@ -1223,12 +1228,12 @@ public class DataSetTableService { excelFileData.setPath(filePath); filename = filename.substring(0, filename.lastIndexOf('.')); - if(retrunSheetDataList.size() == 1){ + if (retrunSheetDataList.size() == 1) { retrunSheetDataList.get(0).setDatasetName(filename); retrunSheetDataList.get(0).setSheetExcelId(excelId); retrunSheetDataList.get(0).setId(UUID.randomUUID().toString()); retrunSheetDataList.get(0).setPath(filePath); - }else { + } else { for (ExcelSheetData excelSheetData : retrunSheetDataList) { excelSheetData.setDatasetName(filename + "-" + excelSheetData.getExcelLable()); excelSheetData.setSheetExcelId(excelId); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 289f98b90a..5a6849daf4 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -283,3 +283,4 @@ i18n_change_task_status_error=Suspension is not allowed. The task status is: i18n_Stopped=END 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. diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 5b08fdea68..33d74594b9 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -282,4 +282,5 @@ i18n_change_task_status_error=不允许暂停,任务状态为: i18n_Stopped=执行结束 i18n_Exec=运行中 i18n_no_trigger=当前设置没有触发任务生成 +i18n_dataset_field_delete=该自定义数据集有关联字段被删除,请重新确认关联关系并重做该数据集 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index e4c9d9736b..c8152f773c 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -285,3 +285,4 @@ i18n_change_task_status_error=不允許暫停,任務狀態為: i18n_Stopped=執行結束 i18n_Exec=運行中 i18n_no_trigger=当前设置没有触发任务生成 當前設置沒有觸發任務生成. +i18n_dataset_field_delete=該自定義數據集有關聯字段被刪除,請重新確認關聯關系並重做該數據集