fix:算例文件归档

This commit is contained in:
2026-02-26 15:50:58 +08:00
parent a8785a7d7b
commit f07412bb05
7 changed files with 59 additions and 8 deletions

View File

@@ -0,0 +1 @@
ALTER TABLE spdm_baseline.simulation_run_key_result MODIFY COLUMN runId varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' NULL COMMENT '所属Run UUID';

View File

@@ -301,8 +301,8 @@ public class DataClientFeignClientImpl implements IDataFeignClient {
}
@Override
public SdmResponse copyFileToTask(CopyFileToTaskReq req) {
SdmResponse response;
public SdmResponse<Long> copyFileToTask(CopyFileToTaskReq req) {
SdmResponse<Long> response;
try {
response = dataClient.copyFileToTask(req);
return response;

View File

@@ -108,5 +108,5 @@ public interface IDataFeignClient {
SdmResponse<byte[]> getMultipartFileByFileId(@RequestParam(value = "fileId") @Validated Long fileId);
@PostMapping("/data/copyFileToTask")
SdmResponse copyFileToTask(@RequestBody CopyFileToTaskReq req);
SdmResponse<Long> copyFileToTask(@RequestBody CopyFileToTaskReq req);
}

View File

@@ -709,7 +709,7 @@ public class DataFileController implements IDataFeignClient {
@PostMapping("/copyFileToTask")
@Operation(summary = "复制关键结果文件到task下", description = "复制关键结果文件到task下")
public SdmResponse copyFileToTask(@RequestBody CopyFileToTaskReq req) {
public SdmResponse<Long> copyFileToTask(@RequestBody CopyFileToTaskReq req) {
return IDataFileService.copyFileToTask(req);
}

View File

@@ -412,7 +412,7 @@ public interface IDataFileService {
SdmResponse<List<BatchAddFileInfoResp>> batchAddFileInfo(UploadFilesReq req);
SdmResponse copyFileToTask(CopyFileToTaskReq req);
SdmResponse<Long> copyFileToTask(CopyFileToTaskReq req);
SdmResponse<ChunkUploadMinioFileResp> chunkUploadToMinio(ChunkUploadMinioFileReq req);

View File

@@ -1610,7 +1610,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
}
@Override
public SdmResponse copyFileToTask(CopyFileToTaskReq req) {
public SdmResponse<Long> copyFileToTask(CopyFileToTaskReq req) {
// 源文件
FileMetadataInfo sourceMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getId, req.getSourceFileId()).one();
if (ObjectUtils.isEmpty(sourceMetadataInfo)) {
@@ -1647,7 +1647,15 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
FileMetadataInfo fileInfo = createFileMetadata(newDirMinioObjectKey, sourceMetadataInfo.getOriginalName(),
null, null, null, targetParentMetadataInfo.getId(), sourceMetadataInfo.getFileSize(), sourceMetadataInfo.getTag1());
fileMetadataInfoService.save(fileInfo);
return SdmResponse.success("复制文件成功");
UploadFilesReq uploadFilesReq = new UploadFilesReq();
uploadFilesReq.setSize(sourceMetadataInfo.getFileSize());
List<Long> ancestorDirIds = collectAncestorDirIds(targetParentMetadataInfo.getId());
saveFileStorageStats(fileInfo, uploadFilesReq, ancestorDirIds);
saveCopyFileTags(uploadFilesReq, fileInfo, sourceMetadataInfo, ancestorDirIds);
createFilePermission(fileInfo.getId());
return SdmResponse.success(fileInfo.getId());
} catch (Exception e) {
log.error("复制文件失败", e);
throw new RuntimeException("复制文件失败: " + e.getMessage(), e);
@@ -2305,6 +2313,38 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
}
}
private void saveCopyFileTags(UploadFilesReq req, FileMetadataInfo fileInfo, FileMetadataInfo oldFileInfo,
List<Long> ancestorDirIds) {
Long tenantId = ThreadLocalContext.getTenantId();
Long creatorId = ThreadLocalContext.getUserId();
long fileSize = resolveFileSize(req);
// 旧文件的标签
List<FileTagRel> oldTagRelList = fileTagRelService.lambdaQuery().eq(FileTagRel::getFileId, oldFileInfo.getId()).list();
if (CollectionUtils.isNotEmpty(oldTagRelList)) {
List<FileTagRel> allTagRelList = new ArrayList<>();
List<Integer> tagIdList = oldTagRelList.stream().map(FileTagRel::getTagId).distinct().toList();
for (Integer tagId : tagIdList) {
// 遍历查询结果,构造文件标签关系
// 为所有目录(当前目录 + 祖先目录)创建标签关系
for (Long dirIdItem : ancestorDirIds) {
FileTagRel tagRel = new FileTagRel();
tagRel.setFileId(fileInfo.getId());
tagRel.setTagId(tagId);
tagRel.setDirId(dirIdItem);
tagRel.setTenantId(tenantId);
tagRel.setCreatorId(creatorId);
tagRel.setFileSize(fileSize);
allTagRelList.add(tagRel);
}
}
// 一次性批量插入所有标签关系
if (CollectionUtils.isNotEmpty(allTagRelList)) {
fileTagRelService.saveBatch(allTagRelList);
}
}
}
private void bindSimulationPool(UploadFilesReq req, FileMetadataInfo fileInfo) {

View File

@@ -2640,6 +2640,7 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
} else {
// 归档关键结果
if (CollectionUtils.isNotEmpty(req.getKeyResultIdList())) {
List<SimulationRunKeyResult> taskKeyResultList = new ArrayList<>();
for (String keyResultId : req.getKeyResultIdList()) {
SimulationRunKeyResult keyResult = simulationKeyResultService.lambdaQuery().eq(SimulationRunKeyResult::getUuid, keyResultId).one();
if (keyResult == null) {
@@ -2658,11 +2659,20 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
}
Long parentDirId = getParentDirId(simulationRun.getTaskId(), dirName);
copyFileToTaskReq.setParentDirId(parentDirId);
SdmResponse response = dataFeignClient.copyFileToTask(copyFileToTaskReq);
SdmResponse<Long> response = dataFeignClient.copyFileToTask(copyFileToTaskReq);
if (!response.isSuccess()) {
return SdmResponse.failed("归档关键结果文件失败");
}
// 同时归档一份keyResult到表里因为任务下的曲线预览也需要展示物理量和单位
SimulationRunKeyResult simulationRunKeyResult = new SimulationRunKeyResult();
BeanUtils.copyProperties(keyResult, simulationRunKeyResult);
simulationRunKeyResult.setId(null);
simulationRunKeyResult.setUuid(RandomUtil.generateString(32));
simulationRunKeyResult.setRunId(null);
simulationRunKeyResult.setFileId(response.getData());
taskKeyResultList.add(simulationRunKeyResult);
}
simulationKeyResultService.saveBatch(taskKeyResultList);
}
} else {
// 将算例下的指标分析值同步到任务指标