Bladeren bron

Merge branch 'gpt_car_func'

zoujiajian 2 jaren geleden
bovenliggende
commit
1cd698a364

+ 6 - 3
netflix-service/src/main/java/com/cyksj/service/chatgpt/ChatGptAccountService.java

@@ -7,10 +7,10 @@ import com.cyksj.model.request.gpt.ConversationRequest;
 import com.cyksj.model.response.ConversationLimitResponse;
 import com.cyksj.model.views.ChatGptUserView;
 import com.cyksj.model.views.ChatgptCarInfoView;
+import com.ejlchina.searcher.SearchResult;
 
 import java.time.LocalDateTime;
 import java.util.List;
-import java.util.Set;
 
 /**
  * @author chan
@@ -23,8 +23,9 @@ public interface ChatGptAccountService {
 
     String getLoginUrl(Long userId, Long relationId);
 
-    String getCarLoginUrl(Long userId, Long relationId, String carId);
-    String getCarLoginUrlWithToken(String userToken, String carId);
+    String getCarLoginUrl(String domain, Long userId, Long relationId, String carId);
+
+    String getCarLoginUrlWithToken(String domain, String userToken, String carId);
 
     ChatgptUser findByUserTokenAndExpireTimeAfter(String userToken, LocalDateTime now);
 
@@ -58,6 +59,8 @@ public interface ChatGptAccountService {
 
     ChatgptUser getCarChatGptUserWithToken(String userToken);
 
+    SearchResult<ChatgptCarInfoView> getCarInfoPage(String userToken, Integer limit, Boolean isPlus);
+
     List<ChatgptCarInfoView> getCarInfoList(String userToken, Integer limit, Boolean isPlus);
 
     ChatGptUserView getUserInfo(long userId, Long relationId);

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

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUnit;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.lang.UUID;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
@@ -29,6 +30,7 @@ import com.cyksj.service.chatgpt.ChatGptAccountService;
 import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.service.user.UserBindRelationService;
 import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.SearchResult;
 import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -40,6 +42,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
 import javax.imageio.stream.FileImageOutputStream;
+import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -108,6 +111,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
 
     private final SysConfigService sysConfigService;
 
+    private final HttpServletRequest request;
+
     @Override
     public String addAccount(Account account) {
         if (isAccountExists(account)) {
@@ -248,40 +253,33 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
      * @return
      */
     @Override
-    public String getCarLoginUrl(Long userId, Long relationId, String carId) {
+    public String getCarLoginUrl(String domain, Long userId, Long relationId, String carId) {
         GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
         GroupsTrips groupsTrips = getGroupsTrips(groupsRelation);
         GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
         if (goodsDonSku != null && goodsDonSku.getIsMirror() && goodsDonSku.getIsCar()) {
             ChatgptUser chatgptUser = getChatgptCarUser(userId, relationId, groupsRelation, goodsDonSku);
-            String DOMAIN = "https://chat.galaxydvd.com";
-            try {
-                SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, goodsDonSku.getId() == 444 ? "zhihu_gpt_domain" : "mirror_gpt_domain"));
-                if (sysConfig != null) {
-                    String sysValue = sysConfig.getSysValue();
-                    if (JSONUtil.isJsonArray(sysValue)) {
-                        List<String> domainList = JSONUtil.parseArray(sysValue).toList(String.class);
-                        DOMAIN = domainList.get(RandomUtil.randomInt(domainList.size()));
-                    }
-                }
-            } catch (Exception e) {
-                log.error("随机抽取域名错误. msg:{}", StringUtil.getErrorText(e));
-            }
-
+            String DOMAIN = getGptDomain(domain, goodsDonSku);
             log.info("domain:{},用户:{},所在车次:{},座位id:{},在{}获取跳转GPT镜像的登录url", DOMAIN, userId, groupsTrips.getId(), relationId, DateTime.now());
             return DOMAIN + "/auth/logintoken?carid=" + carId + "&usertoken=" + chatgptUser.getUserToken();
         } else {
             throw BusinessRuntimeException.getInstance("服务器出了点问题");
         }
     }
+
     /**
      * 根据userToken获取车队登录url
      */
     @Override
-    public String getCarLoginUrlWithToken(String userToken, String carId) {
+    public String getCarLoginUrlWithToken(String domain, String userToken, String carId) {
         ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
         if (chatgptUser != null) {
-            String DOMAIN = "https://chat.galaxydvd.com";
+            ChatgptUserTokenPrepare chatgptUserTokenPrepare = chatgptUserTokenPrepareMapper.selectOne(Wrappers.lambdaQuery(ChatgptUserTokenPrepare.class)
+                    .eq(ChatgptUserTokenPrepare::getUserToken, userToken)
+                    .last("limit 1"));
+            Long skuId = chatgptUserTokenPrepare.getSkuId();
+            GoodsDonSku goodsDonSku = skuMapper.selectById(skuId);
+            String DOMAIN = getGptDomain(domain, goodsDonSku);
             log.info("domain:{},渠道用户:{},在{}获取跳转GPT镜像的登录url", DOMAIN, userToken, DateTime.now());
             return DOMAIN + "/auth/logintoken?carid=" + carId + "&usertoken=" + chatgptUser.getUserToken();
         } else {
@@ -687,6 +685,17 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         return null;
     }
 
+    /**
+     * 获取车队分页信息
+     */
+    @Override
+    public SearchResult<ChatgptCarInfoView> getCarInfoPage(String userToken, Integer limit, Boolean isPlus) {
+        SearchResult<ChatgptCarInfoView> chatgptCarInfoViews = beanSearcher.search(ChatgptCarInfoView.class, MapUtils.flatBuilder(request.getParameterMap()).field(ChatgptCarInfoView::getIsPlus, isPlus).orderBy(ChatgptCarInfoView::getScore).asc().build());
+
+        chatgptCarInfoViews.getDataList().forEach(this::buildChatgptCarInfoView);
+        return chatgptCarInfoViews;
+    }
+
     /**
      * 获取车队信息
      */
@@ -942,5 +951,26 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         });
     }
 
+
+    public String getGptDomain(String domain, GoodsDonSku goodsDonSku) {
+        String DOMAIN = domain;
+        if (StrUtil.isEmpty(DOMAIN)) {
+            DOMAIN = "https://chat.galaxydvd.com";
+            try {
+                SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, goodsDonSku != null && goodsDonSku.getId() == 444 ? "zhihu_gpt_domain" : "mirror_gpt_domain"));
+                if (sysConfig != null) {
+                    String sysValue = sysConfig.getSysValue();
+                    if (JSONUtil.isJsonArray(sysValue)) {
+                        List<String> domainList = JSONUtil.parseArray(sysValue).toList(String.class);
+                        DOMAIN = domainList.get(RandomUtil.randomInt(domainList.size()));
+                    }
+                }
+            } catch (Exception e) {
+                log.error("随机抽取域名错误. msg:{}", StringUtil.getErrorText(e));
+            }
+        }
+        return DOMAIN;
+    }
+
 }
 

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

@@ -26,7 +26,7 @@ public interface ClaudeService {
 
     ClaudeUser checkCarAccount(Long userId, Long relationId);
 
-    String getCarLoginUrl(Long userId, Long relationId, String carId);
+    String getCarLoginUrl(String domain, Long userId, Long relationId, String carId);
 
     Long getConversationCount(String userToken, Long limitTime);
 

+ 15 - 11
netflix-service/src/main/java/com/cyksj/service/claude/impl/ClaudeServiceImpl.java

@@ -3,6 +3,7 @@ package com.cyksj.service.claude.impl;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.lang.UUID;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.exception.BusinessRuntimeException;
@@ -169,7 +170,7 @@ public class ClaudeServiceImpl implements ClaudeService {
 
 
     @Override
-    public String getCarLoginUrl(Long userId, Long relationId, String carId) {
+    public String getCarLoginUrl(String domain, Long userId, Long relationId, String carId) {
 
         GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
         GroupsTrips groupsTrips = getGroupsTrips(groupsRelation);
@@ -177,18 +178,21 @@ public class ClaudeServiceImpl implements ClaudeService {
         if (goodsDonSku != null && goodsDonSku.getIsMirror() && goodsDonSku.getIsCar()) {
             ClaudeUser claudeUser = getClaudeUser(userId, relationId, groupsRelation, goodsDonSku);
 
-            String DOMAIN = "https://claudeplus.com.cn";
-            try {
-                SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, "mirror_claude_domain"));
-                if (sysConfig != null) {
-                    String sysValue = sysConfig.getSysValue();
-                    if (JSONUtil.isJsonArray(sysValue)) {
-                        List<String> domainList = JSONUtil.parseArray(sysValue).toList(String.class);
-                        DOMAIN = domainList.get(RandomUtil.randomInt(domainList.size()));
+            String DOMAIN = domain;
+            if (StrUtil.isEmpty(DOMAIN)) {
+                DOMAIN = "https://claudeplus.com.cn";
+                try {
+                    SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, "mirror_claude_domain"));
+                    if (sysConfig != null) {
+                        String sysValue = sysConfig.getSysValue();
+                        if (JSONUtil.isJsonArray(sysValue)) {
+                            List<String> domainList = JSONUtil.parseArray(sysValue).toList(String.class);
+                            DOMAIN = domainList.get(RandomUtil.randomInt(domainList.size()));
+                        }
                     }
+                } catch (Exception e) {
+                    log.error("随机抽取域名错误. msg:{}", StringUtil.getErrorText(e));
                 }
-            } catch (Exception e) {
-                log.error("随机抽取域名错误. msg:{}", StringUtil.getErrorText(e));
             }
             log.info("domain:{},用户:{},所在车次:{},座位id:{},在{}获取跳转Claude镜像的登录url", DOMAIN, userId, groupsTrips.getId(), relationId, DateTime.now());
             return DOMAIN + "/auth/logintoken?carid=" + carId + "&usertoken=" + claudeUser.getUserToken();

+ 6 - 2
netflix-web/src/main/java/com/cyksj/web/controller/group/GroupRelationController.java

@@ -941,17 +941,21 @@ public class GroupRelationController {
         List<RenewUpgradePackageFrontView> renewUpgradePackageFrontViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.class, MapUtils.builder().field(RenewUpgradePackageFrontView::getSkuId, skuId).build());
         renewUpgradePackageFrontViews.forEach(renew -> {
             try {
+                List<Long> upgradeSkuIds = Jsons.parseList(renew.getUpgradeSkuIds(), Long.class);
                 //年付展示
                 MapBuilder builder = MapUtils.builder();
                 if (minMonths.get() == 12) {
                     builder.field(RenewUpgradePackageFrontView.RenewSkuView::getMonths, minMonths.get()).op(Operator.GreaterEqual);
-                }else {
+                    if (renewSkuId != null) {
+                        upgradeSkuIds.remove(renewSkuId);
+                    }
+                } else {
                     builder.field(RenewUpgradePackageFrontView.RenewSkuView::getMonths, minMonths.get()).op(Operator.GreaterThan);
                 }
                 List<RenewUpgradePackageFrontView.RenewSkuView> renewSkuViews = beanSearcher.searchAll(RenewUpgradePackageFrontView.RenewSkuView.class, builder
                         .field(RenewUpgradePackageFrontView.RenewSkuView::getGptLimitNum, minNum.get()).op(Operator.GreaterEqual)
                         .field(RenewUpgradePackageFrontView.RenewSkuView::getGptLimitTime, minTime.get()).op(LessEqual.class)
-                        .field(RenewUpgradePackageFrontView.RenewSkuView::getSkuId, Jsons.parseList(renew.getUpgradeSkuIds(), Long.class)).op(Operator.InList)
+                        .field(RenewUpgradePackageFrontView.RenewSkuView::getSkuId, upgradeSkuIds).op(Operator.InList)
                         .build());
                 renew.setRenewSkus(renewSkuViews);
             } catch (Exception e) {

+ 33 - 11
netflix-web/src/main/java/com/cyksj/web/controller/mirror/MirrorController.java

@@ -2,6 +2,9 @@ package com.cyksj.web.controller.mirror;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.EnvCommonService;
 import com.cyksj.common.exception.BusinessRuntimeException;
@@ -20,6 +23,7 @@ import com.cyksj.service.chatgpt.ChatGptAccountService;
 import com.cyksj.service.claude.ClaudeService;
 import com.cyksj.service.luma.LumaService;
 import com.cyksj.service.midjourney.MidjourneyAccountService;
+import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.web.util.StpUserUtil;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.SearchResult;
@@ -89,6 +93,8 @@ public class MirrorController {
 
     private final LumaService lumaService;
 
+    private final SysConfigService sysConfigService;
+
 
     /**
      * GPT车票跳转登录
@@ -137,10 +143,10 @@ public class MirrorController {
      * @param carId 车队id
      */
     @GetMapping("/chatGptMirror/{relationId}/{carId}")
-    public Result<String> chatGPtCarLogin(@PathVariable Long relationId, @PathVariable String carId) throws IOException {
+    public Result<String> chatGPtCarLogin(String domain, @PathVariable Long relationId, @PathVariable String carId) throws IOException {
         Long userId = StpUserUtil.getLoginIdAsLong();
         chatGptAccountService.checkCarAccount(userId, relationId);
-        String url = chatGptAccountService.getCarLoginUrl(userId, relationId, carId);
+        String url = chatGptAccountService.getCarLoginUrl(domain, userId, relationId, carId);
         return GatewayResponse.SUCCESS.newBuilder().toResult(url);
     }
 
@@ -249,15 +255,15 @@ public class MirrorController {
      * @return
      */
     @GetMapping("/gpt/cars")
-    public Result<List<ChatgptCarInfoView>> getCarInfoList(Long relationId,@RequestParam(defaultValue = "20") Integer limit,@RequestParam(defaultValue = "true") Boolean isPlus) {
+    public Result<SearchResult<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("您还未购买车票");
         }
-        List<ChatgptCarInfoView> carInfoList = chatGptAccountService.getCarInfoList(carChatGptUser.getUserToken(),limit, isPlus);
-        for (ChatgptCarInfoView chatgptCarInfoView : carInfoList) {
+        SearchResult<ChatgptCarInfoView> carInfoList = chatGptAccountService.getCarInfoPage(carChatGptUser.getUserToken(),limit, isPlus);
+        for (ChatgptCarInfoView chatgptCarInfoView : carInfoList.getDataList()) {
             Double score = BigDecimal.valueOf(chatgptCarInfoView.getScore()).multiply(BigDecimal.valueOf(0.5)).setScale(0, RoundingMode.DOWN).doubleValue();
             chatgptCarInfoView.setScore(score);
             if (!"停运".equals(chatgptCarInfoView.getStatus())) {
@@ -332,9 +338,9 @@ public class MirrorController {
      * @param carId 车队id
      */
     @GetMapping("/chatGptMirrorWithToken/{userToken}/{carId}")
-    public Result<String> chatGPtCarLoginWithToken(@PathVariable String userToken, @PathVariable String carId) {
+    public Result<String> chatGPtCarLoginWithToken(String domain, @PathVariable String userToken, @PathVariable String carId) {
         chatGptAccountService.checkCarAccountWithToken(userToken);
-        String url = chatGptAccountService.getCarLoginUrlWithToken(userToken, carId);
+        String url = chatGptAccountService.getCarLoginUrlWithToken(domain, userToken, carId);
         return GatewayResponse.SUCCESS.newBuilder().toResult(url);
     }
 
@@ -374,10 +380,26 @@ public class MirrorController {
      * @param relationId 车票id
      */
     @GetMapping("/midjourneyMirror/{relationId}")
-    public Result<String> midjourneyMirror(@PathVariable Long relationId) {
+    public Result<String> midjourneyMirror(String domain, @PathVariable Long relationId) {
         Long userId = StpUserUtil.getLoginIdAsLong();
         MidjourneyUser midjourneyUser = midjourneyAccountService.getMidjourneyUserToken(userId, relationId);
-        return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyHost + (EnvCommonService.active_prd.equals(envCommonService.getEnv()) ? "/8082":"/8083") +"/api/applets/midjourney/midjourneyMirrorWithToken/" + midjourneyUser.getUserToken());
+        String DOMAIN = domain;
+        if (StrUtil.isEmpty(DOMAIN)) {
+            DOMAIN = midjourneyHost;
+            try {
+                SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, "mirror_mj_discord_domain"));
+                if (sysConfig != null) {
+                    String sysValue = sysConfig.getSysValue();
+                    if (JSONUtil.isJsonArray(sysValue)) {
+                        List<String> domainList = JSONUtil.parseArray(sysValue).toList(String.class);
+                        DOMAIN = domainList.get(RandomUtil.randomInt(domainList.size()));
+                    }
+                }
+            } catch (Exception e) {
+                log.error("随机抽取域名错误. msg:{}", StringUtil.getErrorText(e));
+            }
+        }
+        return GatewayResponse.SUCCESS.newBuilder().toResult(DOMAIN + (EnvCommonService.active_prd.equals(envCommonService.getEnv()) ? "/8082" : "/8083") + "/api/applets/midjourney/midjourneyMirrorWithToken/" + midjourneyUser.getUserToken());
     }
 
     @GetMapping("/midjourneyMirrorWithToken/{userToken}")
@@ -434,10 +456,10 @@ public class MirrorController {
      * @param carId 车队id
      */
     @GetMapping("/claudeMirror/{relationId}/{carId}")
-    public Result<String> claudeCarLogin(@PathVariable Long relationId, @PathVariable String carId) throws IOException {
+    public Result<String> claudeCarLogin(String domain, @PathVariable Long relationId, @PathVariable String carId) throws IOException {
         Long userId = StpUserUtil.getLoginIdAsLong();
         claudeService.checkCarAccount(userId, relationId);
-        String url = claudeService.getCarLoginUrl(userId, relationId, carId);
+        String url = claudeService.getCarLoginUrl(domain, userId, relationId, carId);
         return GatewayResponse.SUCCESS.newBuilder().toResult(url);
     }