diff --git a/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java b/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java index 0f51a4ccc3..37d921e8d4 100644 --- a/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java +++ b/backend/src/main/java/io/dataease/controller/dataset/DataSetTableController.java @@ -100,8 +100,8 @@ public class DataSetTableController { } @PostMapping("excel/upload") - public Map excelUpload(@RequestParam("file") MultipartFile file) throws Exception { - return dataSetTableService.excelSaveAndParse(file); + public Map excelUpload(@RequestParam("file") MultipartFile file, @RequestParam("tableId") String tableId) throws Exception { + return dataSetTableService.excelSaveAndParse(file, tableId); } @PostMapping("checkDorisTableIsExists/{id}") 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 afdb254598..e3ed924526 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -878,10 +878,28 @@ public class DataSetTableService { return map; } - public Map excelSaveAndParse(MultipartFile file) throws Exception { + public Map excelSaveAndParse(MultipartFile file, String tableId) throws Exception { String filename = file.getOriginalFilename(); // parse file Map fileMap = parseExcel(filename, file.getInputStream(), true); + if(StringUtils.isNotEmpty(tableId)){ + List datasetTableFields = dataSetTableFieldsService.getFieldsByTableId(tableId); + datasetTableFields.sort((o1, o2) -> { + if (o1.getColumnIndex() == null) { + return -1; + } + if (o2.getColumnIndex() == null) { + return 1; + } + return o1.getColumnIndex().compareTo(o2.getColumnIndex()); + }); + List fields = (List)fileMap.get("fields"); + List newFields = fields.stream().map(TableFiled::getRemarks).collect(Collectors.toList()); + List oldFields = datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList()); + if (!oldFields.equals(newFields)) { + DataEaseException.throwException(Translator.get("i18n_excel_colume_change")); + } + } // save file String filePath = saveFile(file); Map map = new HashMap<>(fileMap); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 9265246666..d35e0339e4 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -272,4 +272,5 @@ i18n_msg_type_panel_share_cacnel=Dashboard unshared i18n_msg_type_dataset_sync=Data set synchronization i18n_msg_type_dataset_sync_success=Dataset synchronization successful i18n_msg_type_dataset_sync_faild=Dataset synchronization failed -i18n_data_not_sync=Please sync data first \ No newline at end of file +i18n_data_not_sync=Please sync data first +i18n_excel_colume_change=The column name of Excel is inconsistent with the original data set \ 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 afd2b013fe..7ecab9c880 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -272,3 +272,4 @@ i18n_msg_type_dataset_sync=数据集同步 i18n_msg_type_dataset_sync_success=数据集同步成功 i18n_msg_type_dataset_sync_faild=数据集同步失败 i18n_data_not_sync=请先完成数据同步 +i18n_excel_colume_change=Excel的列名与原数据集不一致 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 8edc897158..5a9fc0845c 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -274,4 +274,5 @@ i18n_msg_type_panel_share_cacnel=儀表板取消分享 i18n_msg_type_dataset_sync=數據集同步 i18n_msg_type_dataset_sync_success=數據集同步成功 i18n_msg_type_dataset_sync_faild=數據集同步失敗 -i18n_data_not_sync=請先完成數據同步 \ No newline at end of file +i18n_data_not_sync=請先完成數據同步 +i18n_excel_colume_change=Excel的列名與原數據集不一致 \ No newline at end of file diff --git a/frontend/src/views/dataset/add/AddExcel.vue b/frontend/src/views/dataset/add/AddExcel.vue index 434abebf60..b12d8bbe3f 100644 --- a/frontend/src/views/dataset/add/AddExcel.vue +++ b/frontend/src/views/dataset/add/AddExcel.vue @@ -28,6 +28,7 @@ :multiple="false" :show-file-list="false" :file-list="fileList" + :data="param" accept=".xls,.xlsx," :before-upload="beforeUpload" :on-success="uploadSuccess" @@ -80,6 +81,7 @@