diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 08c36d9281..64e71fa08a 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -34,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Resource; import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; @@ -42,8 +43,6 @@ import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.Collectors; -import javax.annotation.Resource; - @Service @Transactional(rollbackFor = Exception.class) public class PerformanceTestService { @@ -381,6 +380,10 @@ public class PerformanceTestService { if (!CollectionUtils.isEmpty(loadTestFiles)) { loadTestFiles.forEach(loadTestFile -> { FileMetadata fileMetadata = fileService.copyFile(loadTestFile.getFileId()); + if (fileMetadata == null) { + // 如果性能测试出现文件变更,这里会有 null + return; + } loadTestFile.setTestId(copy.getId()); loadTestFile.setFileId(fileMetadata.getId()); loadTestFileMapper.insert(loadTestFile); diff --git a/backend/src/main/java/io/metersphere/service/FileService.java b/backend/src/main/java/io/metersphere/service/FileService.java index 952288f5f8..b82c2f784d 100644 --- a/backend/src/main/java/io/metersphere/service/FileService.java +++ b/backend/src/main/java/io/metersphere/service/FileService.java @@ -60,6 +60,10 @@ public class FileService { FileContentExample example2 = new FileContentExample(); example2.createCriteria().andFileIdIn(ids); fileContentMapper.deleteByExample(example2); + + LoadTestFileExample example3 = new LoadTestFileExample(); + example3.createCriteria().andFileIdIn(ids); + loadTestFileMapper.deleteByExample(example3); } public FileMetadata saveFile(MultipartFile file) {