获取APP的消息点赞和反馈列表
This commit is contained in:
		@@ -13,6 +13,7 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 | 
			
		||||
import java.io.BufferedReader;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.time.Duration;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
@@ -60,6 +61,7 @@ public class DifyChatController extends BaseController {
 | 
			
		||||
     * 配置了5分钟的读取超时时间,用于与Dify API进行通信
 | 
			
		||||
     */
 | 
			
		||||
    private final OkHttpClient client = new OkHttpClient.Builder()
 | 
			
		||||
            .connectTimeout(Duration.ofSeconds(30))  // 添加连接超时时间
 | 
			
		||||
            .readTimeout(Duration.ofMinutes(5))
 | 
			
		||||
            .build();
 | 
			
		||||
 | 
			
		||||
@@ -340,6 +342,96 @@ public class DifyChatController extends BaseController {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取APP的消息点赞和反馈列表
 | 
			
		||||
     * <p>
 | 
			
		||||
     * 该接口用于获取应用的终端用户反馈、点赞列表
 | 
			
		||||
     * </p>
 | 
			
		||||
     *
 | 
			
		||||
     * @param page 页码,默认值:1
 | 
			
		||||
     * @param limit 每页数量,默认值:20
 | 
			
		||||
     * @return 包含点赞、反馈列表的统一响应结果
 | 
			
		||||
     */
 | 
			
		||||
    @GetMapping("/app/feedbacks")
 | 
			
		||||
    public AjaxResult getAppFeedbacks(
 | 
			
		||||
            @RequestParam(value = "page", defaultValue = "1") String page,
 | 
			
		||||
            @RequestParam(value = "limit", defaultValue = "20") String limit) {
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            // 构建请求URL
 | 
			
		||||
            String url = "https://api.dify.ai/v1/app/feedbacks?page=" + page + "&limit=" + limit;
 | 
			
		||||
 | 
			
		||||
            // 构建请求
 | 
			
		||||
            Request request = new Request.Builder()
 | 
			
		||||
                    .url(url)
 | 
			
		||||
                    .addHeader("Authorization", "Bearer " + DIFY_API_KEY)
 | 
			
		||||
                    .addHeader("Content-Type", "application/json")
 | 
			
		||||
                    .get()
 | 
			
		||||
                    .build();
 | 
			
		||||
 | 
			
		||||
            // 发送请求
 | 
			
		||||
            try (Response response = client.newCall(request).execute()) {
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    String responseBody = response.body().string();
 | 
			
		||||
                    JsonNode rootNode = mapper.readTree(responseBody);
 | 
			
		||||
 | 
			
		||||
                    // 解析数据
 | 
			
		||||
                    JsonNode dataNode = rootNode.get("data");
 | 
			
		||||
                    List<Map<String, Object>> feedbackList = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
                    if (dataNode != null && dataNode.isArray()) {
 | 
			
		||||
                        for (JsonNode feedbackNode : dataNode) {
 | 
			
		||||
                            Map<String, Object> feedbackItem = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
                            // 提取反馈信息
 | 
			
		||||
                            feedbackItem.put("id", feedbackNode.has("id") ? feedbackNode.get("id").asText() : null);
 | 
			
		||||
                            feedbackItem.put("message_id", feedbackNode.has("message_id") ? feedbackNode.get("message_id").asText() : null);
 | 
			
		||||
                            feedbackItem.put("rating", feedbackNode.has("rating") ? feedbackNode.get("rating").asText() : null);
 | 
			
		||||
                            feedbackItem.put("content", feedbackNode.has("content") ? feedbackNode.get("content").asText() : null);
 | 
			
		||||
                            feedbackItem.put("created_at", feedbackNode.has("created_at") ? feedbackNode.get("created_at").asLong() : null);
 | 
			
		||||
                            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);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            feedbackList.add(feedbackItem);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    // 构建返回结果
 | 
			
		||||
                    Map<String, Object> result = new HashMap<>();
 | 
			
		||||
                    result.put("data", feedbackList);
 | 
			
		||||
                    result.put("page", rootNode.has("page") ? rootNode.get("page").asInt() : Integer.parseInt(page));
 | 
			
		||||
                    result.put("limit", rootNode.has("limit") ? rootNode.get("limit").asInt() : Integer.parseInt(limit));
 | 
			
		||||
                    result.put("has_more", rootNode.has("has_more") ? rootNode.get("has_more").asBoolean() : false);
 | 
			
		||||
 | 
			
		||||
                    return AjaxResult.success(result);
 | 
			
		||||
                } else {
 | 
			
		||||
                    String errorMsg = "获取反馈列表失败: " + response.code();
 | 
			
		||||
                    try (ResponseBody errorBody = response.body()) {
 | 
			
		||||
                        if (errorBody != null) {
 | 
			
		||||
                            errorMsg += " - " + errorBody.string();
 | 
			
		||||
                        }
 | 
			
		||||
                    } catch (IOException e) {
 | 
			
		||||
                        errorMsg += " (无法读取错误详情)";
 | 
			
		||||
                    }
 | 
			
		||||
                    return AjaxResult.error(errorMsg);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return AjaxResult.error("获取反馈列表时发生异常: " + e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取会话历史消息的端点
 | 
			
		||||
     * <p>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user