From 26e48a63197e7aa4098fbe8d1d4b00bfc51189a1 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Wed, 10 Jan 2024 15:32:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E7=BC=BA=E9=99=B7=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bug/dto/response/BugCommentDTO.java | 11 ++----- .../bug/service/BugCommentService.java | 29 ++++++++++--------- .../service/FunctionalCaseCommentService.java | 2 +- .../system/dto/CommentUserInfo.java | 14 ++++++--- .../system/mapper/BaseUserMapper.xml | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/response/BugCommentDTO.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/response/BugCommentDTO.java index 644a103d17..343899957a 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/response/BugCommentDTO.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/response/BugCommentDTO.java @@ -2,7 +2,6 @@ package io.metersphere.bug.dto.response; import io.metersphere.bug.domain.BugComment; import io.metersphere.system.dto.CommentUserInfo; -import io.metersphere.system.dto.sdk.OptionDTO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -13,14 +12,8 @@ import java.util.List; @EqualsAndHashCode(callSuper = false) public class BugCommentDTO extends BugComment { - @Schema(description = "评论人信息") - private CommentUserInfo commentUserInfo; - - @Schema(description = "回复人名称") - private String replyUserName; - - @Schema(description = "@通知人集合") - private List notifierOption; + @Schema(description = "评论相关用户信息") + private List commentUserInfos; @Schema(description = "子评论") private List childComments; diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentService.java index 4446bded39..1eb81a7754 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentService.java @@ -12,7 +12,6 @@ import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.CommentUserInfo; -import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.mapper.BaseUserMapper; import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.uid.IDGenerator; @@ -48,7 +47,7 @@ public class BugCommentService { BugCommentExample example = new BugCommentExample(); example.createCriteria().andBugIdEqualTo(bugId); List bugComments = bugCommentMapper.selectByExample(example); - return this.generateCommentDTOs(bugComments); + return generateCommentDTOs(bugComments); } /** @@ -67,10 +66,13 @@ public class BugCommentService { List bugCommentDTOList = bugComments.stream().map(bugComment -> { BugCommentDTO commentDTO = new BugCommentDTO(); BeanUtils.copyBean(commentDTO, bugComment); - commentDTO.setReplyUserName(StringUtils.isNotEmpty(bugComment.getReplyUser()) ? - userMap.get(bugComment.getReplyUser()).getName() : null); - commentDTO.setCommentUserInfo(userMap.get(bugComment.getCreateUser())); - commentDTO.setNotifierOption(getNotifyUserOption(bugComment.getNotifier(), userMap)); + List commentUserInfos = new ArrayList<>(); + commentUserInfos.add(userMap.get(bugComment.getCreateUser())); + if (StringUtils.isNotEmpty(bugComment.getReplyUser())) { + commentUserInfos.add(userMap.get(bugComment.getReplyUser())); + } + commentUserInfos.addAll(getNotifyUserInfo(bugComment.getNotifier(), userMap)); + commentDTO.setCommentUserInfos(commentUserInfos); return commentDTO; }).toList(); @@ -284,17 +286,16 @@ public class BugCommentService { * @param userMap 用户信息Map * @return 通知人选项 */ - private List getNotifyUserOption(String notifier, Map userMap) { + private List getNotifyUserInfo(String notifier, Map userMap) { + List notifyUserInfos = new ArrayList<>(); if (StringUtils.isBlank(notifier)) { return new ArrayList<>(); } - List notifyUserIds = Arrays.asList(notifier.split(";")); - return userMap.values().stream().filter(user -> notifyUserIds.contains(user.getId())).map(user -> { - OptionDTO optionDTO = new OptionDTO(); - optionDTO.setId(user.getId()); - optionDTO.setName(user.getName()); - return optionDTO; - }).toList(); + String[] notifyUserIds = notifier.split(";"); + for (String notifyUserId : notifyUserIds) { + notifyUserInfos.add(userMap.get(notifyUserId)); + } + return notifyUserInfos; } /** diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCommentService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCommentService.java index ebd602d7dc..caa64dc8ec 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCommentService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCommentService.java @@ -269,7 +269,7 @@ public class FunctionalCaseCommentService { */ private Map getUserMap(List userIds) { List commentUserInfos = baseUserMapper.getCommentUserInfoByIds(userIds); - return commentUserInfos.stream().collect(Collectors.toMap(User::getId, item -> item)); + return commentUserInfos.stream().collect(Collectors.toMap(CommentUserInfo::getId, item -> item)); } /** diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/CommentUserInfo.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/CommentUserInfo.java index cfe0a6a6a5..9c55e6c470 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/CommentUserInfo.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/CommentUserInfo.java @@ -1,13 +1,19 @@ package io.metersphere.system.dto; -import io.metersphere.system.domain.User; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; @Data -@EqualsAndHashCode(callSuper = false) -public class CommentUserInfo extends User { +public class CommentUserInfo{ + + @Schema(description = "用户ID") + private String id; + + @Schema(description = "用户名") + private String name; + + @Schema(description = "用户邮箱") + private String email; @Schema(description = "用户头像") private String avatar; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.xml index efd7baf4a2..228a977a7b 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/BaseUserMapper.xml @@ -123,7 +123,7 @@