Commit 8ed9f595 by 段启岩

博客列表添加标签、类别

parent 66cdfc82
package cn.meteor.beyondclouds.config;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 时间格式化
* @author meteor
*/
@Configuration
public class LocalDateTimeFormatConfig {
@Bean
public LocalDateTimeSerializer localDateTimeDeserializer() {
return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
@Bean
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
return builder -> builder.serializerByType(LocalDateTime.class, localDateTimeDeserializer());
}
}
...@@ -46,11 +46,6 @@ public class BlogApi { ...@@ -46,11 +46,6 @@ public class BlogApi {
if (result.hasErrors()) { if (result.hasErrors()) {
return Response.fieldError(result.getFieldError()); return Response.fieldError(result.getFieldError());
} }
//如果为不可查看则默认为不可评论和转载
if (0 == publishBlogForm.getViewPrivileges()) {
publishBlogForm.setAllowComment(false);
publishBlogForm.setAllowForward(false);
}
Blog blog = new Blog(); Blog blog = new Blog();
BeanUtils.copyProperties(publishBlogForm, blog); BeanUtils.copyProperties(publishBlogForm, blog);
......
package cn.meteor.beyondclouds.modules.blog.entity; package cn.meteor.beyondclouds.modules.blog.entity;
import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/** /**
* <p> * <p>
* 博客表 * 博客表
...@@ -35,6 +38,9 @@ public class Blog implements Serializable { ...@@ -35,6 +38,9 @@ public class Blog implements Serializable {
@ApiModelProperty(value = "所属类别ID") @ApiModelProperty(value = "所属类别ID")
private Integer categoryId; private Integer categoryId;
@ApiModelProperty(value = "类别名称")
private String category;
@ApiModelProperty(value = "标题") @ApiModelProperty(value = "标题")
private String blogTitle; private String blogTitle;
...@@ -56,6 +62,8 @@ public class Blog implements Serializable { ...@@ -56,6 +62,8 @@ public class Blog implements Serializable {
@ApiModelProperty(value = "是否允许转发") @ApiModelProperty(value = "是否允许转发")
private Boolean allowForward; private Boolean allowForward;
private List<Tag> tags;
private LocalDateTime createTime; private LocalDateTime createTime;
private LocalDateTime updateTime; private LocalDateTime updateTime;
......
...@@ -4,8 +4,6 @@ import lombok.Data; ...@@ -4,8 +4,6 @@ import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.File;
import java.io.FileInputStream;
import java.util.List; import java.util.List;
/** /**
...@@ -25,7 +23,7 @@ public class PublishBlogForm { ...@@ -25,7 +23,7 @@ public class PublishBlogForm {
@NotEmpty(message = "摘要不能为空") @NotEmpty(message = "摘要不能为空")
private String blogAbstract; private String blogAbstract;
@NotNull(message = "文章类型不能为空") @NotNull(message = "博客类型不能为空")
private Integer categoryId; private Integer categoryId;
@NotEmpty(message = "内容不能为空") @NotEmpty(message = "内容不能为空")
......
package cn.meteor.beyondclouds.modules.blog.mapper; package cn.meteor.beyondclouds.modules.blog.mapper;
import cn.meteor.beyondclouds.modules.blog.entity.Blog; import cn.meteor.beyondclouds.modules.blog.entity.Blog;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
/** /**
* <p> * <p>
...@@ -13,4 +17,18 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -13,4 +17,18 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/ */
public interface BlogMapper extends BaseMapper<Blog> { public interface BlogMapper extends BaseMapper<Blog> {
/**
* 分页查询博客获取标签
* @param page
* @return
*/
IPage<Blog> selectPageWithTags(IPage<Blog> page);
/**
* 根据查询条件分页查询博客获取标签
* @param page
* @param queryWrapper
* @return
*/
IPage<Blog> selectPageWithTags(IPage<Blog> page, @Param(Constants.WRAPPER)QueryWrapper<?> queryWrapper);
} }
...@@ -2,4 +2,42 @@ ...@@ -2,4 +2,42 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.meteor.beyondclouds.modules.blog.mapper.BlogMapper"> <mapper namespace="cn.meteor.beyondclouds.modules.blog.mapper.BlogMapper">
<resultMap id="blogWithTagsResultMap" type="cn.meteor.beyondclouds.modules.blog.entity.Blog">
<id property="blogId" column="blog_id"/>
<result property="userId" column="user_id"/>
<result property="categoryId" column="category_id"/>
<result property="category" column="category"/>
<result property="blogTitle" column="blog_title"/>
<result property="blogAbstract" column="blog_abstract"/>
<result property="cover" column="cover"/>
<result property="originLink" column="origin_link"/>
<result property="viewPrivileges" column="view_privileges"/>
<result property="allowComment" column="allow_comment"/>
<result property="allowForward" column="allow_forward"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<collection property="tags" ofType="cn.meteor.beyondclouds.modules.tag.entity.Tag">
<id property="tagId" column="tag_id"/>
<result property="tagName" column="tag_name"/>
<result property="tagType" column="tag_type"/>
</collection>
</resultMap>
<select id="selectPageWithTags" resultMap="blogWithTagsResultMap">
select
b.*,
t.tag_id,
t.tag_name,
t.tag_type,
t.create_time,
t.update_time
from blog b
left join blog_tag bt
on b.blog_id = bt.blog_id
left join tag t
on t.tag_id = bt.tag_id
<if test="ew != null and ew.sqlSegment != null">
and ${ew.sqlSegment}
</if>
</select>
</mapper> </mapper>
...@@ -2,9 +2,6 @@ package cn.meteor.beyondclouds.modules.blog.service; ...@@ -2,9 +2,6 @@ package cn.meteor.beyondclouds.modules.blog.service;
import cn.meteor.beyondclouds.modules.blog.bean.BlogDetail; import cn.meteor.beyondclouds.modules.blog.bean.BlogDetail;
import cn.meteor.beyondclouds.modules.blog.entity.Blog; import cn.meteor.beyondclouds.modules.blog.entity.Blog;
import cn.meteor.beyondclouds.modules.blog.entity.BlogComment;
import cn.meteor.beyondclouds.modules.blog.entity.BlogExt;
import cn.meteor.beyondclouds.modules.blog.entity.BlogTag;
import cn.meteor.beyondclouds.modules.blog.exception.BlogCategoryServiceException; import cn.meteor.beyondclouds.modules.blog.exception.BlogCategoryServiceException;
import cn.meteor.beyondclouds.modules.blog.exception.BlogServiceException; import cn.meteor.beyondclouds.modules.blog.exception.BlogServiceException;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
......
...@@ -22,6 +22,7 @@ import org.springframework.beans.BeanUtils; ...@@ -22,6 +22,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -50,6 +51,13 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -50,6 +51,13 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
private IBlogCategoryService blogCategoryService; private IBlogCategoryService blogCategoryService;
private BlogMapper blogMapper;
@Autowired
public void setBlogMapper(BlogMapper blogMapper) {
this.blogMapper = blogMapper;
}
@Autowired @Autowired
public void setBlogCategoryService(IBlogCategoryService blogCategoryService) { public void setBlogCategoryService(IBlogCategoryService blogCategoryService) {
this.blogCategoryService = blogCategoryService; this.blogCategoryService = blogCategoryService;
...@@ -78,13 +86,21 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -78,13 +86,21 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
@Override @Override
public void publishBlog(Blog blog, String content, List<String> topicIds, List<String> tagIds) throws BlogCategoryServiceException { public void publishBlog(Blog blog, String content, List<String> topicIds, List<String> tagIds) throws BlogCategoryServiceException {
//如果为不可查看则默认为不可评论和转载
if (0 == blog.getViewPrivileges()) {
blog.setAllowComment(false);
blog.setAllowForward(false);
}
//1.判断博客类型是否存在 //1.判断博客类型是否存在
BlogCategory blogCategory = blogCategoryService.getById(blog.getCategoryId()); BlogCategory 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());
save(blog); save(blog);
//3.存入内容 //3.存入内容
...@@ -94,25 +110,30 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -94,25 +110,30 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
blogExtService.save(blogExt); blogExtService.save(blogExt);
//4.判断是否引用话题 //4.判断是否引用话题
if (null != topicIds) { if (!CollectionUtils.isEmpty(topicIds)) {
List<TopicReference> topicReferenceList = new ArrayList<>();
for (String topicId : topicIds) { for (String topicId : topicIds) {
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);
} }
//5.判断是否引用标签 //5.判断是否引用标签
if (null != tagIds) { if (!CollectionUtils.isEmpty(tagIds)) {
List<BlogTag> blogTagList = new ArrayList<>();
for (String tagId : tagIds) { for (String tagId : tagIds) {
BlogTag blogTag = new BlogTag(); BlogTag blogTag = new BlogTag();
blogTag.setBlogId(blog.getBlogId()); blogTag.setBlogId(blog.getBlogId());
blogTag.setTagId(tagId); blogTag.setTagId(tagId);
blogTagService.save(blogTag); blogTagList.add(blogTag);
} }
blogTagService.saveBatch(blogTagList);
} }
} }
...@@ -212,10 +233,11 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB ...@@ -212,10 +233,11 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
@Override @Override
public IPage<Blog> getBlogPage(Integer pageNumber, Integer pageSize) { public IPage<Blog> getBlogPage(Integer pageNumber, Integer pageSize) {
IPage<Blog> page = new Page<>(pageNumber, pageSize); IPage<Blog> page = new Page<>(pageNumber, pageSize);
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper<Blog> blogQueryWrapper = new QueryWrapper<>();
queryWrapper.eq("view_privileges", 1); blogQueryWrapper.eq("view_privileges", 1);
queryWrapper.orderByDesc("create_time"); blogQueryWrapper.orderByDesc("b.create_time");
return page(page,queryWrapper); IPage<Blog> blogPage = blogMapper.selectPageWithTags(page, blogQueryWrapper);
return blogPage;
} }
/** /**
......
...@@ -2,6 +2,7 @@ package cn.meteor.beyondclouds.modules.tag.entity; ...@@ -2,6 +2,7 @@ package cn.meteor.beyondclouds.modules.tag.entity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -39,8 +40,10 @@ public class Tag implements Serializable { ...@@ -39,8 +40,10 @@ public class Tag implements Serializable {
@ApiModelProperty(value = "标签类型:0博客标签,2-问题标签") @ApiModelProperty(value = "标签类型:0博客标签,2-问题标签")
private Integer tagType; private Integer tagType;
@JsonInclude(JsonInclude.Include.NON_NULL)
private LocalDateTime createTime; private LocalDateTime createTime;
@JsonInclude(JsonInclude.Include.NON_NULL)
private LocalDateTime updateTime; private LocalDateTime updateTime;
......
...@@ -32,4 +32,4 @@ beyondclouds: ...@@ -32,4 +32,4 @@ beyondclouds:
qq: qq:
client-id: 101846021 client-id: 101846021
client-secret: 5bc41deeb7e152e2e6aff97726bbf86a client-secret: 5bc41deeb7e152e2e6aff97726bbf86a
redirect-uri: http://meteor.natapp1.cc/auth/qq redirect-uri: http://meteor.natapp1.cc/auth/qq
\ No newline at end of file
...@@ -26,6 +26,11 @@ aliyun: ...@@ -26,6 +26,11 @@ aliyun:
mybatis-plus: mybatis-plus:
mapper-locations: classpath*:cn/meteor/beyondclouds/modules/**/xml/*.xml mapper-locations: classpath*:cn/meteor/beyondclouds/modules/**/xml/*.xml
logging:
level:
cn:
meteor:
beyondclouds: debug
beyondclouds: beyondclouds:
debug: true debug: true
auth: auth:
......
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