fix:分片上传同名文件覆盖&编辑报告名称为工况+时间戳
This commit is contained in:
@@ -2315,7 +2315,15 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
|||||||
|
|
||||||
SdmResponse<?> existsResponse = ensureFileNotExists(fileMinioObjectKey);
|
SdmResponse<?> existsResponse = ensureFileNotExists(fileMinioObjectKey);
|
||||||
if (!existsResponse.isSuccess()) {
|
if (!existsResponse.isSuccess()) {
|
||||||
|
if (!req.getIsConverSameNameFile()) {
|
||||||
return SdmResponse.failed(existsResponse.getMessage());
|
return SdmResponse.failed(existsResponse.getMessage());
|
||||||
|
} else {
|
||||||
|
// 同名文件覆盖 更新一下时间
|
||||||
|
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getObjectKey, fileMinioObjectKey).one();
|
||||||
|
fileMetadataInfo.setUpdateTime(LocalDateTime.now());
|
||||||
|
fileMetadataInfoService.updateById(fileMetadataInfo);
|
||||||
|
return buildBatchUploadSuccess(originalName, fileMetadataInfo.getId(), uploadFileId, req.getUploadTaskId(), fileMinioObjectKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -2343,19 +2351,23 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
|||||||
bindSimulationPool(req, fileInfo);
|
bindSimulationPool(req, fileInfo);
|
||||||
createFilePermission(fileInfo.getId());
|
createFilePermission(fileInfo.getId());
|
||||||
|
|
||||||
BatchAddFileInfoResp addFileInfoResp = new BatchAddFileInfoResp();
|
return buildBatchUploadSuccess(originalName, fileInfo.getId(), uploadFileId, req.getUploadTaskId(), fileMinioObjectKey);
|
||||||
addFileInfoResp.setSourceFileName(originalName);
|
|
||||||
addFileInfoResp.setBusinessId(fileInfo.getId());
|
|
||||||
addFileInfoResp.setUploadFileId(uploadFileId);
|
|
||||||
addFileInfoResp.setUploadTaskId(req.getUploadTaskId());
|
|
||||||
addFileInfoResp.setObjectKey(fileMinioObjectKey);
|
|
||||||
return SdmResponse.success(addFileInfoResp);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("上传文件失败", e);
|
log.error("上传文件失败", e);
|
||||||
throw new RuntimeException("上传文件失败: " + e.getMessage(), e);
|
throw new RuntimeException("上传文件失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SdmResponse<BatchAddFileInfoResp> buildBatchUploadSuccess(String originalName, Long fileId, String uploadFileId, String uploadTaskId, String fileMinioObjectKey) {
|
||||||
|
BatchAddFileInfoResp addFileInfoResp = new BatchAddFileInfoResp();
|
||||||
|
addFileInfoResp.setSourceFileName(originalName);
|
||||||
|
addFileInfoResp.setBusinessId(fileId);
|
||||||
|
addFileInfoResp.setUploadFileId(uploadFileId);
|
||||||
|
addFileInfoResp.setUploadTaskId(uploadTaskId);
|
||||||
|
addFileInfoResp.setObjectKey(fileMinioObjectKey);
|
||||||
|
return SdmResponse.success(addFileInfoResp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private SdmResponse<FileMetadataInfo> resolveUploadDirectory(UploadFilesReq req) {
|
private SdmResponse<FileMetadataInfo> resolveUploadDirectory(UploadFilesReq req) {
|
||||||
|
|
||||||
|
|||||||
@@ -1162,8 +1162,9 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
|
|||||||
if (!Files.exists(uploadPath)) {
|
if (!Files.exists(uploadPath)) {
|
||||||
Files.createDirectories(uploadPath);
|
Files.createDirectories(uploadPath);
|
||||||
}
|
}
|
||||||
|
String originalFileName = Objects.requireNonNull(file.getOriginalFilename()).replaceAll("\\s", "");
|
||||||
// 生成唯一的文件名
|
// 生成唯一的文件名
|
||||||
String fileName = RandomUtil.generateString(16) + "_" + file.getOriginalFilename();
|
String fileName = RandomUtil.generateString(16) + "_" + originalFileName;
|
||||||
Path filePath = uploadPath.resolve(fileName);
|
Path filePath = uploadPath.resolve(fileName);
|
||||||
// 保存文件
|
// 保存文件
|
||||||
Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|||||||
Reference in New Issue
Block a user