From 68fb516019b6167ba1f32781c015c5e3b0ddd7c9 Mon Sep 17 00:00:00 2001 From: firefly <1633489380@qq.com> Date: Thu, 14 Aug 2025 11:28:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/aitutor/AiChatController.java | 92 ++++++++----------- 1 file changed, 39 insertions(+), 53 deletions(-) diff --git a/srs-admin/src/main/java/com/srs/web/controller/aitutor/AiChatController.java b/srs-admin/src/main/java/com/srs/web/controller/aitutor/AiChatController.java index a040f79..5f5ea23 100644 --- a/srs-admin/src/main/java/com/srs/web/controller/aitutor/AiChatController.java +++ b/srs-admin/src/main/java/com/srs/web/controller/aitutor/AiChatController.java @@ -16,6 +16,7 @@ import okhttp3.*; import com.srs.common.core.domain.AjaxResult; // ✅ RuoYi 的返回结果类 import okhttp3.RequestBody; import okhttp3.ResponseBody; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -38,41 +39,49 @@ import java.util.concurrent.CompletableFuture; @RestController @RequestMapping("/aitutor/aichat") public class AiChatController extends BaseController { - /** - * Dify API的URL地址 - * 用于发送聊天消息请求到Dify服务 - */ - - private static final String DIFY_API_URL = "http://47.112.118.149:8100/v1/chat-messages"; - //private static final String DIFY_API_URL = "http://localhost:8080/v1/chat-messages"; - - /** - * Dify反馈API的基础URL - * 用于提交消息反馈(点赞、点踩等) - */ - private static final String DIFY_FEEDBACK_BASE_URL = "http://47.112.118.149:8100/v1/messages"; - //private static final String DIFY_FEEDBACK_BASE_URL = "http://localhost:8080/v1/messages"; - - private static final String DIFY_API_HISTORY_URL = "http://47.112.118.149:8100/v1/messages"; - //private static final String DIFY_API_HISTORY_URL = "http://localhost:8080/v1/messages"; - - /** - * Dify会话API的基础URL - * 用于获取会话列表 - */ - private static final String DIFY_CONVERSATIONS_URL = "http://47.112.118.149:8100/v1/conversations"; - //private static final String DIFY_CONVERSATIONS_URL = "http://localhost:8080/v1/conversations"; - - //文件上传 - private static final String DIFY_FILES_URL = "http://47.112.118.149:8100/v1/files/upload"; /** * Dify API的访问密钥 * 用于身份验证,授权访问Dify服务 */ private static final String DIFY_API_KEY = "app-2wjqcYI9n6igHTVHdH8qXlnh"; - //private static final String DIFY_API_KEY = "app-"; + /** + * Dify API的URL地址 + * 用于发送聊天消息请求到Dify服务 + */ + + private static final String DIFY_API_URL = "http://47.112.118.149:8100/v1/chat-messages"; + + /** + * Dify反馈API的基础URL + * 用于提交消息反馈(点赞、点踩等) + */ + private static final String DIFY_FEEDBACK_BASE_URL = "http://47.112.118.149:8100/v1/messages"; + + /** + * Dify获取反馈API的基础URL + * 用于获取消息反馈(点赞、点踩等) + */ + private static final String DIFY_API_FEEDBACK_URL = "http://47.112.118.149:8100/v1/app/feedbacks?page="; + + /** + * Dify消息历史记录API的基础URL + * 用于获取消息历史记录 + */ + private static final String DIFY_API_HISTORY_URL = "http://47.112.118.149:8100/v1/messages"; + + /** + * Dify会话API的基础URL + * 用于获取会话列表 + */ + private static final String DIFY_CONVERSATIONS_URL = "http://47.112.118.149:8100/v1/conversations"; + + /** + * Dify文件上传API的URL地址 + * 用于上传文件到Dify服务,支持图文多模态理解 + */ + private static final String DIFY_FILES_URL = "http://47.112.118.149:8100/v1/files/upload"; /** * HTTP客户端实例 @@ -386,12 +395,9 @@ public class AiChatController extends BaseController { // 参数校验和限制 int limitValue = Math.min(Math.max(Integer.parseInt(limit), 1), 100); - // 构建请求URL - String url = "http://47.112.118.149:8100/v1/app/feedbacks?page=" + page + "&limit=" + limitValue; - // 构建请求 Request request = new Request.Builder() - .url(url) + .url(DIFY_API_FEEDBACK_URL + page + "&limit=" + limitValue) .addHeader("Authorization", "Bearer " + DIFY_API_KEY) .addHeader("Content-Type", "application/json") .get() @@ -420,27 +426,6 @@ public class AiChatController extends BaseController { feedbackItem.put("app_id", feedbackNode.has("app_id") ? feedbackNode.get("app_id").asText() : null); feedbackItem.put("conversation_id", feedbackNode.has("conversation_id") ? feedbackNode.get("conversation_id").asText() : null); - // 提取用户信息 - if (feedbackNode.has("from_end_user")) { - JsonNode userNode = feedbackNode.get("from_end_user"); - Map userMap = new HashMap<>(); - userMap.put("id", userNode.has("id") ? userNode.get("id").asText() : null); - userMap.put("name", userNode.has("name") ? userNode.get("name").asText() : null); - userMap.put("email", userNode.has("email") ? userNode.get("email").asText() : null); - feedbackItem.put("from_end_user", userMap); - } - - // 提取消息内容 - if (feedbackNode.has("message")) { - JsonNode messageNode = feedbackNode.get("message"); - Map messageMap = new HashMap<>(); - messageMap.put("id", messageNode.has("id") ? messageNode.get("id").asText() : null); - messageMap.put("query", messageNode.has("query") ? messageNode.get("query").asText() : null); - messageMap.put("answer", messageNode.has("answer") ? messageNode.get("answer").asText() : null); - messageMap.put("created_at", messageNode.has("created_at") ? messageNode.get("created_at").asLong() : null); - feedbackItem.put("message", messageMap); - } - feedbackList.add(feedbackItem); } } @@ -476,6 +461,7 @@ public class AiChatController extends BaseController { } // 权限标识为辅导员 + @PreAuthorize("@ss.hasPermi('cph:teacher:list')") @GetMapping("/getMessagesToAdmin") public AjaxResult getMessagesToAdmin(@RequestParam String user, @RequestParam(required = false) String firstId,