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
6922b4fd
Commit
6922b4fd
authored
Feb 11, 2020
by
胡明森
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
引用该话题所有动态
parent
0485dd57
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
1 deletions
+81
-1
src/main/java/cn/meteor/beyondclouds/modules/topic/api/TopicApi.java
+16
-0
src/main/java/cn/meteor/beyondclouds/modules/topic/service/ITopicService.java
+11
-0
src/main/java/cn/meteor/beyondclouds/modules/topic/service/impl/TopicServiceImpl.java
+54
-1
No files found.
src/main/java/cn/meteor/beyondclouds/modules/topic/api/TopicApi.java
View file @
6922b4fd
...
...
@@ -6,6 +6,7 @@ import cn.meteor.beyondclouds.core.annotation.Anonymous;
import
cn.meteor.beyondclouds.core.annotation.CurrentSubject
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.authentication.Subject
;
import
cn.meteor.beyondclouds.modules.post.entity.Post
;
import
cn.meteor.beyondclouds.modules.topic.bean.TopicDetail
;
import
cn.meteor.beyondclouds.modules.topic.entity.Topic
;
import
cn.meteor.beyondclouds.modules.topic.exception.TopicServiceException
;
...
...
@@ -167,4 +168,19 @@ public class TopicApi {
return
Response
.
success
(
topicPageVO
);
}
@Anonymous
@ApiOperation
(
"引用该话题所有动态"
)
@GetMapping
(
"/topic/{topicName}/posts"
)
public
Response
<
PageVO
<
Post
>>
getPostByTopicName
(
@Valid
PageForm
pageForm
,
@PathVariable
(
"topicName"
)
String
topicName
)
{
try
{
IPage
<
Post
>
post
=
topicService
.
getPostByTopicName
(
pageForm
.
getPage
(),
pageForm
.
getSize
(),
topicName
);
PageVO
<
Post
>
postPageVO
=
new
PageVO
<>(
post
);
return
Response
.
success
(
postPageVO
);
}
catch
(
TopicServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
();
}
}
}
src/main/java/cn/meteor/beyondclouds/modules/topic/service/ITopicService.java
View file @
6922b4fd
package
cn
.
meteor
.
beyondclouds
.
modules
.
topic
.
service
;
import
cn.meteor.beyondclouds.modules.post.entity.Post
;
import
cn.meteor.beyondclouds.modules.topic.bean.TopicDetail
;
import
cn.meteor.beyondclouds.modules.topic.entity.Topic
;
import
cn.meteor.beyondclouds.modules.topic.exception.TopicServiceException
;
...
...
@@ -128,4 +129,14 @@ public interface ITopicService extends IService<Topic> {
* @return
*/
IPage
<
Topic
>
getHotPage
(
Integer
pageNumber
,
Integer
pageSize
);
/**
*该话题下所有的动态
* @param pageNumber
* @param pageSize
* @param topicName
* @throws TopicServiceException
* @return IPage<Post>
*/
IPage
<
Post
>
getPostByTopicName
(
Integer
pageNumber
,
Integer
pageSize
,
String
topicName
)
throws
TopicServiceException
;
}
src/main/java/cn/meteor/beyondclouds/modules/topic/service/impl/TopicServiceImpl.java
View file @
6922b4fd
package
cn
.
meteor
.
beyondclouds
.
modules
.
topic
.
service
.
impl
;
import
cn.meteor.beyondclouds.modules.post.entity.Post
;
import
cn.meteor.beyondclouds.modules.post.service.IPostService
;
import
cn.meteor.beyondclouds.modules.topic.bean.TopicDetail
;
import
cn.meteor.beyondclouds.modules.topic.entity.Topic
;
import
cn.meteor.beyondclouds.modules.topic.entity.TopicFollow
;
import
cn.meteor.beyondclouds.modules.topic.entity.TopicReference
;
import
cn.meteor.beyondclouds.modules.topic.enums.TopicErrorCode
;
import
cn.meteor.beyondclouds.modules.topic.exception.TopicServiceException
;
import
cn.meteor.beyondclouds.modules.topic.mapper.TopicMapper
;
import
cn.meteor.beyondclouds.modules.topic.service.ITopicFollowService
;
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
;
...
...
@@ -41,10 +45,16 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
private
TopicMapper
topicMapper
;
private
ITopicReferenceService
topicReferenceService
;
private
IPostService
postService
;
@Autowired
public
TopicServiceImpl
(
ITopicFollowService
topicFollowService
,
TopicMapper
topicMapper
)
{
public
TopicServiceImpl
(
ITopicFollowService
topicFollowService
,
TopicMapper
topicMapper
,
ITopicReferenceService
topicReferenceService
,
IPostService
postService
)
{
this
.
topicFollowService
=
topicFollowService
;
this
.
topicMapper
=
topicMapper
;
this
.
topicReferenceService
=
topicReferenceService
;
this
.
postService
=
postService
;
}
@Autowired
...
...
@@ -290,4 +300,47 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
}
@Override
public
IPage
<
Post
>
getPostByTopicName
(
Integer
pageNumber
,
Integer
pageSize
,
String
topicName
)
throws
TopicServiceException
{
//1. 设置分页信息
IPage
<
TopicReference
>
page
=
new
Page
<>(
pageNumber
,
pageSize
);
//2. 判断该话题是否存在
QueryWrapper
<
Topic
>
topicQueryWrapper
=
new
QueryWrapper
<>();
topicQueryWrapper
.
eq
(
"topic_name"
,
topicName
);
Topic
topic
=
getOne
(
topicQueryWrapper
);
if
(
topic
==
null
)
{
throw
new
TopicServiceException
(
TopicErrorCode
.
TOPIC_NOT_EXISTS
);
}
//3. 通过话题id与动态类型3查找该话题下的所有动态
QueryWrapper
<
TopicReference
>
topicReferenceQueryWrapper
=
new
QueryWrapper
<>();
topicReferenceQueryWrapper
.
eq
(
"topic_id"
,
topic
.
getTopicId
()).
eq
(
"referencer_type"
,
3
);
IPage
<
TopicReference
>
topicReferenceIPage
=
topicReferenceService
.
page
(
page
,
topicReferenceQueryWrapper
);
//4. 获取查询到的referencerId
List
<
String
>
referencerId
=
topicReferenceIPage
.
getRecords
().
stream
()
.
map
(
TopicReference:
:
getReferencerId
)
.
collect
(
Collectors
.
toList
());
//5. 通过referencerId批量查询动态
List
<
Post
>
posts
;
if
(!
CollectionUtils
.
isEmpty
(
referencerId
))
{
posts
=
postService
.
listByIds
(
referencerId
);
}
else
{
posts
=
List
.
of
();
}
// 6.构造分页结果
IPage
<
Post
>
postIPage
=
new
Page
<>();
postIPage
.
setSize
(
topicReferenceIPage
.
getSize
());
postIPage
.
setCurrent
(
topicReferenceIPage
.
getCurrent
());
postIPage
.
setPages
(
topicReferenceIPage
.
getPages
());
postIPage
.
setTotal
(
topicReferenceIPage
.
getTotal
());
postIPage
.
setRecords
(
posts
);
return
postIPage
;
}
}
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