Quellcode durchsuchen

通过userToken登录镜像车队

chenbiao vor 2 Jahren
Ursprung
Commit
729893615b

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

@@ -23,13 +23,15 @@ public interface ChatGptAccountService {
     String getLoginUrl(Long userId, Long relationId);
 
     String getCarLoginUrl(Long userId, Long relationId, String carId);
+    String getCarLoginUrlWithToken(String userToken, String carId);
 
     ChatgptUser findByUserTokenAndExpireTimeAfter(String userToken, LocalDateTime now);
 
     /**
      * 对话限制
+     *
      * @param userToken 用户token
-     * @param model 对话模型
+     * @param model     对话模型
      * @return 是否限制
      */
     ConversationLimitResponse conversationLimit(String userToken, String model, String carId, ChatgptUser user, Boolean isCar);
@@ -38,6 +40,7 @@ public interface ChatGptAccountService {
 
     /**
      * 获取对话次数
+     *
      * @param userToken 用户token
      * @param limitTime 限制时间
      * @return
@@ -48,12 +51,18 @@ public interface ChatGptAccountService {
 
     Boolean checkCarAccount(long userId, Long relationId);
 
+    Boolean checkCarAccountWithToken(String userToken);
+
     ChatgptUser getCarChatGptUser(long userId, Long relationId);
 
+    ChatgptUser getCarChatGptUserWithToken(String userToken);
+
     Set<ChatgptCarInfoView> getCarInfoList(String userToken);
 
     ChatGptUserView getUserInfo(long userId, Long relationId);
 
+    ChatGptUserView getUserInfoWithToken(String userToken);
+
     void genTitleSync(String messageId, String carid, String userToken);
 
     /**
@@ -64,5 +73,6 @@ public interface ChatGptAccountService {
     /**
      * 获取GPT session
      */
-   String getGptSession(String account, String password);
+    String getGptSession(String account, String password);
+
 }

+ 57 - 11
netflix-service/src/main/java/com/cyksj/service/chatgpt/impl/ChatGptAccountServiceImpl.java

@@ -211,8 +211,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
 
         if (goodsDonSku != null && goodsDonSku.getIsMirror()) {
             ChatgptUser chatgptUser = getChatgptUser(userId, relationId, groupsRelation, groupsTrips, goodsDonSku);
-            if(214610L == relationId){
-                 return "https://cdn.galaxydvd.com/login_token?access_token=" + chatgptUser.getUserToken();
+            if (214610L == relationId) {
+                return "https://cdn.galaxydvd.com/login_token?access_token=" + chatgptUser.getUserToken();
             }
             return GPT_DOMAIN + "/login_token?access_token=" + chatgptUser.getUserToken();
         } else {
@@ -239,6 +239,18 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
             throw BusinessRuntimeException.getInstance("服务器出了点问题");
         }
     }
+    /**
+     * 根据userToken获取车队登录url
+     */
+    @Override
+    public String getCarLoginUrlWithToken(String userToken, String carId) {
+        ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
+        if (chatgptUser != null) {
+            return CAR_GPT_DOMAIN + "/auth/logintoken?carid=" + carId + "&usertoken=" + chatgptUser.getUserToken();
+        } else {
+            throw BusinessRuntimeException.getInstance("服务出了点问题");
+        }
+    }
 
     /**
      * 获取车位信息
@@ -377,9 +389,9 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
     public void saveConversationRecord(String userToken, ConversationRequest conversationRequest) {
         LambdaQueryWrapper<ChatgptSession> wrapper = Wrappers.lambdaQuery(ChatgptSession.class);
 
-        if(StringUtils.isNotBlank(conversationRequest.getCarId())){
+        if (StringUtils.isNotBlank(conversationRequest.getCarId())) {
             wrapper.eq(ChatgptSession::getCarId, conversationRequest.getCarId());
-        }else {
+        } else {
             ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
             if (chatgptUser.getSessionId() != null) {
                 wrapper.eq(ChatgptSession::getId, chatgptUser.getSessionId());
@@ -399,7 +411,7 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         chatgptUserConversationRecord.setModel(conversationRequest.getModel());
         chatgptUserConversationRecordMapper.insert(chatgptUserConversationRecord);
 
-        if(StringUtils.isNotBlank(chatgptSession.getCarId())){
+        if (StringUtils.isNotBlank(chatgptSession.getCarId())) {
             updateExperienceAndScore(chatgptSession.getCarId(), !"text-davinci-002-render-sha".equals(conversationRequest.getModel()), System.currentTimeMillis());
         }
 
@@ -458,7 +470,6 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
     }
 
 
-
     /**
      * 获取指定用户ID在滑动窗口内的提问次数
      *
@@ -532,6 +543,15 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         }
     }
 
+    @Override
+    public Boolean checkCarAccountWithToken(String userToken) {
+
+        ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
+
+        return chatgptUser != null;
+
+    }
+
     @Override
     public ChatgptUser getCarChatGptUser(long userId, Long relationId) {
         GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
@@ -539,7 +559,18 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
 
         if (goodsDonSku != null && goodsDonSku.getIsMirror() && goodsDonSku.getIsCar()) {
-            ChatgptUser chatgptUser = getChatgptCarUser(userId, relationId, groupsRelation, goodsDonSku);
+            return getChatgptCarUser(userId, relationId, groupsRelation, goodsDonSku);
+        }
+        return null;
+    }
+
+    @Override
+    public ChatgptUser getCarChatGptUserWithToken(String userToken) {
+        ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken).last(" limit 1"));
+        if (chatgptUser != null) {
+            if(!chatgptUser.getIsCar()){
+                throw BusinessRuntimeException.getInstance("您非车队用户,请购买车队套餐");
+            }
             return chatgptUser;
         }
         return null;
@@ -624,7 +655,7 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         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()));
-        return chatgptSessions.stream().map((chatgptSession)-> buildChatgptCarInfoView(chatgptSession.getCarId(),chatgptSession.getCarName(), chatgptSession.getIsPlus(), collect.get(chatgptSession.getCarId())))
+        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));
     }
 
@@ -653,7 +684,7 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         ChatgptCarInfoView view = new ChatgptCarInfoView();
         view.setCarId(carId);
         // 假设以下方法从Redis或其他服务获取数据
-        view.setScore(Math.min(score,100));
+        view.setScore(Math.min(score, 100));
         view.setStatus(score >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
 
         view.setType(isPlus == 1 ? "plus" : "3.5");
@@ -687,6 +718,21 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
             throw BusinessRuntimeException.getInstance("您还未购买该车票");
         }
     }
+    @Override
+    public ChatGptUserView getUserInfoWithToken(String userToken) {
+        if (checkCarAccountWithToken(userToken)) {
+            ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
+            return ChatGptUserView.builder()
+                    .skuName("")
+                    .expireTime(chatgptUser.getExpireTime())
+                    .limitNum(chatgptUser.getLimitNum())
+                    .limitTime(chatgptUser.getLimitTime())
+                    .use(getConversationCount(chatgptUser.getUserToken(), chatgptUser.getLimitTime()))
+                    .build();
+        } else {
+            throw BusinessRuntimeException.getInstance("您还未购买该车票");
+        }
+    }
 
     @Override
     public void genTitleSync(String conversationId, String carid, String userToken) {
@@ -705,12 +751,12 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
 
     @Override
     public void carLimited(String carId, String userToken, Long expTime) {
-        if(carId == null){
+        if (carId == null) {
             if (StringUtils.isNotBlank(userToken)) {
                 ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
                 if (chatgptUser != null && chatgptUser.getSessionId() != null) {
                     ChatgptSession chatgptSession = chatgptSessionMapper.selectById(chatgptUser.getSessionId());
-                    if(chatgptSession != null){
+                    if (chatgptSession != null) {
                         carId = chatgptSession.getCarId();
                     }
                 }

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

@@ -238,4 +238,43 @@ public class MirrorController {
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
 
+
+    /**
+     * 根据userToken获取gpt车票信息
+     */
+    @GetMapping("/gpt/userInfoWithToken")
+    public Result<ChatGptUserView> getUserInfoWithToken(String userToken) {
+        ChatGptUserView user = chatGptAccountService.getUserInfoWithToken(userToken);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(user);
+    }
+
+    /**
+     * 根据userToken GPT车队跳转登录
+     *
+     * @param carId 车队id
+     */
+    @GetMapping("/chatGptMirrorWithToken/{userToken}/{carId}")
+    public Result<String> chatGPtCarLoginWithToken(@PathVariable String userToken, @PathVariable String carId) {
+        chatGptAccountService.checkCarAccountWithToken(userToken);
+        String url = chatGptAccountService.getCarLoginUrlWithToken(userToken, carId);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(url);
+    }
+
+    /**
+     * 根据userToken获取车队列表
+     */
+    @GetMapping("/gpt/cars/withToken")
+    public Result<Set<ChatgptCarInfoView>> getCarInfoListWithToken(String userToken) {
+        //查看用户是否存在车票
+        ChatgptUser carChatGptUser = chatGptAccountService.getCarChatGptUserWithToken(userToken);
+        if (carChatGptUser == null) {
+            throw BusinessRuntimeException.getInstance("您还未购买车票");
+        }
+
+        Set<ChatgptCarInfoView> carInfoList = chatGptAccountService.getCarInfoList(carChatGptUser.getUserToken());
+        return GatewayResponse.SUCCESS.newBuilder().toResult(carInfoList);
+    }
+
+
+
 }