mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 10:29:19 +08:00
fix(order-import): 支持从OSS读取CSV文件
问题:订单导入任务上传文件改用OSS后,后端处理时仍尝试从本地文件系统读取文件 解决: 1. 在 OssService 中新增 downloadFile 和 getFileAsStream 方法 2. 在 ImportTaskProcessorServiceImpl 中: - 优先从本地文件系统读取CSV - 本地文件不存在时,视为OSS存储路径,从OSS下载到临时文件后再处理 - 使用 BufferedInputStream 包装以支持编码检测时的 mark/reset 操作 3. detectFileEncoding 方法改为接受 InputStream 参数
This commit is contained in:
+17
@@ -51,5 +51,22 @@ public interface OssService {
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean fileExists(String storagePath);
|
||||
|
||||
/**
|
||||
* 从OSS下载文件到本地临时文件
|
||||
*
|
||||
* @param storagePath 存储路径/Key
|
||||
* @param localFile 本地目标文件
|
||||
* @return 是否下载成功
|
||||
*/
|
||||
boolean downloadFile(String storagePath, java.io.File localFile);
|
||||
|
||||
/**
|
||||
* 获取OSS文件的输入流
|
||||
*
|
||||
* @param storagePath 存储路径/Key
|
||||
* @return 文件输入流(使用完后需自行关闭),如果失败返回null
|
||||
*/
|
||||
java.io.InputStream getFileAsStream(String storagePath);
|
||||
}
|
||||
|
||||
|
||||
+25
@@ -299,5 +299,30 @@ public class OssServiceImpl implements OssService {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean downloadFile(String storagePath, java.io.File localFile) {
|
||||
if (ossClient == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ossClient.getObject(ossConfig.getBucketName(), storagePath, localFile);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.io.InputStream getFileAsStream(String storagePath) {
|
||||
if (ossClient == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return ossClient.getObject(ossConfig.getBucketName(), storagePath).getObjectContent();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user