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
8da61f2b
Commit
8da61f2b
authored
Feb 04, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
发布博客时判断标签和话题是否存在,并更新话题引用次数
parent
a7a32246
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
+40
-3
src/main/java/cn/meteor/beyondclouds/modules/blog/service/impl/BlogServiceImpl.java
+18
-3
src/main/java/cn/meteor/beyondclouds/modules/topic/service/ITopicService.java
+14
-0
src/main/java/cn/meteor/beyondclouds/modules/topic/service/impl/TopicServiceImpl.java
+8
-0
No files found.
src/main/java/cn/meteor/beyondclouds/modules/blog/service/impl/BlogServiceImpl.java
View file @
8da61f2b
...
...
@@ -12,7 +12,9 @@ import cn.meteor.beyondclouds.modules.blog.exception.BlogCategoryServiceExceptio
import
cn.meteor.beyondclouds.modules.blog.exception.BlogServiceException
;
import
cn.meteor.beyondclouds.modules.blog.mapper.BlogMapper
;
import
cn.meteor.beyondclouds.modules.blog.service.*
;
import
cn.meteor.beyondclouds.modules.tag.entity.Tag
;
import
cn.meteor.beyondclouds.modules.tag.service.ITagService
;
import
cn.meteor.beyondclouds.modules.topic.entity.Topic
;
import
cn.meteor.beyondclouds.modules.topic.entity.TopicReference
;
import
cn.meteor.beyondclouds.modules.topic.service.ITopicReferenceService
;
import
cn.meteor.beyondclouds.modules.topic.service.ITopicService
;
...
...
@@ -24,6 +26,7 @@ import lombok.extern.java.Log;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.Assert
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
...
...
@@ -84,6 +87,7 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
* @throws BlogCategoryServiceException
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
publishBlog
(
Blog
blog
,
String
content
,
List
<
String
>
topicIds
,
List
<
String
>
tagIds
)
throws
BlogCategoryServiceException
{
//如果为不可查看则默认为不可评论和转载
...
...
@@ -111,23 +115,33 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
//4.判断是否引用话题
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
:
t
opicIds
)
{
for
(
String
topicId
:
existsT
opicIds
)
{
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
(!
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
:
t
agIds
)
{
for
(
String
tagId
:
existsT
agIds
)
{
BlogTag
blogTag
=
new
BlogTag
();
blogTag
.
setBlogId
(
blog
.
getBlogId
());
blogTag
.
setTagId
(
tagId
);
...
...
@@ -136,6 +150,7 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
blogTagService
.
saveBatch
(
blogTagList
);
}
}
}
/**
* 删除博客
...
...
src/main/java/cn/meteor/beyondclouds/modules/topic/service/ITopicService.java
View file @
8da61f2b
...
...
@@ -64,5 +64,19 @@ public interface ITopicService extends IService<Topic> {
*/
IPage
<
User
>
getTopicsFollower
(
Integer
page
,
Integer
size
,
String
topicId
);
/**
* 获取话题分页
* @param page
* @param size
* @param userId
* @return
*/
IPage
<
Topic
>
getTopicPage
(
Integer
page
,
Integer
size
,
String
userId
);
/**
* 增加话题引用次数
* @param topicId
* @param count
*/
void
increaseReferenceCount
(
String
topicId
,
int
count
);
}
src/main/java/cn/meteor/beyondclouds/modules/topic/service/impl/TopicServiceImpl.java
View file @
8da61f2b
...
...
@@ -185,5 +185,13 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
return
page
(
page
,
topicQueryWrapper
);
}
@Override
public
void
increaseReferenceCount
(
String
topicId
,
int
count
)
{
Topic
topic
=
getById
(
topicId
);
if
(
null
!=
topic
)
{
topic
.
setReferenceCount
(
topic
.
getReferenceCount
()
+
count
);
updateById
(
topic
);
}
}
}
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