From 396ed75b403d66fa9dffaf4888f137d0c29c0201 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Thu, 29 Aug 2024 19:07:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=8A=E4=BC=A0excel=E5=87=BA?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/server/DatasourceServer.java | 26 +++++++++++++++++-- .../extensions/datasource/dto/TableField.java | 3 ++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java index d4c2fa8a94..cb83fe5337 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java @@ -65,6 +65,10 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.util.*; import java.util.stream.Collectors; @@ -850,6 +854,25 @@ public class DatasourceServer implements DatasourceApi { datasourceSyncManage.extractedData(null, coreDatasource, updateType, MANUAL.toString()); } + public static List deepCopy(List originalList) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(originalList); + oos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bis); + List newList = (List) ois.readObject(); + ois.close(); + + return newList; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + public ExcelFileData excelUpload(@RequestParam("file") MultipartFile file, @RequestParam("id") long datasourceId, @RequestParam("editType") Integer editType) throws DEException { ExcelUtils excelUtils = new ExcelUtils(); ExcelFileData excelFileData = excelUtils.excelSaveAndParse(file); @@ -863,11 +886,10 @@ public class DatasourceServer implements DatasourceApi { for (ExcelSheetData sheet : excelFileData.getSheets()) { for (DatasetTableDTO datasetTableDTO : datasetTableDTOS) { if (excelDataTableName(datasetTableDTO.getTableName()).equals(sheet.getTableName()) || isCsv(file.getOriginalFilename())) { - List newTableFields = sheet.getFields(); + List newTableFields = deepCopy(sheet.getFields()); newTableFields.sort((o1, o2) -> { return o1.getName().compareTo(o2.getName()); }); - datasourceRequest.setTable(datasetTableDTO.getTableName()); List oldTableFields = ExcelUtils.getTableFields(datasourceRequest); oldTableFields.sort((o1, o2) -> { diff --git a/sdk/extensions/extensions-datasource/src/main/java/io/dataease/extensions/datasource/dto/TableField.java b/sdk/extensions/extensions-datasource/src/main/java/io/dataease/extensions/datasource/dto/TableField.java index fb2474b6c2..d504956ae6 100644 --- a/sdk/extensions/extensions-datasource/src/main/java/io/dataease/extensions/datasource/dto/TableField.java +++ b/sdk/extensions/extensions-datasource/src/main/java/io/dataease/extensions/datasource/dto/TableField.java @@ -2,11 +2,12 @@ package io.dataease.extensions.datasource.dto; import lombok.Data; +import java.io.Serializable; import java.util.List; @Data -public class TableField { +public class TableField implements Serializable { private String name; private String originName; private String type; //SQL type from java.sql.Types