浏览代码

fix 账号均分次数

zwhui 2 年之前
父节点
当前提交
8f435316d9

+ 1 - 0
netflix-dao/src/main/java/com/cyksj/model/response/SubmitResult.java

@@ -22,6 +22,7 @@ public class SubmitResult {
      */
     private String result;
 
+    private Long instanceId;
     /**
      * 扩展字段
      */

+ 10 - 5
netflix-service/src/main/java/com/cyksj/service/midjourney/impl/MidjourneyServiceImpl.java

@@ -107,6 +107,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             conversation.setChannelId(properties.get("discordChannelId") == null ? null : Long.parseLong(properties.get("discordChannelId").toString()))
                     .setInstanceId(properties.get("discordInstanceId") == null ? null : Long.parseLong(properties.get("discordInstanceId").toString()));
         }
+        if (conversation.getInstanceId() == null) {
+            conversation.setInstanceId(result.getInstanceId());
+        }
         conversationMapper.insert(conversation);
         return conversation;
     }
@@ -261,8 +264,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             if (code == 3) {
                 if(mode == 2 && StringUtils.isNotBlank(accountWithMinUsage)){
                     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, instanceId).last("limit 1"));
+                        MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
                         midjourneyAccountService.updateStatus(account.getId());
                     });
                 }
@@ -277,6 +281,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             log.error("action:" + action + " error message:" + submitResult.getDescription());
             throw BusinessRuntimeException.getInstance("队列已满,请稍后尝试");
         }
+        submitResult.setInstanceId(Long.valueOf(accountWithMinUsage));
+        // 增加使用次数
+        if (StringUtils.isNotBlank(accountWithMinUsage) && mode == 2) {
+            redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), accountWithMinUsage, 1.0);
+        }
         return submitResult;
     }
 
@@ -306,10 +315,6 @@ public class MidjourneyServiceImpl implements MidjourneyService {
                     }
                 }
             }
-            // 增加使用次数
-            if (minAccountId != null) {
-                redisService.hincr(key, minAccountId, 1.0);
-            }
             return minAccountId;
         } catch (Exception e) {
             throw BusinessRuntimeException.getInstance("获取账号失败");