Parcourir la source

gpt用户切换模式

zoujiajian il y a 1 an
Parent
commit
a347677e10

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/ChatgptUser.java

@@ -111,4 +111,9 @@ public class ChatgptUser extends BaseEntity {
      */
     @TableField(updateStrategy = FieldStrategy.IGNORED)
     private Date renewExpiryTime;
+
+    /**
+     * 用户目前模式 0旧版 1新版
+     */
+    private Integer model;
 }

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/chatgpt/ChatGptAccountService.java

@@ -55,4 +55,6 @@ public interface ChatGptAccountService {
     String getGptSession(String account, String password);
 
     void clearGptNum(Long relationId) throws Exception;
+
+    void gptSwitchModel(long userId, Long relationId);
 }

+ 16 - 0
netflix-service/src/main/java/com/cyksj/service/chatgpt/impl/ChatGptAccountServiceImpl.java

@@ -126,6 +126,22 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         }
     }
 
+    @Override
+    public void gptSwitchModel(long userId, Long relationId) {
+        List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
+        Integer count = groupsRelationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
+                .in(GroupsRelation::getUserId, userIdList)
+                .eq(GroupsRelation::getId, relationId));
+        if (count > 0) {
+            Optional.ofNullable(chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
+                    .eq(ChatgptUser::getRelationId, relationId)
+                    .last("limit 1"))).ifPresent(cu -> {
+                cu.setModel(cu.getModel() == 0 ? 1 : 0);
+                chatgptUserMapper.updateById(cu);
+            });
+        }
+    }
+
     /**
      * 获取登录结果
      *

+ 10 - 5
netflix-web/src/main/java/com/cyksj/web/controller/mirror/MirrorController.java

@@ -1,7 +1,6 @@
 package com.cyksj.web.controller.mirror;
 
 import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONObject;
@@ -17,8 +16,6 @@ import com.cyksj.mapper.GroupsMapper;
 import com.cyksj.mapper.GroupsRelationMapper;
 import com.cyksj.mapper.renew.RenewUpgradePackageMapper;
 import com.cyksj.model.entity.*;
-import com.cyksj.model.request.gpt.ConversationRequest;
-import com.cyksj.model.response.ConversationLimitResponse;
 import com.cyksj.model.views.*;
 import com.cyksj.service.chatgpt.ChatGptAccountService;
 import com.cyksj.service.claude.ClaudeService;
@@ -32,7 +29,6 @@ import com.ejlchina.searcher.util.MapBuilder;
 import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
@@ -41,7 +37,6 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.time.LocalDateTime;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -256,6 +251,16 @@ public class MirrorController {
         return GatewayResponse.SUCCESS.newBuilder().toResult(search);
     }
 
+    /**
+     * GPT切换模式
+     */
+    @PutMapping("/gpt/switch/model/{relationId}")
+    public Result<String> gptSwitchModel(@PathVariable Long relationId) {
+        long userId = StpUserUtil.getLoginIdAsLong();
+        chatGptAccountService.gptSwitchModel(userId, relationId);
+        return GatewayResponse.SUCCESS.newBuilder().toResult();
+    }
+
 
 
     /**