zwhui 2 лет назад
Родитель
Сommit
f189f68532

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

@@ -63,6 +63,7 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
         Long instanceId = getAccount(midjourneyAccount.getId());
         midjourneyAccount.setInstanceId(instanceId);
         baseMapper.updateById(midjourneyAccount);
+        redisService.hset(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),midjourneyAccount.getInstanceId().toString(),0);
     }
 
     @Override
@@ -75,6 +76,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 +100,12 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
         midjourneyAccount.setStatus(!midjourneyAccount.getStatus());
         baseMapper.updateById(midjourneyAccount);
         updAccount(midjourneyAccount);
+
+        if (!midjourneyAccount.getStatus()) {
+            redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),midjourneyAccount.getInstanceId());
+        }else {
+            redisService.hset(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),midjourneyAccount.getInstanceId().toString(),0);
+        }
     }
 
     @Override

+ 12 - 2
netflix-service/src/main/java/com/cyksj/service/midjourney/impl/MidjourneyServiceImpl.java

@@ -1,6 +1,7 @@
 package com.cyksj.service.midjourney.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpUtil;
@@ -226,6 +227,9 @@ 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);
         }
@@ -257,6 +261,10 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             if (code == 3) {
                 if(mode == 2 && StringUtils.isNotBlank(accountWithMinUsage)){
                     redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),accountWithMinUsage);
+                    TASK_EXECUTOR.execute(() -> {
+                        MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, instanceId).last("limit 1"));
+                        midjourneyAccountService.updateStatus(account.getId());
+                    });
                 }
                 throw BusinessRuntimeException.getInstance("账号不存在");
             }
@@ -412,13 +420,15 @@ public class MidjourneyServiceImpl implements MidjourneyService {
     private static String uploadPic(String url, String prefix) throws IOException {
         byte[] body = HttpUtil.downloadBytes(url);
         Path tempFile = Files.createTempFile(prefix, ".png");
-        try (FileImageOutputStream imageOutput = new FileImageOutputStream(tempFile.toFile())) {
+        File file = tempFile.toFile();
+        try (FileImageOutputStream imageOutput = new FileImageOutputStream(file)) {
             imageOutput.write(body, 0, body.length);
         }
         Map<String, Object> paramMap = new HashMap<>();
-        paramMap.put("file", tempFile.toFile());
+        paramMap.put("file", file);
         String json = HttpUtil.post("https://files.liuliangbang.vip/pic/ups", paramMap);
         log.info("上传图片结果:url:{},json:{}",url, json);
+        FileUtil.del(file);
         return new JSONObject(json).getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl");
     }