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