Ver código fonte

fix 新增繁忙空闲状态

chenbiao 2 anos atrás
pai
commit
ed9e6e3cca

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/claude/ClaudeService.java

@@ -29,4 +29,6 @@ public interface ClaudeService {
     String getCarLoginUrl(Long userId, Long relationId, String carId);
 
     Long getConversationCount(String userToken, Long limitTime);
+
+    Long carLimit(String carId);
 }

+ 10 - 5
netflix-service/src/main/java/com/cyksj/service/claude/impl/ClaudeServiceImpl.java

@@ -5,14 +5,12 @@ import cn.hutool.core.lang.UUID;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.StringUtil;
 import com.cyksj.mapper.*;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.request.gpt.ConversationRequest;
 import com.cyksj.model.response.ConversationLimitResponse;
-import com.cyksj.model.views.ChatGptUserView;
 import com.cyksj.model.views.ClaudeUserView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.claude.ClaudeService;
@@ -24,7 +22,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 
-import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Set;
@@ -140,7 +137,7 @@ public class ClaudeServiceImpl implements ClaudeService {
         claudeUserConversationRecordMapper.insert(claudeUserConversationRecord);
 
 
-        String key = RedisService.key.CHATGPT_CONVERSATION_LIMIT.getName() + ":" + userToken;
+        String key = RedisService.key.CLAUDE_CONVERSATION_LIMIT.getName() + ":" + userToken;
         long currentTimeMillis = System.currentTimeMillis();
 
         if (redisService.hasKey("claude:clears_in:" + conversationRequest.getCarId())) {
@@ -220,6 +217,14 @@ public class ClaudeServiceImpl implements ClaudeService {
         return currentSize != null ? currentSize : 0L;
     }
 
+    @Override
+    public Long carLimit(String carId) {
+        if(redisService.hasKey("claude:clears_in:" + carId)){
+            return redisService.getExpire("claude:clears_in:" + carId);
+        }
+        return 0L;
+    }
+
 
     /**
      * 获取车位信息
@@ -358,7 +363,7 @@ public class ClaudeServiceImpl implements ClaudeService {
     private void recalculateScore(String carId, long currentTimestamp) {
         // 实际应用中,你需要根据高级体验和低级体验的数量重新计算得分
         double highExperienceScore = (double) redisService.zCount(RedisService.key.CLAUDE_CAR_CHAT.getName() + carId, currentTimestamp - (3 * 60 * 60 * 1000), currentTimestamp) * 2;
-        redisService.zAdd(RedisService.key.CHATGPT_CAR_SCORES.getName(), highExperienceScore, carId);
+        redisService.zAdd(RedisService.key.CLAUDE_CAR_SCORES.getName(), highExperienceScore, carId);
     }
 
 

+ 10 - 0
netflix-web/src/main/java/com/cyksj/web/controller/mirror/MirrorController.java

@@ -1,5 +1,6 @@
 package com.cyksj.web.controller.mirror;
 
+import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.EnvCommonService;
@@ -545,6 +546,15 @@ public class MirrorController {
             throw BusinessRuntimeException.getInstance("您还未购买车票");
         }
         SearchResult<ClaudeCarInfoView> carInfoList = beanSearcher.search(ClaudeCarInfoView.class, MapUtils.flatBuilder(request.getParameterMap()).field(ClaudeCarInfoView::getStatus, true).build());
+        carInfoList.getDataList().forEach((claudeCarInfoView)->{
+            Long aLong = claudeService.carLimit(claudeCarInfoView.getCarId());
+            if (aLong != 0L) {
+                claudeCarInfoView.setStatus("停运");
+                claudeCarInfoView.setExpTime(new DateTime(System.currentTimeMillis() + aLong * 1000));
+            }else {
+                claudeCarInfoView.setStatus(claudeCarInfoView.getScore() > 50 ? "繁忙":"空闲");
+            }
+        });
         return GatewayResponse.SUCCESS.newBuilder().toResult(carInfoList);
     }