|
|
@@ -431,11 +431,10 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
@Override
|
|
|
public void saveConversationRecord(String userToken, ConversationRequest conversationRequest) {
|
|
|
LambdaQueryWrapper<ChatgptSession> wrapper = Wrappers.lambdaQuery(ChatgptSession.class);
|
|
|
-
|
|
|
+ ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
|
|
|
if (StringUtils.isNotBlank(conversationRequest.getCarId())) {
|
|
|
wrapper.eq(ChatgptSession::getCarId, conversationRequest.getCarId());
|
|
|
} else {
|
|
|
- ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
|
|
|
if (chatgptUser.getSessionId() != null) {
|
|
|
wrapper.eq(ChatgptSession::getId, chatgptUser.getSessionId());
|
|
|
}
|
|
|
@@ -454,7 +453,22 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
chatgptUserConversationRecord.setModel(conversationRequest.getModel());
|
|
|
chatgptUserConversationRecordMapper.insert(chatgptUserConversationRecord);
|
|
|
|
|
|
+ String key = RedisService.key.CHATGPT_CONVERSATION_LIMIT.getName() + ":" + userToken;
|
|
|
+ long currentTimeMillis = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 如果未超过限制,记录当前请求的时间戳
|
|
|
+ redisService.zAdd(key, currentTimeMillis, currentTimeMillis);
|
|
|
+ // 设置ZSet的过期时间,窗口大小加上一段冗余时间
|
|
|
+ redisService.expire(key, (chatgptUser.getLimitTime() * 60 * 60) + 20);
|
|
|
+
|
|
|
if (StringUtils.isNotBlank(chatgptSession.getCarId())) {
|
|
|
+ redisService.del();
|
|
|
+ if(redisService.hasKey("chatgpt:team:clears_in:" + chatgptSession.getCarId())){
|
|
|
+ redisService.del("chatgpt:team:clears_in:" + chatgptSession.getCarId());
|
|
|
+ }
|
|
|
+ if (redisService.hasKey("chatgpt:clears_in:" + chatgptSession.getCarId())) {
|
|
|
+ redisService.del("chatgpt:clears_in:" + chatgptSession.getCarId());
|
|
|
+ }
|
|
|
updateExperienceAndScore(chatgptSession.getCarId(), !"text-davinci-002-render-sha".equals(conversationRequest.getModel()), System.currentTimeMillis());
|
|
|
}
|
|
|
|
|
|
@@ -508,10 +522,6 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
chatgptUserCarUsedRecordMapper.insert(chatgptUserCarUsedRecord);
|
|
|
return conversationLimitResponse;
|
|
|
} else {
|
|
|
- // 如果未超过限制,记录当前请求的时间戳
|
|
|
- redisService.zAdd(key, currentTimeMillis, currentTimeMillis);
|
|
|
- // 设置ZSet的过期时间,窗口大小加上一段冗余时间
|
|
|
- redisService.expire(key, (limitTime * 60 * 60) + 20);
|
|
|
conversationLimitResponse.setLimited(false);
|
|
|
return conversationLimitResponse;
|
|
|
}
|