From 2dcae3d146be662a0897bcd12d77ba4e44c7ecbc Mon Sep 17 00:00:00 2001 From: taojinlong Date: Tue, 28 Sep 2021 18:48:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=9B=E5=BB=BAMySQL=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90=E6=97=B6=E5=87=BA=E7=8E=B0=20Public=20Key=20?= =?UTF-8?q?Retrieval=20is=20not=20allowed=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/utils/ExcelReaderUtil.java | 14 +++++++---- .../commons/utils/ExcelXlsxReader.java | 24 +++++++++++++------ .../datasource/dto/MysqlConfigration.java | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/io/dataease/commons/utils/ExcelReaderUtil.java b/backend/src/main/java/io/dataease/commons/utils/ExcelReaderUtil.java index c2f80fbdff..0f866bd233 100644 --- a/backend/src/main/java/io/dataease/commons/utils/ExcelReaderUtil.java +++ b/backend/src/main/java/io/dataease/commons/utils/ExcelReaderUtil.java @@ -1,6 +1,7 @@ package io.dataease.commons.utils; import com.google.gson.Gson; import io.dataease.datasource.dto.TableFiled; +import org.apache.poi.hssf.usermodel.HSSFCell; import java.io.FileInputStream; import java.io.InputStream; @@ -56,8 +57,9 @@ public class ExcelReaderUtil { } else if (fileName.endsWith(EXCEL07_EXTENSION)) {//处理excel2007文件 ExcelXlsxReader excelXlsxReader = new ExcelXlsxReader(); excelXlsxReader.process(inputStream); - System.out.println(excelXlsxReader.totalSheets.size()); - System.out.println(excelXlsxReader.totalSheets.get(0).getExcelLable()); + + System.out.println(excelXlsxReader.totalSheets.get(0).getFields().size()); + for (TableFiled field : excelXlsxReader.totalSheets.get(0).getFields()) { System.out.println(new Gson().toJson(field)); } @@ -68,8 +70,10 @@ public class ExcelReaderUtil { } } - /* public static void main(String[] args) throws Exception { - String file ="Metersphere_case_DataEase功能用例.xlsx"; + public static void main(String[] args) throws Exception { + + + String file ="各省市GDP-表格_加内容.xlsx"; ExcelReaderUtil.readExcel(file, new FileInputStream("/Users/taojinlong/Desktop/" + file)); - } */ + } } diff --git a/backend/src/main/java/io/dataease/commons/utils/ExcelXlsxReader.java b/backend/src/main/java/io/dataease/commons/utils/ExcelXlsxReader.java index b77f582877..ce95f235e8 100644 --- a/backend/src/main/java/io/dataease/commons/utils/ExcelXlsxReader.java +++ b/backend/src/main/java/io/dataease/commons/utils/ExcelXlsxReader.java @@ -234,7 +234,7 @@ public class ExcelXlsxReader extends DefaultHandler { return; } //t元素也包含字符串 - if (isTElement) {//这个程序没经过 + if (isTElement) { //这个程序没经过 //将单元格内容加入rowlist中,在这之前先去掉字符串前后的空白符 String value = lastIndex.trim(); if(curRow==1){ @@ -271,6 +271,9 @@ public class ExcelXlsxReader extends DefaultHandler { for (int i = 0; i < len; i++) { if(curCol < this.fields.size()){ cellList.add(curCol, ""); + if(curRow==1){ + addField("", curCol); + } curCol++; } } @@ -413,12 +416,7 @@ public class ExcelXlsxReader extends DefaultHandler { break; } if(curRow==1){ - TableFiled tableFiled = new TableFiled(); - tableFiled.setFieldType("TEXT"); - tableFiled.setFieldSize(65533); - tableFiled.setFieldName(thisStr); - tableFiled.setRemarks(thisStr); - this.fields.add(tableFiled); + addField(thisStr, null); }else { if(CollectionUtils.isEmpty(this.getFields())){ throw new RuntimeException(Translator.get("i18n_excel_header_empty")); @@ -443,6 +441,18 @@ public class ExcelXlsxReader extends DefaultHandler { return thisStr; } + private void addField(String columeName, Integer index){ + TableFiled tableFiled = new TableFiled(); + tableFiled.setFieldType("TEXT"); + tableFiled.setFieldSize(65533); + tableFiled.setFieldName(columeName); + tableFiled.setRemarks(columeName); + if(index != null){ + this.fields.add(index, tableFiled); + }else { + this.fields.add(tableFiled); + } + } private String getType(String thisStr){ if(totalRows==0){ return "TEXT"; diff --git a/backend/src/main/java/io/dataease/datasource/dto/MysqlConfigration.java b/backend/src/main/java/io/dataease/datasource/dto/MysqlConfigration.java index fcaeec3906..04ed6a2b0b 100644 --- a/backend/src/main/java/io/dataease/datasource/dto/MysqlConfigration.java +++ b/backend/src/main/java/io/dataease/datasource/dto/MysqlConfigration.java @@ -11,7 +11,7 @@ public class MysqlConfigration extends JdbcDTO { public String getJdbc() { // 连接参数先写死,后边要把编码、时区等参数放到数据源的设置中 - return "jdbc:mysql://HOSTNAME:PORT/DATABASE?characterEncoding=UTF-8&connectTimeout=5000&useSSL=false" + return "jdbc:mysql://HOSTNAME:PORT/DATABASE?characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true" .replace("HOSTNAME", getHost().trim()) .replace("PORT", getPort().toString().trim()) .replace("DATABASE", getDataBase().trim());