From fe92ca1d102dff72733e16fd6405daefdc153be7 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Wed, 12 Mar 2025 16:28:52 +0800 Subject: [PATCH] Pr@dev v2@fixexcel (#15319) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix:[Bug]汇总表分享的公共链接下载成Excel打开乱码 #15254 * fix:修复excel 表头支持数值 * fix:【数据源】远程数据源中文名称无法加载 --------- Co-authored-by: taojinlong --- .../datasource/provider/ExcelUtils.java | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/datasource/provider/ExcelUtils.java b/core/core-backend/src/main/java/io/dataease/datasource/provider/ExcelUtils.java index 9231adcc0f..f354ee0276 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/provider/ExcelUtils.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/provider/ExcelUtils.java @@ -762,42 +762,31 @@ public class ExcelUtils { DEException.throwException("无效的地址!"); } } - if (StringUtils.isNotEmpty(remoteExcelRequest.getUserName()) && StringUtils.isNotEmpty(remoteExcelRequest.getPasswd())) { - username = remoteExcelRequest.getUserName(); - password = remoteExcelRequest.getPasswd(); - } filePath = filePath.startsWith("/") ? filePath.substring(1) : filePath; - int port = 21; String suffix = filePath.substring(filePath.lastIndexOf(".") + 1); + if (!Arrays.asList("csv", "xlsx", "xls").contains(suffix)) { + DEException.throwException("不支持的文件格式!"); + } String tranName = UUID.randomUUID().toString() + "." + suffix; String localFilePath = path + tranName; fileNames.put("fileName", filePath); fileNames.put("tranName", tranName); - FTPClient ftpClient = new FTPClient(); + try { - ftpClient.setConnectTimeout(5 * 1000); - ftpClient.connect(serverAddress, port); - ftpClient.login(username, password); - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTP.BINARY_FILE_TYPE); - File localFile = new File(localFilePath); - try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(localFile))) { - boolean success = ftpClient.retrieveFile(filePath, outputStream); - if (!success) { - DEException.throwException("文件下载失败!"); - } + String command = "curl -o " + localFilePath; // 在Unix/Linux系统中 + if (StringUtils.isNotEmpty(remoteExcelRequest.getUserName()) && StringUtils.isNotEmpty(remoteExcelRequest.getPasswd())) { + command = command + " -u " + remoteExcelRequest.getUserName() + ":" + remoteExcelRequest.getPasswd(); + } + command = command + " " + remoteExcelRequest.getUrl(); + Process process = Runtime.getRuntime().exec(command); + int exitValue = process.waitFor(); + if (exitValue != 0) { + DEException.throwException("文件下载失败!"); } } catch (IOException e) { - DEException.throwException(e); - } finally { - try { - if (ftpClient.isConnected()) { - ftpClient.logout(); - ftpClient.disconnect(); - } - } catch (IOException e) { - e.printStackTrace(); - } + e.printStackTrace(); + } catch (InterruptedException e) { + throw new RuntimeException(e); } return fileNames; }