Browse Source

gpt 车列表修改

chenbiao 2 years ago
parent
commit
6bd3b71158

+ 16 - 11
netflix-dao/src/main/java/com/cyksj/model/views/ChatgptCarInfoView.java

@@ -1,5 +1,8 @@
 package com.cyksj.model.views;
 
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.DbIgnore;
+import com.ejlchina.searcher.bean.SearchBean;
 import lombok.Data;
 
 import java.util.Date;
@@ -10,61 +13,63 @@ import java.util.Objects;
  * @date 2024/4/8 17:02
  */
 @Data
+@SearchBean(
+        tables = "chatgpt_session cs"
+)
 public class ChatgptCarInfoView {
 
     /**
      * 车次id
      */
+    @DbField("cs.carId")
     private String carId;
 
     /**
      * 车次名称
      */
+    @DbField("cs.car_name")
     private String carName;
 
     /**
      * 车次状态 繁忙 空闲 停运
      */
-
+    @DbIgnore
     private String status;
 
 
     /**
      * 得分
      */
+    @DbField("cs.score")
     private Double score;
 
     /**
      * 可用时间
      */
+    @DbIgnore
     private Date expTime;
 
     /**
      * 车队可用时间
      */
+    @DbIgnore
     private Date teamExpTime;
 
     /**
      * 车次类型 team plus 3.5
      */
-
+    @DbIgnore
     private String type;
 
-    /**
-     * 限制次数
-     */
-    private Integer gptLimit;
-
     /**
      * 使用次数
      */
 
     private Integer use;
 
-    /**
-     * 是否为历史车次
-     */
-    private Boolean isHistory;
+    @DbField("cs.isPlus")
+    private Integer isPlus;
+
 
     @Override
     public boolean equals(Object o) {

+ 2 - 1
netflix-service/src/main/java/com/cyksj/service/chatgpt/ChatGptAccountService.java

@@ -9,6 +9,7 @@ import com.cyksj.model.views.ChatGptUserView;
 import com.cyksj.model.views.ChatgptCarInfoView;
 
 import java.time.LocalDateTime;
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -57,7 +58,7 @@ public interface ChatGptAccountService {
 
     ChatgptUser getCarChatGptUserWithToken(String userToken);
 
-    Set<ChatgptCarInfoView> getCarInfoList(String userToken, Integer limit, Boolean isPlus);
+    List<ChatgptCarInfoView> getCarInfoList(String userToken, Integer limit, Boolean isPlus);
 
     ChatGptUserView getUserInfo(long userId, Long relationId);
 

+ 17 - 46
netflix-service/src/main/java/com/cyksj/service/chatgpt/impl/ChatGptAccountServiceImpl.java

@@ -697,22 +697,9 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
      * 获取车队信息
      */
     @Override
-    public Set<ChatgptCarInfoView> getCarInfoList(String userToken, Integer limit, Boolean isPlus) {
-        SearchResult<ChatGptUserConversationRecordHistoryView> search = beanSearcher.search(ChatGptUserConversationRecordHistoryView.class, MapUtils.builder().field("userToken", userToken).limit(0, 2).build());
-        Set<ChatgptCarInfoView> res = search.getDataList().stream()
-                .map((historyView) -> {
-                    ChatgptCarInfoView chatgptCarInfoView = buildChatgptCarInfoView(historyView.getCarId(), historyView.getCarName(), historyView.getIsPLus(), redisService.zScore(RedisService.key.CHATGPT_CAR_SCORES.getName(), historyView.getCarId()));
-                    chatgptCarInfoView.setIsHistory(true);
-                    chatgptCarInfoView.setScore(Math.min(redisService.zScore(RedisService.key.CHATGPT_CAR_SCORES.getName(), historyView.getCarId()), 200));
-
-                    return chatgptCarInfoView;
-                }).collect(Collectors.toCollection(LinkedHashSet::new));
-
-        Set<ChatgptCarInfoView> lowestScoreFleets = getLowestScoreFleets(limit, isPlus);
-
-        res.addAll(lowestScoreFleets);
-
-        return res;
+    public List<ChatgptCarInfoView> getCarInfoList(String userToken, Integer limit, Boolean isPlus) {
+        List<ChatgptCarInfoView> lowestScoreFleets = getLowestScoreFleets(limit, isPlus);
+        return lowestScoreFleets;
     }
 
 
@@ -758,22 +745,11 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
 
 
     // 获取得分最低的N个车队的方法
-    public Set<ChatgptCarInfoView> getLowestScoreFleets(int count, Boolean isPlus) {
-        Set<ZSetOperations.TypedTuple<Object>> lowestScorecarIds;
-        Long fleetsSize = redisService.zCard(RedisService.key.CHATGPT_CAR_SCORES.getName());
-        // 构建ChatgptCarInfoView集合
-        if (fleetsSize != null && fleetsSize > 10) {
-            TASK_EXECUTOR.execute(() -> {
-                initFleets(true);
-            });
-        } else {
-            initFleets(false);
-        }
-        lowestScorecarIds = redisService.zRangeWithScores(RedisService.key.CHATGPT_CAR_SCORES.getName(), 0L, count - 1);
-        Map<Object, Double> collect = lowestScorecarIds.stream().collect(Collectors.toMap(ZSetOperations.TypedTuple::getValue, ZSetOperations.TypedTuple::getScore));
-        List<ChatgptSession> chatgptSessions = chatgptSessionMapper.selectList(Wrappers.lambdaQuery(ChatgptSession.class).in(ChatgptSession::getCarId, collect.keySet()).eq(isPlus !=null && isPlus, ChatgptSession::getIsPlus, true));
-        return chatgptSessions.stream().map((chatgptSession)-> buildChatgptCarInfoView(chatgptSession.getCarId(),chatgptSession.getCarName(), chatgptSession.getIsPlus(), collect.get(chatgptSession.getCarId())))
-                .sorted(Comparator.comparing(ChatgptCarInfoView::getScore)).collect(Collectors.toCollection(LinkedHashSet::new));
+    public List<ChatgptCarInfoView> getLowestScoreFleets(int count, Boolean isPlus) {
+        List<ChatgptCarInfoView> chatgptCarInfoViews = beanSearcher.searchList(ChatgptCarInfoView.class, MapUtils.builder().field(ChatgptCarInfoView::getIsPlus, isPlus).orderBy(ChatgptCarInfoView::getScore).desc().limit(0, count).build());
+
+        chatgptCarInfoViews.forEach(this::buildChatgptCarInfoView);
+        return chatgptCarInfoViews;
     }
 
     public void initFleets(Boolean flag) {
@@ -796,21 +772,18 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
 
 
     // 构建ChatgptCarInfoView对象
-    private ChatgptCarInfoView buildChatgptCarInfoView(String carId, String carName, Integer isPlus, Double score) {
+    private ChatgptCarInfoView buildChatgptCarInfoView(ChatgptCarInfoView view) {
         // 在这里根据carId获取相关信息并填充到ChatgptCarInfoView对象中
-        ChatgptCarInfoView view = new ChatgptCarInfoView();
-        view.setCarId(carId);
-        // 假设以下方法从Redis或其他服务获取数据
-        view.setScore(Math.min(score, 200));
-        view.setStatus(score >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
 
-        if(carName.contains("T")){
+        view.setStatus(view.getScore() >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
+
+        if(view.getCarName().contains("T") && view.getIsPlus() == 1){
             view.setType("Team");
-            Long team = carOaiLimit(carId, true);
+            Long team = carOaiLimit(view.getCarId(), true);
             if (team != 0L) {
                 view.setTeamExpTime(new DateTime(System.currentTimeMillis() + team * 1000));
             }
-            Long aLong = carOaiLimit(carId, false);
+            Long aLong = carOaiLimit(view.getCarId(), false);
             if (aLong != 0L) {
                 view.setExpTime(new DateTime(System.currentTimeMillis() + aLong * 1000));
             }
@@ -820,17 +793,15 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
                 view.setStatus("部分停运");
             }
         }else {
-            view.setType(isPlus == 1 ? "Plus" : "3.5");
-            Long aLong = carOaiLimit(carId, false);
+            view.setType(view.getIsPlus() == 1 ? "Plus" : "3.5");
+            Long aLong = carOaiLimit(view.getCarId(), false);
             if (aLong != 0L) {
                 view.setStatus("停运");
                 view.setExpTime(new DateTime(System.currentTimeMillis() + aLong * 1000));
             }
         }
-        int use = getCarConversationCount(carId, 3L).intValue();
+        int use = getCarConversationCount(view.getCarId(), 3L).intValue();
         view.setUse(use);
-
-        view.setCarName(carName);
         return view;
     }
 

+ 5 - 4
netflix-web/src/main/java/com/cyksj/web/controller/mirror/MirrorController.java

@@ -36,6 +36,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.util.Date;
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -215,14 +216,14 @@ public class MirrorController {
      * @return
      */
     @GetMapping("/gpt/cars")
-    public Result<Set<ChatgptCarInfoView>> getCarInfoList(Long relationId,@RequestParam(defaultValue = "10") Integer limit,@RequestParam(defaultValue = "false") Boolean isPlus) {
+    public Result<List<ChatgptCarInfoView>> getCarInfoList(Long relationId,@RequestParam(defaultValue = "20") Integer limit,@RequestParam(defaultValue = "true") Boolean isPlus) {
         long userId = StpUserUtil.getLoginIdAsLong();
         //查看用户是否存在车票
         ChatgptUser carChatGptUser = chatGptAccountService.getCarChatGptUser(userId, relationId);
         if (carChatGptUser == null) {
             throw BusinessRuntimeException.getInstance("您还未购买车票");
         }
-        Set<ChatgptCarInfoView> carInfoList = chatGptAccountService.getCarInfoList(carChatGptUser.getUserToken(),10, isPlus);
+        List<ChatgptCarInfoView> carInfoList = chatGptAccountService.getCarInfoList(carChatGptUser.getUserToken(),limit, isPlus);
         for (ChatgptCarInfoView chatgptCarInfoView : carInfoList) {
             Double score = BigDecimal.valueOf(chatgptCarInfoView.getScore()).multiply(BigDecimal.valueOf(0.5)).setScale(0, RoundingMode.DOWN).doubleValue();
             chatgptCarInfoView.setScore(score);
@@ -308,13 +309,13 @@ public class MirrorController {
      * 根据userToken获取车队列表
      */
     @GetMapping("/gpt/cars/withToken")
-    public Result<Set<ChatgptCarInfoView>> getCarInfoListWithToken(String userToken,@RequestParam(defaultValue = "10") Integer limit, @RequestParam(defaultValue = "false") Boolean isPlus) {
+    public Result<List<ChatgptCarInfoView>> getCarInfoListWithToken(String userToken,@RequestParam(defaultValue = "10") Integer limit, @RequestParam(defaultValue = "false") Boolean isPlus) {
         //查看用户是否存在车票
         ChatgptUser carChatGptUser = chatGptAccountService.getCarChatGptUserWithToken(userToken);
         if (carChatGptUser == null) {
             throw BusinessRuntimeException.getInstance("您还未购买车票");
         }
-        Set<ChatgptCarInfoView> carInfoList = chatGptAccountService.getCarInfoList(carChatGptUser.getUserToken(), limit, isPlus);
+        List<ChatgptCarInfoView> carInfoList = chatGptAccountService.getCarInfoList(carChatGptUser.getUserToken(), limit, isPlus);
         return GatewayResponse.SUCCESS.newBuilder().toResult(carInfoList);
     }