From 5dc30b41cfa82cd33de9b39c78e5a3e5212b79a3 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Fri, 8 Mar 2024 23:51:05 +0800 Subject: [PATCH] feat: comment user badges --- .../comment/controller/CommentController.java | 17 +++++++++++++++++ .../java/com/luoo/comment/pojo/CommentResp.java | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index 245e95d..93785c3 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -197,6 +197,14 @@ public class CommentController extends BaseController { comment.setReplyToNickname(replyToUserInfo.getNickName()); } CommentResp commentResp = new CommentResp(); + if (StringUtils.isNotEmpty(commentUserInfo.getBadges())){ + Set badgeSet = new HashSet<>(); + Arrays.stream(commentUserInfo.getBadges().split(",")).forEach(b->{ + int code=Integer.valueOf(b.substring(0, 1)); + badgeSet.add(code); + }); + commentResp.setBadgeList(new ArrayList<>(badgeSet)); + } BeanUtils.copyProperties(comment,commentResp); if(comment.getCommentCount()>0){ @@ -227,12 +235,21 @@ public class CommentController extends BaseController { UserInfo commentUserInfo = userInfoService.findById(comment.getUserId()); comment.setNickName(commentUserInfo.getNickName()); comment.setAvatar(Constants.RESOURCE_PREFIX+commentUserInfo.getAvatar()); + if(StringUtils.isNotEmpty(comment.getReplyToUserId())){ UserInfo replyToUserInfo = userInfoService.findById(comment.getReplyToUserId()); comment.setReplyToNickname(replyToUserInfo.getNickName()); } CommentResp commentResp = new CommentResp(); BeanUtils.copyProperties(comment,commentResp); + if (StringUtils.isNotEmpty(commentUserInfo.getBadges())){ + Set badgeSet = new HashSet<>(); + Arrays.stream(commentUserInfo.getBadges().split(",")).forEach(b->{ + int code=Integer.valueOf(b.substring(0, 1)); + badgeSet.add(code); + }); + commentResp.setBadgeList(new ArrayList<>(badgeSet)); + } if(comment.getCommentCount()>0){ Comment topComment = commentService.findByParentId(comment.get_id(),1,1).getContent().get(0); diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentResp.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentResp.java index 711ae77..e492286 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentResp.java +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentResp.java @@ -2,11 +2,13 @@ package com.luoo.comment.pojo; import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.util.Date; +import java.util.List; @Data public class CommentResp implements Serializable { @@ -60,4 +62,7 @@ public class CommentResp implements Serializable { private String replyToNickname; private Comment topChildrenComment; + + @ApiModelProperty(value = "用户标识,贡献者:1 ") + private List badgeList; }