Commit 164fd5ed authored by alex yao's avatar alex yao

style:AgentApplicationService#getRecommendQuestions

parent 4dc76bfc
......@@ -14,6 +14,7 @@ import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService;
import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import cn.com.poc.agent_application.service.BizMemberAgentApplicationCollectService;
import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.constant.XLangConstant;
import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.JsonUtils;
......@@ -191,7 +192,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@Override
public List<String> getRecommendQuestions(String xlang, Long memberId) {
if (StringUtils.isBlank(xlang)) {
xlang = "zh-cn";
xlang = XLangConstant.ZH_CN;
}
String redisKey = AGENT_APPLICATION_RECOMMEND_QUESTIONS + xlang;
......@@ -210,32 +211,40 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
return null;
}
// 获取用户上一次的推荐话题ID,并在本次不重复获取该ID
String lastRecommendQuestionRedisKey = MEMBER_RECOMMEND_QUESTIONS_LAST + memberId;
List<Object> lastRecomendIdSet = null;
if (redisService.hasKey(lastRecommendQuestionRedisKey)) {
lastRecomendIdSet = redisService.lGet(lastRecommendQuestionRedisKey, 0, -1);
// 获取用户上一次的推荐话题ID,并在本次不重复获取该ID
if (memberId != null) {
String lastRecommendQuestionRedisKey = MEMBER_RECOMMEND_QUESTIONS_LAST + memberId;
if (redisService.hasKey(lastRecommendQuestionRedisKey)) {
lastRecomendIdSet = redisService.lGet(lastRecommendQuestionRedisKey, 0, -1);
}
}
Set<Long> indexSet = new HashSet<>(3);
SecureRandom secureRandom = new SecureRandom();
do {
long id = (long) secureRandom.nextInt((int) size);
if (lastRecomendIdSet != null && lastRecomendIdSet.stream().anyMatch(v -> String.valueOf(v).equals(String.valueOf(id)))) {
long id = secureRandom.nextInt((int) size);
if (CollectionUtils.isNotEmpty(lastRecomendIdSet) && lastRecomendIdSet.stream().anyMatch(v -> String.valueOf(v).equals(String.valueOf(id)))) {
continue;
}
indexSet.add(id);
} while (indexSet.size() < 3);
List<String> result = new ArrayList<>();
List<Object> recordId = new ArrayList<>(3);
List<String> result = new ArrayList<>(3);
List<Object> recordIds = new ArrayList<>(3);
for (Long index : indexSet) {
recordId.add(index);
Object str = redisService.lGetIndex(redisKey, index);
result.add(str.toString());
recordIds.add(index);
}
//更新记录
if (memberId != null) {
String lastRecommendQuestionRedisKey = MEMBER_RECOMMEND_QUESTIONS_LAST + memberId;
redisService.del(lastRecommendQuestionRedisKey);
redisService.lSet(lastRecommendQuestionRedisKey, recordIds, 10 * 60);
}
redisService.del(lastRecommendQuestionRedisKey);
redisService.lSet(lastRecommendQuestionRedisKey, recordId);
return result;
}
......@@ -257,7 +266,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
largeModelResponse.setMessages(messages);
LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse);
if (largeModelResponse == null || !"0".equals(largeModelDemandResult.getCode())) {
if (largeModelDemandResult == null || !"0".equals(largeModelDemandResult.getCode())) {
throw new I18nMessageException("exception/failed.to.generate.recommendation.question");
}
String res = largeModelDemandResult.getMessage();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment