From 4ad3bfa614cea4d963ad92b1dec5ba1dda11c0cf Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 12 Nov 2025 17:53:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20bug/=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/services/chat.go | 11 ++++-- internal/tools_bot/dtalk_bot.go | 67 +++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/internal/services/chat.go b/internal/services/chat.go index 4708bef..06925e2 100644 --- a/internal/services/chat.go +++ b/internal/services/chat.go @@ -99,9 +99,14 @@ func (h *ChatService) Chat(c *websocket.Conn) { } //简单协议:bind: - if c.Headers("Sec-Websocket-Protocol") == "bind" && req.SessionID != "" { - uid := c.Query("x-session") - _ = h.Gw.BindUid(clientID, req.SessionID) + // if c.Headers("Sec-Websocket-Protocol") == "bind" && req.SessionID != "" { + // uid := c.Query("x-session") + // _ = h.Gw.BindUid(clientID, req.SessionID) + // log.Printf("bind %s -> uid:%s\n", clientID, uid) + // } + uid := c.Query("x-session") + if uid != "" { + _ = h.Gw.BindUid(clientID, uid) log.Printf("bind %s -> uid:%s\n", clientID, uid) } diff --git a/internal/tools_bot/dtalk_bot.go b/internal/tools_bot/dtalk_bot.go index 9f312c9..99270b0 100644 --- a/internal/tools_bot/dtalk_bot.go +++ b/internal/tools_bot/dtalk_bot.go @@ -4,21 +4,37 @@ import ( "ai_scheduler/internal/config" "ai_scheduler/internal/data/constants" errors "ai_scheduler/internal/data/error" + "ai_scheduler/internal/data/impl" "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg" + "ai_scheduler/internal/pkg/l_request" "ai_scheduler/internal/pkg/utils_ollama" "context" + "encoding/json" + "fmt" "github.com/gofiber/fiber/v2/log" + "xorm.io/builder" ) type BotTool struct { - config *config.Config - llm *utils_ollama.Client + config *config.Config + llm *utils_ollama.Client + sessionImpl *impl.SessionImpl } // NewBotTool 创建直连天下订单详情工具 -func NewBotTool(config *config.Config, llm *utils_ollama.Client) *BotTool { - return &BotTool{config: config, llm: llm} +func NewBotTool(config *config.Config, llm *utils_ollama.Client, sessionImpl *impl.SessionImpl) *BotTool { + return &BotTool{config: config, llm: llm, sessionImpl: sessionImpl} +} + +// BugOptimizationSubmitForm 工单提交表单参数 +type BugOptimizationSubmitForm struct { + Mark string `json:"mark"` // 工单标识 + Text string `json:"text"` // 工单描述 + Img string `json:"img"` // 工单截图 + Creator string `json:"creator"` // 工单创建人 + Session string `json:"session"` // 会话ID } // Execute 执行直连天下订单详情查询 @@ -34,6 +50,49 @@ func (w *BotTool) Execute(ctx context.Context, toolName string, requireData *ent } func (w *BotTool) BugOptimizationSubmit(ctx context.Context, requireData *entitys.RequireData) (err error) { + // 获取用户信息 + cond := builder.NewCond() + cond = cond.And(builder.Eq{"session_id": requireData.Session}) + sessionInfo, err := w.sessionImpl.GetOneBySearch(&cond) + if err != nil { + err = errors.SysErr("获取历史记录失败:%v", err.Error()) + return + } + userName := sessionInfo["user_name"].(string) + // 构建工单表单参数 + body := BugOptimizationSubmitForm{ + Mark: requireData.Match.Index, + Text: requireData.Req.Text, + Img: requireData.Req.Img, + Creator: userName, + Session: requireData.Session, + } + + request := l_request.Request{ + Url: "https://connector.dingtalk.com/webhook/flow/10352c521dd02104cee9000c", + Method: "POST", + Headers: map[string]string{ + "Content-Type": "application/json", + }, + JsonByte: pkg.JsonByteIgonErr(body), + } + res, err := request.Send() + if err != nil { + log.Errorf("发送请求失败: %s", err.Error()) + return + } + + data := make(map[string]bool) + if err = json.Unmarshal(res.Content, &data); err != nil { + return fmt.Errorf("解析商品数据失败:%w", err) + } + + if data["success"] { + entitys.ResLoading(requireData.Ch, requireData.Match.Index, "问题信息记录中...") + return + } + + entitys.ResJson(requireData.Ch, requireData.Match.Index, "bug问题请咨询 @温子新 ,优化建议请咨询 @贺泽琨 。") return }