Browse Source

fix mj添加账号

zwhui 2 years ago
parent
commit
f99b464af4

+ 1 - 0
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -838,6 +838,7 @@ public class RedisService {
         MIDJOURNEY_RELAX_LIMIT("midjourney:relax:limit:", "midjourney relax次数", 60 * 60 * 48L),
         MIDJOURNEY_EXPIRE_TIME("midjourney:expire:time:", "midjourney expire time", 60 * 60 * 48L),
         MIDJOURNEY_USER("midjourney:user:", "midjourney user", 60 * 60 * 2L),
+        MIDJOURNEY_ACCOUNT("midjourney:account:", "midjourney account", 60 * 60 * 48L),
         APPLY_MONEY_DAY_LIMIT_KEY("apply_money_day_limit_key:%s:%s:%s", "每日提现次数限制", 60 * 60 * 24L),
 
         ;

+ 15 - 0
netflix-service/src/main/java/com/cyksj/service/midjourney/impl/MidJourneyAccountServiceImpl.java

@@ -63,6 +63,11 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
         Long instanceId = getAccount(midjourneyAccount.getId());
         midjourneyAccount.setInstanceId(instanceId);
         baseMapper.updateById(midjourneyAccount);
+        String key = RedisService.key.MIDJOURNEY_ACCOUNT.getName();
+        Map<Object, Object> accountsUsage = redisService.hmget(key);
+        if (MapUtil.isNotEmpty(accountsUsage)) {
+            redisService.hset(key,midjourneyAccount.getInstanceId().toString(),accountsUsage.values().toArray()[0]);
+        }
     }
 
     @Override
@@ -75,6 +80,7 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
         baseMapper.deleteById(id);
         //删除plus服务账号信息
         delAcount(midjourneyAccount.getInstanceId());
+        redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),midjourneyAccount.getInstanceId());
     }
 
     @Override
@@ -98,6 +104,15 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
         midjourneyAccount.setStatus(!midjourneyAccount.getStatus());
         baseMapper.updateById(midjourneyAccount);
         updAccount(midjourneyAccount);
+        String key = RedisService.key.MIDJOURNEY_ACCOUNT.getName();
+        if (!midjourneyAccount.getStatus()) {
+            redisService.hdel(key,midjourneyAccount.getInstanceId());
+        }else {
+            Map<Object, Object> accountsUsage = redisService.hmget(key);
+            if (MapUtil.isNotEmpty(accountsUsage)) {
+                redisService.hset(key,midjourneyAccount.getInstanceId().toString(),accountsUsage.values().toArray()[0]);
+            }
+        }
     }
 
     @Override