Commit 67f307f8 by 段启岩

修复更新时删除话题喝和标签的问题,话题列表添加排序

parent 082de629
......@@ -354,10 +354,6 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
}
//4.判断是否引用话题
// 删除旧话题引用
QueryWrapper<TopicReference> topicReferenceQueryWrapper = new QueryWrapper<>();
topicReferenceQueryWrapper.eq("referencer_id", blog.getBlogId());
topicReferenceService.remove(topicReferenceQueryWrapper);
// 添加新话题引用
if (!CollectionUtils.isEmpty(topicIds)) {
......@@ -365,6 +361,11 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
List<Topic> topicList = topicService.listByIds(topicIds);
List<String> existsTopicIds = topicList.stream().map(Topic::getTopicId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(existsTopicIds)) {
// 删除旧话题引用
QueryWrapper<TopicReference> topicReferenceQueryWrapper = new QueryWrapper<>();
topicReferenceQueryWrapper.eq("referencer_id", blog.getBlogId());
topicReferenceService.remove(topicReferenceQueryWrapper);
List<TopicReference> topicReferenceList = new ArrayList<>();
for (String topicId : existsTopicIds) {
TopicReference topicReference = new TopicReference();
......@@ -383,15 +384,17 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
}
//5.判断是否引用标签
// 删除旧标签
QueryWrapper<BlogTag> blogTagQueryWrapper = new QueryWrapper<>();
blogTagQueryWrapper.eq("blog_id", blog.getBlogId());
blogTagService.remove(blogTagQueryWrapper);
// 添加新标签
if (!CollectionUtils.isEmpty(tagIds)) {
List<String> existsTagIds = tagService.listByIds(tagIds).stream().map(Tag::getTagId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(existsTagIds)) {
// 删除旧标签
QueryWrapper<BlogTag> blogTagQueryWrapper = new QueryWrapper<>();
blogTagQueryWrapper.eq("blog_id", blog.getBlogId());
blogTagService.remove(blogTagQueryWrapper);
List<BlogTag> blogTagList = new ArrayList<>();
for (String tagId : existsTagIds) {
BlogTag blogTag = new BlogTag();
......
......@@ -232,16 +232,17 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
questionExtService.update(questionExt,updateWrapper);
}
// 删除旧话题引用
QueryWrapper<TopicReference> topicReferenceQueryWrapper = new QueryWrapper<>();
topicReferenceQueryWrapper.eq("referencer_id", question.getQuestionId());
topicReferenceService.remove(topicReferenceQueryWrapper);
//5.判断是否引用话题
if (!CollectionUtils.isEmpty(topicIds)) {
// 获取要引用的话题,不正确的话题ID会被自动过滤
List<String> existsTopicIds = topicService.listByIds(topicIds).stream().map(Topic::getTopicId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(existsTopicIds)) {
// 删除旧话题引用
QueryWrapper<TopicReference> topicReferenceQueryWrapper = new QueryWrapper<>();
topicReferenceQueryWrapper.eq("referencer_id", question.getQuestionId());
topicReferenceService.remove(topicReferenceQueryWrapper);
List<TopicReference> topicReferenceList = new ArrayList<>();
for (String topicId : existsTopicIds) {
TopicReference topicReference = new TopicReference();
......@@ -261,14 +262,14 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
//5.判断是否引用标签
// 删除旧标签
QueryWrapper<QuestionTag> questionTagQueryWrapper = new QueryWrapper<>();
questionTagQueryWrapper.eq("question_id", question.getQuestionId());
questionTagService.remove(questionTagQueryWrapper);
if (!CollectionUtils.isEmpty(tagIds)) {
List<String> existsTagIds = tagService.listByIds(tagIds).stream().map(Tag::getTagId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(existsTagIds)) {
// 删除旧标签
QueryWrapper<QuestionTag> questionTagQueryWrapper = new QueryWrapper<>();
questionTagQueryWrapper.eq("question_id", question.getQuestionId());
questionTagService.remove(questionTagQueryWrapper);
List<QuestionTag> questionTagList = new ArrayList<>();
for (String tagId : existsTagIds) {
QuestionTag questionTag = new QuestionTag();
......
......@@ -12,7 +12,6 @@ import cn.meteor.beyondclouds.modules.topic.form.CreateTopicForm;
import cn.meteor.beyondclouds.modules.topic.service.ITopicService;
import cn.meteor.beyondclouds.modules.user.entity.User;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -57,8 +56,7 @@ public class TopicApi {
int pageNo = pageForm.getPage();
int pageSize = pageForm.getSize();
IPage<Topic> page = new Page<>(pageNo, pageSize);
IPage<Topic> topicPage = topicService.page(page);
IPage<Topic> topicPage = topicService.getTopicPage(pageNo, pageSize);
PageVO<Topic> topicPageVO = new PageVO<>(topicPage);
return Response.success(topicPageVO);
}
......
......@@ -65,7 +65,7 @@ public interface ITopicService extends IService<Topic> {
IPage<User> getTopicsFollower(Integer page, Integer size, String topicId);
/**
* 获取话题分页
* 获取用户的话题分页
* @param page
* @param size
* @param userId
......@@ -74,6 +74,14 @@ public interface ITopicService extends IService<Topic> {
IPage<Topic> getTopicPage(Integer page, Integer size, String userId);
/**
* 获取话题分页
* @param pageNumber
* @param pageSize
* @return
*/
IPage<Topic> getTopicPage(Integer pageNumber, Integer pageSize);
/**
* 增加话题引用次数
* @param topicId
* @param count
......
......@@ -191,6 +191,15 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
IPage<Topic> page = new Page<>(pageNumber, pageSize);
QueryWrapper<Topic> topicQueryWrapper = new QueryWrapper<>();
topicQueryWrapper.eq("user_id", userId);
topicQueryWrapper.orderByDesc("create_time");
return page(page, topicQueryWrapper);
}
@Override
public IPage<Topic> getTopicPage(Integer pageNumber, Integer pageSize) {
IPage<Topic> page = new Page<>(pageNumber, pageSize);
QueryWrapper<Topic> topicQueryWrapper = new QueryWrapper<>();
topicQueryWrapper.orderByDesc("create_time");
return page(page, topicQueryWrapper);
}
......
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