Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-question
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
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
xingmin
yd-question
Commits
a9152dbd
Commit
a9152dbd
authored
Oct 15, 2025
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
149c9d8a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
10 deletions
+34
-10
yd-question-api/src/main/java/com/yd/question/api/service/impl/ApiQuestionnairesServiceImpl.java
+34
-10
No files found.
yd-question-api/src/main/java/com/yd/question/api/service/impl/ApiQuestionnairesServiceImpl.java
View file @
a9152dbd
...
@@ -25,10 +25,8 @@ import org.springframework.beans.BeanUtils;
...
@@ -25,10 +25,8 @@ import org.springframework.beans.BeanUtils;
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
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.*
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Slf4j
@Slf4j
...
@@ -207,23 +205,49 @@ public class ApiQuestionnairesServiceImpl implements ApiQuestionnairesService {
...
@@ -207,23 +205,49 @@ public class ApiQuestionnairesServiceImpl implements ApiQuestionnairesService {
ApiFirstAndSecondCategoryDto
firstCategoryDto
=
new
ApiFirstAndSecondCategoryDto
();
ApiFirstAndSecondCategoryDto
firstCategoryDto
=
new
ApiFirstAndSecondCategoryDto
();
firstCategoryDto
.
setFirstCategory
(
entry
.
getKey
());
firstCategoryDto
.
setFirstCategory
(
entry
.
getKey
());
// 对当前一级分类下的数据进行二级分类分组
// 对当前一级分类下的数据进行二级分类分组
,并按relQuestionnaireQuestionsSortOrder升序排序
Map
<
String
,
List
<
ApiRelQuestionsGroupDto
>>
secondCategoryMap
=
entry
.
getValue
().
stream
()
Map
<
String
,
List
<
ApiRelQuestionsGroupDto
>>
secondCategoryMap
=
entry
.
getValue
().
stream
()
// 过滤掉secondCategory为null的记录
// 过滤掉secondCategory为null的记录
.
filter
(
dto
->
dto
.
getSecondCategory
()
!=
null
)
.
filter
(
dto
->
dto
.
getSecondCategory
()
!=
null
)
.
collect
(
Collectors
.
groupingBy
(
ApiRelQuestionsGroupDto:
:
getSecondCategory
));
// 收集到LinkedHashMap中保持排序
.
collect
(
Collectors
.
groupingBy
(
ApiRelQuestionsGroupDto:
:
getSecondCategory
,
// 使用LinkedHashMap来保持插入顺序
LinkedHashMap:
:
new
,
// 对每个分组内的数据按照relQuestionnaireQuestionsSortOrder升序排序
Collectors
.
collectingAndThen
(
Collectors
.
toList
(),
list
->
list
.
stream
()
.
sorted
(
Comparator
.
comparing
(
ApiRelQuestionsGroupDto:
:
getRelQuestionnaireQuestionsSortOrder
))
.
collect
(
Collectors
.
toList
())
)
));
// 然后对Map的key(二级分类)按照其下最小relQuestionnaireQuestionsSortOrder进行排序
List
<
Map
.
Entry
<
String
,
List
<
ApiRelQuestionsGroupDto
>>>
sortedEntries
=
secondCategoryMap
.
entrySet
().
stream
()
.
sorted
(
Comparator
.
comparing
(
entry2
->
entry2
.
getValue
().
stream
()
.
mapToInt
(
ApiRelQuestionsGroupDto:
:
getRelQuestionnaireQuestionsSortOrder
)
.
min
()
.
orElse
(
Integer
.
MAX_VALUE
)
))
.
collect
(
Collectors
.
toList
());
// 重新构建排序后的Map
Map
<
String
,
List
<
ApiRelQuestionsGroupDto
>>
sortedSecondCategoryMap
=
new
LinkedHashMap
<>();
for
(
Map
.
Entry
<
String
,
List
<
ApiRelQuestionsGroupDto
>>
sortedEntry
:
sortedEntries
)
{
sortedSecondCategoryMap
.
put
(
sortedEntry
.
getKey
(),
sortedEntry
.
getValue
());
}
// 转换为二级分类DTO列表
// 转换为二级分类DTO列表
List
<
ApiSecondCategoryDto
>
secondCategoryDtoList
=
secondCategoryMap
.
entrySet
().
stream
()
List
<
ApiSecondCategoryDto
>
secondCategoryDtoList
=
s
ortedS
econdCategoryMap
.
entrySet
().
stream
()
.
map
(
secondEntry
->
{
.
map
(
secondEntry
->
{
ApiSecondCategoryDto
secondCategoryDto
=
new
ApiSecondCategoryDto
();
ApiSecondCategoryDto
secondCategoryDto
=
new
ApiSecondCategoryDto
();
secondCategoryDto
.
setSecondCategory
(
secondEntry
.
getKey
());
secondCategoryDto
.
setSecondCategory
(
secondEntry
.
getKey
());
// 设置问题列表
// 设置问题列表
(已经按relQuestionnaireQuestionsSortOrder排序过)
List
<
ApiRelQuestionsGroupDto
>
questionsDtoList
=
secondEntry
.
getValue
();
List
<
ApiRelQuestionsGroupDto
>
questionsDtoList
=
secondEntry
.
getValue
();
if
(!
CollectionUtils
.
isEmpty
(
questionsDtoList
))
{
if
(!
CollectionUtils
.
isEmpty
(
questionsDtoList
))
{
//设置问题列表
secondCategoryDto
.
setQuestionsDtoList
(
questionsDtoList
(
questionsDtoList
,
questionnaireBizId
,
objectBizId
));
secondCategoryDto
.
setQuestionsDtoList
(
questionsDtoList
(
questionsDtoList
,
questionnaireBizId
,
objectBizId
));
}
}
return
secondCategoryDto
;
return
secondCategoryDto
;
...
...
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