From 419c876f4ffc867b8df3feb1470a028d09a0664b Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 18 May 2022 16:02:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E9=99=84=E4=BB=B6=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1013257 --user=李玉号 【测试跟踪】github#13671,测试用例附件丢失-必现 https://www.tapd.cn/55049933/s/1159858 Closes #13671 --- .../request/testcase/EditTestCaseRequest.java | 2 + .../track/service/TestCaseService.java | 46 ++++++++++--------- .../track/case/components/TestCaseEdit.vue | 3 ++ .../case/components/TestCaseEditOtherInfo.vue | 3 +- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/request/testcase/EditTestCaseRequest.java b/backend/src/main/java/io/metersphere/track/request/testcase/EditTestCaseRequest.java index f8cba8d58d..f7044430e5 100644 --- a/backend/src/main/java/io/metersphere/track/request/testcase/EditTestCaseRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testcase/EditTestCaseRequest.java @@ -20,6 +20,8 @@ public class EditTestCaseRequest extends TestCaseWithBLOBs { */ private List fileIds = new ArrayList<>(); private List> selected = new ArrayList<>(); + // 是否处理附件文件 + private boolean handleAttachment = true; /** * 创建新版本时 是否连带复制其他信息的配置类 diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index f4f7c11cc5..3df9324dab 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -55,6 +55,7 @@ import io.metersphere.xmind.pojo.TestCaseXmindData; import io.metersphere.xmind.utils.XmindExportUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections4.ListUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -1820,30 +1821,33 @@ public class TestCaseService { MSException.throwException(Translator.get("edit_load_test_not_found") + request.getId()); } - // 新选择了一个文件,删除原来的文件 - List updatedFiles = request.getUpdatedFileList(); - List originFiles = fileService.getFileMetadataByCaseId(request.getId()); - List updatedFileIds = updatedFiles.stream().map(FileMetadata::getId).collect(Collectors.toList()); - List originFileIds = originFiles.stream().map(FileMetadata::getId).collect(Collectors.toList()); - // 相减 - List deleteFileIds = ListUtils.subtract(originFileIds, updatedFileIds); - fileService.deleteFileRelatedByIds(deleteFileIds); + if (BooleanUtils.isTrue(request.isHandleAttachment())) { + // 新选择了一个文件,删除原来的文件 + List updatedFiles = request.getUpdatedFileList(); + List originFiles = fileService.getFileMetadataByCaseId(request.getId()); + List updatedFileIds = updatedFiles.stream().map(FileMetadata::getId).collect(Collectors.toList()); + List originFileIds = originFiles.stream().map(FileMetadata::getId).collect(Collectors.toList()); + // 相减 + List deleteFileIds = ListUtils.subtract(originFileIds, updatedFileIds); + fileService.deleteFileRelatedByIds(deleteFileIds); - if (!CollectionUtils.isEmpty(deleteFileIds)) { - TestCaseFileExample testCaseFileExample = new TestCaseFileExample(); - testCaseFileExample.createCriteria().andFileIdIn(deleteFileIds); - testCaseFileMapper.deleteByExample(testCaseFileExample); + if (!CollectionUtils.isEmpty(deleteFileIds)) { + TestCaseFileExample testCaseFileExample = new TestCaseFileExample(); + testCaseFileExample.createCriteria().andFileIdIn(deleteFileIds); + testCaseFileMapper.deleteByExample(testCaseFileExample); + } + + if (files != null) { + files.forEach(file -> { + final FileMetadata fileMetadata = fileService.saveFile(file, testCaseWithBLOBs.getProjectId()); + TestCaseFile testCaseFile = new TestCaseFile(); + testCaseFile.setFileId(fileMetadata.getId()); + testCaseFile.setCaseId(request.getId()); + testCaseFileMapper.insert(testCaseFile); + }); + } } - if (files != null) { - files.forEach(file -> { - final FileMetadata fileMetadata = fileService.saveFile(file, testCaseWithBLOBs.getProjectId()); - TestCaseFile testCaseFile = new TestCaseFile(); - testCaseFile.setFileId(fileMetadata.getId()); - testCaseFile.setCaseId(request.getId()); - testCaseFileMapper.insert(testCaseFile); - }); - } this.setNode(request); return editTestCase(request); } diff --git a/frontend/src/business/components/track/case/components/TestCaseEdit.vue b/frontend/src/business/components/track/case/components/TestCaseEdit.vue index 74ef208668..00156cd73a 100644 --- a/frontend/src/business/components/track/case/components/TestCaseEdit.vue +++ b/frontend/src/business/components/track/case/components/TestCaseEdit.vue @@ -89,6 +89,7 @@ :label-width="formLabelWidth" :case-id="form.id" :type="type" :comments="comments" @openComment="openComment" + :is-click-attachment-tab.sync="isClickAttachmentTab" :version-enable="versionEnable" ref="otherInfo"/> 0 && !id) { return;