chenbiao 2 жил өмнө
parent
commit
ef8de34c39

+ 14 - 0
netflix-dao/src/main/java/com/cyksj/model/views/ChatgptCarInfoView.java

@@ -3,6 +3,7 @@ package com.cyksj.model.views;
 import lombok.Data;
 
 import java.util.Date;
+import java.util.Objects;
 
 /**
  * @author chan
@@ -59,4 +60,17 @@ public class ChatgptCarInfoView {
      * 是否为历史车次
      */
     private Boolean isHistory;
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        ChatgptCarInfoView that = (ChatgptCarInfoView) o;
+        return Objects.equals(carId, that.carId);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(carId);
+    }
 }

+ 4 - 2
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -820,8 +820,10 @@ public class RedisService {
 
         CHATGPT_CAR_CONVERSATION_LIMIT("chatgpt:conversation:car:", "chatGpt 车队对话数量", 3 * 60 * 60L),
         CHATGPT_CAR_SCORES("chatgpt:car:scores","chatGpt 车队分数", 48 * 60 * 60L),
-        CHATGPT_CAR_HIGH_CHAT("chatgpt:car:high:chat:%s","chatGpt gpt4 对话次数", 48 * 60 * 60L),
-        CHATGPT_CAR_LOW_CHAT("chatgpt:car:low:chat:%s","chatGpt 3.5 对话次数", 48 * 60 * 60L),
+        CHATGPT_CAR_HIGH_CHAT("chatgpt:car:high:chat:","chatGpt gpt4 对话次数", 48 * 60 * 60L),
+        CHATGPT_CAR_LOW_CHAT("chatgpt:car:low:chat:","chatGpt 3.5 对话次数", 48 * 60 * 60L),
+
+        CHATGPT_CAR_SEESSION("sesstion:","chatGpt 车队 session", 48 * 60 * 60L),
         ;
 
         private String name;

+ 23 - 3
netflix-service/src/main/java/com/cyksj/service/chatgpt/impl/ChatGptAccountServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.http.Method;
+import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -547,6 +548,17 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
                 .map((historyView) -> {
                     ChatgptCarInfoView chatgptCarInfoView = buildChatgptCarInfoView(historyView.getCarId(), redisService.zScore(RedisService.key.CHATGPT_CAR_SCORES.getName(), historyView.getCarId()));
                     chatgptCarInfoView.setIsHistory(true);
+                    String sessionVar = redisService.getStr(RedisService.key.CHATGPT_CAR_SEESSION.getName() + historyView.getCarId());
+                    if(JSONUtil.isJson(sessionVar)){
+                        JSONObject sessionJson = new JSONObject(sessionVar);
+                        JSONArray models = sessionJson.getJSONArray("models");
+                        if(models.size() > 1){
+                            chatgptCarInfoView.setType("plus");
+                        }else {
+                            chatgptCarInfoView.setType("3.5");
+                        }
+                    }
+
                     return chatgptCarInfoView;
                 }).collect(Collectors.toSet());
 
@@ -592,8 +604,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
     // 重新计算指定车队的评分
     private void recalculateScore(String carId, long currentTimestamp) {
         // 实际应用中,你需要根据高级体验和低级体验的数量重新计算得分
-        Double highExperienceScore = (double) redisService.zCount(RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId, currentTimestamp - (3 * 60 * 60 * 1000), currentTimestamp);
-        Double lowExperienceScore = (double) redisService.zCount(RedisService.key.CHATGPT_CAR_LOW_CHAT.getName() + carId, currentTimestamp - (3 * 60 * 60 * 1000), currentTimestamp) / 2;
+        Double highExperienceScore = (double) redisService.zCount(RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId, currentTimestamp - (3 * 60 * 60 * 1000), currentTimestamp) * 2;
+        Double lowExperienceScore = (double) redisService.zCount(RedisService.key.CHATGPT_CAR_LOW_CHAT.getName() + carId, currentTimestamp - (3 * 60 * 60 * 1000), currentTimestamp);
         double newScore = highExperienceScore + lowExperienceScore;
         redisService.zAdd(RedisService.key.CHATGPT_CAR_SCORES.getName(), newScore, carId);
     }
@@ -649,7 +661,15 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         view.setCarId(carId);
         // 假设以下方法从Redis或其他服务获取数据
         view.setStatus(score >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
-        view.setType("plus");
+        String sessionVar = redisService.getStr(RedisService.key.CHATGPT_CAR_SEESSION.getName() + carId);
+        if(JSONUtil.isJson(sessionVar)){
+            JSONArray models = new JSONObject(sessionVar).getJSONArray("models");
+            if(models!= null && models.size() > 1){
+                view.setType("plus");
+            }else {
+                view.setType("3.5");
+            }
+        }
         view.setGptLimit(40); // 假设值
         int use = getCarConversationCount(carId, 3L).intValue();
         view.setUse(Math.min(use, 40));