From a8cfb118febc0d004624ba91a138b8c0b00b0b3f Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Fri, 21 Nov 2025 15:04:15 +0800 Subject: [PATCH] feat: dev --- config/config_test.yaml | 3 + internal/config/config.go | 2 + internal/tools/manager.go | 6 + internal/tools/zltx_order_after_supplier.go | 169 ++++++++++++++++++++ internal/tools_bot/after_sales_supplier.go | 77 --------- internal/tools_bot/dtalk_bot.go | 6 - 6 files changed, 180 insertions(+), 83 deletions(-) create mode 100644 internal/tools/zltx_order_after_supplier.go delete mode 100644 internal/tools_bot/after_sales_supplier.go diff --git a/config/config_test.yaml b/config/config_test.yaml index ff2d2d8..1e7907b 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -55,6 +55,9 @@ tools: enabled: true api_key: "dingsbbntrkeiyazcfdg" api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu" + zltxOrderAfterSaleSupplier: + enabled: true + base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier" default_prompt: img_recognize: diff --git a/internal/config/config.go b/internal/config/config.go index de68808..c1e13a7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -93,6 +93,8 @@ type ToolsConfig struct { ZltxOrderAfterSaleDetail ToolConfig `mapstructure:"zltxOrderAfterSaleDetail"` //下游订单预检 ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"` + // 上游订单售后 + ZltxOrderAfterSaleSupplier ToolConfig `mapstructure:"zltxOrderAfterSaleSupplier"` } // ToolConfig 单个工具配置 diff --git a/internal/tools/manager.go b/internal/tools/manager.go index d6dc195..148d8fd 100644 --- a/internal/tools/manager.go +++ b/internal/tools/manager.go @@ -81,6 +81,12 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager { m.tools[zltxOrderAfterSalePreCheckTool.Name()] = zltxOrderAfterSalePreCheckTool } + // 注册直连天下上游售后订单工具 + if config.Tools.ZltxOrderAfterSaleSupplier.Enabled { + zltxOrderAfterSaleSupplierTool := NewZltxOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier) + m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool + } + // 普通对话 chat := NewNormalChatTool(m.llm, config) m.tools[chat.Name()] = chat diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go new file mode 100644 index 0000000..5b311de --- /dev/null +++ b/internal/tools/zltx_order_after_supplier.go @@ -0,0 +1,169 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "context" + "encoding/json" + "fmt" +) + +type ZltxOrderAfterSaleSupplierTool struct { + config config.ToolConfig +} + +// NewZltxOrderAfterSaleSupplierTool 创建售后订单预检工具 +func NewZltxOrderAfterSaleSupplierTool(config config.ToolConfig) *ZltxOrderAfterSaleSupplierTool { + return &ZltxOrderAfterSaleSupplierTool{config: config} +} + +// Name 返回工具名称 +func (t *ZltxOrderAfterSaleSupplierTool) Name() string { + return "zltxOrderAfterSaleSupplier" +} + +func (t *ZltxOrderAfterSaleSupplierTool) Description() string { + return "直连天下售后订单供应商工具" +} + +func (t *ZltxOrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition { + return entitys.ToolDefinition{ + Type: "function", + Function: entitys.FunctionDef{ + Name: t.Name(), + Description: t.Description(), + Parameters: map[string]interface{}{ + "type": "object", + "properties": map[string]interface{}{ + "orderType": map[string]interface{}{ + "type": "integer", + "description": "售后订单类型", + }, + "orderNumber": map[string]interface{}{ + "type": "string", + "description": "售后订单号", + }, + }, + "required": []string{"orderType", "orderNumber"}, + }, + }, + } +} + +type ZltxOrderAfterSaleSupplierRequest struct { + OrderNumber string `json:"orderNumber"` // 订单号 + SerialNumber string `json:"serialNumber"` // 流水号 + Account string `json:"account"` // 充值账号 + OrderTimeStart string `json:"orderTimeStart"` // 订单执行开始时间 + OrderTimeEnd string `json:"orderTimeEnd"` // 订单执行结束时间 + AfterSalesReason string `json:"afterSalesReason"` // 售后原因 + AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 +} + +type ZltxOrderAfterSaleSupplierResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data []CheckResult2 `json:"data"` +} + +type CheckResult2 struct { + OrderType int `json:"orderType"` + OrderNumber string `json:"orderNumber"` + OrderAmount float64 `json:"orderAmount"` + OrderPrice float64 `json:"orderPrice"` + SignCompany int `json:"signCompany"` + OrderQuantity int `json:"orderQuantity"` + ResellerID int `json:"resellerId"` + ResellerName string `json:"resellerName"` + OurProductID int `json:"ourProductId"` + OurProductTitle string `json:"ourProductTitle"` + Account []string `json:"account"` + Platforms struct { + Num4 string `json:"4"` + } `json:"platforms"` +} + +func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSaleSupplierRequest + if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { + return err + } + if req.OrderNumber == "" { + return fmt.Errorf("orderType and orderNumber are required") + } + return t.checkZltxOrderAfterSaleSupplier(req.OrderNumber, requireData) +} + +func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNumber string, requireData *entitys.RequireData) error { + // req := l_request.Request{ + // Url: t.config.BaseURL, + // Headers: map[string]string{ + // "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), + // }, + // Method: "POST", + // Data: map[string]string{ + // // "orderType": fmt.Sprintf("%d", orderType), + // "orderNumber": orderNumber, + // }, + // } + // res, err := req.Send() + // if err != nil { + // return err + // } + // // 解析响应 + // var resp ZltxOrderAfterSaleSupplierResponse + // if err := json.Unmarshal(res.Content, &resp); err != nil { + // return err + // } + // if resp.Code != 0 { + // return fmt.Errorf("check failed: %s", resp.Msg) + // } + resp := ZltxOrderAfterSaleSupplierResponse{ + Code: 0, + Msg: "success", + Data: []CheckResult2{ + { + OrderType: 1, + OrderNumber: orderNumber, + OrderAmount: 100, + OrderPrice: 100, + SignCompany: 1, + OrderQuantity: 1, + ResellerID: 1, + ResellerName: "测试", + OurProductID: 1, + OurProductTitle: "测试", + Account: []string{"123456"}, + Platforms: struct { + Num4 string `json:"4"` + }{ + Num4: "123456", + }, + }, + { + OrderType: 2, + OrderNumber: orderNumber, + OrderAmount: 100, + OrderPrice: 100, + SignCompany: 1, + OrderQuantity: 1, + ResellerID: 1, + ResellerName: "测试", + OurProductID: 1, + OurProductTitle: "测试", + Account: []string{"123456"}, + Platforms: struct { + Num4 string `json:"4"` + }{ + Num4: "123456", + }, + }, + }, + } + jsonByte, err := json.Marshal(resp) + if err != nil { + return err + } + entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) + return nil +} diff --git a/internal/tools_bot/after_sales_supplier.go b/internal/tools_bot/after_sales_supplier.go deleted file mode 100644 index aca4a45..0000000 --- a/internal/tools_bot/after_sales_supplier.go +++ /dev/null @@ -1,77 +0,0 @@ -package tools_bot - -import ( - "ai_scheduler/internal/entitys" - "context" - "encoding/json" - "fmt" - "strings" - - "github.com/ollama/ollama/api" -) - -type AfterSalesSupplierArgs struct { - OrderNumber string `json:"orderNumber"` - SerialNumber string `json:"serialNumber"` - Account string `json:"account"` - OrderTimeStart int `json:"orderTimeStart"` - OrderTimeEnd int `json:"orderTimeEnd"` -} - -type AfterSalesSupplierList struct { - AfterSalesSupplierData []*AfterSalesSupplierData `json:"afterSalesSupplierData"` -} - -type AfterSalesSupplierData struct { - OrderNumber string `json:"orderNumber"` - SerialNumber string `json:"serialNumber"` - Account string `json:"account"` - OrderTimeStart int `json:"orderTimeStart"` - OrderTimeEnd int `json:"orderTimeEnd"` -} - -// AfterSalesSupplier 售后供应商 -func (w *BotTool) AfterSalesSupplier(ctx context.Context, requireData *entitys.RequireData) (err error) { - // 1. 参数提取 - extractResponse, err := w.llm.Generation(ctx, &api.GenerateRequest{ - Model: w.config.Ollama.Model, - Stream: new(bool), - System: ` - 你是一个内容提取工具,用户会提供上游供应商售后流水/订单相关问题,你需要提取用户咨询的订单/流水信息。 - - 提取的信息有 订单号、流水号、充值账号、订单时间区间 - - 仅返回json: {"orderNumber":"","serialNumber":"","account":"","orderTimeStart":unix时间戳,"orderTimeEnd":unix时间戳} - - 不要有额外的描述、markdown等 - 用户输入:%s - `, - Prompt: requireData.Req.Text, - }) - if err != nil { - return - } - afterSalesSupplierArgs := &AfterSalesSupplierArgs{} - _ = json.Unmarshal([]byte(extractResponse.Response), afterSalesSupplierArgs) - - // 流水号为空 - if afterSalesSupplierArgs.SerialNumber == "" { - // 1.1 通过充值账号查询订单号 - - // 1.2 通过订单号拉取流水号 - - } - - // 流水号不存在 - if afterSalesSupplierArgs.SerialNumber == "" { - return fmt.Errorf("serialNumber is required") - } - - // 流水号转切片 - serialNumbers := strings.Split(afterSalesSupplierArgs.SerialNumber, ",") - _ = serialNumbers - - // 2. 获取流水详情 - // ZltxOrderAfterSaleDetailTool - - // 3. 组装售后订单详情 - - return nil -} diff --git a/internal/tools_bot/dtalk_bot.go b/internal/tools_bot/dtalk_bot.go index e699a3b..0e9525a 100644 --- a/internal/tools_bot/dtalk_bot.go +++ b/internal/tools_bot/dtalk_bot.go @@ -30,12 +30,6 @@ func (w *BotTool) Execute(ctx context.Context, toolName string, requireData *ent switch toolName { case constants.BotToolsBugOptimizationSubmit: err = w.BugOptimizationSubmit(ctx, requireData) - case constants.BotToolsAfterSalesSupplier: - err = w.AfterSalesSupplier(ctx, requireData) - // case constants.BotToolsAfterSalesResellerSingle: - // err = w.AfterSalesResellerSingle(ctx, requireData) - // case constants.BotToolsAfterSalesResellerBatch: - // err = w.AfterSalesResellerBatch(ctx, requireData) default: log.Errorf("未知的工具类型:%s", toolName) err = errors.ParamErr("未知的工具类型:%s", toolName)