refactor: 修改uploadFile方法参数类型为File
- 将LsfxAnalysisClient.uploadFile方法参数从MultipartFile改为File - 在LsfxTestController中添加MultipartFile到File的转换逻辑 - 使用临时文件处理转换,并在finally块中自动清理
This commit is contained in:
@@ -15,8 +15,8 @@ import jakarta.annotation.Resource;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -109,8 +109,8 @@ public class LsfxAnalysisClient {
|
|||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传文件
|
||||||
*/
|
*/
|
||||||
public UploadFileResponse uploadFile(Integer groupId, MultipartFile file) {
|
public UploadFileResponse uploadFile(Integer groupId, File file) {
|
||||||
log.info("【流水分析】上传文件请求: groupId={}, fileName={}", groupId, file.getOriginalFilename());
|
log.info("【流水分析】上传文件请求: groupId={}, fileName={}", groupId, file.getName());
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ import jakarta.annotation.Resource;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流水分析平台接口测试控制器
|
* 流水分析平台接口测试控制器
|
||||||
*/
|
*/
|
||||||
@@ -76,8 +82,28 @@ public class LsfxTestController {
|
|||||||
return AjaxResult.error("文件大小超过限制:最大10MB");
|
return AjaxResult.error("文件大小超过限制:最大10MB");
|
||||||
}
|
}
|
||||||
|
|
||||||
UploadFileResponse response = lsfxAnalysisClient.uploadFile(groupId, file);
|
// 将 MultipartFile 转换为 File
|
||||||
return AjaxResult.success(response);
|
Path tempFile = null;
|
||||||
|
try {
|
||||||
|
// 创建临时文件
|
||||||
|
tempFile = Files.createTempFile("upload_", "_" + file.getOriginalFilename());
|
||||||
|
Files.copy(file.getInputStream(), tempFile, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
|
File convertedFile = tempFile.toFile();
|
||||||
|
UploadFileResponse response = lsfxAnalysisClient.uploadFile(groupId, convertedFile);
|
||||||
|
return AjaxResult.success(response);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return AjaxResult.error("文件转换失败:" + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
// 删除临时文件
|
||||||
|
if (tempFile != null) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(tempFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// 忽略删除失败
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "拉取行内流水", description = "从数仓拉取行内流水数据")
|
@Operation(summary = "拉取行内流水", description = "从数仓拉取行内流水数据")
|
||||||
|
|||||||
Reference in New Issue
Block a user