From 15a0da3b7343dedd238dd1bf0ecbaf076efcbb26 Mon Sep 17 00:00:00 2001 From: MeterSphere Bot <78466014+metersphere-bot@users.noreply.github.com> Date: Tue, 20 Sep 2022 13:45:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=85=B3=E8=81=94=E7=AC=AC=E4=B8=89=E6=96=B9=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=20(#18075)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016957,1016945,1016941,1016938 --user=宋昌昌 【测试跟踪】测试用例-关联文件报错 https://www.tapd.cn/55049933/s/1246636 Co-authored-by: song-cc-rock --- .../metersphere/track/service/AttachmentService.java | 11 +++++++++-- .../io/metersphere/track/service/IssuesService.java | 7 ++++--- .../io/metersphere/track/service/TestCaseService.java | 4 ++-- .../components/track/issue/IssueEditDetail.vue | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/service/AttachmentService.java b/backend/src/main/java/io/metersphere/track/service/AttachmentService.java index 9d9c036c38..cc7a879c95 100644 --- a/backend/src/main/java/io/metersphere/track/service/AttachmentService.java +++ b/backend/src/main/java/io/metersphere/track/service/AttachmentService.java @@ -253,8 +253,8 @@ public class AttachmentService { FileAttachmentMetadata fileAttachmentMetadata = new FileAttachmentMetadata(); BeanUtils.copyBean(fileAttachmentMetadata, fileMetadata); fileAttachmentMetadata.setId(record.getAttachmentId()); - fileAttachmentMetadata.setCreator(fileMetadata.getCreateUser()); - fileAttachmentMetadata.setFilePath(fileMetadata.getPath()); + fileAttachmentMetadata.setCreator(fileMetadata.getCreateUser() == null ? "" : fileMetadata.getCreateUser()); + fileAttachmentMetadata.setFilePath(fileMetadata.getPath() == null ? "" : fileMetadata.getPath()); fileAttachmentMetadataBatchMapper.insert(fileAttachmentMetadata); // 缺陷类型的附件, 关联时需单独同步第三方平台 if (AttachmentType.ISSUE.type().equals(request.getBelongType())) { @@ -296,6 +296,13 @@ public class AttachmentService { example.createCriteria().andRelationIdEqualTo(request.getBelongId()) .andRelationTypeEqualTo(request.getBelongType()) .andAttachmentIdIn(request.getMetadataRefIds()); + List relations = attachmentModuleRelationMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(relations)) { + List refIds = relations.stream().map(AttachmentModuleRelation::getFileMetadataRefId).collect(Collectors.toList()); + FileAssociationExample associationExample = new FileAssociationExample(); + associationExample.createCriteria().andIdIn(refIds); + fileAssociationMapper.deleteByExample(associationExample); + } FileAttachmentMetadataExample exampleAttachment = new FileAttachmentMetadataExample(); exampleAttachment.createCriteria().andIdIn(request.getMetadataRefIds()); fileAttachmentMetadataMapper.deleteByExample(exampleAttachment); diff --git a/backend/src/main/java/io/metersphere/track/service/IssuesService.java b/backend/src/main/java/io/metersphere/track/service/IssuesService.java index f822177261..f42d818836 100644 --- a/backend/src/main/java/io/metersphere/track/service/IssuesService.java +++ b/backend/src/main/java/io/metersphere/track/service/IssuesService.java @@ -139,6 +139,7 @@ public class IssuesService { attachmentService.copyAttachment(attachmentRequest); } else { final String issueId = issues.getId(); + final String platform = issues.getPlatform(); // 新增, 需保存并同步所有待上传的附件 if (CollectionUtils.isNotEmpty(files)) { files.forEach(file -> { @@ -174,14 +175,14 @@ public class IssuesService { FileAttachmentMetadata fileAttachmentMetadata = new FileAttachmentMetadata(); BeanUtils.copyBean(fileAttachmentMetadata, fileMetadata); fileAttachmentMetadata.setId(relation.getAttachmentId()); - fileAttachmentMetadata.setCreator(fileMetadata.getCreateUser()); - fileAttachmentMetadata.setFilePath(fileMetadata.getPath()); + fileAttachmentMetadata.setCreator(fileMetadata.getCreateUser() == null ? "" : fileMetadata.getCreateUser()); + fileAttachmentMetadata.setFilePath(fileMetadata.getPath() == null ? "" : fileMetadata.getPath()); fileAttachmentMetadataBatchMapper.insert(fileAttachmentMetadata); // 下载文件管理文件, 同步到第三方平台 File refFile = attachmentService.downloadMetadataFile(filemetaId, fileMetadata.getName()); IssuesRequest addIssueRequest = new IssuesRequest(); addIssueRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); - Objects.requireNonNull(IssueFactory.createPlatform(issuesRequest.getPlatform(), addIssueRequest)) + Objects.requireNonNull(IssueFactory.createPlatform(platform, addIssueRequest)) .syncIssuesAttachment(issuesRequest, refFile, AttachmentSyncType.UPLOAD); FileUtils.deleteFile(FileUtils.ATTACHMENT_TMP_DIR + File.separator + fileMetadata.getName()); }); 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 69e3347c6d..fa5ae8a881 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -2130,8 +2130,8 @@ public class TestCaseService { FileAttachmentMetadata fileAttachmentMetadata = new FileAttachmentMetadata(); BeanUtils.copyBean(fileAttachmentMetadata, fileMetadata); fileAttachmentMetadata.setId(record.getAttachmentId()); - fileAttachmentMetadata.setCreator(fileMetadata.getCreateUser()); - fileAttachmentMetadata.setFilePath(fileMetadata.getPath()); + fileAttachmentMetadata.setCreator(fileMetadata.getCreateUser() == null ? "" : fileMetadata.getCreateUser()); + fileAttachmentMetadata.setFilePath(fileMetadata.getPath() == null ? "" : fileMetadata.getPath()); fileAttachmentMetadataBatchMapper.insert(fileAttachmentMetadata); }); sqlSession.flushStatements(); diff --git a/frontend/src/business/components/track/issue/IssueEditDetail.vue b/frontend/src/business/components/track/issue/IssueEditDetail.vue index 6bac1202d0..2b16cac6b8 100644 --- a/frontend/src/business/components/track/issue/IssueEditDetail.vue +++ b/frontend/src/business/components/track/issue/IssueEditDetail.vue @@ -840,7 +840,7 @@ export default { } } if (!repeatRecord) { - if (this.type === 'add') { + if (this.type === 'add' || this.isCaseEdit) { // 新增 rows.forEach(row => { this.relateFiles.push(row.id);