|
@@ -488,57 +488,61 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
SubmitResult submitResult = submit2MjProxy(url, token, mode, action, param);
|
|
SubmitResult submitResult = submit2MjProxy(url, token, mode, action, param);
|
|
|
int code = submitResult.getCode();
|
|
int code = submitResult.getCode();
|
|
|
if (code != 1 && code != 21 && code != 22) {
|
|
if (code != 1 && code != 21 && code != 22) {
|
|
|
- if (code == 3) {
|
|
|
|
|
- if(mode == 2){
|
|
|
|
|
- redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),accountWithMinUsage);
|
|
|
|
|
- String finalAccountWithMinUsage = accountWithMinUsage;
|
|
|
|
|
- TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
- MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
|
|
|
|
|
- midjourneyAccountService.updateStatus(account.getId());
|
|
|
|
|
- });
|
|
|
|
|
- if(RETRY_ACTION.contains(action)){
|
|
|
|
|
- submit(user,mode, action, instanceId, param, null);
|
|
|
|
|
- }
|
|
|
|
|
- } else if(mode == 1) {
|
|
|
|
|
- // 重试逻辑,切换供应商域名
|
|
|
|
|
- if(RETRY_ACTION.contains(action)){
|
|
|
|
|
- List<MidjourneyApiChannel> midjourneyApiChannels = midjourneyApiChannelMapper.selectList(QueryWrapperUtils.buildWrapper((wrapper) -> {
|
|
|
|
|
- wrapper.eq(MidjourneyApiChannel::getIsDefault, false);
|
|
|
|
|
- }));
|
|
|
|
|
- for (MidjourneyApiChannel midjourneyApiChannel : midjourneyApiChannels) {
|
|
|
|
|
- submitResult = submit2MjProxy(midjourneyApiChannel.getUrl(), midjourneyApiChannel.getToken(), mode, action, param);
|
|
|
|
|
- if (submitResult.getCode() == 1 || submitResult.getCode() == 22){
|
|
|
|
|
- log.info("taskId:{},切换到:{}", submitResult.getResult(),midjourneyApiChannel.getName());
|
|
|
|
|
- submitResult.setApiChannelId(midjourneyApiChannel.getId());
|
|
|
|
|
|
|
+ submitResult = checkResult(user, mode, action, instanceId, param, code, accountWithMinUsage, submitResult);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(accountWithMinUsage) && mode == 2) {
|
|
|
|
|
+ submitResult.setInstanceId(Long.valueOf(accountWithMinUsage));
|
|
|
|
|
+ userSubmitLimit(user,action,param.get("customId"));
|
|
|
|
|
+ }
|
|
|
|
|
+ return submitResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private SubmitResult checkResult(MidjourneyUser user, Integer mode, String action, Long instanceId, Map<String, Object> param, int code, String accountWithMinUsage, SubmitResult submitResult) throws Exception {
|
|
|
|
|
+ if (code == 3) {
|
|
|
|
|
+ if(mode == 2){
|
|
|
|
|
+ redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), accountWithMinUsage);
|
|
|
|
|
+ TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
+ MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, accountWithMinUsage).last("limit 1"));
|
|
|
|
|
+ midjourneyAccountService.updateStatus(account.getId());
|
|
|
|
|
+ });
|
|
|
|
|
+ if(RETRY_ACTION.contains(action)){
|
|
|
|
|
+ submit(user,mode, action, instanceId, param, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if(mode == 1) {
|
|
|
|
|
+ // 重试逻辑,切换供应商域名
|
|
|
|
|
+ if(RETRY_ACTION.contains(action)){
|
|
|
|
|
+ List<MidjourneyApiChannel> midjourneyApiChannels = midjourneyApiChannelMapper.selectList(QueryWrapperUtils.buildWrapper((wrapper) -> {
|
|
|
|
|
+ wrapper.eq(MidjourneyApiChannel::getIsDefault, false);
|
|
|
|
|
+ }));
|
|
|
|
|
+ for (MidjourneyApiChannel midjourneyApiChannel : midjourneyApiChannels) {
|
|
|
|
|
+ submitResult = submit2MjProxy(midjourneyApiChannel.getUrl(), midjourneyApiChannel.getToken(), mode, action, param);
|
|
|
|
|
+ if (submitResult.getCode() == 1 || submitResult.getCode() == 22){
|
|
|
|
|
+ log.info("taskId:{},切换到:{}", submitResult.getResult(),midjourneyApiChannel.getName());
|
|
|
|
|
+ submitResult.setApiChannelId(midjourneyApiChannel.getId());
|
|
|
|
|
+ return submitResult;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ if(submitResult.getCode() == 3){
|
|
|
|
|
+ log.info("服务商 :{}, 账号短缺", midjourneyApiChannel.getName());
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该任务所属的源Mj账号已被官网封禁或暂时风控。请稍后再试,或重新生成图片");
|
|
|
}else {
|
|
}else {
|
|
|
- if(submitResult.getCode() == 3){
|
|
|
|
|
- log.info("服务商 :{}, 账号短缺", midjourneyApiChannel.getName());
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("该任务所属的源Mj账号已被官网封禁或暂时风控。请稍后再试,或重新生成图片");
|
|
|
|
|
- }else {
|
|
|
|
|
- log.error("服务商:{}, action:{}, error message:{}", midjourneyApiChannel.getName(), action, submitResult.getDescription());
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("该任务源Mj账号队列已满,请稍后尝试");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ log.error("服务商:{}, action:{}, error message:{}", midjourneyApiChannel.getName(), action, submitResult.getDescription());
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该任务源Mj账号队列已满,请稍后尝试");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- if (code == 4) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance(submitResult.getDescription());
|
|
|
|
|
- }else if (code == 24) {
|
|
|
|
|
- JSONObject jsonObject = JSONUtil.parseObj(submitResult.getResult());
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("prompt包含敏感词:"+jsonObject.getStr("bannedWord"));
|
|
|
|
|
- }else {
|
|
|
|
|
- log.error("action:" + action + " error message:" + submitResult.getDescription());
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("该任务源Mj账号队列已满,请稍后尝试");
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (StringUtils.isNotBlank(accountWithMinUsage) && mode == 2) {
|
|
|
|
|
- submitResult.setInstanceId(Long.valueOf(accountWithMinUsage));
|
|
|
|
|
- userSubmitLimit(user,action,param.get("customId"));
|
|
|
|
|
|
|
+ if (code == 4) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance(submitResult.getDescription());
|
|
|
|
|
+ }else if (code == 24) {
|
|
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(submitResult.getResult());
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("prompt包含敏感词:"+jsonObject.getStr("bannedWord"));
|
|
|
|
|
+ }else {
|
|
|
|
|
+ log.error("action:" + action + " error message:" + submitResult.getDescription());
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该任务源Mj账号队列已满,请稍后尝试");
|
|
|
}
|
|
}
|
|
|
- return submitResult;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private SubmitResult submit2MjProxy(String url, String token, Integer mode, String action, Map<String, Object> param) throws Exception {
|
|
private SubmitResult submit2MjProxy(String url, String token, Integer mode, String action, Map<String, Object> param) throws Exception {
|
|
@@ -549,8 +553,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
request = mode == 1 ? request.header("Authorization", token) : request.header("mj-api-secret", token);
|
|
request = mode == 1 ? request.header("Authorization", token) : request.header("mj-api-secret", token);
|
|
|
String body = request.execute().body();
|
|
String body = request.execute().body();
|
|
|
log.info("action body:{}", body);
|
|
log.info("action body:{}", body);
|
|
|
- SubmitResult submitResult = Jsons.parseObject(body, SubmitResult.class);
|
|
|
|
|
- return submitResult;
|
|
|
|
|
|
|
+ return Jsons.parseObject(body, SubmitResult.class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void switchSupplierDomain() {
|
|
private void switchSupplierDomain() {
|