|
|
@@ -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);
|
|
|
}
|
|
|
|