From 94ec9cf0ca5e9a2d9db66299095aa75b2f868363 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Tue, 29 Oct 2024 14:57:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E4=B8=B4=E6=97=B6=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1047792 --user=宋昌昌 【缺陷管理】编辑缺陷-点击更新按钮-报SQL异常 https://www.tapd.cn/55049933/s/1600345 --- .../bug/service/BugAttachmentService.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java index 75d3cdbc0f..2983c81eda 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java @@ -622,9 +622,13 @@ public class BugAttachmentService { // 添加文件与功能用例的关联关系 Map addFileMap = Maps.newHashMapWithExpectedSize(8); LogUtils.info("开始上传富文本里的附件"); - List localAttachments = fileIds.stream().map(fileId -> { - BugLocalAttachment localAttachment = new BugLocalAttachment(); + List localAttachments = new ArrayList<>(); + for (String fileId : fileIds) { String fileName = getTempFileNameByFileId(fileId); + if (StringUtils.isEmpty(fileName)) { + continue; + } + BugLocalAttachment localAttachment = new BugLocalAttachment(); localAttachment.setId(IDGenerator.nextStr()); localAttachment.setBugId(bugId); localAttachment.setFileId(fileId); @@ -643,10 +647,11 @@ public class BugAttachmentService { localAttachment.setCreateUser(userId); localAttachment.setCreateTime(System.currentTimeMillis()); addFileMap.put(fileId, fileName); - return localAttachment; - }).toList(); - List normalAttachments = localAttachments.stream().filter(attachment -> StringUtils.isNotEmpty(attachment.getFileName())).toList(); - bugLocalAttachmentMapper.batchInsert(normalAttachments); + localAttachments.add(localAttachment); + } + if (!CollectionUtils.isEmpty(localAttachments)) { + bugLocalAttachmentMapper.batchInsert(localAttachments); + } // 上传文件到对象存储 LogUtils.info("upload to minio start"); String bugDir = DefaultRepositoryDir.getBugDir(projectId, bugId);