refactor(缺陷管理): 优化缺陷评论返回

This commit is contained in:
song-cc-rock 2024-01-10 15:32:37 +08:00 committed by 刘瑞斌
parent 7edeaa06c4
commit 26e48a6319
5 changed files with 29 additions and 29 deletions

View File

@ -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<OptionDTO> notifierOption;
@Schema(description = "评论相关用户信息")
private List<CommentUserInfo> commentUserInfos;
@Schema(description = "子评论")
private List<BugCommentDTO> childComments;

View File

@ -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<BugComment> bugComments = bugCommentMapper.selectByExample(example);
return this.generateCommentDTOs(bugComments);
return generateCommentDTOs(bugComments);
}
/**
@ -67,10 +66,13 @@ public class BugCommentService {
List<BugCommentDTO> 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<CommentUserInfo> 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<OptionDTO> getNotifyUserOption(String notifier, Map<String, CommentUserInfo> userMap) {
private List<CommentUserInfo> getNotifyUserInfo(String notifier, Map<String, CommentUserInfo> userMap) {
List<CommentUserInfo> notifyUserInfos = new ArrayList<>();
if (StringUtils.isBlank(notifier)) {
return new ArrayList<>();
}
List<String> 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;
}
/**

View File

@ -269,7 +269,7 @@ public class FunctionalCaseCommentService {
*/
private Map<String, CommentUserInfo> getUserMap(List<String> userIds) {
List<CommentUserInfo> commentUserInfos = baseUserMapper.getCommentUserInfoByIds(userIds);
return commentUserInfos.stream().collect(Collectors.toMap(User::getId, item -> item));
return commentUserInfos.stream().collect(Collectors.toMap(CommentUserInfo::getId, item -> item));
}
/**

View File

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

View File

@ -123,7 +123,7 @@
</select>
<select id="getCommentUserInfoByIds" resultType="io.metersphere.system.dto.CommentUserInfo">
SELECT u.*, ue.avatar as avatar
SELECT u.id, u.name, u.email, ue.avatar as avatar
FROM user u left join user_extend ue on u.id = ue.id
WHERE u.id IN
<foreach collection="ids" item="id" index="index"