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
664f2ee9
Commit
664f2ee9
authored
Feb 11, 2020
by
Author name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2.11 发布删除话题时更新话题引用次数
parent
bbced110
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
3 deletions
+64
-3
src/main/java/cn/meteor/beyondclouds/modules/post/api/PostApi.java
+1
-1
src/main/java/cn/meteor/beyondclouds/modules/post/form/PostForm.java
+3
-0
src/main/java/cn/meteor/beyondclouds/modules/post/service/IPostService.java
+5
-1
src/main/java/cn/meteor/beyondclouds/modules/post/service/impl/PostServiceImpl.java
+55
-1
No files found.
src/main/java/cn/meteor/beyondclouds/modules/post/api/PostApi.java
View file @
664f2ee9
...
...
@@ -79,7 +79,7 @@ public class PostApi {
//发布动态
try
{
postService
.
publishPost
(
post
);
postService
.
publishPost
(
post
,
postForm
.
getTopicIds
()
);
return
Response
.
success
();
}
catch
(
ProjectServiceException
e
)
{
e
.
printStackTrace
();
...
...
src/main/java/cn/meteor/beyondclouds/modules/post/form/PostForm.java
View file @
664f2ee9
...
...
@@ -26,4 +26,7 @@ public class PostForm {
@NullOrNotBlank
(
message
=
"请传入有效的视频内容"
)
private
String
video
;
@ElementNotBlank
(
message
=
"话题Id不可为空"
)
private
List
<
String
>
topicIds
;
}
src/main/java/cn/meteor/beyondclouds/modules/post/service/IPostService.java
View file @
664f2ee9
...
...
@@ -6,6 +6,8 @@ import cn.meteor.beyondclouds.modules.project.exception.ProjectServiceException;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
java.util.List
;
/**
* <p>
* 动态表 服务类
...
...
@@ -19,8 +21,10 @@ public interface IPostService extends IService<Post> {
/**
* 发布动态
* @param post
* @param topicIds
* @throws ProjectServiceException
*/
void
publishPost
(
Post
post
)
throws
ProjectServiceException
;
void
publishPost
(
Post
post
,
List
<
String
>
topicIds
)
throws
ProjectServiceException
;
/**
* 删除动态
...
...
src/main/java/cn/meteor/beyondclouds/modules/post/service/impl/PostServiceImpl.java
View file @
664f2ee9
...
...
@@ -9,6 +9,11 @@ import cn.meteor.beyondclouds.modules.post.mapper.PostMapper;
import
cn.meteor.beyondclouds.modules.post.service.IPostService
;
import
cn.meteor.beyondclouds.modules.project.exception.ProjectServiceException
;
import
cn.meteor.beyondclouds.modules.queue.service.IMessageQueueService
;
import
cn.meteor.beyondclouds.modules.topic.entity.Topic
;
import
cn.meteor.beyondclouds.modules.topic.entity.TopicReference
;
import
cn.meteor.beyondclouds.modules.topic.enums.TopicReferenceType
;
import
cn.meteor.beyondclouds.modules.topic.service.ITopicReferenceService
;
import
cn.meteor.beyondclouds.modules.topic.service.ITopicService
;
import
cn.meteor.beyondclouds.modules.user.entity.User
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
...
...
@@ -18,6 +23,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* <p>
...
...
@@ -34,6 +44,20 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
private
IMessageQueueService
messageQueueService
;
private
ITopicService
topicService
;
private
ITopicReferenceService
topicReferenceService
;
@Autowired
public
void
setTopicReferenceService
(
ITopicReferenceService
topicReferenceService
)
{
this
.
topicReferenceService
=
topicReferenceService
;
}
@Autowired
public
void
setTopicService
(
ITopicService
topicService
)
{
this
.
topicService
=
topicService
;
}
@Autowired
public
void
setUserService
(
IUserService
userService
)
{
this
.
userService
=
userService
;
...
...
@@ -50,7 +74,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
* @throws ProjectServiceException
*/
@Override
public
void
publishPost
(
Post
post
)
throws
ProjectServiceException
{
public
void
publishPost
(
Post
post
,
List
<
String
>
topicIds
)
throws
ProjectServiceException
{
//1.判断是否视频和图片都传了
if
(
null
!=
post
.
getPictures
()
&&
null
!=
post
.
getVideo
())
{
throw
new
ProjectServiceException
(
PostErrorCode
.
NOT_APPEAR_SAME_TIME
);
...
...
@@ -79,6 +103,26 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
//2.保存动态
save
(
post
);
//处理话题引用
if
(!
CollectionUtils
.
isEmpty
(
topicIds
))
{
// 获取要引用的话题,不正确的话题ID会被自动过滤
List
<
String
>
existsTopicIds
=
topicService
.
listByIds
(
topicIds
).
stream
().
map
(
Topic:
:
getTopicId
).
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
existsTopicIds
))
{
List
<
TopicReference
>
topicReferences
=
new
ArrayList
<>();
for
(
String
topicId
:
existsTopicIds
)
{
TopicReference
topicReference
=
new
TopicReference
();
topicReference
.
setTopicId
(
topicId
);
topicReference
.
setReferencerId
(
post
.
getPostId
());
topicReference
.
setReferencerType
(
TopicReferenceType
.
POST_REFERENCE
.
getType
());
topicReferences
.
add
(
topicReference
);
}
// 批量保存
topicReferenceService
.
saveBatch
(
topicReferences
);
// 新增话题引用次数
topicService
.
increaseReferenceCountBatch
(
existsTopicIds
,
1
);
}
}
//发送消息到消息队列
messageQueueService
.
sendDataItemChangeMessage
(
DataItemChangeMessage
.
addMessage
(
DataItemType
.
POST
,
post
.
getPostId
(),
post
.
getUserId
()));
}
...
...
@@ -103,6 +147,16 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
//2.删除动态
removeById
(
postId
);
//3.删除动态里的话题引用
QueryWrapper
<
TopicReference
>
topicReferenceQueryWrapper
=
new
QueryWrapper
<>();
topicReferenceQueryWrapper
.
eq
(
"referencer_id"
,
postId
);
//所有的话题引用减1
List
<
String
>
existsTopicIds
=
topicReferenceService
.
list
(
topicReferenceQueryWrapper
).
stream
().
map
(
TopicReference:
:
getTopicId
).
collect
(
Collectors
.
toList
());
topicService
.
decreaseReferenceCountBatch
(
existsTopicIds
,
1
);
topicReferenceService
.
remove
(
topicReferenceQueryWrapper
);
//发送消息到消息队列
messageQueueService
.
sendDataItemChangeMessage
(
DataItemChangeMessage
.
deleteMessage
(
DataItemType
.
POST
,
post
.
getPostId
(),
userId
));
}
...
...
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