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
6af80433
Commit
6af80433
authored
Feb 08, 2020
by
胡学良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化通过标签ID得到问答列表
parent
c8e81e9f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionApi.java
+1
-1
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionServiceImpl.java
+15
-9
No files found.
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionApi.java
View file @
6af80433
...
...
@@ -256,7 +256,7 @@ public class QuestionApi {
}
@Anonymous
@ApiOperation
(
"标签下的问答列表"
)
@ApiOperation
(
"
得到
标签下的问答列表"
)
@GetMapping
(
"/tag/{tagId}/questions"
)
public
Response
<
PageVO
<
Question
>>
getQuestionsByTagId
(
@Valid
PageForm
pageForm
,
@PathVariable
(
"tagId"
)
String
tagId
)
{
try
{
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionServiceImpl.java
View file @
6af80433
...
...
@@ -421,25 +421,31 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
@Override
public
IPage
<
Question
>
getQuestionsByTagId
(
Integer
pageNumber
,
Integer
pageSize
,
String
tagId
)
throws
QuestionTagServiceException
{
IPage
<
Question
>
page
=
new
Page
<>(
pageNumber
,
pageSize
);
//1.检查标签是否存在
Tag
tag
=
tagService
.
getById
(
tagId
);
if
(
null
==
tag
)
{
throw
new
QuestionTagServiceException
(
QuestionTagErrorCode
.
TAG_NOT_FOUND
);
}
IPage
<
Question
>
questionPage
=
new
Page
<>(
pageNumber
,
pageSize
);
IPage
<
QuestionTag
>
questionTagPage
=
new
Page
<>(
pageNumber
,
pageSize
);
//2.通过标签ID得到对应的问题ID
List
<
String
>
questionIds
=
questionTagService
.
list
(
QuestionUtils
.
getWrapper
(
"tag_id"
,
tag
.
getTagId
()))
.
stream
().
map
(
QuestionTag:
:
getQuestionId
).
collect
(
Collectors
.
toList
());
QueryWrapper
<
QuestionTag
>
questionTagQueryWrapper
=
new
QueryWrapper
<>();
questionTagQueryWrapper
.
eq
(
"tag_id"
,
tag
.
getTagId
());
questionTagService
.
page
(
questionTagPage
,
questionTagQueryWrapper
);
List
<
String
>
questionIds
=
questionTagPage
.
getRecords
().
stream
().
map
(
QuestionTag:
:
getQuestionId
).
collect
(
Collectors
.
toList
());
questionPage
.
setTotal
(
questionTagPage
.
getTotal
());
questionPage
.
setCurrent
(
questionTagPage
.
getCurrent
());
if
(!
CollectionUtils
.
isEmpty
(
questionIds
))
{
QueryWrapper
<
Question
>
questionQueryWrapper
=
new
QueryWrapper
<>();
questionQueryWrapper
.
in
(
"q.question_id"
,
questionIds
)
.
orderByDesc
(
"q.create_time"
);
return
questionMapper
.
selectPageWithTags
(
page
,
questionQueryWrapper
);
questionPage
.
setRecords
(
questionMapper
.
listByIdsWithTags
(
questionIds
));
}
else
{
return
page
;
questionPage
.
setRecords
(
List
.
of
())
;
}
return
questionPage
;
}
}
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