From 80c4cedb7f0bf3a570802305559270b8954a9593 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Wed, 1 Mar 2023 16:43:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=B2=BE=E7=AE=80=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=8A=BD=E5=8F=96csv=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/mysql/MysqlDDLProvider.java | 6 +---- .../service/dataset/ExtractDataService.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/dataease/provider/engine/mysql/MysqlDDLProvider.java b/backend/src/main/java/io/dataease/provider/engine/mysql/MysqlDDLProvider.java index 019da6d96e..259169b614 100644 --- a/backend/src/main/java/io/dataease/provider/engine/mysql/MysqlDDLProvider.java +++ b/backend/src/main/java/io/dataease/provider/engine/mysql/MysqlDDLProvider.java @@ -56,11 +56,7 @@ public class MysqlDDLProvider extends DDLProviderImpl { Integer size = datasetTableField.getSize() * 4; switch (datasetTableField.getDeExtractType()) { case 0: - if (size < 65533) { - Column_Fields.append("varchar(length)".replace("length", String.valueOf(datasetTableField.getSize()))).append(",`"); - }else { - Column_Fields.append("longtext").append(",`"); - } + Column_Fields.append("longtext").append(",`"); break; case 1: size = size < 50? 50 : size; diff --git a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java index e539ae10c8..9e2982175b 100644 --- a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java +++ b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java @@ -741,6 +741,33 @@ public class ExtractDataService { totalSheets = excelXlsxReader.totalSheets; } + if (StringUtils.equalsIgnoreCase(suffix, "csv")) { + List fields = new ArrayList<>(); + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(excelSheetData.getPath()), StandardCharsets.UTF_8)); + String s = reader.readLine();// first line + String[] split = s.split(","); + for (String s1 : split) { + TableField tableFiled = new TableField(); + tableFiled.setFieldName(s1); + tableFiled.setRemarks(s1); + tableFiled.setFieldType("TEXT"); + fields.add(tableFiled); + } + List> csvData = new ArrayList<>(); + String line; + while ((line = reader.readLine()) != null) { + csvData.add(Arrays.asList(line.split(","))); + } + ExcelSheetData csvSheetData = new ExcelSheetData(); + String[] fieldArray = fields.stream().map(TableField::getFieldName).toArray(String[]::new); + csvSheetData.setFields(fields); + csvSheetData.setData(csvData); + csvSheetData.setExcelLabel(excelSheetData.getExcelLabel()); + csvSheetData.setFieldsMd5(Md5Utils.md5(StringUtils.join(fieldArray, ","))); + totalSheets = Arrays.asList(csvSheetData); + } + + for (ExcelSheetData sheet : totalSheets) { if (sheet.getExcelLabel().equalsIgnoreCase(excelSheetData.getExcelLabel())) { for (List dataItem : sheet.getData()) {