From 89a53aa006a4100111c43e2901968706e1b97dcb Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Sun, 7 Apr 2024 00:56:12 +0800 Subject: [PATCH] fix commentList avatar errors --- .../comment/controller/CommentController.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) 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 6d65573..a7dbb4e 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 @@ -194,21 +194,27 @@ public class CommentController extends BaseController { comment.setHaveThumbup(isExists); // UserInfo commentUserInfo = userInfoService.findById(comment.getUserId()); - comment.setNickName(commentUserInfo.getNickName()); - comment.setAvatar(getAvatar(commentUserInfo)); - if(StringUtils.isNotEmpty(comment.getReplyToUserId())){ - UserInfo replyToUserInfo = userInfoService.findById(comment.getReplyToUserId()); - comment.setReplyToNickname(replyToUserInfo.getNickName()); + if(null != commentUserInfo) { + comment.setNickName(commentUserInfo.getNickName()); + comment.setAvatar(getAvatar(commentUserInfo)); + if(StringUtils.isNotEmpty(comment.getReplyToUserId())){ + UserInfo replyToUserInfo = userInfoService.findById(comment.getReplyToUserId()); + 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)); + if (null!= commentUserInfo) { + 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){ @@ -254,8 +260,8 @@ public class CommentController extends BaseController { CommentResp commentResp = new CommentResp(); BeanUtils.copyProperties(comment,commentResp); if (null != commentUserInfo) { - comment.setNickName(commentUserInfo.getNickName()); - comment.setAvatar(getAvatar(commentUserInfo)); + commentResp.setNickName(commentUserInfo.getNickName()); + commentResp.setAvatar(getAvatar(commentUserInfo)); if (StringUtils.isNotEmpty(commentUserInfo.getBadges())){ Set badgeSet = new HashSet<>(); Arrays.stream(commentUserInfo.getBadges().split(",")).forEach(b->{