Commit 0b2384c0 by 段启岩

Merge remote-tracking branch 'origin/fix-issue#42'

parents 962fac72 bdc8c62a
package cn.meteor.beyondclouds.modules.post.listener; package cn.meteor.beyondclouds.modules.post.listener;
import cn.meteor.beyondclouds.core.listener.DataItemChangeListener; import cn.meteor.beyondclouds.core.listener.DataItemChangeListener;
import cn.meteor.beyondclouds.modules.post.service.IPostCommentService;
import cn.meteor.beyondclouds.modules.post.service.IPostService;
import cn.meteor.beyondclouds.modules.queue.message.DataItemChangeMessage; import cn.meteor.beyondclouds.modules.queue.message.DataItemChangeMessage;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
...@@ -13,8 +16,30 @@ import org.springframework.stereotype.Component; ...@@ -13,8 +16,30 @@ import org.springframework.stereotype.Component;
@Component("postUserInfoChangeListener") @Component("postUserInfoChangeListener")
public class UserInfoChangeListener extends DataItemChangeListener { public class UserInfoChangeListener extends DataItemChangeListener {
private IPostService postService;
private IPostCommentService postCommentService;
@Autowired
public UserInfoChangeListener(IPostService postService, IPostCommentService postCommentService) {
this.postService = postService;
this.postCommentService = postCommentService;
}
@Override @Override
public void onUserAvatarUpdate(DataItemChangeMessage dataItemChangeMessage) { public void onUserAvatarUpdate(DataItemChangeMessage dataItemChangeMessage) {
String userId = String.valueOf(dataItemChangeMessage.getItemId());
postService.updatePostUserAvatar(userId);
postCommentService.updatePostUserAvatar(userId);
log.debug("post-用户头像更新:{}", dataItemChangeMessage); log.debug("post-用户头像更新:{}", dataItemChangeMessage);
}
@Override
public void onUserNickUpdate(DataItemChangeMessage dataItemChangeMessage) {
String userId = String.valueOf(dataItemChangeMessage.getItemId());
postService.updatePostUserNick(userId);
postCommentService.updatePostUserNick(userId);
log.debug("post-用户昵称更新:{}", dataItemChangeMessage);
} }
} }
...@@ -46,4 +46,15 @@ public interface IPostCommentService extends IService<PostComment> { ...@@ -46,4 +46,15 @@ public interface IPostCommentService extends IService<PostComment> {
IPage<PostComment> getCommentPage(Integer pageNumber, Integer size, String postId, Integer parentId) throws PostCommentServiceException; IPage<PostComment> getCommentPage(Integer pageNumber, Integer size, String postId, Integer parentId) throws PostCommentServiceException;
/**
* 更新动态评论里面的用户头像
* @param userId
*/
void updatePostUserAvatar(String userId);
/**
* 更新动态评论里的用户昵称
* @param userId
*/
void updatePostUserNick(String userId);
} }
...@@ -46,4 +46,16 @@ public interface IPostService extends IService<Post> { ...@@ -46,4 +46,16 @@ public interface IPostService extends IService<Post> {
* @return * @return
*/ */
IPage<Post> getUserPostPage (Integer pageNumber , Integer pageSize , String userId); IPage<Post> getUserPostPage (Integer pageNumber , Integer pageSize , String userId);
/**
* 更新动态里的用户头像
* @param userId
*/
void updatePostUserAvatar(String userId);
/**
* 更新动态里的用户昵称
* @param userId
*/
void updatePostUserNick(String userId);
} }
...@@ -12,6 +12,7 @@ import cn.meteor.beyondclouds.modules.post.service.IPostService; ...@@ -12,6 +12,7 @@ import cn.meteor.beyondclouds.modules.post.service.IPostService;
import cn.meteor.beyondclouds.modules.user.entity.User; import cn.meteor.beyondclouds.modules.user.entity.User;
import cn.meteor.beyondclouds.modules.user.service.IUserService; import cn.meteor.beyondclouds.modules.user.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -167,4 +168,30 @@ public class PostCommentServiceImpl extends ServiceImpl<PostCommentMapper, PostC ...@@ -167,4 +168,30 @@ public class PostCommentServiceImpl extends ServiceImpl<PostCommentMapper, PostC
return page(page,postCommentQueryWrapper); return page(page,postCommentQueryWrapper);
} }
/**
* 更新动态评论里的用户头像
* @param userId
*/
@Override
public void updatePostUserAvatar(String userId) {
User user = userService.getById(userId);
if(null != user){
UpdateWrapper<PostComment> postUpdateWrapper = new UpdateWrapper<>();
postUpdateWrapper.eq("user_id", userId);
postUpdateWrapper.set("user_avatar", user.getUserAvatar());
update(postUpdateWrapper);
}
}
@Override
public void updatePostUserNick(String userId) {
User user = userService.getById(userId);
if(null != user){
UpdateWrapper<PostComment> postUpdateWrapper = new UpdateWrapper<>();
postUpdateWrapper.eq("user_id", userId);
postUpdateWrapper.set("user_nick", user.getNickName());
update(postUpdateWrapper);
}
}
} }
package cn.meteor.beyondclouds.modules.post.service.impl; package cn.meteor.beyondclouds.modules.post.service.impl;
import cn.meteor.beyondclouds.modules.post.entity.Post; import cn.meteor.beyondclouds.modules.post.entity.Post;
import cn.meteor.beyondclouds.modules.post.entity.PostComment;
import cn.meteor.beyondclouds.modules.post.enums.PostErrorCode; import cn.meteor.beyondclouds.modules.post.enums.PostErrorCode;
import cn.meteor.beyondclouds.modules.post.exception.PostServiceException; import cn.meteor.beyondclouds.modules.post.exception.PostServiceException;
import cn.meteor.beyondclouds.modules.post.mapper.PostMapper; import cn.meteor.beyondclouds.modules.post.mapper.PostMapper;
...@@ -9,6 +10,7 @@ import cn.meteor.beyondclouds.modules.project.exception.ProjectServiceException; ...@@ -9,6 +10,7 @@ import cn.meteor.beyondclouds.modules.project.exception.ProjectServiceException;
import cn.meteor.beyondclouds.modules.user.entity.User; import cn.meteor.beyondclouds.modules.user.entity.User;
import cn.meteor.beyondclouds.modules.user.service.IUserService; import cn.meteor.beyondclouds.modules.user.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -125,5 +127,36 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -125,5 +127,36 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
return page(postPage, queryWrapper); return page(postPage, queryWrapper);
} }
/**
* 更新动态里的用户头像
* @param userId
*/
@Override
public void updatePostUserAvatar(String userId) {
User user = userService.getById(userId);
if(null != user){
UpdateWrapper<Post> postUpdateWrapper = new UpdateWrapper<>();
postUpdateWrapper.eq("user_id", userId);
postUpdateWrapper.set("user_avatar", user.getUserAvatar());
update(postUpdateWrapper);
}
}
/**
* 更新动态里的用户昵称
* @param userId
*/
@Override
public void updatePostUserNick(String userId) {
User user = userService.getById(userId);
if(null != user){
UpdateWrapper<Post> postUpdateWrapper = new UpdateWrapper<>();
postUpdateWrapper.eq("user_id", userId);
postUpdateWrapper.set("user_nick", user.getNickName());
update(postUpdateWrapper);
}
}
} }
...@@ -5,7 +5,7 @@ spring: ...@@ -5,7 +5,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username: root username: root
password: 100Centa30821%mysql password: 2018006709
# 邮箱 # 邮箱
mail: mail:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment