Commit 181c79d7 by 段启岩

动态发布修复

parent 973b79c0
...@@ -230,7 +230,7 @@ GET /api/my/topic/followed ...@@ -230,7 +230,7 @@ GET /api/my/topic/followed
GET /api/my/topic/created GET /api/my/topic/created
``` ```
###### 9.热搜话题:pushpin: ###### :white_check_mark: 9.热搜话题
``` ```
GET /api/topic/hotSearches GET /api/topic/hotSearches
......
...@@ -159,7 +159,7 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -159,7 +159,7 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
blogExtService.save(blogExt); blogExtService.save(blogExt);
//4.更新标签和话题的引用 //4.更新标签和话题的引用
updateTopicAndTagReference(topicIds, tagIds, blog.getBlogId(), false); updateTopicAndTagReference(user.getUserId(), topicIds, tagIds, blog.getBlogId(), false);
// 5.发送消息到消息队列 // 5.发送消息到消息队列
messageQueueService messageQueueService
...@@ -420,7 +420,7 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -420,7 +420,7 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
} }
//4.更新标签和话题的引用 //4.更新标签和话题的引用
updateTopicAndTagReference(topicIds, tagIds, blog.getBlogId(), true); updateTopicAndTagReference(blog.getUserId(), topicIds, tagIds, blog.getBlogId(), true);
// 5.发送消息到消息队列 // 5.发送消息到消息队列
messageQueueService messageQueueService
...@@ -432,13 +432,13 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -432,13 +432,13 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
/** /**
* 更新博客里面对标签和话题的引用 * 更新博客里面对标签和话题的引用
* * @param userId
* @param tagIds * @param tagIds
* @param topicIds * @param topicIds
* @param blogId * @param blogId
* @param update * @param update
*/ */
private void updateTopicAndTagReference(List<String> topicIds, List<String> tagIds, String blogId, boolean update) { private void updateTopicAndTagReference(String userId, List<String> topicIds, List<String> tagIds, String blogId, boolean update) {
// 如果用户传的topicIds为[]并且现在在执行修改博客的操作,就删除该博客以前引用的所有话题 // 如果用户传的topicIds为[]并且现在在执行修改博客的操作,就删除该博客以前引用的所有话题
if (CollectionUtils.isEmpty(topicIds) && update) { if (CollectionUtils.isEmpty(topicIds) && update) {
deleteOldTopicReferences(blogId); deleteOldTopicReferences(blogId);
...@@ -463,6 +463,7 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -463,6 +463,7 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
List<TopicReference> topicReferenceList = new ArrayList<>(); List<TopicReference> topicReferenceList = new ArrayList<>();
for (String topicId : existsTopicIds) { for (String topicId : existsTopicIds) {
TopicReference topicReference = new TopicReference(); TopicReference topicReference = new TopicReference();
topicReference.setUserId(userId);
topicReference.setTopicId(topicId); topicReference.setTopicId(topicId);
topicReference.setReferencerId(blogId); topicReference.setReferencerId(blogId);
topicReference.setReferencerType(TopicReferenceType.BLOG_REFERENCE.getType()); topicReference.setReferencerType(TopicReferenceType.BLOG_REFERENCE.getType());
......
...@@ -81,6 +81,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -81,6 +81,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
/** /**
* 发布动态 * 发布动态
*
* @param post * @param post
* @throws ProjectServiceException * @throws ProjectServiceException
*/ */
...@@ -101,7 +102,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -101,7 +102,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
type = 0; type = 0;
} else if (null == post.getVideo() && null != post.getPictures()) { } else if (null == post.getVideo() && null != post.getPictures()) {
type = 1; type = 1;
}else { } else {
type = 2; type = 2;
} }
...@@ -121,12 +122,13 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -121,12 +122,13 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
List<String> topicNames = TopicUtils.parseTopics(post.getContent()); List<String> topicNames = TopicUtils.parseTopics(post.getContent());
if (!CollectionUtils.isEmpty(topicNames)) { if (!CollectionUtils.isEmpty(topicNames)) {
List<Topic> topics = topicService.queryAndCreateByTopicNames(topicNames, post.getUserId()); List<Topic> topics = topicService.queryAndCreateByTopicNames(topicNames, post.getUserId());
List<String >topicIds = topics.stream().map(Topic::getTopicId).collect(Collectors.toList()); List<String> topicIds = topics.stream().map(Topic::getTopicId).collect(Collectors.toList());
// 关联话题和动态 // 关联话题和动态
List<TopicReference> topicReferences = new ArrayList<>(); List<TopicReference> topicReferences = new ArrayList<>();
for (String topicId : topicIds) { for (String topicId : topicIds) {
TopicReference topicReference = new TopicReference(); TopicReference topicReference = new TopicReference();
topicReference.setUserId(user.getUserId());
topicReference.setTopicId(topicId); topicReference.setTopicId(topicId);
topicReference.setReferencerId(post.getPostId()); topicReference.setReferencerId(post.getPostId());
topicReference.setReferencerType(TopicReferenceType.POST_REFERENCE.getType()); topicReference.setReferencerType(TopicReferenceType.POST_REFERENCE.getType());
...@@ -147,6 +149,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -147,6 +149,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
/** /**
* 删除动态 * 删除动态
*
* @param postId * @param postId
* @param userId * @param userId
* @throws PostServiceException * @throws PostServiceException
...@@ -155,10 +158,10 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -155,10 +158,10 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
public void deletePost(String postId, String userId) throws PostServiceException { public void deletePost(String postId, String userId) throws PostServiceException {
//1.判断是不是该用户发布的动态 //1.判断是不是该用户发布的动态
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("post_id",postId); queryWrapper.eq("post_id", postId);
queryWrapper.eq("user_id", userId); queryWrapper.eq("user_id", userId);
Post post = getOne(queryWrapper); Post post = getOne(queryWrapper);
if ( null == post ) { if (null == post) {
throw new PostServiceException(PostErrorCode.USER_POST_NOT_FOUND); throw new PostServiceException(PostErrorCode.USER_POST_NOT_FOUND);
} }
...@@ -182,6 +185,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -182,6 +185,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
/** /**
* 获取动态列表 * 获取动态列表
*
* @param pageNumber * @param pageNumber
* @param pageSize * @param pageSize
* @param type * @param type
...@@ -189,17 +193,18 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -189,17 +193,18 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
*/ */
@Override @Override
public IPage<Post> getPostPage(Integer pageNumber, Integer pageSize, Integer type) { public IPage<Post> getPostPage(Integer pageNumber, Integer pageSize, Integer type) {
IPage<Post> postPage = new Page<>(pageNumber,pageSize); IPage<Post> postPage = new Page<>(pageNumber, pageSize);
QueryWrapper<Post> queryWrapper = new QueryWrapper(); QueryWrapper<Post> queryWrapper = new QueryWrapper();
queryWrapper.orderByDesc("create_time"); queryWrapper.orderByDesc("create_time");
if (null != type) { if (null != type) {
queryWrapper.eq("type", type); queryWrapper.eq("type", type);
} }
return page(postPage , queryWrapper); return page(postPage, queryWrapper);
} }
/** /**
*个人动态列表 * 个人动态列表
*
* @param pageNumber * @param pageNumber
* @param pageSize * @param pageSize
* @param userId * @param userId
...@@ -211,18 +216,19 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -211,18 +216,19 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
queryWrapper.eq("user_id", userId); queryWrapper.eq("user_id", userId);
queryWrapper.orderByDesc("create_time"); queryWrapper.orderByDesc("create_time");
IPage<Post> postPage = new Page<>(pageNumber,pageSize); IPage<Post> postPage = new Page<>(pageNumber, pageSize);
return page(postPage, queryWrapper); return page(postPage, queryWrapper);
} }
/** /**
* 更新动态里的用户头像 * 更新动态里的用户头像
*
* @param userId * @param userId
*/ */
@Override @Override
public void updatePostUserAvatar(String userId) { public void updatePostUserAvatar(String userId) {
User user = userService.getById(userId); User user = userService.getById(userId);
if(null != user){ if (null != user) {
UpdateWrapper<Post> postUpdateWrapper = new UpdateWrapper<>(); UpdateWrapper<Post> postUpdateWrapper = new UpdateWrapper<>();
postUpdateWrapper.eq("user_id", userId); postUpdateWrapper.eq("user_id", userId);
postUpdateWrapper.set("user_avatar", user.getUserAvatar()); postUpdateWrapper.set("user_avatar", user.getUserAvatar());
...@@ -232,12 +238,13 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP ...@@ -232,12 +238,13 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
/** /**
* 更新动态里的用户昵称 * 更新动态里的用户昵称
*
* @param userId * @param userId
*/ */
@Override @Override
public void updatePostUserNick(String userId) { public void updatePostUserNick(String userId) {
User user = userService.getById(userId); User user = userService.getById(userId);
if(null != user){ if (null != user) {
UpdateWrapper<Post> postUpdateWrapper = new UpdateWrapper<>(); UpdateWrapper<Post> postUpdateWrapper = new UpdateWrapper<>();
postUpdateWrapper.eq("user_id", userId); postUpdateWrapper.eq("user_id", userId);
postUpdateWrapper.set("user_nick", user.getNickName()); postUpdateWrapper.set("user_nick", user.getNickName());
......
...@@ -164,7 +164,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -164,7 +164,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
questionExtService.save(questionExt); questionExtService.save(questionExt);
// 5.处理对话题和标签的引用 // 5.处理对话题和标签的引用
updateTopicAndTagReference(topicIds, tagIds, question.getQuestionId(), false); updateTopicAndTagReference(question.getUserId(), topicIds, tagIds, question.getQuestionId(), false);
// 6.发送消息到消息队列 // 6.发送消息到消息队列
messageQueueService messageQueueService
...@@ -255,7 +255,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -255,7 +255,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
} }
// 5.处理对话题和标签的引用 // 5.处理对话题和标签的引用
updateTopicAndTagReference(topicIds, tagIds, question.getQuestionId(), true); updateTopicAndTagReference(question.getUserId(), topicIds, tagIds, question.getQuestionId(), true);
// 6.发送消息到消息队列 // 6.发送消息到消息队列
messageQueueService messageQueueService
...@@ -373,12 +373,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -373,12 +373,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
/** /**
* 更新问题里面对标签和话题的引用 * 更新问题里面对标签和话题的引用
* @param userId
* @param tagIds * @param tagIds
* @param topicIds * @param topicIds
* @param questionId * @param questionId
* @param update * @param update
*/ */
private void updateTopicAndTagReference(List<String> topicIds, List<String> tagIds, String questionId, boolean update) { private void updateTopicAndTagReference(String userId, List<String> topicIds, List<String> tagIds, String questionId, boolean update) {
// 如果用户传的topicIds为[]并且现在在执行修改问答的操作,就删除该问答以前引用的所有话题 // 如果用户传的topicIds为[]并且现在在执行修改问答的操作,就删除该问答以前引用的所有话题
if (CollectionUtils.isEmpty(topicIds) && update) { if (CollectionUtils.isEmpty(topicIds) && update) {
deleteOldTopicReferences(questionId); deleteOldTopicReferences(questionId);
...@@ -403,6 +404,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -403,6 +404,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
List<TopicReference> topicReferenceList = existsTopicIds.stream() List<TopicReference> topicReferenceList = existsTopicIds.stream()
.map(topicId -> { .map(topicId -> {
TopicReference topicReference = new TopicReference(); TopicReference topicReference = new TopicReference();
topicReference.setUserId(userId);
topicReference.setTopicId(topicId); topicReference.setTopicId(topicId);
topicReference.setReferencerId(questionId); topicReference.setReferencerId(questionId);
topicReference.setReferencerType(TopicReferenceType.QUESTION_REFERENCE.getType()); topicReference.setReferencerType(TopicReferenceType.QUESTION_REFERENCE.getType());
......
...@@ -32,6 +32,9 @@ public class TopicReference implements Serializable { ...@@ -32,6 +32,9 @@ public class TopicReference implements Serializable {
@ApiModelProperty(value = "话题ID") @ApiModelProperty(value = "话题ID")
private String topicId; private String topicId;
@ApiModelProperty(value = "用户ID")
private String userId;
@ApiModelProperty(value = "引用者(博客,项目动态等)ID") @ApiModelProperty(value = "引用者(博客,项目动态等)ID")
private String referencerId; private String referencerId;
......
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