Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
8ed9f595
Commit
8ed9f595
authored
Feb 04, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
博客列表添加标签、类别
parent
66cdfc82
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
133 additions
and
22 deletions
+133
-22
src/main/java/cn/meteor/beyondclouds/config/LocalDateTimeFormatConfig.java
+27
-0
src/main/java/cn/meteor/beyondclouds/modules/blog/api/BlogApi.java
+0
-5
src/main/java/cn/meteor/beyondclouds/modules/blog/entity/Blog.java
+10
-2
src/main/java/cn/meteor/beyondclouds/modules/blog/form/PublishBlogForm.java
+1
-3
src/main/java/cn/meteor/beyondclouds/modules/blog/mapper/BlogMapper.java
+18
-0
src/main/java/cn/meteor/beyondclouds/modules/blog/mapper/xml/BlogMapper.xml
+38
-0
src/main/java/cn/meteor/beyondclouds/modules/blog/service/IBlogService.java
+0
-3
src/main/java/cn/meteor/beyondclouds/modules/blog/service/impl/BlogServiceImpl.java
+31
-9
src/main/java/cn/meteor/beyondclouds/modules/tag/entity/Tag.java
+3
-0
src/main/resources/application-dev.yml
+0
-0
src/main/resources/application.yml
+5
-0
No files found.
src/main/java/cn/meteor/beyondclouds/config/LocalDateTimeFormatConfig.java
0 → 100644
View file @
8ed9f595
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
());
}
}
src/main/java/cn/meteor/beyondclouds/modules/blog/api/BlogApi.java
View file @
8ed9f595
...
...
@@ -46,11 +46,6 @@ public class BlogApi {
if
(
result
.
hasErrors
())
{
return
Response
.
fieldError
(
result
.
getFieldError
());
}
//如果为不可查看则默认为不可评论和转载
if
(
0
==
publishBlogForm
.
getViewPrivileges
())
{
publishBlogForm
.
setAllowComment
(
false
);
publishBlogForm
.
setAllowForward
(
false
);
}
Blog
blog
=
new
Blog
();
BeanUtils
.
copyProperties
(
publishBlogForm
,
blog
);
...
...
src/main/java/cn/meteor/beyondclouds/modules/blog/entity/Blog.java
View file @
8ed9f595
package
cn
.
meteor
.
beyondclouds
.
modules
.
blog
.
entity
;
import
cn.meteor.beyondclouds.modules.tag.entity.Tag
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
java.time.LocalDateTime
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
java.io.Serializable
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.List
;
/**
* <p>
* 博客表
...
...
@@ -35,6 +38,9 @@ public class Blog implements Serializable {
@ApiModelProperty
(
value
=
"所属类别ID"
)
private
Integer
categoryId
;
@ApiModelProperty
(
value
=
"类别名称"
)
private
String
category
;
@ApiModelProperty
(
value
=
"标题"
)
private
String
blogTitle
;
...
...
@@ -56,6 +62,8 @@ public class Blog implements Serializable {
@ApiModelProperty
(
value
=
"是否允许转发"
)
private
Boolean
allowForward
;
private
List
<
Tag
>
tags
;
private
LocalDateTime
createTime
;
private
LocalDateTime
updateTime
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/blog/form/PublishBlogForm.java
View file @
8ed9f595
...
...
@@ -4,8 +4,6 @@ import lombok.Data;
import
javax.validation.constraints.NotEmpty
;
import
javax.validation.constraints.NotNull
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.util.List
;
/**
...
...
@@ -25,7 +23,7 @@ public class PublishBlogForm {
@NotEmpty
(
message
=
"摘要不能为空"
)
private
String
blogAbstract
;
@NotNull
(
message
=
"
文章
类型不能为空"
)
@NotNull
(
message
=
"
博客
类型不能为空"
)
private
Integer
categoryId
;
@NotEmpty
(
message
=
"内容不能为空"
)
...
...
src/main/java/cn/meteor/beyondclouds/modules/blog/mapper/BlogMapper.java
View file @
8ed9f595
package
cn
.
meteor
.
beyondclouds
.
modules
.
blog
.
mapper
;
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.metadata.IPage
;
import
com.baomidou.mybatisplus.core.toolkit.Constants
;
import
org.apache.ibatis.annotations.Param
;
/**
* <p>
...
...
@@ -13,4 +17,18 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
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
);
}
src/main/java/cn/meteor/beyondclouds/modules/blog/mapper/xml/BlogMapper.xml
View file @
8ed9f595
...
...
@@ -2,4 +2,42 @@
<!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"
>
<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>
src/main/java/cn/meteor/beyondclouds/modules/blog/service/IBlogService.java
View file @
8ed9f595
...
...
@@ -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.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.BlogServiceException
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/blog/service/impl/BlogServiceImpl.java
View file @
8ed9f595
...
...
@@ -22,6 +22,7 @@ import org.springframework.beans.BeanUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.Assert
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.ArrayList
;
...
...
@@ -50,6 +51,13 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
private
IBlogCategoryService
blogCategoryService
;
private
BlogMapper
blogMapper
;
@Autowired
public
void
setBlogMapper
(
BlogMapper
blogMapper
)
{
this
.
blogMapper
=
blogMapper
;
}
@Autowired
public
void
setBlogCategoryService
(
IBlogCategoryService
blogCategoryService
)
{
this
.
blogCategoryService
=
blogCategoryService
;
...
...
@@ -78,13 +86,21 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
@Override
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.判断博客类型是否存在
BlogCategory
blogCategory
=
blogCategoryService
.
getById
(
blog
.
getCategoryId
());
if
(
null
==
blogCategory
)
{
throw
new
BlogCategoryServiceException
(
BlogCategoryErrorCode
.
INCORRECT_CATEGORY
);
}
//2.保存博客
blog
.
setCategory
(
blogCategory
.
getCategory
());
save
(
blog
);
//3.存入内容
...
...
@@ -94,25 +110,30 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
blogExtService
.
save
(
blogExt
);
//4.判断是否引用话题
if
(
null
!=
topicIds
)
{
if
(!
CollectionUtils
.
isEmpty
(
topicIds
))
{
List
<
TopicReference
>
topicReferenceList
=
new
ArrayList
<>();
for
(
String
topicId
:
topicIds
)
{
TopicReference
topicReference
=
new
TopicReference
();
topicReference
.
setTopicId
(
topicId
);
topicReference
.
setReferencerId
(
blog
.
getBlogId
());
topicReference
.
setReferencerType
(
0
);
topicReference
Service
.
save
(
topicReference
);
topicReference
List
.
add
(
topicReference
);
}
// 批量保存
topicReferenceService
.
saveBatch
(
topicReferenceList
);
}
//5.判断是否引用标签
if
(
null
!=
tagIds
)
{
if
(!
CollectionUtils
.
isEmpty
(
tagIds
))
{
List
<
BlogTag
>
blogTagList
=
new
ArrayList
<>();
for
(
String
tagId
:
tagIds
)
{
BlogTag
blogTag
=
new
BlogTag
();
blogTag
.
setBlogId
(
blog
.
getBlogId
());
blogTag
.
setTagId
(
tagId
);
blogTag
Service
.
save
(
blogTag
);
blogTag
List
.
add
(
blogTag
);
}
blogTagService
.
saveBatch
(
blogTagList
);
}
}
...
...
@@ -212,10 +233,11 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
@Override
public
IPage
<
Blog
>
getBlogPage
(
Integer
pageNumber
,
Integer
pageSize
)
{
IPage
<
Blog
>
page
=
new
Page
<>(
pageNumber
,
pageSize
);
QueryWrapper
queryWrapper
=
new
QueryWrapper
();
queryWrapper
.
eq
(
"view_privileges"
,
1
);
queryWrapper
.
orderByDesc
(
"create_time"
);
return
page
(
page
,
queryWrapper
);
QueryWrapper
<
Blog
>
blogQueryWrapper
=
new
QueryWrapper
<>();
blogQueryWrapper
.
eq
(
"view_privileges"
,
1
);
blogQueryWrapper
.
orderByDesc
(
"b.create_time"
);
IPage
<
Blog
>
blogPage
=
blogMapper
.
selectPageWithTags
(
page
,
blogQueryWrapper
);
return
blogPage
;
}
/**
...
...
src/main/java/cn/meteor/beyondclouds/modules/tag/entity/Tag.java
View file @
8ed9f595
...
...
@@ -2,6 +2,7 @@ package cn.meteor.beyondclouds.modules.tag.entity;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
...
...
@@ -39,8 +40,10 @@ public class Tag implements Serializable {
@ApiModelProperty
(
value
=
"标签类型:0博客标签,2-问题标签"
)
private
Integer
tagType
;
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
private
LocalDateTime
createTime
;
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
private
LocalDateTime
updateTime
;
...
...
src/main/resources/application-dev.yml
View file @
8ed9f595
src/main/resources/application.yml
View file @
8ed9f595
...
...
@@ -26,6 +26,11 @@ aliyun:
mybatis-plus
:
mapper-locations
:
classpath*:cn/meteor/beyondclouds/modules/**/xml/*.xml
logging
:
level
:
cn
:
meteor
:
beyondclouds
:
debug
beyondclouds
:
debug
:
true
auth
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment