Преглед изворни кода

Merge branch 'picture' into dev

# Conflicts:
#	netflix-common/src/main/java/com/cyksj/common/constant/Constant.java
#	netflix-dao/src/main/java/com/cyksj/model/entity/MirrorNotice.java
#	netflix-dao/src/main/java/com/cyksj/model/entity/UserReceiveTrialTicketRecord.java
#	netflix-service/src/main/java/com/cyksj/redis/RedisService.java
#	netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java
#	netflix-service/src/main/java/com/cyksj/service/ticket/impl/UserReceiveTrialTicketRecordServiceImpl.java
#	netflix-web/src/main/java/com/cyksj/web/controller/mirror/MidjourneyController.java
#	netflix-web/src/main/resources/application-dev.yml
#	netflix-web/src/main/resources/application-prd.yml
zwhui пре 2 година
родитељ
комит
10a25fa42d

+ 14 - 0
netflix-dao/src/main/java/com/cyksj/mapper/MidjourneyUserMapper.java

@@ -2,10 +2,24 @@ package com.cyksj.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.MidjourneyUser;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
 
 /**
  * @author zwhui
  * @date 2024/4/16 17:46
  */
 public interface MidjourneyUserMapper extends BaseMapper<MidjourneyUser> {
+
+    @Update("update midjourney_user set mj_fast_num = mj_fast_num + #{num} where id = #{id}")
+    int incrFastNum(@Param("id") Long id, @Param("num") Integer num);
+
+    @Update("update midjourney_user set mj_fast_num = mj_fast_num - #{num} where id = #{id} and mj_fast_num = #{mjFastNum} and mj_fast_num > 0")
+    int decFastNum(@Param("id") Long id, @Param("num") Integer num, @Param("mjFastNum") Integer mjFastNum);
+
+    @Update("update midjourney_user set mj_relax_num = mj_relax_num + #{num} where id = #{id}")
+    int incrRelaxNum(@Param("id") Long id, @Param("num") Integer num);
+
+    @Update("update midjourney_user set mj_relax_num = mj_relax_num - #{num} where id = #{id} and mj_relax_num = #{relaxNum} and mj_relax_num > 0")
+    int decRelaxNum(@Param("id") Long id, @Param("num") Integer num, @Param("relaxNum") Integer relaxNum);
 }

+ 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;
     /**
      * 扩展字段
      */

+ 4 - 3
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -835,14 +835,15 @@ public class RedisService {
         CHATGPT_CAR_LOW_CHAT("chatgpt:car:low:chat:","chatGpt 3.5 对话次数", 48 * 60 * 60L),
         //车票到期前每日通知key
         TICKET_EXPIRY_NOTIFY_DAY("ticket_expiry_notify_day:%s:%s", "车票到期前每日通知key", 60 * 60 * 24L),
-        MIDJOURNEY_FAST_LIMIT("midjourney:fast:limit:", "midjourney fast次数", 60 * 60 * 48L),
-        MIDJOURNEY_RELAX_LIMIT("midjourney:relax:limit:", "midjourney relax次数", 60 * 60 * 48L),
+        MIDJOURNEY_FAST_LIMIT("midjourney:fast:limit:", "midjourney fast次数", 60 * 60 * 24L * 7),
+        MIDJOURNEY_RELAX_LIMIT("midjourney:relax:limit:", "midjourney relax次数", 60 * 60 * 24L * 7),
         MIDJOURNEY_EXPIRE_TIME("midjourney:expire:time:", "midjourney expire time", 60 * 60 * 48L),
         MIDJOURNEY_USER("midjourney:user:", "midjourney user", 60 * 60 * 2L),
         MIDJOURNEY_CONVERSATION("midjourney:conversation:", "midjourney conversation", 60 * 60 * 2L),
         MIDJOURNEY_ACCOUNT("midjourney:account:", "midjourney account", 60 * 60 * 48L),
         MIDJOURNEY_QUERY("midjourney:query:", "midjourney query", 60 * 60 * 2L),
-
+        MIDJOURNEY_RELAX_CONVERSATION("midjourney:relax:conversation:", "midjourney relax conversation", 60 * 60 * 2L),
+        MIDJOURNEY_ACCOUNT_USED("midjourney:account:used:", "midjourney account used", 60 * 60 * 48L),
         APPLY_MONEY_DAY_LIMIT_KEY("apply_money_day_limit_key:%s:%s:%s", "每日提现次数限制", 60 * 60 * 24L),
 
         ;

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/midjourney/MidjourneyService.java

@@ -25,7 +25,7 @@ public interface MidjourneyService {
 
     List<MidjourneyUserConversation> listConversationByIds(Integer mode, List<Long> ids) throws Exception;
 
-    SubmitResult submitAction(MidjourneyUser user, Long taskId, String customId, Long num, String botType) throws Exception;
+    Object submitAction(MidjourneyUser user, Long taskId, String customId, Long num, String botType) throws Exception;
 
     MidjourneyUserConversation cancelConversation(MidjourneyUser user, Long id);
 

+ 82 - 57
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;
@@ -12,14 +13,13 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.EnvCommonService;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
-import com.cyksj.common.util.Codec;
-import com.cyksj.common.util.J11HttpC;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.common.util.StringUtil;
 import com.cyksj.mapper.MidjourneyUserConversationMapper;
 import com.cyksj.mapper.MidjourneyUserMapper;
 import com.cyksj.model.dto.BlendDimensions;
 import com.cyksj.model.dto.MessageButton;
+import com.cyksj.model.dto.SubmitModalDTO;
 import com.cyksj.model.entity.MidjourneyAccount;
 import com.cyksj.model.entity.MidjourneyUser;
 import com.cyksj.model.entity.MidjourneyUserConversation;
@@ -33,18 +33,10 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import javax.imageio.ImageIO;
 import javax.imageio.stream.FileImageOutputStream;
-import java.awt.image.BufferedImage;
 import java.io.*;
-import java.net.URI;
-import java.net.URLEncoder;
-import java.net.http.HttpResponse;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.security.MessageDigest;
-import java.time.ZoneOffset;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
@@ -73,6 +65,8 @@ public class MidjourneyServiceImpl implements MidjourneyService {
 
     @Value("${midjourney.url}")
     private String midjourneyHost;
+    @Value("${midjourney.cdn}")
+    private String midjourneyCdnHost;
 
     private final EnvCommonService envCommonService;
 
@@ -91,6 +85,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             imagineParam.put("base64Array", base64Array);
         }
         SubmitResult result = submit(user.getMode(),"imagine", null,imagineParam);
+        if (user.getMode() == 2) {
+            redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
+        }
         return saveConversation(user.getId(), user.getMode(),result,"IMAGINE", StringUtils.EMPTY, botType);
     }
 
@@ -106,6 +103,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;
     }
@@ -118,6 +118,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
                 .put("base64", base64)
                 .build();
         SubmitResult result = submit(user.getMode(),"describe", null, param);
+        if (user.getMode() == 2) {
+            redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
+        }
         return saveConversation(user.getId(), user.getMode(),result,"DESCRIBE", StringUtils.EMPTY, botType);
     }
 
@@ -131,6 +134,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             param.put("dimensions", dimensions);
         }
         SubmitResult result = submit(user.getMode(),"blend", null, param);
+        if (user.getMode() == 2) {
+            redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
+        }
         return saveConversation(user.getId(), user.getMode(),result,"BLEND", StringUtils.EMPTY, botType);
     }
 
@@ -147,54 +153,61 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             param.put("maskBase64", maskBase64);
         }
         SubmitResult result = submit(user.getMode(),"modal", null, param);
+        if (user.getMode() == 2) {
+            redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
+        }
         return saveConversation(user.getId(),  user.getMode(),result,"MODAL", StringUtils.EMPTY, StringUtils.EMPTY);
     }
 
     @Override
-    public MidjourneyUserConversation submitShorten(MidjourneyUser user, String prompt, String botType) throws Exception {
+    public MidjourneyUserConversation submitShorten(MidjourneyUser user, String botType, String prompt) throws Exception {
         Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
                 .put("prompt", prompt)
                 .put("state", user.getId())
                 .build();
         SubmitResult result = submit(user.getMode(),"shorten", null, param);
+        if (user.getMode() == 2) {
+            redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
+        }
         return saveConversation(user.getId(), user.getMode(), result,"SHORTEN", StringUtils.EMPTY, botType);
     }
 
     /**
      * 恢复次数
      */
-    public Long recoverUserLimit(Long id,Integer mode,Long num){
+    public void recoverUserLimit(Long id,Integer mode,Long num){
         if (mode == 1){
-            num =  redisService.incr(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + id, 1L);
+            redisService.incr(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + id, 1L);
+            midjourneyUserMapper.incrFastNum(id, 1);
         }
         if (mode == 2){
-            if (num != null) {
-                num = redisService.incr(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + id, 1L);
+            if (num != null){
+                redisService.incr(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + id, 1L);
+                midjourneyUserMapper.incrRelaxNum(id, 1);
             }
         }
-        return num;
-    }
-    /**
-     * 同步数据库
-     */
-    public void syncUser(Long id,Integer mode,Long num){
-        log.info("同步次数 id:{},mode:{},num:{}",id,mode,num);
-        if (num == null){
-            return;
-        }
-        LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
-                .eq(MidjourneyUser::getId, id);
-        if (mode == 1){
-            wrapper.set(MidjourneyUser::getMjFastNum, num);
-        }
-        if (mode == 2){
-            wrapper.set(MidjourneyUser::getMjRelaxNum, num);
-        }
-        midjourneyUserMapper.update(null, wrapper);
     }
+//    /**
+//     * 同步数据库
+//     */
+//    public void syncUser(Long id,Integer mode,Long num){
+//        log.info("同步次数 id:{},mode:{},num:{}",id,mode,num);
+//        if (num == null){
+//            return;
+//        }
+//        LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
+//                .eq(MidjourneyUser::getId, id);
+//        if (mode == 1){
+//            wrapper.set(MidjourneyUser::getMjFastNum, num);
+//        }
+//        if (mode == 2){
+//            wrapper.set(MidjourneyUser::getMjRelaxNum, num);
+//        }
+//        midjourneyUserMapper.update(null, wrapper);
+//    }
 
     @Override
-    public SubmitResult submitAction(MidjourneyUser user, Long taskId, String customId, Long num, String botType) throws Exception {
+    public Object submitAction(MidjourneyUser user, Long taskId, String customId, Long num, String botType) throws Exception {
         MidjourneyUserConversation conversation = conversationMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUserConversation.class).eq(MidjourneyUserConversation::getTaskId, taskId).last("limit 1"));
         if (conversation == null) {
             throw BusinessRuntimeException.getInstance("关联任务不存在或已失效");
@@ -202,12 +215,16 @@ public class MidjourneyServiceImpl implements MidjourneyService {
         if (!user.getMode().equals(conversation.getMode())) {
             throw BusinessRuntimeException.getInstance("当前出图模式与关联任务出图模式不符");
         }
+        AtomicBoolean modalFlag = new AtomicBoolean(false);
         if (StringUtils.isNotBlank(conversation.getButtons())){
             List<MessageButton> messageButtons = Jsons.parseList(conversation.getButtons(), MessageButton.class);
             messageButtons.forEach(button -> {
                 if (button.getCustomId().equals(customId)) {
                     log.info("action customId:{}", customId);
                     button.setStyle(3);
+                    if (!"Vary (Region)".equals(button.getLabel()) && !"Custom Zoom".equals(button.getLabel())) {
+                        modalFlag.set(true);
+                    }
                 }
             });
             conversation.setButtons(Jsons.toJson(messageButtons));
@@ -224,10 +241,19 @@ public class MidjourneyServiceImpl implements MidjourneyService {
                 .build();
         SubmitResult result = submit(user.getMode(),"action", conversation.getInstanceId(),param);
         if (result.getCode() == 21) {
-            // 以上操作有弹窗确认,恢复次数
-            recoverUserLimit(user.getId(), user.getMode(),num);
+            if (user.getMode() == 2 && modalFlag.get()){
+                MidjourneyUserConversation modal = submitModal(user, Long.valueOf(result.getResult()), conversation.getPrompt() + " --v 6", null);
+                log.info("action-modal:{}", modal);
+                return modal;
+            }else {
+                // 以上操作有弹窗确认,恢复次数
+                recoverUserLimit(user.getId(), user.getMode(),num);
+            }
         }else {
-            syncUser(user.getId(), user.getMode(),num);
+            //syncUser(user.getId(), user.getMode(),num);
+            if (!customId.contains("upsample") && user.getMode() == 2) {
+                redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
+            }
         }
         saveConversation(user.getId(), user.getMode(), result,"ACTION", StringUtils.EMPTY, botType);
         return result;
@@ -257,6 +283,11 @@ 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, finalAccountWithMinUsage).last("limit 1"));
+                        midjourneyAccountService.updateStatus(account.getId());
+                    });
                 }
                 throw BusinessRuntimeException.getInstance("账号不存在");
             }
@@ -264,11 +295,15 @@ public class MidjourneyServiceImpl implements MidjourneyService {
                 throw BusinessRuntimeException.getInstance(submitResult.getDescription());
             }
             if (code == 24) {
-                throw BusinessRuntimeException.getInstance("prompt包含敏感词");
+                JSONObject jsonObject = JSONUtil.parseObj(submitResult.getResult());
+                throw BusinessRuntimeException.getInstance("prompt包含敏感词:"+jsonObject.getStr("bannedWord"));
             }
             log.error("action:" + action + " error message:" + submitResult.getDescription());
             throw BusinessRuntimeException.getInstance("队列已满,请稍后尝试");
         }
+        if (StringUtils.isNotBlank(accountWithMinUsage) && mode == 2) {
+            submitResult.setInstanceId(Long.valueOf(accountWithMinUsage));
+        }
         return submitResult;
     }
 
@@ -279,9 +314,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             Map<Object, Object> accountsUsage = redisService.hmget(key);
 
             if (accountsUsage == null || accountsUsage.isEmpty()) {
-                Map<Object, Object> map = midjourneyAccountService.list(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getStatus,Boolean.TRUE)).stream().collect(Collectors.toMap(k -> k.getInstanceId().toString(), v -> 0));
+                accountsUsage = midjourneyAccountService.list(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getStatus,Boolean.TRUE)).stream().collect(Collectors.toMap(k -> k.getInstanceId().toString(), v -> 0));
                 // 保存所有账号ID和使用次数
-                redisService.hmset(key, map);
+                redisService.hmset(key, accountsUsage);
             }
 
             // 找到使用次数最少的账号ID
@@ -298,10 +333,6 @@ public class MidjourneyServiceImpl implements MidjourneyService {
                     }
                 }
             }
-            // 增加使用次数
-            if (minAccountId != null) {
-                redisService.hincr(key, minAccountId, 1.0);
-            }
             return minAccountId;
         } catch (Exception e) {
             throw BusinessRuntimeException.getInstance("获取账号失败");
@@ -367,14 +398,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             MidjourneyUserConversation dbConversation = conversationMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUserConversation.class).eq(MidjourneyUserConversation::getTaskId, conversation.getTaskId())
                     .eq(MidjourneyUserConversation::getUserId, userId).orderByDesc(MidjourneyUserConversation::getId).last("limit 1"));
             if (dbConversation != null) {
-                if ("SUCCESS".equals(dbConversation.getStatus())) {
+                if ("SUCCESS".equals(dbConversation.getStatus()) || "FAILURE".equals(dbConversation.getStatus()) || "MODAL".equals(dbConversation.getStatus())) {
                     return;
                 }
                 conversation.setId(dbConversation.getId());
                 conversationMapper.updateById(conversation);
-                if (dbConversation.getMode() == 2){
-                    redisService.hdecr(RedisService.key.MIDJOURNEY_ACCOUNT.getName() , dbConversation.getInstanceId().toString(), 1.0);
-                }
                 TASK_EXECUTOR.execute(() -> {
                     try {
                         String imageUrl = conversation.getImageUrl();
@@ -409,17 +437,14 @@ public class MidjourneyServiceImpl implements MidjourneyService {
     }
 
 
-    private static String uploadPic(String url, String prefix) throws IOException {
+    private 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())) {
+        Path tempFile = Files.createTempFile(Path.of("/mnt/pirture"),prefix, ".png");
+        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());
-        String json = HttpUtil.post("https://files.liuliangbang.vip/pic/ups", paramMap);
-        log.info("上传图片结果:url:{},json:{}",url, json);
-        return new JSONObject(json).getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl");
+        return midjourneyCdnHost + "/picture/" + file.getName();
     }
 
     private static List<String> uploadBase64Pic(List<String> base64Array) throws IOException {

+ 0 - 1
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -3,7 +3,6 @@ package com.cyksj.service.order.impl;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUnit;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.ObjectUtil;

+ 89 - 79
netflix-web/src/main/java/com/cyksj/web/controller/mirror/MidjourneyController.java

@@ -14,12 +14,17 @@ import com.cyksj.mapper.MidjourneyUserMapper;
 import com.cyksj.model.dto.*;
 import com.cyksj.model.entity.GroupsRelation;
 import com.cyksj.model.entity.MidjourneyPaintingPlaza;
+import com.cyksj.model.entity.GroupsRelation;
+import com.cyksj.model.entity.MidjourneyPaintingPlaza;
 import com.cyksj.model.entity.MidjourneyUser;
 import com.cyksj.model.entity.MidjourneyUserConversation;
+import com.cyksj.model.response.SubmitResult;
+import com.cyksj.model.views.MidjourneyPaintingUserView;
+import com.cyksj.model.views.MidjourneyUserPaintingDayRecordView;
+import com.cyksj.model.views.MidjourneyUserPaintingRecordView;
 import com.cyksj.model.views.MidjourneyPaintingUserView;
 import com.cyksj.model.views.MidjourneyUserPaintingDayRecordView;
 import com.cyksj.model.views.MidjourneyUserPaintingRecordView;
-import com.cyksj.model.response.SubmitResult;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.midjourney.MidjourneyAccountService;
 import com.cyksj.service.midjourney.MidjourneyService;
@@ -61,46 +66,28 @@ public class MidjourneyController {
     private final GroupsRelationMapper groupsRelationMapper;
 
     private final MidjourneyPaintingPlazaMapper midjourneyPaintingPlazaMapper;
+
     public MidjourneyUser getUser(){
         String userToken = request.getHeader("user-token");
-        MidjourneyUser midjourneyUser = (MidjourneyUser) redisService.get(RedisService.key.MIDJOURNEY_USER.getName() + userToken);
+
+        MidjourneyUser midjourneyUser = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class)
+                .eq(MidjourneyUser::getUserToken, userToken).last("limit 1"));
         if (midjourneyUser == null){
-            midjourneyUser = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class)
-                    .eq(MidjourneyUser::getUserToken, userToken).last("limit 1"));
-            if (midjourneyUser == null){
-                throw new BusinessRuntimeException("账号不存在,请重新登录");
-            }
-            Long relationId = midjourneyUser.getRelationId();
-            GroupsRelation relation = groupsRelationMapper.selectById(relationId);
-            midjourneyUser.setAqType(relation.getAqType());
-            redisService.set(RedisService.key.MIDJOURNEY_USER.getName() + userToken, midjourneyUser, RedisService.key.MIDJOURNEY_USER.getTimeout());
-            Object fastNum = redisService.get(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId());
-            if (fastNum == null){
-                redisService.set(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId(), midjourneyUser.getMjFastNum(), RedisService.key.MIDJOURNEY_FAST_LIMIT.getTimeout());
-            }
-            Object relaxNum = redisService.get(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId());
-            if (relaxNum == null){
-                if (midjourneyUser.getMjRelaxNum() != null){
-                    redisService.set(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId(), midjourneyUser.getMjRelaxNum(), RedisService.key.MIDJOURNEY_RELAX_LIMIT.getTimeout());
-                }
-            }
-        }else {
-            Object fastNum = redisService.get(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId());
-            if (fastNum == null){
-                redisService.set(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId(), midjourneyUser.getMjFastNum(), RedisService.key.MIDJOURNEY_FAST_LIMIT.getTimeout());
-            }else {
-                midjourneyUser.setMjFastNum(Integer.parseInt(fastNum.toString()));
-            }
-            Object relaxNum = redisService.get(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId());
-            if (relaxNum == null){
-                if (midjourneyUser.getMjRelaxNum() != null){
-                    redisService.set(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId(), midjourneyUser.getMjRelaxNum(), RedisService.key.MIDJOURNEY_RELAX_LIMIT.getTimeout());
-                }
-            }else {
-                midjourneyUser.setMjRelaxNum(Integer.parseInt(relaxNum.toString()));
-            }
+            throw new BusinessRuntimeException("账号不存在,请重新登录");
+        }
+        if(!redisService.hasKey(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId())){
+            redisService.set(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + midjourneyUser.getId(),midjourneyUser.getMjFastNum());
+        }
+
+        if(!redisService.hasKey(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId())){
+            redisService.set(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + midjourneyUser.getId(),midjourneyUser.getMjRelaxNum());
         }
+        Long relationId = midjourneyUser.getRelationId();
+        GroupsRelation relation = groupsRelationMapper.selectById(relationId);
+        midjourneyUser.setAqType(relation.getAqType());
+
         return midjourneyUser;
+
     }
 
 
@@ -113,18 +100,35 @@ public class MidjourneyController {
             throw BusinessRuntimeException.getInstance("账号已过期");
         }
        if (user.getMode() == 1){
+
            num = redisService.decr(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + user.getId(), 1L);
+
            if (num < 0) {
                user.setMode(2);
+               midjourneyUserMapper.update(null, Wrappers.lambdaUpdate(MidjourneyUser.class).eq(MidjourneyUser::getId, user.getId()).set(MidjourneyUser::getMode, user.getMode()));
                redisService.incr(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + user.getId(), 1L);
+
+           }else {
+               int i = midjourneyUserMapper.decFastNum(user.getId(), 1, user.getMjFastNum());
+               if (i == 0) {
+                   redisService.incr(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + user.getId(), 1L);
+                   throw BusinessRuntimeException.getInstance("网络异常,请稍后再试");
+               }
            }
        }
        if (user.getMode() == 2){
            Object relax = redisService.get(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + user.getId());
+
            if (relax != null){
                num = redisService.decr(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + user.getId(), 1L);
                if (num < 0){
                    redisService.incr(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + user.getId(), 1L);
+               }else {
+                   int i = midjourneyUserMapper.decRelaxNum(user.getId(), 1, user.getMjRelaxNum());
+                   if (i == 0) {
+                       redisService.incr(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + user.getId(), 1L);
+                       throw BusinessRuntimeException.getInstance("网络异常,请稍后再试");
+                   }
                }
            }else {
                num = null;
@@ -139,32 +143,34 @@ public class MidjourneyController {
     public void recoverUserLimit(Long id,Integer mode,Long num){
         if (mode == 1){
             redisService.incr(RedisService.key.MIDJOURNEY_FAST_LIMIT.getName() + id, 1L);
+            midjourneyUserMapper.incrFastNum(id, 1);
         }
         if (mode == 2){
             if (num != null){
                 redisService.incr(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + id, 1L);
+                midjourneyUserMapper.incrRelaxNum(id, 1);
             }
         }
     }
 
-    /**
-     * 同步数据库
-     */
-    public void syncUser(Long id,Integer mode,Long num){
-        log.info("同步次数 id:{},mode:{},num:{}",id,mode,num);
-        if (num == null){
-            return;
-        }
-        LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
-                .eq(MidjourneyUser::getId, id);
-        if (mode == 1){
-            wrapper.set(MidjourneyUser::getMjFastNum, num);
-        }
-        if (mode == 2){
-            wrapper.set(MidjourneyUser::getMjRelaxNum, num);
-        }
-        midjourneyUserMapper.update(null, wrapper);
-    }
+    ///**
+    // * 同步数据库
+    // */
+    //public void syncUser(Long id,Integer mode,Long num){
+    //    log.info("同步次数 id:{},mode:{},num:{}",id,mode,num);
+    //    if (num == null){
+    //        return;
+    //    }
+    //    LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
+    //            .eq(MidjourneyUser::getId, id);
+    //    if (mode == 1){
+    //        wrapper.set(MidjourneyUser::getMjFastNum, num);
+    //    }
+    //    if (mode == 2){
+    //        wrapper.set(MidjourneyUser::getMjRelaxNum, num);
+    //    }
+    //    midjourneyUserMapper.update(null, wrapper);
+    //}
 
 
     /**
@@ -183,7 +189,7 @@ public class MidjourneyController {
     @PostMapping("/submit/imagine")
     @NoSubmit
     public Result<MidjourneyUserConversation> submitImagine(@RequestBody SubmitImagineDTO submitImagineDTO) {
-        log.info("提交Imagine任务,提示:{},base64数组长度:{}",submitImagineDTO.getPrompt(),submitImagineDTO.getBase64Array());
+        log.info("提交Imagine任务,提示:{}",submitImagineDTO.getPrompt());
         MidjourneyUser user = getUser();
         Long num = checkUserLimit(user);
         if (num != null && num < 0){
@@ -196,7 +202,7 @@ public class MidjourneyController {
             recoverUserLimit(user.getId(), user.getMode(),num);
             throw BusinessRuntimeException.getInstance(e.getMessage());
         }
-        syncUser(user.getId(), user.getMode(), num);
+        //syncUser(user.getId(), user.getMode(), num);
         return GatewayResponse.SUCCESS.newBuilder().toResult(conversation);
     }
 
@@ -214,12 +220,12 @@ public class MidjourneyController {
         }
         MidjourneyUserConversation conversation;
         try {
-            conversation = midjourneyService.submitDescribe(user, submitDescribeDTO.getBase64(), submitDescribeDTO.getBotType());
+            conversation = midjourneyService.submitDescribe(user, submitDescribeDTO.getBotType(),submitDescribeDTO.getBase64());
         } catch (Exception e) {
             recoverUserLimit(user.getId(), user.getMode(),num);
             throw BusinessRuntimeException.getInstance(e.getMessage());
         }
-        syncUser(user.getId(), user.getMode(), num);
+        //syncUser(user.getId(), user.getMode(), num);
         return GatewayResponse.SUCCESS.newBuilder().toResult(conversation);
     }
 
@@ -242,7 +248,7 @@ public class MidjourneyController {
             recoverUserLimit(user.getId(), user.getMode(),num);
             throw BusinessRuntimeException.getInstance(e.getMessage());
         }
-        syncUser(user.getId(), user.getMode(), num);
+        //syncUser(user.getId(), user.getMode(), num);
         return GatewayResponse.SUCCESS.newBuilder().toResult(conversation);
     }
 
@@ -252,7 +258,7 @@ public class MidjourneyController {
     @PostMapping("/submit/modal")
     @NoSubmit
     public Result<MidjourneyUserConversation> submitModal(@RequestBody SubmitModalDTO submitModalDTO) {
-        log.info("提交Modal任务,taskId:{},提示:{},base64数组长度:{}",submitModalDTO.getTaskId(),submitModalDTO.getPrompt(),submitModalDTO.getMaskBase64());
+        log.info("提交Modal任务,taskId:{},提示:{}",submitModalDTO.getTaskId(),submitModalDTO.getPrompt());
         MidjourneyUser user = getUser();
         Long num = checkUserLimit(user);
         if (num != null && num < 0){
@@ -265,7 +271,7 @@ public class MidjourneyController {
             recoverUserLimit(user.getId(), user.getMode(),num);
             throw BusinessRuntimeException.getInstance(e.getMessage());
         }
-        syncUser(user.getId(), user.getMode(), num);
+        //syncUser(user.getId(), user.getMode(), num);
         return GatewayResponse.SUCCESS.newBuilder().toResult(conversation);
     }
 
@@ -288,7 +294,7 @@ public class MidjourneyController {
             recoverUserLimit(user.getId(), user.getMode(),num);
             throw BusinessRuntimeException.getInstance(e.getMessage());
         }
-        syncUser(user.getId(), user.getMode(), num);
+        //syncUser(user.getId(), user.getMode(), num);
         return GatewayResponse.SUCCESS.newBuilder().toResult(conversation);
     }
 
@@ -297,14 +303,17 @@ public class MidjourneyController {
      */
     @PostMapping("/submit/action")
     @NoSubmit
-    public Result<SubmitResult> action(@RequestBody SubmitActionDTO actionDTO) {
+    public Result<Object> action(@RequestBody SubmitActionDTO actionDTO) {
         log.info("任务id:{},执行动作:{}",actionDTO.getTaskId(),actionDTO.getCustomId());
         MidjourneyUser user = getUser();
-        Long num = checkUserLimit(user);
-        if (num != null && num < 0){
-            throw BusinessRuntimeException.getInstance("次数已用完");
+        Long num = 0L;
+        if (!actionDTO.getCustomId().contains("BOOKMARK")) {
+            num = checkUserLimit(user);
+            if (num != null && num < 0) {
+                throw BusinessRuntimeException.getInstance("次数已用完");
+            }
         }
-        SubmitResult conversation;
+        Object conversation;
         try {
             conversation = midjourneyService.submitAction(user, actionDTO.getTaskId(), actionDTO.getCustomId(),num, actionDTO.getBotType());
         } catch (Exception e) {
@@ -362,20 +371,21 @@ public class MidjourneyController {
         }
         midjourneyUser.setMode(mode);
         midjourneyUserMapper.updateById(midjourneyUser);
-        redisService.del(RedisService.key.MIDJOURNEY_USER.getName() + midjourneyUser.getUserToken());
+        //redisService.del(RedisService.key.MIDJOURNEY_USER.getName() + midjourneyUser.getUserToken());
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
 
-	/**
-	 * midjourney 回调
-	 */
-	@PostMapping("/notifyHook")
-	public void notifyHook(HttpServletRequest request) throws Exception {
-		InputStream inputStream = request.getInputStream();
-		byte[] bytes = IoKit.toBytes(inputStream);
-		String json = new String(bytes, StandardCharsets.UTF_8);
-		midjourneyService.notifyHook(json);
-	}
+    /**
+     * midjourney 回调
+     */
+    @PostMapping("/notifyHook")
+    public void notifyHook(HttpServletRequest request) throws Exception {
+        InputStream inputStream = request.getInputStream();
+        byte[] bytes = IoKit.toBytes(inputStream);
+        String json = new String(bytes, StandardCharsets.UTF_8);
+        midjourneyService.notifyHook(json);
+    }
+
 
 
     /**
@@ -408,7 +418,7 @@ public class MidjourneyController {
         MidjourneyUser user = getUser();
         String condition = String.format(" and mc.user_id = %s", user.getId());
         if (StrUtil.isNotBlank(prompt)) {
-            condition += String.format(" and mc.prompt = '%s'", prompt);
+            condition += String.format(" and mc.prompt like '%%%s%%'", prompt);
         }
         if (bookmark != null) {
             condition += String.format(" and mc.bookmark is %s", bookmark);

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
netflix-web/src/main/resources/application-dev.yml


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
netflix-web/src/main/resources/application-prd.yml


+ 2 - 1
netflix-web/src/main/resources/application-pre.yml

@@ -197,4 +197,5 @@ smsVerify:
 
 midjourney:
   url: https://nf.video
-  drawUrl: https://nf.video/drawTest/web/
+  drawUrl: https://nf.video/drawTest/web/
+  cdn: https://nf.video

Неке датотеке нису приказане због велике количине промена