|
|
@@ -383,6 +383,10 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
}
|
|
|
}
|
|
|
ChatgptSession chatgptSession = chatgptSessionMapper.selectOne(wrapper);
|
|
|
+ if(conversationRequest.getCarId() == null && chatgptSession.getIsCar() && chatgptSession.getCarId() != null){
|
|
|
+ conversationRequest.setCarId(chatgptSession.getCarId());
|
|
|
+ }
|
|
|
+ conversationRequest.setCarId(chatgptSession.getCarId());
|
|
|
ChatgptUserConversationRecord chatgptUserConversationRecord = new ChatgptUserConversationRecord();
|
|
|
chatgptUserConversationRecord.setUserToken(userToken);
|
|
|
chatgptUserConversationRecord.setCarId(chatgptSession.getCarId());
|
|
|
@@ -412,21 +416,6 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
if (chatgptUser.getIsCar()) {
|
|
|
conversationLimitResponse = isConversationAllowed(userToken, chatgptUser.getLimitNum(), chatgptUser.getLimitTime());
|
|
|
}
|
|
|
- if(carId == null){
|
|
|
- if (StringUtils.isNotBlank(userToken)) {
|
|
|
- if (chatgptUser.getSessionId() != null) {
|
|
|
- ChatgptSession chatgptSession = chatgptSessionMapper.selectById(chatgptUser.getSessionId());
|
|
|
- if(chatgptSession != null){
|
|
|
- carId = chatgptSession.getCarId();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //车队次数记录
|
|
|
- String finalCarId = carId;
|
|
|
- TASK_EXECUTOR.execute(() -> {
|
|
|
- cardConversationRecord(finalCarId);
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
return conversationLimitResponse;
|
|
|
@@ -470,29 +459,6 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 记录车队的提问次数
|
|
|
- */
|
|
|
- public boolean cardConversationRecord(String carid) {
|
|
|
- String key = RedisService.key.CHATGPT_CAR_CONVERSATION_LIMIT.getName() + ":" + carid;
|
|
|
- long currentTimeMillis = System.currentTimeMillis();
|
|
|
- long windowStartMillis = currentTimeMillis - (WINDOW_SIZE) * 1000;
|
|
|
-
|
|
|
- // 清除时间窗口之前的请求记录
|
|
|
- redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
|
|
|
-
|
|
|
- Long currentSize = redisService.zCard(key);
|
|
|
- if (currentSize != null && currentSize >= MAX_REQUESTS) {
|
|
|
- // 如果当前请求次数超过限制,则拒绝请求
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- // 如果未超过限制,记录当前请求的时间戳
|
|
|
- redisService.zAdd(key, currentTimeMillis, currentTimeMillis);
|
|
|
- // 设置ZSet的过期时间,窗口大小加上一段冗余时间
|
|
|
- redisService.expire(key, (WINDOW_SIZE * 60 * 60) + 20);
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 获取指定用户ID在滑动窗口内的提问次数
|
|
|
@@ -521,9 +487,12 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
* @return 滑动窗口内的请求次数
|
|
|
*/
|
|
|
private Long getCarConversationCount(String carId, Long limitTime) {
|
|
|
- String key = RedisService.key.CHATGPT_CAR_CONVERSATION_LIMIT.getName() + ":" + carId;
|
|
|
- long currentTimeMillis = System.currentTimeMillis();
|
|
|
- long windowStartMillis = currentTimeMillis - (limitTime * 60 * 60) * 1000;
|
|
|
+ // 定义键名
|
|
|
+ String key = RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId;
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ // 更新体验数据
|
|
|
+ redisService.zAdd(key, timestamp, String.valueOf(timestamp));
|
|
|
+ long windowStartMillis = timestamp - (limitTime * 60 * 60 * 1000);
|
|
|
|
|
|
// 清除时间窗口之前的请求记录(可选,根据需要决定是否在此处清理过期记录)
|
|
|
redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
|