Commit a83fa510 by 段启岩

修改博客功能修复

parent dac935fc
...@@ -142,7 +142,7 @@ public class BlogApi { ...@@ -142,7 +142,7 @@ public class BlogApi {
blog.setBlogId(blogId); blog.setBlogId(blogId);
//更新项目 //更新项目
try { try {
blogService.updateBlog(blog, updateBlogForm.getContent(),updateBlogForm.getTopicIds(),updateBlogForm.getTagIds()); blogService.updateBlog(blog, updateBlogForm.getContent(), updateBlogForm.getTopicIds(),updateBlogForm.getTagIds());
return Response.success(); return Response.success();
} catch (BlogServiceException | BlogCategoryServiceException e) { } catch (BlogServiceException | BlogCategoryServiceException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -15,17 +15,20 @@ import java.util.List; ...@@ -15,17 +15,20 @@ import java.util.List;
@Data @Data
public class PublishBlogForm { public class PublishBlogForm {
@NotNull(message = "标题不能为空")
@NotEmpty(message = "标题不能为空") @NotEmpty(message = "标题不能为空")
private String blogTitle; private String blogTitle;
private String originLink; private String originLink;
@NotNull(message = "摘要不能为空")
@NotEmpty(message = "摘要不能为空") @NotEmpty(message = "摘要不能为空")
private String blogAbstract; private String blogAbstract;
@NotNull(message = "博客类型不能为空") @NotNull(message = "博客类型不能为空")
private Integer categoryId; private Integer categoryId;
@NotNull(message = "内容不能为空")
@NotEmpty(message = "内容不能为空") @NotEmpty(message = "内容不能为空")
private String blogContent; private String blogContent;
...@@ -42,6 +45,7 @@ public class PublishBlogForm { ...@@ -42,6 +45,7 @@ public class PublishBlogForm {
@NotNull(message = "转载权限不能为空") @NotNull(message = "转载权限不能为空")
private Boolean allowForward; private Boolean allowForward;
@NotNull(message = "封面图不能为空")
@NotEmpty(message = "封面图不能为空") @NotEmpty(message = "封面图不能为空")
private String cover; private String cover;
} }
...@@ -3,7 +3,6 @@ package cn.meteor.beyondclouds.modules.blog.form; ...@@ -3,7 +3,6 @@ package cn.meteor.beyondclouds.modules.blog.form;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/** /**
...@@ -14,15 +13,18 @@ import java.util.List; ...@@ -14,15 +13,18 @@ import java.util.List;
@Data @Data
public class UpdateBlogForm { public class UpdateBlogForm {
@NotEmpty(message = "标题不能为空")
private String blogTitle; private String blogTitle;
private String originLink; private String originLink;
@NotEmpty(message = "摘要不能为空")
private String blogAbstract; private String blogAbstract;
private Integer categoryId; private Integer categoryId;
private String Content; @NotEmpty(message = "内容不能为空")
private String content;
private List<String> topicIds; private List<String> topicIds;
...@@ -34,6 +36,7 @@ public class UpdateBlogForm { ...@@ -34,6 +36,7 @@ public class UpdateBlogForm {
private Boolean allowForward; private Boolean allowForward;
@NotEmpty(message = "封面图不能为空")
private String cover; private String cover;
} }
...@@ -326,18 +326,20 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -326,18 +326,20 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
.eq("user_id", blog.getUserId()); .eq("user_id", blog.getUserId());
Blog blogInDb = getOne(blogQueryWrapper); Blog blogInDb = getOne(blogQueryWrapper);
if (null == blogInDb) { if (null == blogInDb) {
throw new BlogServiceException(BlogErrorCode.BLOG_NOT_FOUND); throw new BlogServiceException(BlogErrorCode.USER_BLOG_NOT_FOUND);
} }
//判断博客类型是否正确 //判断博客类型是否正确
BlogCategory blogCategory = null;
if (blog.getCategoryId() != null) { if (blog.getCategoryId() != null) {
BlogCategory blogCategory = blogCategoryService.getById(blog.getCategoryId()); blogCategory = blogCategoryService.getById(blog.getCategoryId());
if (null == blogCategory) { if (null == blogCategory) {
throw new BlogCategoryServiceException(BlogCategoryErrorCode.INCORRECT_CATEGORY); throw new BlogCategoryServiceException(BlogCategoryErrorCode.INCORRECT_CATEGORY);
} }
} }
//2.更新博客基本信息 //2.更新博客基本信息
blog.setCategory(blogCategory.getCategory());
updateById(blog); updateById(blog);
//3.更新博客内容 //3.更新博客内容
...@@ -350,36 +352,55 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -350,36 +352,55 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
blogExtService.update(blogExt,blogExtQueryWrapper); blogExtService.update(blogExt,blogExtQueryWrapper);
} }
//4.更新标签 //4.判断是否引用话题
if (!StringUtils.isEmpty(tagIds)) { // 删除旧话题引用
QueryWrapper tagIdQueryWrapperTag = new QueryWrapper(); QueryWrapper<TopicReference> topicReferenceQueryWrapper = new QueryWrapper<>();
tagIdQueryWrapperTag.eq("blog_id", blog.getBlogId()); topicReferenceQueryWrapper.eq("referencer_id", blog.getBlogId());
blogTagService.remove(tagIdQueryWrapperTag); topicReferenceService.remove(topicReferenceQueryWrapper);
for (String tagId : tagIds) {
BlogTag blogTag = new BlogTag();
blogTag.setBlogId(blog.getBlogId());
blogTag.setTagId(tagId);
blogTagService.save(blogTag);
}
}
//5.更新话题 // 添加新话题引用
if (!StringUtils.isEmpty(topicIds)) { if (!CollectionUtils.isEmpty(topicIds)) {
QueryWrapper topicIdQueryWrapper = new QueryWrapper(); // 获取要引用的话题,不正确的话题ID会被自动过滤
topicIdQueryWrapper.eq("referencer_id", blog.getBlogId()); List<Topic> topicList = topicService.listByIds(topicIds);
topicReferenceService.remove(topicIdQueryWrapper); List<String> existsTopicIds = topicList.stream().map(Topic::getTopicId).collect(Collectors.toList());
for (String topicId : topicIds) { if (!CollectionUtils.isEmpty(existsTopicIds)) {
List<TopicReference> topicReferenceList = new ArrayList<>();
for (String topicId : existsTopicIds) {
TopicReference topicReference = new TopicReference(); TopicReference topicReference = new TopicReference();
topicReference.setTopicId(topicId); topicReference.setTopicId(topicId);
topicReference.setReferencerId(blog.getBlogId()); topicReference.setReferencerId(blog.getBlogId());
topicReference.setReferencerType(0); topicReference.setReferencerType(0);
topicReferenceService.save(topicReference); topicReferenceList.add(topicReference);
} }
// 批量保存
topicReferenceService.saveBatch(topicReferenceList);
// 更新话题引用次数
existsTopicIds.forEach(topicId -> {
topicService.increaseReferenceCount(topicId, 1);
});
} }
} }
//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)) {
List<BlogTag> blogTagList = new ArrayList<>();
for (String tagId : existsTagIds) {
BlogTag blogTag = new BlogTag();
blogTag.setBlogId(blog.getBlogId());
blogTag.setTagId(tagId);
blogTagList.add(blogTag);
}
blogTagService.saveBatch(blogTagList);
}
}
}
} }
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