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
7893c73d
Commit
7893c73d
authored
Jul 04, 2024
by
陈立彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
会话上下文
parent
e4e5c1d9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
ExamController.java
src/main/java/cn/aibreeze/exam/api/ExamController.java
+40
-0
No files found.
src/main/java/cn/aibreeze/exam/api/ExamController.java
View file @
7893c73d
...
@@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils;
...
@@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormat
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
...
@@ -50,6 +51,10 @@ public class ExamController {
...
@@ -50,6 +51,10 @@ public class ExamController {
private
static
String
EXAM_REDIS_SESSION_KEY
=
"EXAM_MASTER_SESSION:%d:%s"
;
private
static
String
EXAM_REDIS_SESSION_KEY
=
"EXAM_MASTER_SESSION:%d:%s"
;
private
static
String
USER_SESSION_CONTEXT_KEY
=
"USER_SESSION_CONTEXT:%d:%s:%s"
;
private
static
String
USER_SESSION_CONTEXT_COUNT
=
"USER_SESSION_CONTEXT_COUNT"
;
@GetMapping
(
value
=
"/list"
)
@GetMapping
(
value
=
"/list"
)
public
String
list
()
{
public
String
list
()
{
LambdaQueryWrapper
<
ElehKnowledgeDo
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
LambdaQueryWrapper
<
ElehKnowledgeDo
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
...
@@ -270,4 +275,39 @@ public class ExamController {
...
@@ -270,4 +275,39 @@ public class ExamController {
}
}
return
ApiResponse
.
fail
(
"no cache data."
);
return
ApiResponse
.
fail
(
"no cache data."
);
}
}
@GetMapping
(
value
=
"/get_user_session_context"
)
public
ApiResponse
<
String
>
getUserSessionContext
(
@RequestParam
(
value
=
"tenant"
)
Integer
tenant
,
@RequestParam
(
value
=
"user_id"
)
String
userId
,
@RequestParam
(
value
=
"session_id"
)
String
sessionId
,
@RequestParam
(
value
=
"query"
)
String
query
)
{
List
<
String
>
contextList
=
Lists
.
newArrayList
();
String
redisKey
=
String
.
format
(
USER_SESSION_CONTEXT_KEY
,
tenant
,
sessionId
,
userId
);
Long
contextCount
=
redisTemplate
.
opsForList
().
size
(
redisKey
);
// 最多获取5条上下文
long
maxCount
=
3
;
String
cacheMaxCount
=
redisTemplate
.
opsForValue
().
get
(
USER_SESSION_CONTEXT_COUNT
);
if
(
StringUtils
.
isNotEmpty
(
cacheMaxCount
))
{
maxCount
=
Long
.
valueOf
(
cacheMaxCount
);
}
contextCount
=
contextCount
>
maxCount
?
maxCount
:
contextCount
;
if
(
contextCount
>
0
)
{
contextList
=
redisTemplate
.
opsForList
().
range
(
redisKey
,
0
,
contextCount
-
1
);
Collections
.
reverse
(
contextList
);
}
log
.
info
(
"当前用户ID = {}, 会话历史 = {} "
,
userId
,
JSONObject
.
toJSONString
(
contextList
));
// 存储当前用户提问
redisTemplate
.
opsForList
().
leftPush
(
redisKey
,
query
);
return
ApiResponse
.
ok
(
JSONObject
.
toJSONString
(
contextList
));
}
}
}
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