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
3e004bac
Commit
3e004bac
authored
Feb 11, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/fix-issue#47'
parents
0485dd57
664f2ee9
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 @
3e004bac
...
@@ -79,7 +79,7 @@ public class PostApi {
...
@@ -79,7 +79,7 @@ public class PostApi {
//发布动态
//发布动态
try
{
try
{
postService
.
publishPost
(
post
);
postService
.
publishPost
(
post
,
postForm
.
getTopicIds
()
);
return
Response
.
success
();
return
Response
.
success
();
}
catch
(
ProjectServiceException
e
)
{
}
catch
(
ProjectServiceException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
src/main/java/cn/meteor/beyondclouds/modules/post/form/PostForm.java
View file @
3e004bac
...
@@ -26,4 +26,7 @@ public class PostForm {
...
@@ -26,4 +26,7 @@ public class PostForm {
@NullOrNotBlank
(
message
=
"请传入有效的视频内容"
)
@NullOrNotBlank
(
message
=
"请传入有效的视频内容"
)
private
String
video
;
private
String
video
;
@ElementNotBlank
(
message
=
"话题Id不可为空"
)
private
List
<
String
>
topicIds
;
}
}
src/main/java/cn/meteor/beyondclouds/modules/post/service/IPostService.java
View file @
3e004bac
...
@@ -6,6 +6,8 @@ import cn.meteor.beyondclouds.modules.project.exception.ProjectServiceException;
...
@@ -6,6 +6,8 @@ import cn.meteor.beyondclouds.modules.project.exception.ProjectServiceException;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
java.util.List
;
/**
/**
* <p>
* <p>
* 动态表 服务类
* 动态表 服务类
...
@@ -19,8 +21,10 @@ public interface IPostService extends IService<Post> {
...
@@ -19,8 +21,10 @@ public interface IPostService extends IService<Post> {
/**
/**
* 发布动态
* 发布动态
* @param 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 @
3e004bac
...
@@ -9,6 +9,11 @@ import cn.meteor.beyondclouds.modules.post.mapper.PostMapper;
...
@@ -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.post.service.IPostService
;
import
cn.meteor.beyondclouds.modules.project.exception.ProjectServiceException
;
import
cn.meteor.beyondclouds.modules.project.exception.ProjectServiceException
;
import
cn.meteor.beyondclouds.modules.queue.service.IMessageQueueService
;
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.entity.User
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
...
@@ -18,6 +23,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
...
@@ -18,6 +23,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
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.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
/**
* <p>
* <p>
...
@@ -34,6 +44,20 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
...
@@ -34,6 +44,20 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
private
IMessageQueueService
messageQueueService
;
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
@Autowired
public
void
setUserService
(
IUserService
userService
)
{
public
void
setUserService
(
IUserService
userService
)
{
this
.
userService
=
userService
;
this
.
userService
=
userService
;
...
@@ -50,7 +74,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
...
@@ -50,7 +74,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
* @throws ProjectServiceException
* @throws ProjectServiceException
*/
*/
@Override
@Override
public
void
publishPost
(
Post
post
)
throws
ProjectServiceException
{
public
void
publishPost
(
Post
post
,
List
<
String
>
topicIds
)
throws
ProjectServiceException
{
//1.判断是否视频和图片都传了
//1.判断是否视频和图片都传了
if
(
null
!=
post
.
getPictures
()
&&
null
!=
post
.
getVideo
())
{
if
(
null
!=
post
.
getPictures
()
&&
null
!=
post
.
getVideo
())
{
throw
new
ProjectServiceException
(
PostErrorCode
.
NOT_APPEAR_SAME_TIME
);
throw
new
ProjectServiceException
(
PostErrorCode
.
NOT_APPEAR_SAME_TIME
);
...
@@ -79,6 +103,26 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
...
@@ -79,6 +103,26 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
//2.保存动态
//2.保存动态
save
(
post
);
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
()));
messageQueueService
.
sendDataItemChangeMessage
(
DataItemChangeMessage
.
addMessage
(
DataItemType
.
POST
,
post
.
getPostId
(),
post
.
getUserId
()));
}
}
...
@@ -103,6 +147,16 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
...
@@ -103,6 +147,16 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IP
//2.删除动态
//2.删除动态
removeById
(
postId
);
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
));
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