|
@@ -20,6 +20,7 @@ import com.yhlxj.dao.mapper.GroupsRelationMapper;
|
|
|
import com.yhlxj.dao.mapper.midjourney.MidjourneyApiChannelMapper;
|
|
import com.yhlxj.dao.mapper.midjourney.MidjourneyApiChannelMapper;
|
|
|
import com.yhlxj.dao.mapper.midjourney.MidjourneyUserConversationMapper;
|
|
import com.yhlxj.dao.mapper.midjourney.MidjourneyUserConversationMapper;
|
|
|
import com.yhlxj.dao.mapper.midjourney.MidjourneyUserMapper;
|
|
import com.yhlxj.dao.mapper.midjourney.MidjourneyUserMapper;
|
|
|
|
|
+import com.yhlxj.dao.mapper.midjourney.MidjourneyWhiteMapper;
|
|
|
import com.yhlxj.dao.model.dto.BlendDimensions;
|
|
import com.yhlxj.dao.model.dto.BlendDimensions;
|
|
|
import com.yhlxj.dao.model.dto.MessageButton;
|
|
import com.yhlxj.dao.model.dto.MessageButton;
|
|
|
import com.yhlxj.dao.model.dto.MjVersionStatus;
|
|
import com.yhlxj.dao.model.dto.MjVersionStatus;
|
|
@@ -110,6 +111,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
|
|
public static final Map<String, MjVersionStatus> MJ_VERSION_STATUS_MAP = new ConcurrentHashMap<>();
|
|
public static final Map<String, MjVersionStatus> MJ_VERSION_STATUS_MAP = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
+ private final MidjourneyWhiteMapper midjourneyWhiteMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public MidjourneyUser getUser(String userToken) {
|
|
public MidjourneyUser getUser(String userToken) {
|
|
@@ -570,7 +572,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (count == null) {
|
|
if (count == null) {
|
|
|
redisService.set(key, 1L,RedisService.key.MIDJOURNEY_USER_TIME.getTimeout());
|
|
redisService.set(key, 1L,RedisService.key.MIDJOURNEY_USER_TIME.getTimeout());
|
|
|
}else {
|
|
}else {
|
|
|
- if (redisService.incr(key, 1L) > 200) {
|
|
|
|
|
|
|
+ Integer white = midjourneyWhiteMapper.selectCount(Wrappers.lambdaQuery(MidjourneyWhite.class).eq(MidjourneyWhite::getUserId, user.getId()));
|
|
|
|
|
+ int limit = white == 0 ? 200 : 400;
|
|
|
|
|
+ if (redisService.incr(key, 1L) > limit) {
|
|
|
//24小时内提交次数超过200次 拉黑
|
|
//24小时内提交次数超过200次 拉黑
|
|
|
user.setIsBlack(true);
|
|
user.setIsBlack(true);
|
|
|
midjourneyUserMapper.updateById(user);
|
|
midjourneyUserMapper.updateById(user);
|
|
@@ -586,15 +590,15 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public String getAccountWithMinUsage(Long instanceId) {
|
|
public String getAccountWithMinUsage(Long instanceId) {
|
|
|
- String key = RedisService.key.MIDJOURNEY_ACCOUNT.getName();
|
|
|
|
|
|
|
+ RedisService.key key = RedisService.key.MIDJOURNEY_ACCOUNT;
|
|
|
try {
|
|
try {
|
|
|
// 获取所有账号ID和使用次数
|
|
// 获取所有账号ID和使用次数
|
|
|
- Map<Object, Object> accountsUsage = redisService.hmget(key);
|
|
|
|
|
|
|
+ Map<Object, Object> accountsUsage = redisService.hmget(key.getName());
|
|
|
|
|
|
|
|
if (accountsUsage == null || accountsUsage.isEmpty()) {
|
|
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)).stream().collect(Collectors.toMap(k -> k.getInstanceId().toString(), v -> 0));
|
|
|
// 保存所有账号ID和使用次数
|
|
// 保存所有账号ID和使用次数
|
|
|
- redisService.hmset(key, accountsUsage);
|
|
|
|
|
|
|
+ redisService.hmset(key.getName(), accountsUsage,key.getTimeout());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 找到使用次数最少的账号ID
|
|
// 找到使用次数最少的账号ID
|
|
@@ -716,7 +720,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
//失败返还次数
|
|
//失败返还次数
|
|
|
if ("FAILURE".equals(conversation.getStatus())){
|
|
if ("FAILURE".equals(conversation.getStatus())){
|
|
|
if (StringUtils.equals("未知频道",conversation.getFailReason())) {
|
|
if (StringUtils.equals("未知频道",conversation.getFailReason())) {
|
|
|
- redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),dbConversation.getInstanceId());
|
|
|
|
|
|
|
+ redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),dbConversation.getInstanceId().toString());
|
|
|
String finalAccountWithMinUsage = dbConversation.getInstanceId().toString();
|
|
String finalAccountWithMinUsage = dbConversation.getInstanceId().toString();
|
|
|
TASK_EXECUTOR.execute(() -> {
|
|
TASK_EXECUTOR.execute(() -> {
|
|
|
MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
|
|
MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
|
|
@@ -824,6 +828,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
MidjourneyUserConversation conversation = JSONUtil.toBean(jsons, MidjourneyUserConversation.class);
|
|
MidjourneyUserConversation conversation = JSONUtil.toBean(jsons, MidjourneyUserConversation.class);
|
|
|
conversation.setUserId(jsons.getLong("state"));
|
|
conversation.setUserId(jsons.getLong("state"));
|
|
|
conversation.setTaskId(jsons.getLong("id"));
|
|
conversation.setTaskId(jsons.getLong("id"));
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject(conversation.getProperties());
|
|
|
|
|
+ if ("SUBMITTED".equals(conversation.getStatus())){
|
|
|
|
|
+ jsonObject.set("messageContent","**"+conversation.getPrompt()+"** - <@mj>" + (conversation.getMode() == 1 ? "(fast)" : "(relax)"));
|
|
|
|
|
+ conversation.setProperties(jsonObject.toString());
|
|
|
|
|
+ }
|
|
|
if (StringUtil.isNotBlank(conversation.getImageUrl())) {
|
|
if (StringUtil.isNotBlank(conversation.getImageUrl())) {
|
|
|
log.info("获取到的图片 url:{}", conversation.getImageUrl());
|
|
log.info("获取到的图片 url:{}", conversation.getImageUrl());
|
|
|
ImgSize imgSize = TASK_IMG_SIZE_MAP.get(conversation.getTaskId());
|
|
ImgSize imgSize = TASK_IMG_SIZE_MAP.get(conversation.getTaskId());
|