// Package controller - RAGFlow控制器 // 功能:接收来自外部的RAGFlow请求(测试/调试用) package controller import ( "customer-server/consumer" "gitea.com/red-future/common/redis" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" ) type ragflow struct{} var RAGFlow = new(ragflow) // Process 处理RAGFlow请求 // 参数: r - HTTP请求对象 // 功能: 接收外部RAGFlow消息请求,直接调用consumer处理逻辑(用于测试) // 注意: 正常流程不经过此接口,而是直接消费Redis Stream func (c *ragflow) Process(r *ghttp.Request) { ctx := r.Context() // 调试:打印原始请求体 bodyBytes := r.GetBody() g.Log().Infof(ctx, "收到原始请求体: %s", string(bodyBytes)) var req redis.SendStreamMessage if err := r.Parse(&req); err != nil { r.Response.WriteJsonExit(g.Map{ "code": 400, "msg": "参数错误: " + err.Error(), }) return } g.Log().Infof(ctx, "收到RAGFlow请求 - 用户: %s, 内容: %s", req.UserId, req.Content) // 直接调用consumer的处理逻辑 message := map[string]interface{}{ "UserId": req.UserId, "Content": req.Content, "MessageId": req.MessageId, "Platform": req.Platform, "TenantId": req.TenantId, "AccountName": req.AccountName, "ChatId": req.ChatId, "ReplyQueue": req.ReplyQueue, "History": req.History, } if err := consumer.HandleMessageHTTP(ctx, message); err != nil { r.Response.WriteJsonExit(g.Map{ "code": 500, "msg": "处理失败: " + err.Error(), }) return } r.Response.WriteJsonExit(g.Map{ "code": 0, "msg": "success", }) }