diff --git a/backend/src/main/java/io/metersphere/service/FileService.java b/backend/src/main/java/io/metersphere/service/FileService.java index 007213083a..b5ead89244 100644 --- a/backend/src/main/java/io/metersphere/service/FileService.java +++ b/backend/src/main/java/io/metersphere/service/FileService.java @@ -140,7 +140,7 @@ public class FileService { String uploadPath = FileUtils.ATTACHMENT_DIR + "/" + attachmentType + "/" + belongId; File parentFile = new File(uploadPath); if (!parentFile.exists()) { - parentFile.mkdir(); + parentFile.mkdirs(); } try (OutputStream os = new FileOutputStream(uploadPath + "/" + attachmentName)){ InputStream in = new ByteArrayInputStream(bytes); diff --git a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java index 6c8695d8a2..703a77b0bb 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -527,14 +527,15 @@ public class JiraPlatform extends AbstractIssuePlatform { issues.forEach(item -> { try { - getUpdateIssue(item, jiraClientV2.getIssues(item.getPlatformId())); + JiraIssue jiraIssue = jiraClientV2.getIssues(item.getPlatformId()); + getUpdateIssue(item, jiraIssue); String customFields = item.getCustomFields(); // 把自定义字段存入新表 List customFieldResource = customFieldService.getCustomFieldResource(customFields); customFieldMap.put(item.getId(), customFieldResource); issuesMapper.updateByPrimaryKeySelective(item); // 同步第三方平台附件 - syncJiraIssueAttachments(item, jiraClientV2.getIssues(item.getPlatformId())); + syncJiraIssueAttachments(item, jiraIssue); } catch (HttpClientErrorException e) { if (e.getRawStatusCode() == 404) { // 标记成删除 @@ -874,14 +875,17 @@ public class JiraPlatform extends AbstractIssuePlatform { String filename = attachment.getString("filename"); if ((issue.getDescription() == null || !issue.getDescription().contains(filename)) && (issue.getCustomFields() == null || !issue.getCustomFields().contains(filename))) { - String id = attachment.getString("id"); - byte[] content = jiraClientV2.getAttachmentContent(id); - FileAttachmentMetadata fileAttachmentMetadata = fileService.saveAttachmentByBytes(content, AttachmentType.ISSUE.type(), issue.getId(), filename); - AttachmentModuleRelation attachmentModuleRelation = new AttachmentModuleRelation(); - attachmentModuleRelation.setAttachmentId(fileAttachmentMetadata.getId()); - attachmentModuleRelation.setRelationId(issue.getId()); - attachmentModuleRelation.setRelationType(AttachmentType.ISSUE.type()); - attachmentModuleRelationMapper.insert(attachmentModuleRelation); + try { + byte[] content = jiraClientV2.getAttachmentContent(attachment.getString("content")); + FileAttachmentMetadata fileAttachmentMetadata = fileService.saveAttachmentByBytes(content, AttachmentType.ISSUE.type(), issue.getId(), filename); + AttachmentModuleRelation attachmentModuleRelation = new AttachmentModuleRelation(); + attachmentModuleRelation.setAttachmentId(fileAttachmentMetadata.getId()); + attachmentModuleRelation.setRelationId(issue.getId()); + attachmentModuleRelation.setRelationType(AttachmentType.ISSUE.type()); + attachmentModuleRelationMapper.insert(attachmentModuleRelation); + } catch (Exception e) { + LogUtil.error(e); + } } } } diff --git a/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java b/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java index 2145a96618..1edab73d82 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java @@ -257,11 +257,10 @@ public abstract class JiraAbstractClient extends BaseClient { return (JiraIssueListResponse)getResultForObject(JiraIssueListResponse.class, responseEntity); } - public byte[] getAttachmentContent(String contentId) { + public byte[] getAttachmentContent(String url) { ResponseEntity responseEntity; - String url = getBaseUrl() + "/attachment/content/{1}"; responseEntity = restTemplate.exchange(url, - HttpMethod.GET, getAuthHttpEntity(), byte[].class, contentId); + HttpMethod.GET, getAuthHttpEntity(), byte[].class); return responseEntity.getBody(); }