Browse Source

fix 同步mj账号启用账号时,缓存使用次数取可用账号的次数

zwhui 2 years ago
parent
commit
8c10149f28

+ 7 - 3
midjourney/src/main/java/com/yhlxj/service/midjourney/impl/MidJourneyAccountServiceImpl.java

@@ -306,6 +306,7 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
         List<MidjourneyProxyAccountInfo> content = JSONUtil.parseArray(jsonObject.getStr("content")).toList(MidjourneyProxyAccountInfo.class);
         //如果 该账号不存在于 proxy 上,则在本地删除该账号
 
+        String key = RedisService.key.MIDJOURNEY_ACCOUNT.getName();
         content.forEach((accountInfo)->{
             if (StringUtils.isNotBlank(accountInfo.getRemark()) && StringUtils.isNumeric(accountInfo.getRemark())) {
                 MidjourneyAccount midjourneyAccount = getById(Long.parseLong(accountInfo.getRemark()));
@@ -322,7 +323,10 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
                     midjourneyAccount.setStatus(accountInfo.isEnable());
                     Long instanceId = midjourneyAccount.getInstanceId();
                     if(accountInfo.isEnable()){
-                        redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), instanceId.toString(), 1.0);
+                        Map<Object, Object> accountsUsage = redisService.hmget(key);
+                        if (MapUtil.isNotEmpty(accountsUsage)) {
+                            redisService.hset(key,midjourneyAccount.getInstanceId().toString(),accountsUsage.values().toArray()[0]);
+                        }
                         //重置setting
                         TASK_EXECUTOR.execute(() -> {
                             if (!"default".equals(accountInfo.getVersion()) || !accountInfo.isRaw()) {
@@ -330,7 +334,7 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
                             }
                         });
                     }else {
-                        redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), instanceId.toString());
+                        redisService.hdel(key, instanceId.toString());
                     }
 
                 }
@@ -345,7 +349,7 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
         list.forEach((account)->{
             if (!ids.contains(account.getInstanceId().toString())) {
                 removeById(account.getId());
-                redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),account.getInstanceId().toString());
+                redisService.hdel(key,account.getInstanceId().toString());
             }
         });