Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poc
poc-api
Commits
4dc76bfc
Commit
4dc76bfc
authored
Nov 12, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:【首页】推荐问 - 针对用户上次推荐不重复
parent
209f514f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
6 deletions
+32
-6
AgentApplicationService.java
.../cn/com/poc/expose/aggregate/AgentApplicationService.java
+4
-1
AgentApplicationServiceImpl.java
...oc/expose/aggregate/impl/AgentApplicationServiceImpl.java
+25
-4
AgentApplicationRestImpl.java
...cn/com/poc/expose/rest/impl/AgentApplicationRestImpl.java
+2
-1
AgentApplicationInfoTest.java
src/test/java/cn/com/poc/AgentApplicationInfoTest.java
+1
-0
No files found.
src/main/java/cn/com/poc/expose/aggregate/AgentApplicationService.java
View file @
4dc76bfc
...
@@ -23,8 +23,11 @@ public interface AgentApplicationService {
...
@@ -23,8 +23,11 @@ public interface AgentApplicationService {
/**
/**
* [首页] 获取推荐问
* [首页] 获取推荐问
*
* @param xlang 语言 zh-cn 中文简体 en 英文 zh-tw 中文繁体
* @param memberId 用户ID
*/
*/
List
<
String
>
getRecommendQuestions
(
String
xlang
)
throws
InterruptedException
;
List
<
String
>
getRecommendQuestions
(
String
xlang
,
Long
memberId
)
throws
InterruptedException
;
/**
/**
* [首页] 生成推荐问
* [首页] 生成推荐问
...
...
src/main/java/cn/com/poc/expose/aggregate/impl/AgentApplicationServiceImpl.java
View file @
4dc76bfc
...
@@ -54,6 +54,11 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -54,6 +54,11 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
final
private
String
AGENT_APPLICATION_RECOMMEND_QUESTIONS
=
"AGENT_APPLICATION_RECOMMEND_QUESTIONS:"
;
final
private
String
AGENT_APPLICATION_RECOMMEND_QUESTIONS
=
"AGENT_APPLICATION_RECOMMEND_QUESTIONS:"
;
/**
* 用户获取推荐问题的上一次记录
*/
final
private
String
MEMBER_RECOMMEND_QUESTIONS_LAST
=
AGENT_APPLICATION_RECOMMEND_QUESTIONS
+
"MEMBER_LAST:"
;
@Resource
@Resource
private
BizMemberAgentApplicationCollectService
bizMemberAgentApplicationCollectService
;
private
BizMemberAgentApplicationCollectService
bizMemberAgentApplicationCollectService
;
...
@@ -184,10 +189,11 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -184,10 +189,11 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
}
}
@Override
@Override
public
List
<
String
>
getRecommendQuestions
(
String
xlang
)
{
public
List
<
String
>
getRecommendQuestions
(
String
xlang
,
Long
memberId
)
{
if
(
StringUtils
.
isBlank
(
xlang
))
{
if
(
StringUtils
.
isBlank
(
xlang
))
{
xlang
=
"zh-cn"
;
xlang
=
"zh-cn"
;
}
}
String
redisKey
=
AGENT_APPLICATION_RECOMMEND_QUESTIONS
+
xlang
;
String
redisKey
=
AGENT_APPLICATION_RECOMMEND_QUESTIONS
+
xlang
;
if
(!
redisService
.
hasKey
(
redisKey
))
{
if
(!
redisService
.
hasKey
(
redisKey
))
{
...
@@ -204,17 +210,32 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
...
@@ -204,17 +210,32 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
return
null
;
return
null
;
}
}
Set
<
Long
>
indexSet
=
new
HashSet
<>();
// 获取用户上一次的推荐话题ID,并在本次不重复获取该ID
String
lastRecommendQuestionRedisKey
=
MEMBER_RECOMMEND_QUESTIONS_LAST
+
memberId
;
List
<
Object
>
lastRecomendIdSet
=
null
;
if
(
redisService
.
hasKey
(
lastRecommendQuestionRedisKey
))
{
lastRecomendIdSet
=
redisService
.
lGet
(
lastRecommendQuestionRedisKey
,
0
,
-
1
);
}
Set
<
Long
>
indexSet
=
new
HashSet
<>(
3
);
SecureRandom
secureRandom
=
new
SecureRandom
();
SecureRandom
secureRandom
=
new
SecureRandom
();
do
{
do
{
indexSet
.
add
((
long
)
secureRandom
.
nextInt
((
int
)
size
));
long
id
=
(
long
)
secureRandom
.
nextInt
((
int
)
size
);
if
(
lastRecomendIdSet
!=
null
&&
lastRecomendIdSet
.
stream
().
anyMatch
(
v
->
String
.
valueOf
(
v
).
equals
(
String
.
valueOf
(
id
))))
{
continue
;
}
indexSet
.
add
(
id
);
}
while
(
indexSet
.
size
()
<
3
);
}
while
(
indexSet
.
size
()
<
3
);
List
<
String
>
result
=
new
ArrayList
<>();
List
<
String
>
result
=
new
ArrayList
<>();
List
<
Object
>
recordId
=
new
ArrayList
<>(
3
);
for
(
Long
index
:
indexSet
)
{
for
(
Long
index
:
indexSet
)
{
recordId
.
add
(
index
);
Object
str
=
redisService
.
lGetIndex
(
redisKey
,
index
);
Object
str
=
redisService
.
lGetIndex
(
redisKey
,
index
);
result
.
add
(
str
.
toString
());
result
.
add
(
str
.
toString
());
}
}
redisService
.
del
(
lastRecommendQuestionRedisKey
);
redisService
.
lSet
(
lastRecommendQuestionRedisKey
,
recordId
);
return
result
;
return
result
;
}
}
...
...
src/main/java/cn/com/poc/expose/rest/impl/AgentApplicationRestImpl.java
View file @
4dc76bfc
...
@@ -61,7 +61,8 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
...
@@ -61,7 +61,8 @@ public class AgentApplicationRestImpl implements AgentApplicationRest {
@Override
@Override
public
List
<
String
>
getRecommendQuestions
(
HttpServletRequest
httpServletRequest
)
throws
Exception
{
public
List
<
String
>
getRecommendQuestions
(
HttpServletRequest
httpServletRequest
)
throws
Exception
{
return
agentApplicationService
.
getRecommendQuestions
(
httpServletRequest
.
getHeader
(
"x-lang"
));
UserBaseEntity
userBaseEntity
=
BlContext
.
getCurrentUserNotException
();
return
agentApplicationService
.
getRecommendQuestions
(
httpServletRequest
.
getHeader
(
"x-lang"
),
userBaseEntity
.
getUserId
());
}
}
@Override
@Override
...
...
src/test/java/cn/com/poc/AgentApplicationInfoTest.java
View file @
4dc76bfc
...
@@ -65,6 +65,7 @@ public class AgentApplicationInfoTest {
...
@@ -65,6 +65,7 @@ public class AgentApplicationInfoTest {
public
void
test
()
{
public
void
test
()
{
List
<
Object
>
list
=
Lists
.
newArrayList
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"1"
);
List
<
Object
>
list
=
Lists
.
newArrayList
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"1"
);
redisService
.
lSet
(
"key"
,
list
);
redisService
.
lSet
(
"key"
,
list
);
// redisService.sSet("key",1);
}
}
...
...
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