From ea5c6fcb81512deb37906c9dca68b23d8e1beb7b Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Fri, 15 Mar 2024 16:26:23 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=9A=82=E6=97=B6=E4=BF=AE=E6=94=B9ai?= =?UTF-8?q?=E4=B8=BApublic=EF=BC=8C=E4=B8=8B=E6=AC=A1=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=85=88=E5=89=8D=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/frontend/AiController.java | 2 +- .../service/impl/ChatMessageServiceImpl.java | 5 ++-- .../service/impl/ChatSessionServiceImpl.java | 28 ++++++++++--------- src/main/java/cn/teammodel/utils/PdfUtil.java | 2 -- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/java/cn/teammodel/controller/frontend/AiController.java b/src/main/java/cn/teammodel/controller/frontend/AiController.java index fdda18e..141b7e4 100644 --- a/src/main/java/cn/teammodel/controller/frontend/AiController.java +++ b/src/main/java/cn/teammodel/controller/frontend/AiController.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; @RestController -@RequestMapping("/ai") +@RequestMapping("public/ai") @Api(tags = "AI 能力") public class AiController { @Resource diff --git a/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java b/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java index 19a7f34..e5faaff 100644 --- a/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java @@ -115,8 +115,9 @@ public class ChatMessageServiceImpl implements ChatMessageService { * 会话模式 */ private SseEmitter completionBySession(ChatCompletionReqDto chatCompletionReqDto) { - User user = SecurityUtil.getLoginUser(); - String userId = user.getId(); +// User user = SecurityUtil.getLoginUser(); +// String userId = user.getId(); + String userId = "1595321354"; String userPrompt = chatCompletionReqDto.getText(); String sessionId = chatCompletionReqDto.getSessionId(); diff --git a/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java b/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java index 5fe3a36..b5bfb30 100644 --- a/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java @@ -4,12 +4,10 @@ import cn.hutool.core.lang.UUID; import cn.teammodel.common.ErrorCode; import cn.teammodel.common.PK; import cn.teammodel.config.exception.ServiceException; -import cn.teammodel.repository.ChatSessionRepository; import cn.teammodel.model.dto.ai.UpdateSessionDto; -import cn.teammodel.model.entity.User; import cn.teammodel.model.entity.ai.ChatSession; import cn.teammodel.model.entity.ai.ChatSession.Message; -import cn.teammodel.security.utils.SecurityUtil; +import cn.teammodel.repository.ChatSessionRepository; import cn.teammodel.service.ChatSessionService; import cn.teammodel.utils.RepositoryUtil; import com.azure.cosmos.models.CosmosPatchOperations; @@ -36,10 +34,11 @@ public class ChatSessionServiceImpl implements ChatSessionService { @Override public String createSession() { - User user = SecurityUtil.getLoginUser(); - String userId = user.getId(); +// todo User user = SecurityUtil.getLoginUser(); || 2. user.getName() +// String userId = user.getId(); + String userId = "1595321354"; // 初始化欢迎语 - Message message = Message.of("", "你好" + user.getName() + " ,我是你的私人 AI 助手小豆,你可以问我任何包括但不仅限于教育的问题,我会尽力为您解答!"); + Message message = Message.of("", "你好" + "罗老师" + " ,我是你的私人 AI 助手小豆,你可以问我任何包括但不仅限于教育的问题,我会尽力为您解答!"); List history = Collections.singletonList(message); ChatSession chatSession = new ChatSession(); chatSession.setId(UUID.randomUUID().toString()); @@ -54,7 +53,8 @@ public class ChatSessionServiceImpl implements ChatSessionService { @Override public List listMySession() { - String userId = SecurityUtil.getUserId(); +// String userId = SecurityUtil.getUserId(); + String userId = "1595321354"; List sessions = chatSessionRepository.findByUserId(userId); // 按更新时间排序 if (ObjectUtils.isNotEmpty(sessions)) { @@ -67,8 +67,9 @@ public class ChatSessionServiceImpl implements ChatSessionService { public ChatSession updateSession(UpdateSessionDto updateSessionDto) { String id = updateSessionDto.getId(); String title = updateSessionDto.getTitle(); - User user = SecurityUtil.getLoginUser(); - String userId = user.getId(); +// User user = SecurityUtil.getLoginUser(); +// String userId = user.getId(); + String userId = "1595321354"; ChatSession session = RepositoryUtil.findOne(chatSessionRepository.findBySessionId(id), ""); if (!session.getUserId().equals(userId)) { @@ -82,8 +83,9 @@ public class ChatSessionServiceImpl implements ChatSessionService { @Override public void deleteSession(String id) { - User user = SecurityUtil.getLoginUser(); - String userId = user.getId(); +// User user = SecurityUtil.getLoginUser(); +// String userId = user.getId(); + String userId = "1595321354"; ChatSession session = RepositoryUtil.findOne(chatSessionRepository.findBySessionId(id), "该会话不存在"); // 鉴权 if (!session.getUserId().equals(userId)) { @@ -94,8 +96,8 @@ public class ChatSessionServiceImpl implements ChatSessionService { @Override public List listMyHistory(String sessionId) { - User user = SecurityUtil.getLoginUser(); - String userId = user.getId(); +// User user = SecurityUtil.getLoginUser(); + String userId = "1595321354"; ChatSession session = chatSessionRepository.findChatSessionByIdAndCode(sessionId, PK.CHAT_SESSION); if (!userId.equals(session.getUserId())) { throw new ServiceException(ErrorCode.NO_AUTH_ERROR); diff --git a/src/main/java/cn/teammodel/utils/PdfUtil.java b/src/main/java/cn/teammodel/utils/PdfUtil.java index 4e07a00..af5bdf7 100644 --- a/src/main/java/cn/teammodel/utils/PdfUtil.java +++ b/src/main/java/cn/teammodel/utils/PdfUtil.java @@ -22,7 +22,6 @@ public class PdfUtil { Font boldFont = new Font(baseFont, 16, Font.BOLD); AcroFields fields = stamper.getAcroFields(); for (Map.Entry entry : data.entrySet()) { - fields.setFieldProperty(entry.getKey(), "textsize", boldFont.getSize(), null); fields.setFieldProperty(entry.getKey(), "textfont", baseFont, null); // 设置字体为加粗 fields.setField(entry.getKey(), entry.getValue()); @@ -41,5 +40,4 @@ public class PdfUtil { image.setAbsolutePosition(x, y); content.addImage(image); } - } \ No newline at end of file