From 0b8ad47f631f0fd5d6f721b81c1c2541d8d6aab6 Mon Sep 17 00:00:00 2001 From: Gary Date: Fri, 15 Mar 2024 07:15:01 +0800 Subject: [PATCH] 1.update comment component --- .../comment/controller/CommentController.java | 18 +++++++++++++----- .../java/com/luoo/comment/pojo/UserInfo.java | 4 ++++ 2 files changed, 17 insertions(+), 5 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 fe15d5d..b998249 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 @@ -35,6 +35,7 @@ import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; import util.IdWorker; +import util.StringTools; import javax.servlet.http.HttpServletRequest; import java.util.*; @@ -191,7 +192,7 @@ public class CommentController extends BaseController { UserInfo commentUserInfo = userInfoService.findById(comment.getUserId()); comment.setNickName(commentUserInfo.getNickName()); - comment.setAvatar(Constants.RESOURCE_PREFIX+commentUserInfo.getAvatar()); + comment.setAvatar(getAvatar(commentUserInfo)); if(StringUtils.isNotEmpty(comment.getReplyToUserId())){ UserInfo replyToUserInfo = userInfoService.findById(comment.getReplyToUserId()); comment.setReplyToNickname(replyToUserInfo.getNickName()); @@ -211,7 +212,7 @@ public class CommentController extends BaseController { Comment topComment = commentService.findByParentId(comment.get_id(),1,1).getContent().get(0); UserInfo topCommentUserInfo = userInfoService.findById(topComment.getUserId()); topComment.setNickName(topCommentUserInfo.getNickName()); - topComment.setAvatar(Constants.RESOURCE_PREFIX+topCommentUserInfo.getAvatar()); + topComment.setAvatar(getAvatar(topCommentUserInfo)); if(StringUtils.isNotEmpty(topComment.getReplyToUserId())){ UserInfo topReplyUserInfo = userInfoService.findById(topComment.getReplyToUserId()); topComment.setReplyToNickname(topReplyUserInfo.getNickName()); @@ -228,13 +229,20 @@ public class CommentController extends BaseController { - private CommentResp getCommentResp(Comment comment) { + private String getAvatar(UserInfo commentUserInfo) { + if(StringTools.isEmpty(commentUserInfo.getThumbnail())) { + return Constants.RESOURCE_PREFIX+commentUserInfo.getAvatar(); + } + return Constants.RESOURCE_PREFIX+commentUserInfo.getThumbnail(); + } + + private CommentResp getCommentResp(Comment comment) { UserInfo commentUserInfo = userInfoService.findById(comment.getUserId()); comment.setNickName(commentUserInfo.getNickName()); - comment.setAvatar(Constants.RESOURCE_PREFIX+commentUserInfo.getAvatar()); + comment.setAvatar(getAvatar(commentUserInfo)); if(StringUtils.isNotEmpty(comment.getReplyToUserId())){ UserInfo replyToUserInfo = userInfoService.findById(comment.getReplyToUserId()); @@ -255,7 +263,7 @@ public class CommentController extends BaseController { Comment topComment = commentService.findByParentId(comment.get_id(),1,1).getContent().get(0); UserInfo topCommentUserInfo = userInfoService.findById(topComment.getUserId()); topComment.setNickName(topCommentUserInfo.getNickName()); - topComment.setAvatar(Constants.RESOURCE_PREFIX+topCommentUserInfo.getAvatar()); + topComment.setAvatar(getAvatar(topCommentUserInfo)); if(StringUtils.isNotEmpty(topComment.getReplyToUserId())){ UserInfo topReplyUserInfo = userInfoService.findById(topComment.getReplyToUserId()); topComment.setReplyToNickname(topReplyUserInfo.getNickName()); diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/UserInfo.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/UserInfo.java index 4b1cb47..bbdbfd5 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/pojo/UserInfo.java +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/UserInfo.java @@ -39,6 +39,10 @@ public class UserInfo implements Serializable { * 头像 */ private String avatar; + /** + * 头像缩略图 200X200 + */ + private String thumbnail; /** * 个性签名 */