|
|
@@ -3,7 +3,6 @@ package com.yhlxj.service.midjourney.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.URLUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
@@ -16,7 +15,6 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
-import com.cyksj.common.util.IoKit;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.QueryWrapperUtils;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
@@ -50,9 +48,7 @@ import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
-import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
-import java.nio.charset.Charset;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.util.*;
|
|
|
@@ -168,11 +164,13 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (CollectionUtil.isNotEmpty(base64Array)) {
|
|
|
imagineParam.put("base64Array", base64Array);
|
|
|
}
|
|
|
- SubmitResult result = submit(user,mode,"imagine", null,imagineParam, null,false, num);
|
|
|
- if (mode == 2) {
|
|
|
+ SubmitResult result = submit(user,mode,"imagine", null,imagineParam, false, num);
|
|
|
+ if (mode == 1){
|
|
|
+ redisService.hincr(RedisService.key.MIDJOURNEY_FAST_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
+ }else {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
}
|
|
|
- saveConversation(user.getId(), mode,result,"IMAGINE", StringUtils.EMPTY, botType,result.getApiChannelId());
|
|
|
+ saveConversation(user.getId(), mode,result,"IMAGINE", StringUtils.EMPTY, botType);
|
|
|
Map<String, Object> properties = result.getProperties();
|
|
|
String modeStr;
|
|
|
String mjVersionStatusKey;
|
|
|
@@ -198,7 +196,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public MidjourneyUserConversation saveConversation(Long userId,Integer mode,SubmitResult result, String action,String prompt, String botType, Long apiChannelId) throws Exception {
|
|
|
+ public MidjourneyUserConversation saveConversation(Long userId,Integer mode,SubmitResult result, String action,String prompt,String botType) throws Exception {
|
|
|
if (result.getCode() == 23) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -228,9 +226,6 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (conversation.getInstanceId() == null) {
|
|
|
conversation.setInstanceId(result.getInstanceId());
|
|
|
}
|
|
|
- if(apiChannelId != null && mode == 1){
|
|
|
- conversation.setApiChannelId(apiChannelId);
|
|
|
- }
|
|
|
if (conversation.getId() == null) {
|
|
|
conversationMapper.insert(conversation);
|
|
|
}else {
|
|
|
@@ -246,11 +241,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
.put("state", user.getId().toString())
|
|
|
.put("base64", base64)
|
|
|
.build();
|
|
|
- SubmitResult result = submit(user,mode,"describe", null, param, null,false, num);
|
|
|
+ SubmitResult result = submit(user,mode,"describe", null, param,false, num);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
}
|
|
|
- saveConversation(user.getId(), mode,result,"DESCRIBE", StringUtils.EMPTY, botType, result.getApiChannelId());
|
|
|
+ saveConversation(user.getId(), mode,result,"DESCRIBE", StringUtils.EMPTY, botType);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -263,11 +258,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (dimensions != null) {
|
|
|
param.put("dimensions", dimensions);
|
|
|
}
|
|
|
- SubmitResult result = submit(user,mode,"blend", null, param, null,false, num);
|
|
|
+ SubmitResult result = submit(user,mode,"blend", null, param,false, num);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
}
|
|
|
- saveConversation(user.getId(), mode,result,"BLEND", StringUtils.EMPTY, botType, result.getApiChannelId());
|
|
|
+ saveConversation(user.getId(), mode,result,"BLEND", StringUtils.EMPTY, botType);
|
|
|
Map<String, Object> properties = result.getProperties();
|
|
|
MjVersionStatus mjVersionStatus = MJ_VERSION_STATUS_MAP.get(mode == 1 ? "v6-fast-model" : "v6-relax-model");
|
|
|
int count = 1;
|
|
|
@@ -296,8 +291,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (StringUtils.isNotBlank(maskBase64)) {
|
|
|
param.put("maskBase64", maskBase64);
|
|
|
}
|
|
|
- Long apiChannelId = midjourneyUserConversation == null ? null : midjourneyUserConversation.getApiChannelId();
|
|
|
- JSONArray jsonArray = listByIds(mode, List.of(taskId), apiChannelId);
|
|
|
+ JSONArray jsonArray = listByIds(List.of(taskId));
|
|
|
if (!jsonArray.isEmpty()){
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(Jsons.toJson(jsonArray.get(0)));
|
|
|
if (!"MODAL".equals(jsonObject.getStr("status"))){
|
|
|
@@ -309,8 +303,8 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
return submitModal(user, mode, taskId, prompt, maskBase64, num);
|
|
|
}
|
|
|
}
|
|
|
- SubmitResult result = submit(user,mode,"modal", null, param, apiChannelId,false, num);
|
|
|
- saveConversation(user.getId(), mode,result,"MODAL", StringUtils.EMPTY, StringUtils.EMPTY,apiChannelId);
|
|
|
+ SubmitResult result = submit(user,mode,"modal", null, param,false, num);
|
|
|
+ saveConversation(user.getId(), mode,result,"MODAL", StringUtils.EMPTY, StringUtils.EMPTY);
|
|
|
Map<String, Object> properties = result.getProperties();
|
|
|
String modeStr;
|
|
|
String mjVersionStatusKey;
|
|
|
@@ -344,11 +338,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
.put("prompt", prompt)
|
|
|
.put("state", user.getId().toString())
|
|
|
.build();
|
|
|
- SubmitResult result = submit(user,mode,"shorten", null, param, null,false, num);
|
|
|
+ SubmitResult result = submit(user,mode,"shorten", null, param,false, num);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
}
|
|
|
- saveConversation(user.getId(), mode, result,"SHORTEN", StringUtils.EMPTY, botType, result.getApiChannelId());
|
|
|
+ saveConversation(user.getId(), mode, result,"SHORTEN", StringUtils.EMPTY, botType);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -434,7 +428,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
// }
|
|
|
|
|
|
@Override
|
|
|
- public SubmitResult submitAction(MidjourneyUser user,MidjourneyUserConversation conversation,Integer mode, Long taskId, String customId, Long num, String botType, Long apiChannelId) throws Exception {
|
|
|
+ public SubmitResult submitAction(MidjourneyUser user,MidjourneyUserConversation conversation,Integer mode, Long taskId, String customId, Long num, String botType) throws Exception {
|
|
|
AtomicBoolean modalFlag = new AtomicBoolean(false);
|
|
|
if (StringUtils.isNotBlank(conversation.getButtons())){
|
|
|
List<MessageButton> messageButtons = Jsons.parseList(conversation.getButtons(), MessageButton.class);
|
|
|
@@ -469,7 +463,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
.put("state", user.getId().toString())
|
|
|
.put("customId", customId)
|
|
|
.build();
|
|
|
- SubmitResult result = submit(user,mode,"action", conversation.getInstanceId(),param, apiChannelId,false, num);
|
|
|
+ SubmitResult result = submit(user,mode,"action", conversation.getInstanceId(),param,false, num);
|
|
|
Map<String, Object> properties = result.getProperties();
|
|
|
String modeStr;
|
|
|
String mjVersionStatusKey;
|
|
|
@@ -510,53 +504,28 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
|
properties.put("estimateTime", System.currentTimeMillis() + (second * count));
|
|
|
properties.put("finalPrompt",conversation.getPrompt());
|
|
|
- MidjourneyUserConversation midjourneyUserConversation = saveConversation(user.getId(), mode, result, "ACTION", StringUtils.EMPTY, botType, apiChannelId);
|
|
|
+ MidjourneyUserConversation midjourneyUserConversation = saveConversation(user.getId(), mode, result, "ACTION", StringUtils.EMPTY, botType);
|
|
|
properties.put("id",midjourneyUserConversation.getId());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public SubmitResult submit(MidjourneyUser user, Integer mode, String action, Long instanceId, Map<String, Object> param, Long apiChannelId,Boolean again, Long num) throws Exception {
|
|
|
-
|
|
|
- String accountWithMinUsage = "";
|
|
|
- String url = "";
|
|
|
- String token = "";
|
|
|
- if (mode == 1) {
|
|
|
- param.put("mode", "FAST");
|
|
|
-
|
|
|
- MidjourneyApiChannel midjourneyApiChannel = midjourneyApiChannelMapper.selectOne(QueryWrapperUtils.buildWrapper((wrapper)->{
|
|
|
- if(apiChannelId != null && apiChannelId != 0){
|
|
|
- wrapper.eq(MidjourneyApiChannel::getId,apiChannelId);
|
|
|
- }else {
|
|
|
- wrapper.eq(MidjourneyApiChannel::getIsDefault, true);
|
|
|
- }
|
|
|
- }));
|
|
|
- if (midjourneyApiChannel == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("FAST模式账号异常");
|
|
|
- }
|
|
|
-
|
|
|
- url = midjourneyApiChannel.getUrl();
|
|
|
- token = midjourneyApiChannel.getToken();
|
|
|
-
|
|
|
- } else if (mode == 2) {
|
|
|
+ public SubmitResult submit(MidjourneyUser user, Integer mode, String action, Long instanceId, Map<String, Object> param,Boolean again, Long num) throws Exception {
|
|
|
+ //查询在使用次数最少的账号
|
|
|
+ String accountWithMinUsage = getAccountWithMinUsage(mode,instanceId);
|
|
|
+ if (accountWithMinUsage == null) {
|
|
|
+ throw new Exception("没有可用的账号");
|
|
|
+ }
|
|
|
+ param.put("accountFilter",MapUtil.builder(new HashMap<String,Object>())
|
|
|
+ .put("instanceId",accountWithMinUsage).build());
|
|
|
+ if (mode == 2) {
|
|
|
synchronized (user.getId()){
|
|
|
userSubmitLimit(user,action,param.get("customId"),again);
|
|
|
}
|
|
|
- url = RELAX_HOST;
|
|
|
- token = RELAX_TOKEN;
|
|
|
- //慢速查询在使用次数最少的账号
|
|
|
- accountWithMinUsage = getAccountWithMinUsage(instanceId);
|
|
|
- if (accountWithMinUsage == null) {
|
|
|
- throw new Exception("没有可用的账号");
|
|
|
- }
|
|
|
- param.put("accountFilter",MapUtil.builder(new HashMap<String,Object>())
|
|
|
- .put("instanceId",accountWithMinUsage).build());
|
|
|
}
|
|
|
- SubmitResult submitResult = submit2MjProxy(url, token, mode, action, param);
|
|
|
+ SubmitResult submitResult = submit2MjProxy(mode, action, param);
|
|
|
+ submitResult.setInstanceId(Long.valueOf(accountWithMinUsage));
|
|
|
int code = submitResult.getCode();
|
|
|
- if (StringUtils.isNotBlank(accountWithMinUsage) && mode == 2) {
|
|
|
- submitResult.setInstanceId(Long.valueOf(accountWithMinUsage));
|
|
|
- }
|
|
|
if (code == 23){
|
|
|
recoverUserLimit(user.getId(), mode, num);
|
|
|
return submitResult;
|
|
|
@@ -569,39 +538,13 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
private SubmitResult checkResult(MidjourneyUser user, Integer mode, String action, Long instanceId, Map<String, Object> param, int code, String accountWithMinUsage, SubmitResult submitResult, Long num) 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)){
|
|
|
- return submit(user,mode, action, instanceId, param, null,true, num);
|
|
|
- }
|
|
|
- } 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 {
|
|
|
- log.error("服务商:{}, action:{}, error message:{}", midjourneyApiChannel.getName(), action, submitResult.getDescription());
|
|
|
- throw BusinessRuntimeException.getInstance("该任务源Mj账号队列已满,请稍后重试");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ redisService.hdel(mode == 1 ? RedisService.key.MIDJOURNEY_FAST_ACCOUNT.getName() : 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)){
|
|
|
+ return submit(user,mode, action, instanceId, param,true, num);
|
|
|
}
|
|
|
}
|
|
|
if (code == 4) {
|
|
|
@@ -609,32 +552,24 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}else if (code == 24) {
|
|
|
Map<String, Object> properties = submitResult.getProperties();
|
|
|
throw BusinessRuntimeException.getInstance("prompt包含敏感词:"+properties.get("bannedWord"));
|
|
|
- }
|
|
|
- else if (code == 3) {
|
|
|
+ }else if (code == 3) {
|
|
|
log.error("action:" + action + " error message:" + submitResult.getDescription());
|
|
|
throw BusinessRuntimeException.getInstance("该任务所属的源Mj账号已被官网封禁或暂时风控,请重新生成图片");
|
|
|
- }
|
|
|
- else {
|
|
|
+ }else {
|
|
|
log.error("action:" + action + " error message:" + submitResult.getDescription());
|
|
|
throw BusinessRuntimeException.getInstance("网络出现异常");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private SubmitResult submit2MjProxy(String url, String token, Integer mode, String action, Map<String, Object> param) throws Exception {
|
|
|
-
|
|
|
- url = url + getActionUrl(action);
|
|
|
+ private SubmitResult submit2MjProxy(Integer mode, String action, Map<String, Object> param) throws Exception {
|
|
|
String host = midjourneyHost;
|
|
|
if (EnvCommonService.active_prd.equals(envCommonService.getEnv())){
|
|
|
- host = host + "/8082/api/applets/midjourney/notifyHook";
|
|
|
- if (mode == 2) {
|
|
|
- host = "http://172.19.0.15:8082/applets/midjourney/notifyHook";
|
|
|
- }
|
|
|
+ host = "http://172.19.0.15:8082/applets/midjourney/notifyHook";
|
|
|
}else {
|
|
|
host = host + "/8083/api/applets/midjourney/notifyHook";
|
|
|
}
|
|
|
param.put("notifyHook",host);
|
|
|
- HttpRequest request = HttpRequest.post(url).body(Jsons.toJson(param));
|
|
|
- request = mode == 1 ? request.header("Authorization", token) : request.header("mj-api-secret", token);
|
|
|
+ HttpRequest request = HttpRequest.post(RELAX_HOST + getActionUrl(action)).header("mj-api-secret", RELAX_TOKEN).body(Jsons.toJson(param));
|
|
|
String body = request.execute().body();
|
|
|
log.info("action body:{}", body);
|
|
|
return Jsons.parseObject(body, SubmitResult.class);
|
|
|
@@ -711,14 +646,14 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String getAccountWithMinUsage(Long instanceId) {
|
|
|
- RedisService.key key = RedisService.key.MIDJOURNEY_ACCOUNT;
|
|
|
+ public String getAccountWithMinUsage(Integer mode,Long instanceId) {
|
|
|
+ RedisService.key key = mode == 1 ? RedisService.key.MIDJOURNEY_FAST_ACCOUNT : RedisService.key.MIDJOURNEY_ACCOUNT;
|
|
|
try {
|
|
|
// 获取所有账号ID和使用次数
|
|
|
Map<Object, Object> accountsUsage = redisService.hmget(key.getName());
|
|
|
|
|
|
if (accountsUsage == null || accountsUsage.isEmpty()) {
|
|
|
- accountsUsage = midjourneyAccountService.list(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getStatus,Boolean.TRUE)).stream().collect(Collectors.toMap(k -> k.getInstanceId().toString(), v -> 0));
|
|
|
+ accountsUsage = midjourneyAccountService.list(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getStatus,Boolean.TRUE).eq(MidjourneyAccount::getMode,mode)).stream().collect(Collectors.toMap(k -> k.getInstanceId().toString(), v -> 0));
|
|
|
// 保存所有账号ID和使用次数
|
|
|
redisService.hmset(key.getName(), accountsUsage,key.getTimeout());
|
|
|
}
|
|
|
@@ -768,7 +703,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
Long count = redisService.incr(queryKey + id, 1L);
|
|
|
if (count%5 == 0) {
|
|
|
try {
|
|
|
- listByIds(mode,List.of(id),null).forEach(json ->{
|
|
|
+ listByIds(List.of(id)).forEach(json ->{
|
|
|
JSONObject jsons = JSONUtil.parseObj(json);
|
|
|
MidjourneyUserConversation conversation = JSONUtil.toBean(jsons, MidjourneyUserConversation.class);
|
|
|
if (StringUtil.isNotBlank(conversation.getImageUrl())) {
|
|
|
@@ -845,8 +780,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
conversationMapper.updateById(conversation);
|
|
|
//失败返还次数
|
|
|
if ("FAILURE".equals(conversation.getStatus()) && !dbConversation.getStatus().equals("MODEL")){
|
|
|
+ Integer mode = dbConversation.getMode();
|
|
|
if (StringUtils.equals("未知频道",conversation.getFailReason())) {
|
|
|
- redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),dbConversation.getInstanceId().toString());
|
|
|
+ redisService.hdel(mode == 1 ? RedisService.key.MIDJOURNEY_FAST_ACCOUNT.getName() : RedisService.key.MIDJOURNEY_ACCOUNT.getName(),dbConversation.getInstanceId().toString());
|
|
|
String finalAccountWithMinUsage = dbConversation.getInstanceId().toString();
|
|
|
TASK_EXECUTOR.execute(() -> {
|
|
|
MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
|
|
|
@@ -858,7 +794,6 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
Object num = redisService.get(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + userId);
|
|
|
LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
|
|
|
.eq(MidjourneyUser::getId, userId);
|
|
|
- Integer mode = dbConversation.getMode();
|
|
|
if (mode == 1){
|
|
|
num = redisService.incr(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + userId, 1L);
|
|
|
wrapper.set(MidjourneyUser::getMjFastNum, num);
|
|
|
@@ -965,31 +900,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
- public JSONArray listByIds(Integer mode, List<Long> ids, Long apiChannelId) throws Exception {
|
|
|
+ public JSONArray listByIds(List<Long> ids) throws Exception {
|
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String, Object>()).put("ids", ids).build();
|
|
|
- String url = "";
|
|
|
- String token = "";
|
|
|
- if (mode == 1) {
|
|
|
- MidjourneyApiChannel midjourneyApiChannel = midjourneyApiChannelMapper.selectOne(QueryWrapperUtils.buildWrapper((wrapper)->{
|
|
|
- if(apiChannelId != null && apiChannelId != 0){
|
|
|
- wrapper.eq(MidjourneyApiChannel::getId,apiChannelId);
|
|
|
- }else {
|
|
|
- wrapper.eq(MidjourneyApiChannel::getIsDefault, true);
|
|
|
- }
|
|
|
- }));
|
|
|
- if (midjourneyApiChannel == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("FAST模式账号异常");
|
|
|
- }
|
|
|
-
|
|
|
- url = midjourneyApiChannel.getUrl();
|
|
|
- token = midjourneyApiChannel.getToken();
|
|
|
-
|
|
|
- } else if (mode == 2) {
|
|
|
- url = RELAX_HOST;
|
|
|
- token = RELAX_TOKEN;
|
|
|
- }
|
|
|
- HttpRequest request = HttpRequest.post(url + "/mj/task/list-by-condition");
|
|
|
- request = mode == 1 ? request.header("Authorization", token) : request.header("mj-api-secret", token);
|
|
|
+ HttpRequest request = HttpRequest.post(RELAX_HOST + "/mj/task/list-by-condition").header("mj-api-secret", RELAX_TOKEN);
|
|
|
String body = request.body(Jsons.toJson(param)).execute().body();
|
|
|
log.info("listByIds body:{}", body);
|
|
|
return JSONUtil.parseArray(body);
|
|
|
@@ -1285,27 +1198,10 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
@Override
|
|
|
public synchronized void syscConversation() throws Exception {
|
|
|
List<MidjourneyUserConversation> fastMidjourneyUserConversations = conversationMapper.selectList(Wrappers.lambdaQuery(MidjourneyUserConversation.class)
|
|
|
- .notIn(MidjourneyUserConversation::getStatus, List.of("SUCCESS","MODAL","FAILURE")).eq(MidjourneyUserConversation::getMode,1).orderByAsc(MidjourneyUserConversation::getId).last(" limit 100"));
|
|
|
-
|
|
|
- List<MidjourneyUserConversation> relaxMidjourneyUserConversations = conversationMapper.selectList(Wrappers.lambdaQuery(MidjourneyUserConversation.class)
|
|
|
- .notIn(MidjourneyUserConversation::getStatus, List.of("SUCCESS","MODAL","FAILURE")).eq(MidjourneyUserConversation::getMode,2).orderByAsc(MidjourneyUserConversation::getId).last(" limit 100"));
|
|
|
-
|
|
|
- Map<Long, List<MidjourneyUserConversation>> fastCollect = fastMidjourneyUserConversations.stream().collect(Collectors.groupingBy(MidjourneyUserConversation::getApiChannelId));
|
|
|
-
|
|
|
- fastCollect.forEach((channel,list)->{
|
|
|
- try {
|
|
|
- JSONArray jsonArray = listByIds(1, list.stream().map(MidjourneyUserConversation::getTaskId).collect(Collectors.toList()), channel);
|
|
|
- for (Object json : jsonArray) {
|
|
|
- log.info("定时任务同步回调notifyHook");
|
|
|
- notifyHook(Jsons.toJson(json));
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
+ .notIn(MidjourneyUserConversation::getStatus, List.of("SUCCESS","MODAL","FAILURE")).orderByAsc(MidjourneyUserConversation::getId).last(" limit 100"));
|
|
|
|
|
|
- JSONArray relaxArray = listByIds(2, relaxMidjourneyUserConversations.stream().map(MidjourneyUserConversation::getTaskId).collect(Collectors.toList()), null);
|
|
|
- for (Object json : relaxArray) {
|
|
|
+ JSONArray jsonArray = listByIds(fastMidjourneyUserConversations.stream().map(MidjourneyUserConversation::getTaskId).collect(Collectors.toList()));
|
|
|
+ for (Object json : jsonArray) {
|
|
|
log.info("定时任务同步回调notifyHook");
|
|
|
notifyHook(Jsons.toJson(json));
|
|
|
}
|