|
|
@@ -49,7 +49,9 @@ import java.net.URL;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
@@ -103,8 +105,6 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
private final GroupsRelationMapper groupsRelationMapper;
|
|
|
|
|
|
- private final MidjourneyApiChannelMapper midjourneyApiChannelMapper;
|
|
|
-
|
|
|
public static final Map<String, MjVersionStatus> MJ_VERSION_STATUS_MAP = new HashMap<>();
|
|
|
|
|
|
private final MidjourneyWhiteMapper midjourneyWhiteMapper;
|
|
|
@@ -113,11 +113,10 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
private final MidjourneySessionMapper midjourneySessionMapper;
|
|
|
|
|
|
- private final ConcurrentHashMap<String, Object> lockMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public MidjourneyUser getUser(String userToken) {
|
|
|
+ public MidjourneyUser getUser(String userToken) throws ExecutionException, InterruptedException {
|
|
|
if(StringUtils.isBlank(userToken)){
|
|
|
throw BusinessRuntimeException.getInstance("10001","请重新至官网登录");
|
|
|
}
|
|
|
@@ -129,19 +128,25 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (midjourneyUser.getIsBlack()){
|
|
|
throw new BusinessRuntimeException("账号异常,请联系客服");
|
|
|
}
|
|
|
- if(!redisService.hasKey(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId())){
|
|
|
- redisService.set(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId(),midjourneyUser.getMjFastNum());
|
|
|
- }
|
|
|
|
|
|
- if(!redisService.hasKey(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId())){
|
|
|
- redisService.set(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId(),midjourneyUser.getMjRelaxNum());
|
|
|
+ if (!redisService.hasKey(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId())
|
|
|
+ || !redisService.hasKey(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId())) {
|
|
|
+ redisService.multiSet(MapUtil.builder((new HashMap<String,Object>()))
|
|
|
+ .put(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId(), midjourneyUser.getMjFastNum())
|
|
|
+ .put(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId(), midjourneyUser.getMjRelaxNum())
|
|
|
+ .build());
|
|
|
}
|
|
|
Long relationId = midjourneyUser.getRelationId();
|
|
|
- GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
+
|
|
|
+ CompletableFuture<GroupsRelation> relationFuture = CompletableFuture.supplyAsync(() -> groupsRelationMapper.selectById(relationId));
|
|
|
+ CompletableFuture<MidjourneyUserSettings> settingsFuture = CompletableFuture.supplyAsync(() -> midjourneyUserSettingsService.getOne(
|
|
|
+ QueryWrapperUtils.buildWrapper(wrapper -> wrapper.eq(MidjourneyUserSettings::getUserId, midjourneyUser.getId()))));
|
|
|
+
|
|
|
+ // 等待查询完成
|
|
|
+ GroupsRelation relation = relationFuture.get();
|
|
|
+ MidjourneyUserSettings midjourneyUserSettings = settingsFuture.get();
|
|
|
midjourneyUser.setAqType(relation.getAqType());
|
|
|
- MidjourneyUserSettings midjourneyUserSettings = midjourneyUserSettingsService.getOne(QueryWrapperUtils.buildWrapper((wrapper) -> {
|
|
|
- wrapper.eq(MidjourneyUserSettings::getUserId, midjourneyUser.getId());
|
|
|
- }));
|
|
|
+
|
|
|
if (midjourneyUserSettings == null) {
|
|
|
midjourneyUserSettings = new MidjourneyUserSettings();
|
|
|
midjourneyUserSettings.setSettings(SETTINGS);
|
|
|
@@ -159,10 +164,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
@Override
|
|
|
public SubmitResult submitImagine(MidjourneyUser user, Integer mode,String prompt, String botType, List<String> base64Array, Long num) throws Exception {
|
|
|
- Map<String, Object> imagineParam = MapUtil.builder(new HashMap<String,Object>())
|
|
|
- .put("prompt", prompt)
|
|
|
- .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
- .build();
|
|
|
+ Map<String, Object> imagineParam = new HashMap<>();
|
|
|
+ imagineParam.put("prompt", prompt);
|
|
|
+ imagineParam.put("state", String.join(",",user.getId().toString(),user.getUserToken()));
|
|
|
if (CollectionUtil.isNotEmpty(base64Array)) {
|
|
|
imagineParam.put("base64Array", base64Array);
|
|
|
}
|
|
|
@@ -235,10 +239,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
@Override
|
|
|
public SubmitResult submitDescribe(MidjourneyUser user,Integer mode, String botType, String base64, Long num) throws Exception {
|
|
|
- Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
- .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
- .put("base64", base64)
|
|
|
- .build();
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("state", String.join(",",user.getId().toString(),user.getUserToken()));
|
|
|
+ param.put("base64", base64);
|
|
|
SubmitResult result = submit(user,mode,"describe", null, param,false, num);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
|
@@ -249,10 +252,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
@Override
|
|
|
public SubmitResult submitBlend(MidjourneyUser user, Integer mode,BlendDimensions dimensions, String botType, List<String> base64Array, Long num) throws Exception {
|
|
|
- Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
- .put("base64Array", base64Array)
|
|
|
- .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
- .build();
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("base64Array", base64Array);
|
|
|
+ param.put("state", String.join(",",user.getId().toString(),user.getUserToken()));
|
|
|
if (dimensions != null) {
|
|
|
param.put("dimensions", dimensions);
|
|
|
}
|
|
|
@@ -279,10 +281,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
@Override
|
|
|
public SubmitResult submitModal(MidjourneyUser user,Integer mode, String taskId, String prompt, String maskBase64, Long num) throws Exception {
|
|
|
MidjourneyUserConversation midjourneyUserConversation = conversationMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUserConversation.class).eq(MidjourneyUserConversation::getTaskId, taskId).last("limit 1"));
|
|
|
- Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
- .put("taskId", taskId.toString())
|
|
|
- .put("state",String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
- .build();
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("taskId", taskId.toString());
|
|
|
+ param.put("state",String.join(",",user.getId().toString(),user.getUserToken()));
|
|
|
if (StringUtils.isNotBlank(prompt)) {
|
|
|
param.put("prompt", prompt);
|
|
|
}
|
|
|
@@ -332,10 +333,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
@Override
|
|
|
public SubmitResult submitShorten(MidjourneyUser user,Integer mode, String botType, String prompt, Long num) throws Exception {
|
|
|
- Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
- .put("prompt", prompt)
|
|
|
- .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
- .build();
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("prompt", prompt);
|
|
|
+ param.put("state", String.join(",",user.getId().toString(),user.getUserToken()));
|
|
|
SubmitResult result = submit(user,mode,"shorten", null, param,false, num);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
|
@@ -425,11 +425,10 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
});
|
|
|
return null;
|
|
|
}
|
|
|
- Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
- .put("taskId", taskId)
|
|
|
- .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
- .put("customId", customId)
|
|
|
- .build();
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("taskId", taskId);
|
|
|
+ param.put("state", String.join(",",user.getId().toString(),user.getUserToken()));
|
|
|
+ param.put("customId", customId);
|
|
|
SubmitResult result = submit(user,mode,"action", conversation.getInstanceId(),param,false, num);
|
|
|
Map<String, Object> properties = result.getProperties();
|
|
|
String modeStr;
|
|
|
@@ -904,7 +903,8 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
return list;
|
|
|
}
|
|
|
public JSONArray listByIds(List<String> ids) throws Exception {
|
|
|
- Map<String, Object> param = MapUtil.builder(new HashMap<String, Object>()).put("ids", ids).build();
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("ids", ids);
|
|
|
HttpRequest request = HttpRequest.post(apiUrl + "/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);
|
|
|
@@ -950,11 +950,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
conversation.setAction(action_list.get(jsons.getInt("action")));
|
|
|
}
|
|
|
if (conversation.getPrompt() == null){
|
|
|
- conversation.setPrompt(jsons.getStr("promptEn"));
|
|
|
- }
|
|
|
- if (conversation.getPrompt() == null){
|
|
|
- conversation.setPrompt(jsons.getStr("promptFull"));
|
|
|
+ conversation.setPrompt(jsons.getStr("promptEn", jsons.getStr("promptFull")));
|
|
|
}
|
|
|
+
|
|
|
String[] states = jsons.getStr("state").split(",");
|
|
|
conversation.setUserId(Long.parseLong(states[0]));
|
|
|
conversation.setUserToken(states[1]);
|
|
|
@@ -1186,7 +1184,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if(JSONUtil.isJson(conversation.getFailReason())){
|
|
|
conversation.setFailReason("生成图片失败");
|
|
|
}
|
|
|
- String url = "https://mj.liuliangbang.vip/8080/api/msg/send";
|
|
|
+ String url = midjourneyHost+"/8080/api/msg/send";
|
|
|
Map<String, Object> data = MapUtil.builder(new HashMap<String,Object>())
|
|
|
.put("taskId", conversation.getTaskId())
|
|
|
.put("msg", JSONUtil.toJsonStr(conversation))
|