优化了部分代码结构
This commit is contained in:
@@ -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<String, Object> 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<String, Object> 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,
|
||||
|
Reference in New Issue
Block a user