Ver Fonte

fix 新增标题优化

chenbiao há 2 anos atrás
pai
commit
f47f725349

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

@@ -380,7 +380,7 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
             }
             conversationLimitResponse = isConversationAllowed(userToken, chatgptUser.getLimitNum(), chatgptUser.getLimitTime());
             //车队次数记录
-            TASK_EXECUTOR.execute(()->{
+            TASK_EXECUTOR.execute(() -> {
                 cardConversationRecord(carId);
             });
         }
@@ -546,12 +546,12 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
                     chatgptCarInfoView.setIsHistory(true);
                     chatgptCarInfoView.setScore(redisService.zScore(RedisService.key.CHATGPT_CAR_SCORES.getName(), historyView.getCarId()));
                     String sessionVar = redisService.getStr(RedisService.key.CHATGPT_CAR_SEESSION.getName() + historyView.getCarId());
-                    if(JSONUtil.isJson(sessionVar)){
+                    if (JSONUtil.isJson(sessionVar)) {
                         JSONObject sessionJson = new JSONObject(sessionVar);
                         JSONArray models = sessionJson.getJSONArray("models");
-                        if(models.size() > 1){
+                        if (models.size() > 1) {
                             chatgptCarInfoView.setType("plus");
-                        }else {
+                        } else {
                             chatgptCarInfoView.setType("3.5");
                         }
                     }
@@ -660,11 +660,11 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         view.setScore(score);
         view.setStatus(score >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
         String sessionVar = redisService.getStr(RedisService.key.CHATGPT_CAR_SEESSION.getName() + carId);
-        if(JSONUtil.isJson(sessionVar)){
+        if (JSONUtil.isJson(sessionVar)) {
             JSONArray models = new JSONObject(sessionVar).getJSONArray("models");
-            if(models!= null && models.size() > 1){
+            if (models != null && models.size() > 1) {
                 view.setType("plus");
-            }else {
+            } else {
                 view.setType("3.5");
             }
         }
@@ -702,15 +702,14 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
     @Override
     public void genTitleSync(String messageId, String carid, String userToken) {
         //同步对话
-        ChatgptUserConversationRecord chatgptUserConversationRecord = chatgptUserConversationRecordMapper.selectOne(Wrappers.lambdaQuery(ChatgptUserConversationRecord.class).eq(ChatgptUserConversationRecord::getMessageId, messageId));
-        if (chatgptUserConversationRecord != null) {
-            if (StringUtils.isBlank(chatgptUserConversationRecord.getConversationId())) {
-                ChatgptUserConversation conversation = chatgptUserConversationMapper.selectOne(Wrappers.lambdaQuery(ChatgptUserConversation.class).eq(ChatgptUserConversation::getMessageId, messageId).last(" limit 1"));
-                if (conversation != null) {
-                    chatgptUserConversationRecord.setConversationId(conversation.getConversationId());
-                    chatgptUserConversationRecordMapper.updateById(chatgptUserConversationRecord);
-                }
-            }
+        if (!StringUtils.isAnyBlank(messageId, carid, userToken)) {
+            ChatgptUserConversation conversation = chatgptUserConversationMapper.selectOne(Wrappers.lambdaQuery(ChatgptUserConversation.class).eq(ChatgptUserConversation::getMessageId, messageId).last(" limit 1"));
+
+            chatgptUserConversationRecordMapper.update(null, Wrappers.lambdaUpdate(ChatgptUserConversationRecord.class)
+                    .set(ChatgptUserConversationRecord::getConversationId, conversation.getConversationId())
+                    .eq(ChatgptUserConversationRecord::getMessageId, messageId)
+                    .eq(ChatgptUserConversationRecord::getCarId, carid)
+                    .eq(ChatgptUserConversationRecord::getUserToken, userToken));
         }
     }
 

+ 8 - 6
netflix-web/src/main/java/com/cyksj/web/controller/mirror/MirrorController.java

@@ -53,7 +53,6 @@ public class MirrorController {
     private final BeanSearcher beanSearcher;
 
 
-
     /**
      * GPT车票跳转登录
      *
@@ -107,12 +106,14 @@ public class MirrorController {
     }
 
     @GetMapping("/gpt/genTitleSync")
-    public Result<String> genTitleSync(String messageId){
+    public Result<String> genTitleSync(String messageId) {
         //1.从request获取请求头Authorization 并取 值内 'Bearer ' 后的值为usertoken
         String authorization = request.getHeader("Authorization");
         String carid = request.getHeader("Carid");
         String userToken = authorization.substring(7);
-        chatGptAccountService.genTitleSync(messageId, carid, userToken);
+        TASK_EXECUTOR.execute(() -> {
+            chatGptAccountService.genTitleSync(messageId, carid, userToken);
+        });
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
 
@@ -137,7 +138,7 @@ public class MirrorController {
         //text-davinci-002-render-sha 3.5
         ConversationLimitResponse conversationLimitResponse = chatGptAccountService.conversationLimit(userToken, conversationRequest.getModel(), conversationRequest.getCarId(), user);
         //记录提问时间,车次,标题和模型
-        TASK_EXECUTOR.execute(()->{
+        TASK_EXECUTOR.execute(() -> {
             chatGptAccountService.saveConversationRecord(userToken, conversationRequest);
         });
         OutputStream out = null;
@@ -146,7 +147,7 @@ public class MirrorController {
             response.setStatus(429);
             String json = "{\"detail\":{\"message\":\"您的账号已达到GPT-4的使用上限。您现在可以继续使用默认模型,或者重试在\",\"code\":\"model_cap_exceeded\",\"clears_in\":2687}}";
             JSONObject res = new JSONObject(json);
-            res.putOpt("clears_in",conversationLimitResponse.getNextAvailableTime()/1000);
+            res.putOpt("clears_in", conversationLimitResponse.getNextAvailableTime() / 1000);
             messgae = res.toString();
         } else {
             response.setStatus(200);
@@ -167,6 +168,7 @@ public class MirrorController {
 
     /**
      * 获取车队列表
+     *
      * @param relationId
      * @return
      */
@@ -201,7 +203,7 @@ public class MirrorController {
     public Result<SearchResult<ChatGptUserConversationRecordHistoryView>> getCarHistory(Long relationId) {
         long userId = StpUserUtil.getLoginIdAsLong();
         ChatgptUser carChatGptUser = chatGptAccountService.getCarChatGptUser(userId, relationId);
-        if(carChatGptUser == null){
+        if (carChatGptUser == null) {
             throw BusinessRuntimeException.getInstance("车票出现了异常.");
         }
         MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap()).field("r.user_token", carChatGptUser.getUserToken());