Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
exam_master
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
exam_master
Commits
850306b5
Commit
850306b5
authored
Jun 21, 2024
by
陈立彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
当前考题
parent
2ba69d46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
pom.xml
pom.xml
+5
-0
ExamController.java
src/main/java/cn/aibreeze/exam/api/ExamController.java
+38
-0
No files found.
pom.xml
View file @
850306b5
...
...
@@ -59,6 +59,11 @@
<version>
2.0.32
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
</dependencies>
<build>
...
...
src/main/java/cn/aibreeze/exam/api/ExamController.java
View file @
850306b5
...
...
@@ -11,13 +11,16 @@ import cn.aibreeze.exam.mapper.ElehKnowledgeTagMapper;
import
cn.aibreeze.exam.mapper.ElehSessionQaRecordMapper
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
io.micrometer.common.util.StringUtils
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.concurrent.TimeUnit
;
@RestController
...
...
@@ -32,6 +35,10 @@ public class ExamController {
private
final
ElehSessionQaRecordMapper
qaRecordMapper
;
private
final
StringRedisTemplate
redisTemplate
;
private
static
String
EXAM_REDIS_SESSION_KEY
=
"EXAM_MASTER:%d:%s:%s"
;
@GetMapping
(
value
=
"/list"
)
public
String
list
()
{
LambdaQueryWrapper
<
ElehKnowledgeDo
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
...
...
@@ -40,6 +47,33 @@ public class ExamController {
return
JSONObject
.
toJSONString
(
elehKnowledgeDos
);
}
@GetMapping
(
value
=
"/get_current_question"
)
public
ApiResponse
<
GetQuestionResponseResult
>
getCurrentQuestion
(
@RequestParam
(
"tenant"
)
Integer
tenant
,
@RequestParam
(
"session_id"
)
String
sessionId
,
@RequestParam
(
"user_id"
)
String
userId
)
{
GetQuestionResponseResult
result
=
new
GetQuestionResponseResult
();
String
redisKey
=
String
.
format
(
EXAM_REDIS_SESSION_KEY
,
tenant
,
sessionId
,
userId
);
String
currentQuestion
=
redisTemplate
.
opsForValue
().
get
(
redisKey
);
if
(
StringUtils
.
isNotEmpty
(
currentQuestion
))
{
ElehKnowledgeDo
knowledgeDo
=
knowledgeMapper
.
selectById
(
Long
.
valueOf
(
currentQuestion
));
if
(
Objects
.
nonNull
(
knowledgeDo
))
{
ElehKnowledgeTagDo
tagDo
=
tagMapper
.
selectById
(
knowledgeDo
.
getTagId
());
result
.
setQuestion
(
knowledgeDo
.
getQuestion
());
result
.
setAnswer
(
knowledgeDo
.
getAnswer
());
result
.
setProject
(
tagDo
.
getName
());
result
.
setCode
(
tagDo
.
getCode
());
result
.
setQuestionId
(
knowledgeDo
.
getId
());
result
.
setNext
(
true
);
}
}
return
ApiResponse
.
ok
(
result
);
}
@GetMapping
(
value
=
"/get_question"
)
public
ApiResponse
<
GetQuestionResponseResult
>
getQuestion
(
@RequestParam
(
"tenant"
)
Integer
tenant
,
@RequestParam
(
"code"
)
String
code
,
...
...
@@ -61,6 +95,10 @@ public class ExamController {
result
.
setCode
(
tagDo
.
getCode
());
result
.
setQuestionId
(
knowledgeDo
.
getId
());
result
.
setNext
(
true
);
// 存储当前会话考试信息
String
redisKey
=
String
.
format
(
EXAM_REDIS_SESSION_KEY
,
tenant
,
sessionId
,
userId
);
redisTemplate
.
opsForValue
().
set
(
redisKey
,
result
.
getQuestionId
()+
""
,
10
,
TimeUnit
.
MINUTES
);
}
}
...
...
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