瀏覽代碼

fix 重置setting

zwhui 2 年之前
父節點
當前提交
9130e6d6b5

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

@@ -3,12 +3,14 @@ package com.yhlxj.service.midjourney.impl;
 import cn.hutool.core.lang.UUID;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.common.util.StringUtil;
 import com.yhlxj.dao.mapper.*;
@@ -61,6 +63,8 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
 
     private final RedisService redisService;
 
+    private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
+
     @Override
     @Transactional(rollbackFor = Throwable.class)
     public void addAccount(MidjourneyAccount midjourneyAccount) throws Exception {
@@ -310,10 +314,17 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
                 midjourneyAccount.setInstanceId(Long.parseLong(accountInfo.getId()));
                 if (midjourneyAccount.getStatus() != accountInfo.isEnable()) {
                     midjourneyAccount.setStatus(accountInfo.isEnable());
-                    if(!accountInfo.isEnable()){
-                        redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),midjourneyAccount.getInstanceId());
+                    Long instanceId = midjourneyAccount.getInstanceId();
+                    if(accountInfo.isEnable()){
+                        redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), instanceId.toString(), 1.0);
+                        //重置setting
+                        TASK_EXECUTOR.execute(() -> {
+                            if (!"default".equals(accountInfo.getVersion()) || !accountInfo.isRaw()) {
+                                resetAccount(instanceId);
+                            }
+                        });
                     }else {
-                        redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), midjourneyAccount.getInstanceId().toString(), 1.0);
+                        redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), instanceId);
                     }
 
                 }
@@ -333,4 +344,11 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
         });
 
     }
+
+    public void resetAccount(Long id) {
+        HttpResponse versionResult = HttpRequest.post("http://43.154.230.104:8080/mj/account/" + id + "/change-version?version=default").execute();
+        log.info("versionResult:{}", versionResult.body());
+        HttpResponse resetSettingResult = HttpRequest.post("http://43.154.230.104:8080/mj/account/" + id + "/action?customId=MJ::Settings::ResetSettings&botType=MID_JOURNEY").execute();
+        log.info("resetSettingResult:{}", resetSettingResult.body());
+    }
 }