|
|
@@ -178,24 +178,24 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
|
return num;
|
|
|
}
|
|
|
- /**
|
|
|
- * 同步数据库
|
|
|
- */
|
|
|
- public void syncUser(Long id,Integer mode,Long num){
|
|
|
- log.info("同步次数 id:{},mode:{},num:{}",id,mode,num);
|
|
|
- if (num == null){
|
|
|
- return;
|
|
|
- }
|
|
|
- LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
|
|
|
- .eq(MidjourneyUser::getId, id);
|
|
|
- if (mode == 1){
|
|
|
- wrapper.set(MidjourneyUser::getMjFastNum, num);
|
|
|
- }
|
|
|
- if (mode == 2){
|
|
|
- wrapper.set(MidjourneyUser::getMjRelaxNum, num);
|
|
|
- }
|
|
|
- midjourneyUserMapper.update(null, wrapper);
|
|
|
- }
|
|
|
+// /**
|
|
|
+// * 同步数据库
|
|
|
+// */
|
|
|
+// public void syncUser(Long id,Integer mode,Long num){
|
|
|
+// log.info("同步次数 id:{},mode:{},num:{}",id,mode,num);
|
|
|
+// if (num == null){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
|
|
|
+// .eq(MidjourneyUser::getId, id);
|
|
|
+// if (mode == 1){
|
|
|
+// wrapper.set(MidjourneyUser::getMjFastNum, num);
|
|
|
+// }
|
|
|
+// if (mode == 2){
|
|
|
+// wrapper.set(MidjourneyUser::getMjRelaxNum, num);
|
|
|
+// }
|
|
|
+// midjourneyUserMapper.update(null, wrapper);
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
|
public SubmitResult submitAction(MidjourneyUser user, Long taskId, String customId, Long num, String botType) throws Exception {
|
|
|
@@ -230,11 +230,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (result.getCode() == 21) {
|
|
|
// 以上操作有弹窗确认,恢复次数
|
|
|
recoverUserLimit(user.getId(), user.getMode(),num);
|
|
|
- if (user.getMode() == 2){
|
|
|
- redisService.hdecr(RedisService.key.MIDJOURNEY_ACCOUNT.getName() , String.valueOf(conversation.getInstanceId()), 1.0);
|
|
|
- }
|
|
|
}else {
|
|
|
- syncUser(user.getId(), user.getMode(),num);
|
|
|
+ //syncUser(user.getId(), user.getMode(),num);
|
|
|
+ if (!customId.contains("upsample") && user.getMode() == 2) {
|
|
|
+ redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
+ }
|
|
|
}
|
|
|
saveConversation(user.getId(), user.getMode(), result,"ACTION", StringUtils.EMPTY, botType);
|
|
|
return result;
|
|
|
@@ -284,7 +284,6 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
// 增加使用次数
|
|
|
if (StringUtils.isNotBlank(accountWithMinUsage) && mode == 2) {
|
|
|
submitResult.setInstanceId(Long.valueOf(accountWithMinUsage));
|
|
|
- redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), accountWithMinUsage, 1.0);
|
|
|
}
|
|
|
return submitResult;
|
|
|
}
|
|
|
@@ -296,9 +295,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
Map<Object, Object> accountsUsage = redisService.hmget(key);
|
|
|
|
|
|
if (accountsUsage == null || accountsUsage.isEmpty()) {
|
|
|
- Map<Object, Object> map = 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和使用次数
|
|
|
- redisService.hmset(key, map);
|
|
|
+ redisService.hmset(key, accountsUsage);
|
|
|
}
|
|
|
|
|
|
// 找到使用次数最少的账号ID
|
|
|
@@ -380,14 +379,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
MidjourneyUserConversation dbConversation = conversationMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUserConversation.class).eq(MidjourneyUserConversation::getTaskId, conversation.getTaskId())
|
|
|
.eq(MidjourneyUserConversation::getUserId, userId).orderByDesc(MidjourneyUserConversation::getId).last("limit 1"));
|
|
|
if (dbConversation != null) {
|
|
|
- if ("SUCCESS".equals(dbConversation.getStatus())) {
|
|
|
+ if ("SUCCESS".equals(dbConversation.getStatus()) || "FAILURE".equals(dbConversation.getStatus()) || "MODAL".equals(dbConversation.getStatus())) {
|
|
|
return;
|
|
|
}
|
|
|
conversation.setId(dbConversation.getId());
|
|
|
conversationMapper.updateById(conversation);
|
|
|
- if (dbConversation.getMode() == 2){
|
|
|
- redisService.hdecr(RedisService.key.MIDJOURNEY_ACCOUNT.getName() , dbConversation.getInstanceId().toString(), 1.0);
|
|
|
- }
|
|
|
TASK_EXECUTOR.execute(() -> {
|
|
|
try {
|
|
|
String imageUrl = conversation.getImageUrl();
|