Commit 3bcf6618 by 胡学良

增加用户昵称头像更新

parent 5fe06029
package cn.meteor.beyondclouds.modules.question.listener; package cn.meteor.beyondclouds.modules.question.listener;
import cn.meteor.beyondclouds.core.listener.DataItemChangeListener; import cn.meteor.beyondclouds.core.listener.DataItemChangeListener;
import cn.meteor.beyondclouds.modules.question.service.IQuestionReplyCommentService;
import cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService;
import cn.meteor.beyondclouds.modules.question.service.IQuestionService;
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 +17,37 @@ import org.springframework.stereotype.Component; ...@@ -13,8 +17,37 @@ import org.springframework.stereotype.Component;
@Component("questionUserInfoChangeListener") @Component("questionUserInfoChangeListener")
public class UserInfoChangeListener extends DataItemChangeListener { public class UserInfoChangeListener extends DataItemChangeListener {
private IQuestionService questionService;
private IQuestionReplyService questionReplyService;
private IQuestionReplyCommentService questionReplyCommentService;
public UserInfoChangeListener(IQuestionService questionService, IQuestionReplyService questionReplyService, IQuestionReplyCommentService questionReplyCommentService) {
this.questionService = questionService;
this.questionReplyService = questionReplyService;
this.questionReplyCommentService = questionReplyCommentService;
}
// @Autowired
// public void setQuestionService(IQuestionService questionService) {
// this.questionService = questionService;
// }
@Override @Override
public void onUserAvatarUpdate(DataItemChangeMessage dataItemChangeMessage) { public void onUserAvatarUpdate(DataItemChangeMessage dataItemChangeMessage) {
String userId = (String) dataItemChangeMessage.getItemId();
questionReplyService.updateQuestionReplyUserAvatar(userId);
questionReplyCommentService.updateQuestionReplyCommentUserAvatar(userId);
log.debug("question-用户头像更新:{}", dataItemChangeMessage); log.debug("question-用户头像更新:{}", dataItemChangeMessage);
} }
@Override
public void onUserNickUpdate(DataItemChangeMessage dataItemChangeMessage) {
String userId = (String) dataItemChangeMessage.getItemId();
questionService.updateQuestionUserNick(userId);
questionReplyService.updateQuestionReplyUserNick(userId);
questionReplyCommentService.updateQuestionReplyCommentUserNick(userId);
log.debug("question-用户昵称更新:{}", dataItemChangeMessage);
}
} }
...@@ -44,4 +44,16 @@ public interface IQuestionReplyCommentService extends IService<QuestionReplyComm ...@@ -44,4 +44,16 @@ public interface IQuestionReplyCommentService extends IService<QuestionReplyComm
* @throws QuestionReplyCommentServiceException * @throws QuestionReplyCommentServiceException
*/ */
IPage<QuestionReplyComment> getReplyCommentPage(Integer pageNumber, Integer pageSize, String replyId, String parentId) throws QuestionReplyCommentServiceException; IPage<QuestionReplyComment> getReplyCommentPage(Integer pageNumber, Integer pageSize, String replyId, String parentId) throws QuestionReplyCommentServiceException;
/**
* 更新用户昵称
* @param userId 用户ID
*/
void updateQuestionReplyCommentUserNick(String userId);
/**
* 更新用户头像
* @param userId 用户ID
*/
void updateQuestionReplyCommentUserAvatar(String userId);
} }
...@@ -58,4 +58,16 @@ public interface IQuestionReplyService extends IService<QuestionReply> { ...@@ -58,4 +58,16 @@ public interface IQuestionReplyService extends IService<QuestionReply> {
* @return * @return
*/ */
IPage<String> participateQuestionIdPage(IPage<String> page, String userId); IPage<String> participateQuestionIdPage(IPage<String> page, String userId);
/**
* 更新用户昵称
* @param userId 用户ID
*/
void updateQuestionReplyUserNick(String userId);
/**
* 更新用户头像
* @param userId 用户ID
*/
void updateQuestionReplyUserAvatar(String userId);
} }
...@@ -112,4 +112,9 @@ public interface IQuestionService extends IService<Question> { ...@@ -112,4 +112,9 @@ public interface IQuestionService extends IService<Question> {
*/ */
IPage<Question> getQuestionsByTagId(Integer pageNumber, Integer pageSize, String tagId) throws QuestionTagServiceException; IPage<Question> getQuestionsByTagId(Integer pageNumber, Integer pageSize, String tagId) throws QuestionTagServiceException;
/**
* 更新用户昵称
* @param userId 用户ID
*/
void updateQuestionUserNick(String userId);
} }
...@@ -14,6 +14,7 @@ import cn.meteor.beyondclouds.modules.question.util.QuestionUtils; ...@@ -14,6 +14,7 @@ import cn.meteor.beyondclouds.modules.question.util.QuestionUtils;
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;
...@@ -161,6 +162,27 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo ...@@ -161,6 +162,27 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo
} }
return page(page, QuestionUtils.getWrapper("parent_id",parentId)); return page(page, QuestionUtils.getWrapper("parent_id",parentId));
}
@Override
public void updateQuestionReplyCommentUserNick(String userId) {
User user = userService.getById(userId);
if (null != user) {
UpdateWrapper<QuestionReplyComment> replyCommentUpdateWrapper = new UpdateWrapper<>();
replyCommentUpdateWrapper.set("user_nick", user.getNickName())
.eq("user_id", user.getUserId());
update(replyCommentUpdateWrapper);
}
}
@Override
public void updateQuestionReplyCommentUserAvatar(String userId) {
User user = userService.getById(userId);
if (null != user) {
UpdateWrapper<QuestionReplyComment> replyCommentUpdateWrapper = new UpdateWrapper<>();
replyCommentUpdateWrapper.set("user_avatar", user.getUserAvatar())
.eq("user_id", user.getUserId());
update(replyCommentUpdateWrapper);
}
} }
} }
...@@ -197,4 +197,26 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q ...@@ -197,4 +197,26 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
public IPage<String> participateQuestionIdPage(IPage<String> page, String userId) { public IPage<String> participateQuestionIdPage(IPage<String> page, String userId) {
return questionReplyMapper.participateQuestionIdPage(page, userId); return questionReplyMapper.participateQuestionIdPage(page, userId);
} }
@Override
public void updateQuestionReplyUserNick(String userId) {
User user = userService.getById(userId);
if (null != user) {
UpdateWrapper<QuestionReply> questionReplyUpdateWrapper = new UpdateWrapper<>();
questionReplyUpdateWrapper.set("user_nick", user.getNickName())
.eq("user_id", user.getUserId());
update(questionReplyUpdateWrapper);
}
}
@Override
public void updateQuestionReplyUserAvatar(String userId) {
User user = userService.getById(userId);
if (null != user) {
UpdateWrapper<QuestionReply> questionReplyUpdateWrapper = new UpdateWrapper<>();
questionReplyUpdateWrapper.set("user_avatar", user.getUserAvatar())
.eq("user_id", user.getUserId());
update(questionReplyUpdateWrapper);
}
}
} }
...@@ -19,6 +19,7 @@ import cn.meteor.beyondclouds.modules.topic.entity.TopicReference; ...@@ -19,6 +19,7 @@ import cn.meteor.beyondclouds.modules.topic.entity.TopicReference;
import cn.meteor.beyondclouds.modules.topic.enums.TopicReferenceType; import cn.meteor.beyondclouds.modules.topic.enums.TopicReferenceType;
import cn.meteor.beyondclouds.modules.topic.service.ITopicReferenceService; import cn.meteor.beyondclouds.modules.topic.service.ITopicReferenceService;
import cn.meteor.beyondclouds.modules.topic.service.ITopicService; import cn.meteor.beyondclouds.modules.topic.service.ITopicService;
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 cn.meteor.beyondclouds.util.AbstractUtils; import cn.meteor.beyondclouds.util.AbstractUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
...@@ -75,13 +76,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -75,13 +76,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
private IMessageQueueService messageQueueService; private IMessageQueueService messageQueueService;
@Autowired @Autowired
public QuestionServiceImpl(IQuestionExtService questionExtService, IQuestionCategoryService questionCategoryService, ITopicService topicService, ITopicReferenceService topicReferenceService, QuestionMapper questionMapper, IUserService userService) { public QuestionServiceImpl(IQuestionExtService questionExtService, IQuestionCategoryService questionCategoryService, ITopicReferenceService topicReferenceService, QuestionMapper questionMapper) {
this.questionExtService = questionExtService; this.questionExtService = questionExtService;
this.questionCategoryService = questionCategoryService; this.questionCategoryService = questionCategoryService;
this.topicService = topicService;
this.topicReferenceService = topicReferenceService; this.topicReferenceService = topicReferenceService;
this.questionMapper = questionMapper; this.questionMapper = questionMapper;
this.userService = userService;
} }
@Autowired @Autowired
...@@ -90,6 +89,16 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -90,6 +89,16 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
} }
@Autowired @Autowired
public void setUserService(IUserService userService) {
this.userService = userService;
}
@Autowired
public void setTopicService(ITopicService topicService) {
this.topicService = topicService;
}
@Autowired
public void setQuestionReplyService(IQuestionReplyService questionReplyService) { public void setQuestionReplyService(IQuestionReplyService questionReplyService) {
this.questionReplyService = questionReplyService; this.questionReplyService = questionReplyService;
} }
...@@ -514,4 +523,15 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -514,4 +523,15 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
} }
return questionPage; return questionPage;
} }
@Override
public void updateQuestionUserNick(String userId) {
User user = userService.getById(userId);
if (null != user) {
UpdateWrapper<Question> questionUpdateWrapper = new UpdateWrapper<>();
questionUpdateWrapper.set("user_nick", user.getNickName())
.eq("user_id", user.getUserId());
update(questionUpdateWrapper);
}
}
} }
...@@ -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: 197442
# 邮箱 # 邮箱
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