From 373424bd010cfae218570e602199e2ac6754a0ef Mon Sep 17 00:00:00 2001 From: ageerle <ageerle@163.com> Date: 星期六, 24 五月 2025 16:18:18 +0800 Subject: [PATCH] feat(更新日志): --- ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java b/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java index 4fa12ee..2a28f0d 100644 --- a/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java +++ b/ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/SseServiceImpl.java @@ -21,6 +21,7 @@ import org.ruoyi.common.core.utils.StringUtils; import org.ruoyi.common.core.utils.file.FileUtils; import org.ruoyi.common.core.utils.file.MimeTypeUtils; +import org.ruoyi.common.satoken.utils.LoginHelper; import org.ruoyi.domain.bo.ChatSessionBo; import org.ruoyi.domain.bo.QueryVectorBo; import org.ruoyi.domain.vo.ChatModelVo; @@ -77,23 +78,22 @@ try { // 鏋勫缓娑堟伅鍒楄〃 buildChatMessageList(chatRequest); - - LocalCache.CACHE.put("userId", chatCostService.getUserId()); - chatRequest.setUserId(chatCostService.getUserId()); - // 淇濆瓨浼氳瘽淇℃伅 - if(chatRequest.getSessionId()==null){ - ChatSessionBo chatSessionBo = new ChatSessionBo(); - chatSessionBo.setUserId(chatCostService.getUserId()); - chatSessionBo.setSessionTitle(getFirst10Characters(chatRequest.getPrompt())); - chatSessionBo.setSessionContent(chatRequest.getPrompt()); - chatSessionService.insertByBo(chatSessionBo); - chatRequest.setSessionId(chatSessionBo.getId()); - } - LocalCache.CACHE.put("sessionId", chatRequest.getSessionId()); // 璁剧疆瀵硅瘽瑙掕壊 chatRequest.setRole(Message.Role.USER.getName()); - // 淇濆瓨娑堟伅璁板綍 骞舵墸闄よ垂鐢� - chatCostService.deductToken(chatRequest); + + if(LoginHelper.isLogin()){ + // 淇濆瓨娑堟伅璁板綍 骞舵墸闄よ垂鐢� + chatCostService.deductToken(chatRequest); + chatRequest.setUserId(chatCostService.getUserId()); + if(chatRequest.getSessionId()==null){ + ChatSessionBo chatSessionBo = new ChatSessionBo(); + chatSessionBo.setUserId(chatCostService.getUserId()); + chatSessionBo.setSessionTitle(getFirst10Characters(chatRequest.getPrompt())); + chatSessionBo.setSessionContent(chatRequest.getPrompt()); + chatSessionService.insertByBo(chatSessionBo); + chatRequest.setSessionId(chatSessionBo.getId()); + } + } // 鏍规嵁妯″瀷鍒嗙被璋冪敤涓嶅悓鐨勫鐞嗛�昏緫 IChatService chatService = chatServiceFactory.getChatService(chatModelVo.getCategory()); chatService.chat(chatRequest, sseEmitter); -- Gitblit v1.9.3