|
@@ -1,5 +1,9 @@
|
|
|
package com.yhlxj.web.mirror;
|
|
package com.yhlxj.web.mirror;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
|
|
+import com.cyksj.common.util.IoKit;
|
|
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.dto.Result;
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.yhlxj.dao.model.dto.AlphaSubmitRequestDTO;
|
|
import com.yhlxj.dao.model.dto.AlphaSubmitRequestDTO;
|
|
@@ -9,12 +13,16 @@ import com.yhlxj.service.midjourney.MidjourneyService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author chan
|
|
* @author chan
|
|
@@ -26,6 +34,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
@RequestMapping("/applets/alpha-midjourney")
|
|
@RequestMapping("/applets/alpha-midjourney")
|
|
|
public class AlphaMidjourneyController {
|
|
public class AlphaMidjourneyController {
|
|
|
|
|
|
|
|
|
|
+ private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
+
|
|
|
private final HttpServletRequest request;
|
|
private final HttpServletRequest request;
|
|
|
|
|
|
|
|
private final HttpServletResponse response;
|
|
private final HttpServletResponse response;
|
|
@@ -40,7 +50,7 @@ public class AlphaMidjourneyController {
|
|
|
private static final String MODE_TURBO = "turbo";
|
|
private static final String MODE_TURBO = "turbo";
|
|
|
|
|
|
|
|
@RequestMapping("/auditLimit")
|
|
@RequestMapping("/auditLimit")
|
|
|
- public AlphaAuditLimitResponse auditLimit(AlphaSubmitRequestDTO submitRequestDTO) {
|
|
|
|
|
|
|
+ public AlphaAuditLimitResponse auditLimit() {
|
|
|
String userToken = getUserTokenFromRequest();
|
|
String userToken = getUserTokenFromRequest();
|
|
|
|
|
|
|
|
if (userToken == null) {
|
|
if (userToken == null) {
|
|
@@ -61,6 +71,13 @@ public class AlphaMidjourneyController {
|
|
|
if (StringUtils.isBlank(mode)) {
|
|
if (StringUtils.isBlank(mode)) {
|
|
|
return badRequestResponse("模式错误.请选择fast 或者 relax模式");
|
|
return badRequestResponse("模式错误.请选择fast 或者 relax模式");
|
|
|
}
|
|
}
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (MODE_RELAX.equals(mode)) {
|
|
|
|
|
+ midjourneyService.userSubmitLimit(user,"imagine", "1234",false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ return badRequestResponse(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (MODE_TURBO.equals(mode)) {
|
|
if (MODE_TURBO.equals(mode)) {
|
|
|
return badRequestResponse("暂不支持turbo 模式.请选择fast 或者 relax模式");
|
|
return badRequestResponse("暂不支持turbo 模式.请选择fast 或者 relax模式");
|
|
@@ -71,7 +88,6 @@ public class AlphaMidjourneyController {
|
|
|
} else if (MODE_RELAX.equals(mode) && user.getMjRelaxNum() < 1) {
|
|
} else if (MODE_RELAX.equals(mode) && user.getMjRelaxNum() < 1) {
|
|
|
return badRequestResponse("您已经没有次数啦。模式:" + mode);
|
|
return badRequestResponse("您已经没有次数啦。模式:" + mode);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return new AlphaAuditLimitResponse();
|
|
return new AlphaAuditLimitResponse();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -88,8 +104,12 @@ public class AlphaMidjourneyController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping("/notifyUrl")
|
|
@RequestMapping("/notifyUrl")
|
|
|
- public Result<String> notifyUrl() {
|
|
|
|
|
- log.info("提交成功 通知扣次数");
|
|
|
|
|
|
|
+ public Result<String> notifyUrl() throws IOException {
|
|
|
|
|
+ InputStream inputStream = request.getInputStream();
|
|
|
|
|
+ byte[] bytes = IoKit.toBytes(inputStream);
|
|
|
|
|
+ String json = new String(bytes, StandardCharsets.UTF_8);
|
|
|
|
|
+ inputStream.close();
|
|
|
|
|
+ log.info("提交成功 通知扣次数 {}", json);
|
|
|
String userToken = getUserTokenFromRequest();
|
|
String userToken = getUserTokenFromRequest();
|
|
|
String carid = request.getHeader("Carid");
|
|
String carid = request.getHeader("Carid");
|
|
|
|
|
|
|
@@ -99,8 +119,11 @@ public class AlphaMidjourneyController {
|
|
|
}
|
|
}
|
|
|
log.info("token:{}, mode:{}", userToken, mode);
|
|
log.info("token:{}, mode:{}", userToken, mode);
|
|
|
MidjourneyUser user = midjourneyService.getUser(userToken);
|
|
MidjourneyUser user = midjourneyService.getUser(userToken);
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if(StringUtils.isNotBlank(carid)){
|
|
|
|
|
+ TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
+ midjourneyService.saveConversationRecord(userToken, json, carid,"SUCCESS");
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
midjourneyService.checkUserLimit(user, MODE_RELAX.equals(mode) ? 2 : 1);
|
|
midjourneyService.checkUserLimit(user, MODE_RELAX.equals(mode) ? 2 : 1);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
}
|