From 8c0f963d726fc6410d4a46c945f954078c1b2a3d Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 27 Mar 2023 16:34:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=BC=BA=E9=99=B7=E9=99=84=E4=BB=B6=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8=E8=BF=87=E5=A4=A7?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4OOM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1024770 --user=陈建星 [测试跟踪]同步JIRA缺陷失败,页面一致转圈后服务挂了 https://www.tapd.cn/55049933/s/1356110 --- pom.xml | 2 +- .../service/AttachmentService.java | 9 +++---- .../io/metersphere/service/IssuesService.java | 24 ++++++++++--------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index be0d4ae4af..dbd63dcf5a 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 17 2022.0.1 2.7.18 - 1.4.0 + 1.5.0 1.11.0 1.5.3 3.1.1 diff --git a/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java b/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java index 310a78833d..287f8d3480 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java @@ -468,17 +468,18 @@ public class AttachmentService { return fileAttachmentMetadata; } - public FileAttachmentMetadata saveAttachmentByBytes(byte[] bytes, String attachmentType, String belongId, String attachmentName) { + public FileAttachmentMetadata saveAttachmentByBytes(InputStream in, String attachmentType, String belongId, String attachmentName) { String uploadPath = FileUtils.ATTACHMENT_DIR + "/" + attachmentType + "/" + belongId; File parentFile = new File(uploadPath); if (!parentFile.exists()) { parentFile.mkdirs(); } try (OutputStream os = new FileOutputStream(uploadPath + "/" + attachmentName)) { - InputStream in = new ByteArrayInputStream(bytes); - int len = 0; + int total = 0; + int len; byte[] buf = new byte[1024]; while ((len = in.read(buf)) != -1) { + total += len; os.write(buf, 0, len); } os.flush(); @@ -487,7 +488,7 @@ public class AttachmentService { fileAttachmentMetadata.setId(UUID.randomUUID().toString()); fileAttachmentMetadata.setName(attachmentName); fileAttachmentMetadata.setType(getFileTypeWithoutEnum(attachmentName)); - fileAttachmentMetadata.setSize(Integer.valueOf(bytes.length).longValue()); + fileAttachmentMetadata.setSize(Integer.valueOf(total).longValue()); fileAttachmentMetadata.setCreateTime(System.currentTimeMillis()); fileAttachmentMetadata.setUpdateTime(System.currentTimeMillis()); fileAttachmentMetadata.setCreator(SessionUtils.getUser().getName()); diff --git a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java index 23d88b0737..190569f5a6 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java @@ -1135,17 +1135,19 @@ public class IssuesService { String fileName, String fileKey, AttachmentModuleRelationMapper batchAttachmentModuleRelationMapper) { try { - byte[] content = platform.getAttachmentContent(fileKey); - if (content == null) { - return; - } - FileAttachmentMetadata fileAttachmentMetadata = attachmentService - .saveAttachmentByBytes(content, AttachmentType.ISSUE.type(), issueId, fileName); - AttachmentModuleRelation attachmentModuleRelation = new AttachmentModuleRelation(); - attachmentModuleRelation.setAttachmentId(fileAttachmentMetadata.getId()); - attachmentModuleRelation.setRelationId(issueId); - attachmentModuleRelation.setRelationType(AttachmentType.ISSUE.type()); - batchAttachmentModuleRelationMapper.insert(attachmentModuleRelation); + platform.getAttachmentContent(fileKey, (in) -> { + if (in == null) { + return; + } + FileAttachmentMetadata fileAttachmentMetadata = attachmentService + .saveAttachmentByBytes(in, AttachmentType.ISSUE.type(), issueId, fileName); + AttachmentModuleRelation attachmentModuleRelation = new AttachmentModuleRelation(); + attachmentModuleRelation.setAttachmentId(fileAttachmentMetadata.getId()); + attachmentModuleRelation.setRelationId(issueId); + attachmentModuleRelation.setRelationType(AttachmentType.ISSUE.type()); + batchAttachmentModuleRelationMapper.insert(attachmentModuleRelation); + }); + } catch (Exception e) { LogUtil.error(e); }