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);