From 48ed6218545bf899e9c6f98857ef23c95df9450d Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 12 Jul 2021 17:24:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=BD=E5=8A=A0/=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20excel=20=E6=95=B0=E6=8D=AE=E9=9B=86=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=88=97=E5=90=8D=E4=B8=8E=E5=8E=9F=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataset/DataSetTableController.java | 4 ++-- .../service/dataset/DataSetTableService.java | 20 +++++++++++++++++- .../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/AddExcel.vue | 21 +++++++++++++++---- 6 files changed, 43 insertions(+), 9 deletions(-) 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 @@