fix(性能测试): 修复性能测试删除文件的时候导致其他测试不能引用相同文件的问题

This commit is contained in:
Captain.B 2021-05-11 18:55:16 +08:00 committed by 刘瑞斌
parent 2a365bd210
commit 39e3bcddd3
1 changed files with 9 additions and 6 deletions

View File

@ -222,16 +222,17 @@ public class PerformanceTestService {
public String edit(EditTestPlanRequest request, List<MultipartFile> files) { public String edit(EditTestPlanRequest request, List<MultipartFile> files) {
checkQuota(request, false); checkQuota(request, false);
// //
LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(request.getId()); String testId = request.getId();
LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(testId);
if (loadTest == null) { if (loadTest == null) {
MSException.throwException(Translator.get("edit_load_test_not_found") + request.getId()); MSException.throwException(Translator.get("edit_load_test_not_found") + testId);
} }
if (StringUtils.containsAny(loadTest.getStatus(), PerformanceTestStatus.Running.name(), PerformanceTestStatus.Starting.name())) { if (StringUtils.containsAny(loadTest.getStatus(), PerformanceTestStatus.Running.name(), PerformanceTestStatus.Starting.name())) {
MSException.throwException(Translator.get("cannot_edit_load_test_running")); MSException.throwException(Translator.get("cannot_edit_load_test_running"));
} }
// 新选择了一个文件删除原来的文件 // 新选择了一个文件删除原来的文件
List<FileMetadata> updatedFiles = request.getUpdatedFileList(); List<FileMetadata> updatedFiles = request.getUpdatedFileList();
List<FileMetadata> originFiles = getFileMetadataByTestId(request.getId()); List<FileMetadata> originFiles = getFileMetadataByTestId(testId);
List<String> updatedFileIds = updatedFiles.stream().map(FileMetadata::getId).collect(Collectors.toList()); List<String> updatedFileIds = updatedFiles.stream().map(FileMetadata::getId).collect(Collectors.toList());
List<String> originFileIds = originFiles.stream().map(FileMetadata::getId).collect(Collectors.toList()); List<String> originFileIds = originFiles.stream().map(FileMetadata::getId).collect(Collectors.toList());
@ -240,13 +241,15 @@ public class PerformanceTestService {
// 删除已经不相关的文件 // 删除已经不相关的文件
if (!CollectionUtils.isEmpty(deleteFileIds)) { if (!CollectionUtils.isEmpty(deleteFileIds)) {
LoadTestFileExample example3 = new LoadTestFileExample(); LoadTestFileExample example3 = new LoadTestFileExample();
example3.createCriteria().andFileIdIn(deleteFileIds); example3.createCriteria()
.andFileIdIn(deleteFileIds)
.andTestIdEqualTo(testId);
loadTestFileMapper.deleteByExample(example3); loadTestFileMapper.deleteByExample(example3);
} }
// 导入项目里其他的文件 // 导入项目里其他的文件
List<String> addFileIds = ListUtils.subtract(updatedFileIds, originFileIds); List<String> addFileIds = ListUtils.subtract(updatedFileIds, originFileIds);
this.importFiles(addFileIds, request.getId(), request.getFileSorts()); this.importFiles(addFileIds, testId, request.getFileSorts());
// 处理新上传的文件 // 处理新上传的文件
this.saveUploadFiles(files, loadTest, request.getFileSorts()); this.saveUploadFiles(files, loadTest, request.getFileSorts());
@ -260,7 +263,7 @@ public class PerformanceTestService {
loadTest.setStatus(PerformanceTestStatus.Saved.name()); loadTest.setStatus(PerformanceTestStatus.Saved.name());
loadTestMapper.updateByPrimaryKeySelective(loadTest); loadTestMapper.updateByPrimaryKeySelective(loadTest);
return request.getId(); return testId;
} }
@Transactional(noRollbackFor = MSException.class)// 保存失败的信息 @Transactional(noRollbackFor = MSException.class)// 保存失败的信息