diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/service/impl/ImportTaskProcessorServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/service/impl/ImportTaskProcessorServiceImpl.java index 9b8577d4..1c0416f7 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/service/impl/ImportTaskProcessorServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/service/impl/ImportTaskProcessorServiceImpl.java @@ -309,60 +309,62 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic // 读取CSV文件 // 通过 fileId 从统一文件系统获取文件信息,根据存储类型读取文件 File csvFile = null; - InputStream fileInputStream = null; + File tempOssFile = null; // 仅当从OSS下载时使用,用于后续清理 - // 获取文件信息 - SysFileVO fileInfo = sysFileService.getFileById(task.getFileId()); - if (fileInfo == null) { - throw new BusinessException("文件不存在,fileId: " + task.getFileId()); - } - - String storagePath = fileInfo.getStoragePath(); - String storageType = fileInfo.getStorageType(); - - if ("local".equals(storageType)) { - // 本地存储:使用 storagePath 作为本地文件路径 - File localFile = new File(storagePath); - if (localFile.exists() && localFile.isFile()) { - fileInputStream = new java.io.BufferedInputStream(new java.io.FileInputStream(localFile)); - csvFile = localFile; + try { + // 获取文件信息 + SysFileVO fileInfo = sysFileService.getFileById(task.getFileId()); + if (fileInfo == null) { + throw new BusinessException("文件不存在,fileId: " + task.getFileId()); + } + + String storagePath = fileInfo.getStoragePath(); + String storageType = fileInfo.getStorageType(); + InputStream fileInputStream; + + if ("local".equals(storageType)) { + // 本地存储:使用 storagePath 作为本地文件路径 + File localFile = new File(storagePath); + if (localFile.exists() && localFile.isFile()) { + fileInputStream = new java.io.BufferedInputStream(new java.io.FileInputStream(localFile)); + csvFile = localFile; + } else { + throw new BusinessException("本地文件不存在: " + storagePath); + } } else { - throw new BusinessException("本地文件不存在: " + storagePath); + // 对象存储(oss/s3/qiniu/cos等):从 OSS 下载到临时文件 + tempOssFile = java.io.File.createTempFile("import-csv-", ".csv"); + + if (!ossService.downloadFile(storagePath, tempOssFile)) { + throw new BusinessException("从对象存储下载文件失败,storagePath: " + storagePath); + } + + csvFile = tempOssFile; + fileInputStream = new java.io.BufferedInputStream(new java.io.FileInputStream(tempOssFile)); } - } else { - // 对象存储(oss/s3/qiniu/cos等):从 OSS 下载到临时文件 - File tempFile = java.io.File.createTempFile("import-csv-", ".csv"); + + // 获取默认订单状态ID(尝试查找"未知状态",如果不存在则使用第一个状态) + Long defaultStatusId = getDefaultOrderStatusId(companyId); + + int totalCount = 0; + int successCount = 0; + int failCount = 0; + StringBuilder errorMessages = new StringBuilder(); + long lastProgressNotifyAt = 0L; + + // 尝试多种编码读取CSV文件(常见的中文编码) + java.nio.charset.Charset charset = detectFileEncoding(fileInputStream); - if (!ossService.downloadFile(storagePath, tempFile)) { - throw new BusinessException("从对象存储下载文件失败,storagePath: " + storagePath); - } - - csvFile = tempFile; - fileInputStream = new java.io.BufferedInputStream(new java.io.FileInputStream(tempFile)); - } - - // 获取默认订单状态ID(尝试查找"未知状态",如果不存在则使用第一个状态) - Long defaultStatusId = getDefaultOrderStatusId(companyId); - - int totalCount = 0; - int successCount = 0; - int failCount = 0; - StringBuilder errorMessages = new StringBuilder(); - long lastProgressNotifyAt = 0L; - - // 尝试多种编码读取CSV文件(常见的中文编码) - java.nio.charset.Charset charset = detectFileEncoding(fileInputStream); - - try (java.io.InputStreamReader reader = new java.io.InputStreamReader(fileInputStream, charset); - CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT.builder() - .setHeader() - .setSkipHeaderRecord(true) - .setIgnoreHeaderCase(true) - .setTrim(true) // 自动去除表头和值的前后空格 - .build())) { + try (java.io.InputStreamReader reader = new java.io.InputStreamReader(fileInputStream, charset); + CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT.builder() + .setHeader() + .setSkipHeaderRecord(true) + .setIgnoreHeaderCase(true) + .setTrim(true) // 自动去除表头和值的前后空格 + .build())) { - List records = csvParser.getRecords(); + List records = csvParser.getRecords(); totalCount = records.size(); // 更新总行数 @@ -415,6 +417,12 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic successCount += flushResult[0]; failCount += flushResult[1]; } + } finally { + // 清理:从OSS下载的临时文件需要手动删除 + if (tempOssFile != null && tempOssFile.exists()) { + tempOssFile.delete(); + } + } // 更新最终状态 String finalStatus = failCount == 0 ? "success" : (successCount > 0 ? "success" : "failed"); diff --git a/ecom-dmb-frontend/apps/web-antd/public/cd-logo.png b/ecom-dmb-frontend/apps/web-antd/public/cd-logo.png new file mode 100755 index 00000000..ff9e78fd Binary files /dev/null and b/ecom-dmb-frontend/apps/web-antd/public/cd-logo.png differ