Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
answer-backend
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
answer
answer-backend
Commits
01bd69f5
Commit
01bd69f5
authored
Feb 03, 2023
by
wqc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多选题答题计算
parent
7df2ecf5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
11 deletions
+30
-11
user-server/src/main/java/com/zq/user/controller/api/QuestionApi.java
+1
-1
user-server/src/main/java/com/zq/user/service/AddressService.java
+1
-1
user-server/src/main/java/com/zq/user/service/QuestionService.java
+28
-9
No files found.
user-server/src/main/java/com/zq/user/controller/api/QuestionApi.java
View file @
01bd69f5
...
@@ -34,7 +34,7 @@ public class QuestionApi {
...
@@ -34,7 +34,7 @@ public class QuestionApi {
@ApiOperation
(
"答题"
)
@ApiOperation
(
"答题"
)
@PostMapping
(
value
=
"/answer"
)
@PostMapping
(
value
=
"/answer"
)
public
ResultVo
answer
(
@RequestBody
AnswerRec
vo
)
{
public
ResultVo
answer
(
@RequestBody
AnswerRec
vo
)
{
AssertUtils
.
hasText
(
vo
.
getUserId
(),
"缺少用户ID"
);
//
AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
AssertUtils
.
hasText
(
vo
.
getAnswerList
(),
"缺少答案"
);
AssertUtils
.
hasText
(
vo
.
getAnswerList
(),
"缺少答案"
);
return
ResultVo
.
success
(
questionService
.
answer
(
vo
));
return
ResultVo
.
success
(
questionService
.
answer
(
vo
));
}
}
...
...
user-server/src/main/java/com/zq/user/service/AddressService.java
View file @
01bd69f5
...
@@ -45,7 +45,7 @@ public class AddressService {
...
@@ -45,7 +45,7 @@ public class AddressService {
}
}
if
(
vo
.
getIsDefault
())
{
if
(
vo
.
getIsDefault
())
{
addressDao
.
update
(
Address
.
builder
().
isDefault
(
fals
e
).
updateTime
(
DateUtil
.
date
()).
build
(),
addressDao
.
update
(
Address
.
builder
().
isDefault
(
tru
e
).
updateTime
(
DateUtil
.
date
()).
build
(),
Wrappers
.
lambdaUpdate
(
Address
.
class
)
Wrappers
.
lambdaUpdate
(
Address
.
class
)
.
eq
(
Address:
:
getUserId
,
vo
.
getUserId
())
.
eq
(
Address:
:
getUserId
,
vo
.
getUserId
())
.
notIn
(
Address:
:
getId
,
vo
.
getId
()));
.
notIn
(
Address:
:
getId
,
vo
.
getId
()));
...
...
user-server/src/main/java/com/zq/user/service/QuestionService.java
View file @
01bd69f5
...
@@ -25,11 +25,13 @@ import com.zq.user.vo.AnswerRecVo;
...
@@ -25,11 +25,13 @@ import com.zq.user.vo.AnswerRecVo;
import
com.zq.user.vo.QuestionFindVo
;
import
com.zq.user.vo.QuestionFindVo
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.math.RoundingMode
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
/**
* @author wilmiam
* @author wilmiam
...
@@ -135,30 +137,47 @@ public class QuestionService {
...
@@ -135,30 +137,47 @@ public class QuestionService {
String
questionId
=
obj
.
getStr
(
"questionId"
);
String
questionId
=
obj
.
getStr
(
"questionId"
);
// 用户所选答案
// 用户所选答案
JSONArray
answerArr
=
obj
.
getJSONArray
(
"answer"
);
JSONArray
answerArr
=
obj
.
getJSONArray
(
"answer"
);
Question
question
=
questionDao
.
selectById
(
questionId
);
Question
question
=
questionDao
.
selectById
(
questionId
);
String
answer
=
question
.
getAnswer
();
String
answer
=
question
.
getAnswer
();
// 正确答案
// 正确答案
List
<
String
>
answerList
=
StrUtil
.
split
(
answer
,
','
);
List
<
String
>
answerList
=
StrUtil
.
split
(
answer
,
','
);
if
(
answerArr
.
size
()>
1
){
for
(
Object
o
:
answerArr
)
{
String
[]
split
=
StringUtils
.
strip
(
answerArr
.
toString
(),
"[]"
).
split
(
","
);
String
s
=
Convert
.
toStr
(
o
,
""
);
List
<
String
>
list
=
new
ArrayList
<>();
// 删除所选答案,正确答案中还有答案就说明答错了
for
(
String
s
:
split
)
{
boolean
remove
=
answerList
.
remove
(
s
);
String
str
=
s
.
replace
(
"\""
,
""
);
if
(!
remove
)
{
list
.
add
(
str
);
}
String
collect
=
list
.
stream
().
collect
(
Collectors
.
joining
(
","
));
if
(!
collect
.
equals
(
answer
)){
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"subject"
,
question
.
getSubject
());
map
.
put
(
"subject"
,
question
.
getSubject
());
map
.
put
(
"answer"
,
question
.
getAnswer
());
map
.
put
(
"answer"
,
question
.
getAnswer
());
map
.
put
(
"analysis"
,
question
.
getAnalysis
());
map
.
put
(
"analysis"
,
question
.
getAnalysis
());
map
.
put
(
"content"
,
question
.
getContent
());
map
.
put
(
"content"
,
question
.
getContent
());
map
.
put
(
"choiceAnswer"
,
answer
);
map
.
put
(
"choiceAnswer"
,
answer
);
wrongQuestionList
.
add
(
map
);
wrongQuestionList
.
add
(
map
);
break
;
break
;
}
}
}
else
{
for
(
Object
o
:
answerArr
)
{
String
s
=
Convert
.
toStr
(
o
,
""
);
// 删除所选答案,正确答案中还有答案就说明答错了
boolean
remove
=
answerList
.
remove
(
s
);
if
(!
remove
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"subject"
,
question
.
getSubject
());
map
.
put
(
"answer"
,
question
.
getAnswer
());
map
.
put
(
"analysis"
,
question
.
getAnalysis
());
map
.
put
(
"content"
,
question
.
getContent
());
map
.
put
(
"choiceAnswer"
,
answer
);
wrongQuestionList
.
add
(
map
);
break
;
}
}
}
}
if
(
CollUtil
.
isEmpty
(
answerList
))
{
if
(
CollUtil
.
isEmpty
(
answerList
))
{
correct
++;
correct
++;
}
}
...
...
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