From 8b4e696c772989aefb03535091f911eaf7ce1150 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Tue, 18 Nov 2025 18:24:00 +0800 Subject: [PATCH 01/19] =?UTF-8?q?feat:=201.=E5=A2=9E=E5=8A=A0=E7=9B=B4?= =?UTF-8?q?=E8=BF=9E=E5=A4=A9=E4=B8=8B=E5=94=AE=E5=90=8E=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=202.=20=E5=A2=9E=E5=8A=A0=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=203.=E5=A2=9E=E5=8A=A0=E8=BE=93=E5=85=A5=E8=BE=93=E5=87=BAmock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 5 ++ internal/config/config.go | 2 + internal/tools/manager.go | 12 ++- internal/tools/zltx_after_sale.go | 131 ++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 internal/tools/zltx_after_sale.go diff --git a/config/config.yaml b/config/config.yaml index 7824fd8..0719bdb 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -55,6 +55,11 @@ tools: enabled: true api_key: "dingsbbntrkeiyazcfdg" api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu" + zltxOrderAfterSale: + enabled: true + base_url: "https://revcl.1688sup.com/api/admin/direct/ai/%s" + add_url: "https://revcl.1688sup.com/api/admin/direct/log/%s/%s" + default_prompt: img_recognize: diff --git a/internal/config/config.go b/internal/config/config.go index d39d80a..18d33a5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -89,6 +89,8 @@ type ToolsConfig struct { //通过账号获取订单统计信息 ZltxOrderStatistics ToolConfig `mapstructure:"zltxOrderStatistics"` DingTalkBot ToolConfig `mapstructure:"dingTalkBot"` + //直连天下订单售后工具 + ZltxOrderAfterSale ToolConfig `mapstructure:"zltxOrderAfterSale"` } // ToolConfig 单个工具配置 diff --git a/internal/tools/manager.go b/internal/tools/manager.go index 4b7425f..77efc10 100644 --- a/internal/tools/manager.go +++ b/internal/tools/manager.go @@ -70,10 +70,16 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager { m.tools[knowledgeTool.Name()] = knowledgeTool } - if config.Tools.Knowledge.Enabled { - knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge) - m.tools[knowledgeTool.Name()] = knowledgeTool + // 注册直连天下订单售后工具 + if config.Tools.ZltxOrderAfterSale.Enabled { + zltxOrderAfterSaleTool := NewZltxOrderAfterSaleTool(config.Tools.ZltxOrderAfterSale) + m.tools[zltxOrderAfterSaleTool.Name()] = zltxOrderAfterSaleTool } + + // if config.Tools.Knowledge.Enabled { + // knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge) + // m.tools[knowledgeTool.Name()] = knowledgeTool + // } // 普通对话 chat := NewNormalChatTool(m.llm, config) m.tools[chat.Name()] = chat diff --git a/internal/tools/zltx_after_sale.go b/internal/tools/zltx_after_sale.go new file mode 100644 index 0000000..d5706ac --- /dev/null +++ b/internal/tools/zltx_after_sale.go @@ -0,0 +1,131 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "context" + "encoding/json" + "fmt" + "sort" + + "gitea.cdlsxd.cn/self-tools/l_request" +) + +type ZltxOrderAfterSaleTool struct { + config config.ToolConfig +} + +func (z ZltxOrderAfterSaleTool) Name() string { + return "zltxOrderAfterSale" +} + +func (z ZltxOrderAfterSaleTool) Description() string { + return "查询直连天下订单售后信息" +} + +func (z ZltxOrderAfterSaleTool) Definition() entitys.ToolDefinition { + return entitys.ToolDefinition{ + Type: "function", + Function: entitys.FunctionDef{ + Name: z.Name(), + Description: z.Description(), + Parameters: map[string]interface{}{ + "type": "object", + "properties": map[string]interface{}{ + "number": map[string]interface{}{ + "type": "string", + "description": "账号或分销商号", + }, + }, + "required": []string{"number"}, + }, + }, + } +} + +type ZltxOrderAfterSaleRequest struct { + Number string `json:"number"` +} + +func (z ZltxOrderAfterSaleTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSaleRequest + if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { + return err + } + if req.Number == "" { + return fmt.Errorf("number is required") + } + return z.getZltxOrderAfterSale(req.Number, requireData) +} + +type ZltxOrderAfterSaleResponse struct { + Code int `json:"code"` + Data struct { + List []*ZltxOrderAfterSaleData `json:"list"` + } `json:"data"` + Error string `json:"error"` +} + +type ZltxOrderAfterSaleData struct { + // 处理方式 价款/扣款 + HandleMethod string `json:"handle_method"` + // 售后金额 + AfterSaleAmount float64 `json:"after_sale_amount"` + // 售后原因 + AfterSaleReason string `json:"after_sale_reason"` + // 原单信息 + OriginalOrderInfo *OrderInfo +} + +type OrderInfo struct { + SerialNumber string `json:"serial_number"` // 订单流水号 + SupplierName string `json:"supplier_name"` // 供应商名称 + SigningBody string `json:"signing_body"` // 签约主体 + ProductName string `json:"product_name"` // 商品名称 + UpstreamPrice float64 `json:"upstream_price"` // 上游价格 + RechargeAccount string `json:"recharge_account"` // 充值账号 + RechargeStatus string `json:"recharge_status"` // 充值状态 +} + +func (z ZltxOrderAfterSaleTool) getZltxOrderAfterSale(number string, requireData *entitys.RequireData) error { + //查询订单详情 + + url := fmt.Sprintf("%s%s", z.config.BaseURL, number) + req := l_request.Request{ + Url: url, + Headers: map[string]string{ + "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), + }, + Method: "GET", + } + res, err := req.Send() + var resData ZltxOrderAfterSaleResponse + if err != nil { + return err + } + if err := json.Unmarshal(res.Content, &resData); err != nil { + return err + } + if resData.Code != 200 { + return fmt.Errorf("为获取到数据,请检查权限: %s", string(res.Content)) + } + //按照日期排序 + sort.Slice(resData.Data.RecentThreeDays, func(i, j int) bool { + return resData.Data.RecentThreeDays[i].Date < resData.Data.RecentThreeDays[j].Date + }) + sort.Slice(resData.Data.RecentOneMonth, func(i, j int) bool { + return resData.Data.RecentOneMonth[i].Date < resData.Data.RecentOneMonth[j].Date + }) + jsonByte, err := json.Marshal(resData) + if err != nil { + return err + } + entitys.ResJson(requireData.Ch, z.Name(), string(jsonByte)) + return nil +} + +func NewZltxOrderAfterSaleTool(config config.ToolConfig) *ZltxOrderAfterSaleTool { + return &ZltxOrderAfterSaleTool{ + config: config, + } +} From 687678e7d515c0d802db9258b6854ca08a8d5cb6 Mon Sep 17 00:00:00 2001 From: wuchao <1272174216@qq.com> Date: Wed, 19 Nov 2025 15:44:53 +0800 Subject: [PATCH 02/19] =?UTF-8?q?feat(config):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=94=AE=E5=90=8E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 9 ++ internal/config/config.go | 4 + internal/tools/manager.go | 11 +++ internal/tools/zltx_after_direct.go | 119 ++++++++++++++++++++++++++ internal/tools/zltx_after_pre.go | 125 ++++++++++++++++++++++++++++ 5 files changed, 268 insertions(+) create mode 100644 internal/tools/zltx_after_direct.go create mode 100644 internal/tools/zltx_after_pre.go diff --git a/config/config.yaml b/config/config.yaml index 7824fd8..51d1009 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -55,6 +55,15 @@ tools: enabled: true api_key: "dingsbbntrkeiyazcfdg" api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu" + zltxOrderAfterSaleDetail: + enabled: true + base_url: "https://revcl.1688sup.com/api/admin/afterSales/direct/%s" + api_key : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ" + zltxOrderAfterSalePreCheck: + enabled: true + base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre" + api_key : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ" + default_prompt: img_recognize: diff --git a/internal/config/config.go b/internal/config/config.go index d39d80a..de68808 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -89,6 +89,10 @@ type ToolsConfig struct { //通过账号获取订单统计信息 ZltxOrderStatistics ToolConfig `mapstructure:"zltxOrderStatistics"` DingTalkBot ToolConfig `mapstructure:"dingTalkBot"` + //上游售后订单流水详情 + ZltxOrderAfterSaleDetail ToolConfig `mapstructure:"zltxOrderAfterSaleDetail"` + //下游订单预检 + ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"` } // ToolConfig 单个工具配置 diff --git a/internal/tools/manager.go b/internal/tools/manager.go index 4b7425f..3530add 100644 --- a/internal/tools/manager.go +++ b/internal/tools/manager.go @@ -74,6 +74,17 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager { knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge) m.tools[knowledgeTool.Name()] = knowledgeTool } + //注册直连天下售后订单详情工具 + if config.Tools.ZltxOrderAfterSaleDetail.Enabled { + zltxOrderAfterSaleDetailTool := NewZltxOrderAfterSaleDetailTool(config.Tools.ZltxOrderAfterSaleDetail) + m.tools[zltxOrderAfterSaleDetailTool.Name()] = zltxOrderAfterSaleDetailTool + } + //注册直连天下售后订单预检工具 + if config.Tools.ZltxOrderAfterSalePreCheck.Enabled { + zltxOrderAfterSalePreCheckTool := NewZltxOrderAfterSalePreCheckTool(config.Tools.ZltxOrderAfterSalePreCheck) + m.tools[zltxOrderAfterSalePreCheckTool.Name()] = zltxOrderAfterSalePreCheckTool + } + // 普通对话 chat := NewNormalChatTool(m.llm, config) m.tools[chat.Name()] = chat diff --git a/internal/tools/zltx_after_direct.go b/internal/tools/zltx_after_direct.go new file mode 100644 index 0000000..5f1e20e --- /dev/null +++ b/internal/tools/zltx_after_direct.go @@ -0,0 +1,119 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg/l_request" + "context" + "encoding/json" + "fmt" +) + +type ZltxOrderAfterSaleDetailTool struct { + config config.ToolConfig +} + +// NewZltxOrderAfterSaleDetailTool 创建售后订单详情工具 +func NewZltxOrderAfterSaleDetailTool(config config.ToolConfig) *ZltxOrderAfterSaleDetailTool { + return &ZltxOrderAfterSaleDetailTool{config: config} +} + +// Definition 返回工具定义 +func (this *ZltxOrderAfterSaleDetailTool) Definition() entitys.ToolDefinition { + return entitys.ToolDefinition{ + Type: "function", + Function: entitys.FunctionDef{ + Name: this.Name(), + Description: this.Description(), + Parameters: map[string]interface{}{ + "type": "object", + "properties": map[string]interface{}{ + "direct_order_number": map[string]interface{}{ + "type": "string", + "description": "售后订单号", + }, + }, + "required": []string{"direct_order_number"}, + }, + }, + } +} + +type ZltxOrderAfterSaleDetailRequest struct { + DirectOrderNumber string `json:"direct_order_number"` +} + +type ZltxOrderAfterSaleDetailResponse struct { + Code int `json:"code"` + Data struct { + AfterSaleOrder ZltxOrderAfterSaleDetailData `json:"afterSaleOrder"` + } `json:"data"` + Error string `json:"error"` +} + +type ZltxOrderAfterSaleDetailData struct { + SerialNumber string `json:"serialNumber"` + PlatformName string `json:"platformName"` + SignCompany int `json:"signCompany"` + PlatformProductName string `json:"platformProductName"` + PlatformPrice float64 `json:"platformPrice"` + TerminalAccount string `json:"terminalAccount"` + Status int `json:"status"` + PlatformProductID int `json:"platformProductId"` + PlatformID int `json:"platformId"` + SignCompanyName string `json:"signCompanyName"` + ExecuteTime int `json:"executeTime"` +} + +func (this *ZltxOrderAfterSaleDetailTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSaleDetailRequest + if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { + return err + } + if req.DirectOrderNumber == "" { + return fmt.Errorf("direct_order_number is required") + } + return this.getZltxOrderAfterSaleDetail(ctx, requireData, req.DirectOrderNumber) +} + +func (this *ZltxOrderAfterSaleDetailTool) getZltxOrderAfterSaleDetail(ctx context.Context, requireData *entitys.RequireData, directOrderNumber string) error { + //查询订单详情 + url := fmt.Sprintf("%s%s", this.config.BaseURL, directOrderNumber) + req := l_request.Request{ + Url: url, + Headers: map[string]string{ + "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), + }, + Method: "GET", + } + res, err := req.Send() + var resData ZltxOrderAfterSaleDetailResponse + if err != nil { + return err + } + if err := json.Unmarshal(res.Content, &resData); err != nil { + return err + } + if resData.Code != 200 { + return fmt.Errorf("为获取到数据,请检查权限: %s", string(res.Content)) + } + jsonByte, err := json.Marshal(resData) + if err != nil { + return err + } + entitys.ResJson(requireData.Ch, this.Name(), string(jsonByte)) + return nil +} + +func (this *ZltxOrderAfterSaleDetailTool) GetConfig() config.ToolConfig { + return this.config +} + +// Name 工具名称 +func (this *ZltxOrderAfterSaleDetailTool) Name() string { + return "zltx_order_after_sale_detail" +} + +func (this *ZltxOrderAfterSaleDetailTool) Description() string { + return "查询直连天下上游售后订单详情" +} diff --git a/internal/tools/zltx_after_pre.go b/internal/tools/zltx_after_pre.go new file mode 100644 index 0000000..b44812b --- /dev/null +++ b/internal/tools/zltx_after_pre.go @@ -0,0 +1,125 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg/l_request" + "context" + "encoding/json" + "fmt" +) + +type ZltxOrderAfterSalePreCheckTool struct { + config config.ToolConfig +} + +// NewZltxOrderAfterSalePreCheckTool 创建售后订单预检工具 +func NewZltxOrderAfterSalePreCheckTool(config config.ToolConfig) *ZltxOrderAfterSalePreCheckTool { + return &ZltxOrderAfterSalePreCheckTool{config: config} +} + +// Name 返回工具名称 +func (t *ZltxOrderAfterSalePreCheckTool) Name() string { + return "zltxOrderAfterSalePreCheck" +} + +func (t *ZltxOrderAfterSalePreCheckTool) Description() string { + return "直连天下售后订单预检工具" +} + +func (t *ZltxOrderAfterSalePreCheckTool) 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 ZltxOrderAfterSalePreCheckRequest struct { + OrderType int `json:"orderType"` + OrderNumber string `json:"orderNumber"` +} + +type ZltxOrderAfterSalePreCheckResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data struct { + CheckResult bool `json:"checkResult"` + } `json:"data"` +} + +type CheckResult 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 *ZltxOrderAfterSalePreCheckTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSalePreCheckRequest + if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { + return err + } + if req.OrderType == 0 || req.OrderNumber == "" { + return fmt.Errorf("orderType and orderNumber are required") + } + return t.checkZltxOrderAfterSalePreCheck(req.OrderType, req.OrderNumber, requireData) +} + +func (t *ZltxOrderAfterSalePreCheckTool) checkZltxOrderAfterSalePreCheck(orderType int, 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 ZltxOrderAfterSalePreCheckResponse + if err := json.Unmarshal(res.Content, &resp); err != nil { + return err + } + if resp.Code != 0 { + return fmt.Errorf("check failed: %s", resp.Msg) + } + jsonByte, err := json.Marshal(resp) + if err != nil { + return err + } + entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) + return nil +} From 4a0cdacbe9c8402df784f0b6fddf324dcb4b7242 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Thu, 20 Nov 2025 19:25:52 +0800 Subject: [PATCH 03/19] =?UTF-8?q?feat:=20=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/constants/bot.go | 5 +- internal/tools/zltx_after_sale.go | 131 --------------------- internal/tools_bot/after_sales_supplier.go | 77 ++++++++++++ internal/tools_bot/dtalk_bot.go | 7 ++ 4 files changed, 88 insertions(+), 132 deletions(-) delete mode 100644 internal/tools/zltx_after_sale.go create mode 100644 internal/tools_bot/after_sales_supplier.go diff --git a/internal/data/constants/bot.go b/internal/data/constants/bot.go index 6dc6680..0863cb8 100644 --- a/internal/data/constants/bot.go +++ b/internal/data/constants/bot.go @@ -3,5 +3,8 @@ package constants type BotTools string const ( - BotToolsBugOptimizationSubmit = "bug_optimization_submit" // 系统的bug/优化建议 + BotToolsBugOptimizationSubmit = "bug_optimization_submit" // 系统的bug/优化建议 + BotToolsAfterSalesSupplier = "after_sales_supplier" // 供应商售后 + BotToolsAfterSalesResellerSingle = "after_sales_reseller_single" // 分销商单条售后 + BotToolsAfterSalesResellerBatch = "after_sales_reseller_batch" // 分销商批量售后 ) diff --git a/internal/tools/zltx_after_sale.go b/internal/tools/zltx_after_sale.go deleted file mode 100644 index d5706ac..0000000 --- a/internal/tools/zltx_after_sale.go +++ /dev/null @@ -1,131 +0,0 @@ -package tools - -import ( - "ai_scheduler/internal/config" - "ai_scheduler/internal/entitys" - "context" - "encoding/json" - "fmt" - "sort" - - "gitea.cdlsxd.cn/self-tools/l_request" -) - -type ZltxOrderAfterSaleTool struct { - config config.ToolConfig -} - -func (z ZltxOrderAfterSaleTool) Name() string { - return "zltxOrderAfterSale" -} - -func (z ZltxOrderAfterSaleTool) Description() string { - return "查询直连天下订单售后信息" -} - -func (z ZltxOrderAfterSaleTool) Definition() entitys.ToolDefinition { - return entitys.ToolDefinition{ - Type: "function", - Function: entitys.FunctionDef{ - Name: z.Name(), - Description: z.Description(), - Parameters: map[string]interface{}{ - "type": "object", - "properties": map[string]interface{}{ - "number": map[string]interface{}{ - "type": "string", - "description": "账号或分销商号", - }, - }, - "required": []string{"number"}, - }, - }, - } -} - -type ZltxOrderAfterSaleRequest struct { - Number string `json:"number"` -} - -func (z ZltxOrderAfterSaleTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { - var req ZltxOrderAfterSaleRequest - if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { - return err - } - if req.Number == "" { - return fmt.Errorf("number is required") - } - return z.getZltxOrderAfterSale(req.Number, requireData) -} - -type ZltxOrderAfterSaleResponse struct { - Code int `json:"code"` - Data struct { - List []*ZltxOrderAfterSaleData `json:"list"` - } `json:"data"` - Error string `json:"error"` -} - -type ZltxOrderAfterSaleData struct { - // 处理方式 价款/扣款 - HandleMethod string `json:"handle_method"` - // 售后金额 - AfterSaleAmount float64 `json:"after_sale_amount"` - // 售后原因 - AfterSaleReason string `json:"after_sale_reason"` - // 原单信息 - OriginalOrderInfo *OrderInfo -} - -type OrderInfo struct { - SerialNumber string `json:"serial_number"` // 订单流水号 - SupplierName string `json:"supplier_name"` // 供应商名称 - SigningBody string `json:"signing_body"` // 签约主体 - ProductName string `json:"product_name"` // 商品名称 - UpstreamPrice float64 `json:"upstream_price"` // 上游价格 - RechargeAccount string `json:"recharge_account"` // 充值账号 - RechargeStatus string `json:"recharge_status"` // 充值状态 -} - -func (z ZltxOrderAfterSaleTool) getZltxOrderAfterSale(number string, requireData *entitys.RequireData) error { - //查询订单详情 - - url := fmt.Sprintf("%s%s", z.config.BaseURL, number) - req := l_request.Request{ - Url: url, - Headers: map[string]string{ - "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth), - }, - Method: "GET", - } - res, err := req.Send() - var resData ZltxOrderAfterSaleResponse - if err != nil { - return err - } - if err := json.Unmarshal(res.Content, &resData); err != nil { - return err - } - if resData.Code != 200 { - return fmt.Errorf("为获取到数据,请检查权限: %s", string(res.Content)) - } - //按照日期排序 - sort.Slice(resData.Data.RecentThreeDays, func(i, j int) bool { - return resData.Data.RecentThreeDays[i].Date < resData.Data.RecentThreeDays[j].Date - }) - sort.Slice(resData.Data.RecentOneMonth, func(i, j int) bool { - return resData.Data.RecentOneMonth[i].Date < resData.Data.RecentOneMonth[j].Date - }) - jsonByte, err := json.Marshal(resData) - if err != nil { - return err - } - entitys.ResJson(requireData.Ch, z.Name(), string(jsonByte)) - return nil -} - -func NewZltxOrderAfterSaleTool(config config.ToolConfig) *ZltxOrderAfterSaleTool { - return &ZltxOrderAfterSaleTool{ - config: config, - } -} diff --git a/internal/tools_bot/after_sales_supplier.go b/internal/tools_bot/after_sales_supplier.go new file mode 100644 index 0000000..aca4a45 --- /dev/null +++ b/internal/tools_bot/after_sales_supplier.go @@ -0,0 +1,77 @@ +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 18ac27f..e699a3b 100644 --- a/internal/tools_bot/dtalk_bot.go +++ b/internal/tools_bot/dtalk_bot.go @@ -17,6 +17,7 @@ type BotTool struct { llm *utils_ollama.Client sessionImpl *impl.SessionImpl taskMap map[string]string // task_id -> session_id + // zltxOrderAfterSaleTool tools.ZltxOrderAfterSaleTool } // NewBotTool 创建直连天下订单详情工具 @@ -29,6 +30,12 @@ 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) From 3de460658d28d42a76ed61b68d7a1660a773388b Mon Sep 17 00:00:00 2001 From: wolter <11@gmail> Date: Fri, 21 Nov 2025 09:31:55 +0800 Subject: [PATCH 04/19] =?UTF-8?q?feat:=E6=8E=A5=E5=85=A5=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config_test.yaml | 10 ++++++- internal/biz/do/handle.go | 61 +++++++++++++++++++++++++++++++++++++++ internal/config/config.go | 26 ++++++++++++----- 3 files changed, 88 insertions(+), 9 deletions(-) diff --git a/config/config_test.yaml b/config/config_test.yaml index ff2d2d8..973afa0 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -64,4 +64,12 @@ default_prompt: 提取出图片中对用户可能有用的关键信息(例如金额、日期、标题、编号、联系信息、商品名称等)。 若图片为文档类(如合同、发票、收据),请结构化输出关键字段(如客户名称、金额、开票日期等)。 ' - user_prompt: '识别图片内容' \ No newline at end of file + user_prompt: '识别图片内容' +# 权限配置 +permissionConfig: + # 统一登录平台基础URL + unified_login_platform_base_url: "https://api.test.user.1688sup.com" + # 白名单接口 + white_list: + - "chat" # 聊天接口 + - "bug_optimization_submit" # 优化建议提交接口 diff --git a/internal/biz/do/handle.go b/internal/biz/do/handle.go index 4c2803d..bfbd76f 100644 --- a/internal/biz/do/handle.go +++ b/internal/biz/do/handle.go @@ -16,6 +16,9 @@ import ( "context" "encoding/json" "fmt" + "github.com/gofiber/fiber/v2/log" + "gorm.io/gorm/utils" + "net/http" "strings" ) @@ -90,6 +93,14 @@ func (r *Handle) HandleMatch(ctx context.Context, requireData *entitys.RequireDa if pointTask == nil || pointTask.Index == "other" { return r.OtherTask(ctx, requireData) } + + // 校验用户权限 + if err = r.PermissionAuth(requireData, pointTask); err != nil { + log.Errorf("权限验证失败: %s", err.Error()) + entitys.ResLog(requireData.Ch, "", "权限验证失败:"+err.Error()) + return + } + switch constants.TaskType(pointTask.Type) { case constants.TaskTypeApi: return r.handleApiTask(ctx, requireData, pointTask) @@ -252,3 +263,53 @@ func (r *Handle) handleApiTask(ctx context.Context, requireData *entitys.Require return } + +// 权限验证 +func (r *Handle) PermissionAuth(requireData *entitys.RequireData, pointTask *model.AiTask) (err error) { + // 白名单接口不要校验权限 + if utils.Contains(r.conf.PermissionConfig.WhiteList, pointTask.Index) { + return nil + } + + // 查询用户权限 + var ( + request l_request.Request + ) + + request.Url = r.conf.PermissionConfig.UnifiedLoginPlatformBaseURL + + request.Method = "GET" + request.Headers = map[string]string{ + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", + "Accept": "application/json, text/plain, */*", + "Authorization": "Bearer " + requireData.Auth, + } + + // 发送请求 + res, err := request.Send() + if err != nil { + return err + } + + // 检查响应状态码 + if res.StatusCode != http.StatusOK { + return fmt.Errorf("unexpected status code: %d", res.StatusCode) + } + + type resp struct { + Codes []string `json:"codes"` + } + // 解析响应体 + var respBody resp + err = json.Unmarshal([]byte(res.Text), &respBody) + if err != nil { + return err + } + + // 检查权限 + if !utils.Contains(respBody.Codes, pointTask.Index) { + return fmt.Errorf("用户权限不足: %s", pointTask.Name) + } + + return nil +} diff --git a/internal/config/config.go b/internal/config/config.go index d39d80a..b2350f7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -9,14 +9,15 @@ import ( // Config 应用配置 type Config struct { - Server ServerConfig `mapstructure:"server"` - Ollama OllamaConfig `mapstructure:"ollama"` - Sys SysConfig `mapstructure:"sys"` - Tools ToolsConfig `mapstructure:"tools"` - Logging LoggingConfig `mapstructure:"logging"` - Redis Redis `mapstructure:"redis"` - DB DB `mapstructure:"db"` - DefaultPrompt SysPrompt `mapstructure:"default_prompt"` + Server ServerConfig `mapstructure:"server"` + Ollama OllamaConfig `mapstructure:"ollama"` + Sys SysConfig `mapstructure:"sys"` + Tools ToolsConfig `mapstructure:"tools"` + Logging LoggingConfig `mapstructure:"logging"` + Redis Redis `mapstructure:"redis"` + DB DB `mapstructure:"db"` + DefaultPrompt SysPrompt `mapstructure:"default_prompt"` + PermissionConfig PermissionConfig `mapstructure:"permissionConfig"` // LLM *LLM `mapstructure:"llm"` } @@ -107,6 +108,15 @@ type LoggingConfig struct { Format string `mapstructure:"format"` } +// PermissionConfig 权限校验配置 +type PermissionConfig struct { + UnifiedLoginPlatformBaseURL string `mapstructure:"unified_login_platform_base_url"` // 统一登录平台基础URL + // 白名单任务 + WhiteList []string `mapstructure:"white_list"` // 白名单任务列表 +} + +// 权限校验配置 + // LoadConfig 加载配置 func LoadConfig(configPath string) (*Config, error) { viper.SetConfigFile(configPath) From 10db75a7aa57c1e2368003b2cbd4a034bbb8a62b Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Fri, 21 Nov 2025 11:57:18 +0800 Subject: [PATCH 05/19] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=8F=90=E7=A4=BA=E8=AF=8D=E5=A2=9E=E5=8A=A0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/llm_service/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/biz/llm_service/common.go b/internal/biz/llm_service/common.go index f10406b..1d62ed7 100644 --- a/internal/biz/llm_service/common.go +++ b/internal/biz/llm_service/common.go @@ -15,7 +15,7 @@ type LlmService interface { // buildSystemPrompt 构建系统提示词 func buildSystemPrompt(prompt string) string { if len(prompt) == 0 { - prompt = "[system] 你是一个智能路由系统,核心职责是 **精准解析用户意图并路由至对应任务模块**\n[rule]\n1.返回以下格式的JSON:{ \"index\": \"工具索引index\", \"confidence\": 0.0-1.0,\"reasoning\": \"判断理由\"}\n2.严格返回字符串格式,禁用markdown格式返回\n3.只返回json字符串,不包含任何其他解释性文字\n4.当用户意图非常不清晰时使用,尝试进行追问具体希望查询内容" + prompt = "[system] 你是一个智能路由系统,核心职责是 **精准解析用户意图并路由至对应任务模块**\n[rule]\n1.返回以下格式的JSON:{ \"index\": \"工具索引index\", \"confidence\": 0.0-1.0,\"reasoning\": \"判断理由\"}\n2.严格返回字符串格式,禁用markdown格式返回\n3.只返回json字符串,不包含任何其他解释性文字\n4.当用户意图非常不清晰时使用,尝试进行追问具体希望查询内容,\n当前时间是:" + time.Now().Format(time.DateTime) } return prompt 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 06/19] 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) From c71c72038e65eea1b3386d46d1f70528a64ee477 Mon Sep 17 00:00:00 2001 From: wolter <11@gmail> Date: Fri, 21 Nov 2025 15:17:47 +0800 Subject: [PATCH 07/19] =?UTF-8?q?feat:=E8=B0=83=E6=95=B4chat=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81=EF=BC=8C=E7=94=A8=E6=88=B7=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config_test.yaml | 11 +- internal/biz/do/ctx.go | 167 +++++++++++++++++++----------- internal/biz/do/handle.go | 53 +++------- internal/biz/router.go | 38 +++++-- internal/config/config.go | 15 ++- internal/data/error/error_code.go | 1 + internal/entitys/response.go | 1 - internal/gateway/client.go | 138 ++++++++++++++++++++++++ internal/gateway/gateway.go | 7 +- internal/services/chat.go | 158 ++++++++++++++++++++-------- 10 files changed, 419 insertions(+), 170 deletions(-) create mode 100644 internal/gateway/client.go diff --git a/config/config_test.yaml b/config/config_test.yaml index 973afa0..f45fff4 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -67,9 +67,14 @@ default_prompt: user_prompt: '识别图片内容' # 权限配置 permissionConfig: - # 统一登录平台基础URL - unified_login_platform_base_url: "https://api.test.user.1688sup.com" - # 白名单接口 + # 不同系统的权限校验配置 + sys_permission: + # 直连天下系统 + zltx: + permission_url: "https://gateway.dev.cdlsxd.cn/zltx_api/test/v1/menu/myCodes?systemCode=zltx" + white_list: + - "knowledge_qa" # 知识问答 + # 通用的白名单接口 white_list: - "chat" # 聊天接口 - "bug_optimization_submit" # 优化建议提交接口 diff --git a/internal/biz/do/ctx.go b/internal/biz/do/ctx.go index a160c8c..b0e7299 100644 --- a/internal/biz/do/ctx.go +++ b/internal/biz/do/ctx.go @@ -6,6 +6,7 @@ import ( "ai_scheduler/internal/data/impl" "ai_scheduler/internal/data/model" "ai_scheduler/internal/entitys" + "ai_scheduler/internal/gateway" "ai_scheduler/internal/pkg" "ai_scheduler/tmpl/dataTemp" "context" @@ -22,7 +23,7 @@ import ( ) type Do struct { - Ctx *entitys.RequireData + //Ctx *entitys.RequireData sessionImpl *impl.SessionImpl sysImpl *impl.SysImpl taskImpl *impl.TaskImpl @@ -44,78 +45,120 @@ func NewDo( } } -func (d *Do) InitCtx(req *entitys.ChatSockRequest) *Do { - d.Ctx = &entitys.RequireData{ - Req: req, +func (d *Do) DataAuth(ctx context.Context, client *gateway.Client, requireData *entitys.RequireData) (err error) { + // 1. 验证客户端数据 + if err = d.validateClientData(client, requireData); err != nil { + return err } - return d + + // 2. 加载系统信息 + if err = d.loadSystemInfo(ctx, client, requireData); err != nil { + return fmt.Errorf("获取系统信息失败: %w", err) + } + + // 3. 加载任务列表 + if err = d.loadTaskList(ctx, client, requireData); err != nil { + return fmt.Errorf("获取任务列表失败: %w", err) + } + + // 4. 加载聊天历史 + if err = d.loadChatHistory(ctx, requireData); err != nil { + return fmt.Errorf("获取历史记录失败: %w", err) + } + + // 5. 加载图片数据 + if err = d.getImgData(requireData); err != nil { + return err + } + + return nil } -func (d *Do) DataAuth(c *websocket.Conn) (err error) { - d.Ctx.Session = c.Query("x-session", "") - if len(d.Ctx.Session) == 0 { - err = errors.SessionNotFound - return - } - d.Ctx.Auth = c.Query("x-authorization", "") - if len(d.Ctx.Auth) == 0 { - err = errors.AuthNotFound - return - } - d.Ctx.Key = c.Query("x-app-key", "") - if len(d.Ctx.Key) == 0 { - err = errors.KeyNotFound - return +// 提取数据验证为单独函数 +func (d *Do) validateClientData(client *gateway.Client, requireData *entitys.RequireData) error { + requireData.Session = client.GetSession() + if len(requireData.Session) == 0 { + return errors.SessionNotFound } - d.Ctx.Sys, err = d.getSysInfo() - if err != nil { - err = errors.SysErr("获取系统信息失败:%v", err.Error()) - return - } - d.Ctx.Histories, err = d.getSessionChatHis() - if err != nil { - err = errors.SysErr("获取历史记录失败:%v", err.Error()) - return + requireData.Auth = client.GetAuth() + if len(requireData.Auth) == 0 { + return errors.AuthNotFound } - d.Ctx.Tasks, err = d.getTasks(d.Ctx.Sys.SysID) - if err != nil { - err = errors.SysErr("获取任务列表失败:%v", err.Error()) - return - } - if err = d.getImgData(); err != nil { - return + requireData.Key = client.GetKey() + if len(requireData.Key) == 0 { + return errors.KeyNotFound } - return + return nil } -func (d *Do) MakeCh(c *websocket.Conn) (ctx context.Context, deferFunc func()) { - d.Ctx.Ch = make(chan entitys.Response) +// 获取系统信息的辅助函数 +func (d *Do) loadSystemInfo(ctx context.Context, client *gateway.Client, requireData *entitys.RequireData) error { + if sysInfo := client.GetSysInfo(); sysInfo == nil { + sys, err := d.getSysInfo(requireData) + if err != nil { + return err + } + client.SetSysInfo(&sys) + requireData.Sys = sys + } else { + requireData.Sys = *sysInfo + } + return nil +} + +// 获取任务列表的辅助函数 +func (d *Do) loadTaskList(ctx context.Context, client *gateway.Client, requireData *entitys.RequireData) error { + if taskInfo := client.GetTasks(); len(taskInfo) == 0 { + tasks, err := d.getTasks(requireData.Sys.SysID) + if err != nil { + return err + } + requireData.Tasks = tasks + client.SetTasks(tasks) + } else { + requireData.Tasks = taskInfo + } + return nil +} + +// 获取历史记录的辅助函数 +func (d *Do) loadChatHistory(ctx context.Context, requireData *entitys.RequireData) error { + histories, err := d.getSessionChatHis(requireData) + if err != nil { + return err + } + requireData.Histories = histories + return nil +} + +func (d *Do) MakeCh(c *websocket.Conn, requireData *entitys.RequireData) (ctx context.Context, deferFunc func()) { + requireData.Ch = make(chan entitys.Response) ctx, cancel := context.WithCancel(context.Background()) - done := d.startMessageHandler(ctx, c) + done := d.startMessageHandler(ctx, c, requireData) return ctx, func() { - close(d.Ctx.Ch) //关闭主通道 - <-done // 等待消息处理完成 + close(requireData.Ch) //关闭主通道 + <-done // 等待消息处理完成 cancel() } } -func (d *Do) getImgData() (err error) { - if len(d.Ctx.Req.Img) == 0 { +func (d *Do) getImgData(requireData *entitys.RequireData) (err error) { + if len(requireData.Req.Img) == 0 { return } - imgs := strings.Split(d.Ctx.Req.Img, ",") + imgs := strings.Split(requireData.Req.Img, ",") if len(imgs) == 0 { return } for k, img := range imgs { baseErr := "获取第" + strconv.Itoa(k+1) + "张图片失败:" - entitys.ResLog(d.Ctx.Ch, "img_get_start", "正在获取第"+strconv.Itoa(k+1)+"张图片") + entitys.ResLog(requireData.Ch, "img_get_start", "正在获取第"+strconv.Itoa(k+1)+"张图片") if err = pkg.ValidateImageURL(img); err != nil { - entitys.ResLog(d.Ctx.Ch, "", baseErr+":expected image content") + entitys.ResLog(requireData.Ch, "", baseErr+":expected image content") continue } req := l_request.Request{ @@ -128,20 +171,20 @@ func (d *Do) getImgData() (err error) { } res, _err := req.Send() if _err != nil { - entitys.ResLog(d.Ctx.Ch, "", baseErr+_err.Error()) + entitys.ResLog(requireData.Ch, "", baseErr+_err.Error()) continue } if _, ex := res.Headers["Content-Type"]; !ex { - entitys.ResLog(d.Ctx.Ch, "", baseErr+":Content-Type不存在") + entitys.ResLog(requireData.Ch, "", baseErr+":Content-Type不存在") continue } if !strings.HasPrefix(res.Headers["Content-Type"], "image/") { - entitys.ResLog(d.Ctx.Ch, "", baseErr+":expected image content") + entitys.ResLog(requireData.Ch, "", baseErr+":expected image content") continue } - d.Ctx.ImgByte = append(d.Ctx.ImgByte, res.Content) - d.Ctx.ImgUrls = append(d.Ctx.ImgUrls, img) - entitys.ResLog(d.Ctx.Ch, "img_get_end", "第"+strconv.Itoa(k+1)+"张图片获取成功") + requireData.ImgByte = append(requireData.ImgByte, res.Content) + requireData.ImgUrls = append(requireData.ImgUrls, img) + entitys.ResLog(requireData.Ch, "img_get_end", "第"+strconv.Itoa(k+1)+"张图片获取成功") } return @@ -152,19 +195,19 @@ func (d *Do) getRequireData() (err error) { return } -func (d *Do) getSysInfo() (sysInfo model.AiSy, err error) { +func (d *Do) getSysInfo(requireData *entitys.RequireData) (sysInfo model.AiSy, err error) { cond := builder.NewCond() - cond = cond.And(builder.Eq{"app_key": d.Ctx.Key}) + cond = cond.And(builder.Eq{"app_key": requireData.Key}) cond = cond.And(builder.IsNull{"delete_at"}) cond = cond.And(builder.Eq{"status": 1}) err = d.sysImpl.GetOneBySearchToStrut(&cond, &sysInfo) return } -func (d *Do) getSessionChatHis() (his []model.AiChatHi, err error) { +func (d *Do) getSessionChatHis(requireData *entitys.RequireData) (his []model.AiChatHi, err error) { cond := builder.NewCond() - cond = cond.And(builder.Eq{"session_id": d.Ctx.Session}) + cond = cond.And(builder.Eq{"session_id": requireData.Session}) _, err = d.hisImpl.GetListToStruct(&cond, &dataTemp.ReqPageBo{Limit: d.conf.Sys.SessionLen}, &his, "his_id desc") @@ -186,7 +229,7 @@ func (d *Do) getTasks(sysId int32) (tasks []model.AiTask, err error) { func (d *Do) startMessageHandler( ctx context.Context, c *websocket.Conn, - + requireData *entitys.RequireData, ) <-chan struct{} { done := make(chan struct{}) var chat []string @@ -200,10 +243,10 @@ func (d *Do) startMessageHandler( ) if len(chat) > 0 { AiRes := &model.AiChatHi{ - SessionID: d.Ctx.Session, - Ques: d.Ctx.Req.Text, + SessionID: requireData.Session, + Ques: requireData.Req.Text, Ans: strings.Join(chat, ""), - Files: d.Ctx.Req.Img, + Files: requireData.Req.Img, } d.hisImpl.AddWithData(AiRes) hisLog.HisId = AiRes.HisID @@ -216,7 +259,7 @@ func (d *Do) startMessageHandler( }() - for v := range d.Ctx.Ch { // 自动检测通道关闭 + for v := range requireData.Ch { // 自动检测通道关闭 if err := sendWithTimeout(c, v, 2*time.Second); err != nil { log.Errorf("Send error: %v", err) return diff --git a/internal/biz/do/handle.go b/internal/biz/do/handle.go index bfbd76f..828e443 100644 --- a/internal/biz/do/handle.go +++ b/internal/biz/do/handle.go @@ -8,6 +8,7 @@ import ( "ai_scheduler/internal/data/impl" "ai_scheduler/internal/data/model" "ai_scheduler/internal/entitys" + "ai_scheduler/internal/gateway" "ai_scheduler/internal/pkg" "ai_scheduler/internal/pkg/l_request" "ai_scheduler/internal/pkg/mapstructure" @@ -18,7 +19,6 @@ import ( "fmt" "github.com/gofiber/fiber/v2/log" "gorm.io/gorm/utils" - "net/http" "strings" ) @@ -71,7 +71,7 @@ func (r *Handle) handleOtherTask(ctx context.Context, requireData *entitys.Requi return } -func (r *Handle) HandleMatch(ctx context.Context, requireData *entitys.RequireData) (err error) { +func (r *Handle) HandleMatch(ctx context.Context, client *gateway.Client, requireData *entitys.RequireData) (err error) { if !requireData.Match.IsMatch { if len(requireData.Match.Chat) != 0 { @@ -95,9 +95,8 @@ func (r *Handle) HandleMatch(ctx context.Context, requireData *entitys.RequireDa } // 校验用户权限 - if err = r.PermissionAuth(requireData, pointTask); err != nil { + if err = r.PermissionAuth(client, pointTask); err != nil { log.Errorf("权限验证失败: %s", err.Error()) - entitys.ResLog(requireData.Ch, "", "权限验证失败:"+err.Error()) return } @@ -265,49 +264,21 @@ func (r *Handle) handleApiTask(ctx context.Context, requireData *entitys.Require } // 权限验证 -func (r *Handle) PermissionAuth(requireData *entitys.RequireData, pointTask *model.AiTask) (err error) { - // 白名单接口不要校验权限 +func (r *Handle) PermissionAuth(client *gateway.Client, pointTask *model.AiTask) (err error) { + // 通用权限校验 if utils.Contains(r.conf.PermissionConfig.WhiteList, pointTask.Index) { return nil } - // 查询用户权限 - var ( - request l_request.Request - ) - - request.Url = r.conf.PermissionConfig.UnifiedLoginPlatformBaseURL - - request.Method = "GET" - request.Headers = map[string]string{ - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", - "Accept": "application/json, text/plain, */*", - "Authorization": "Bearer " + requireData.Auth, + // 系统权限校验 + if v, ok := r.conf.PermissionConfig.SysPermission[client.GetSysCode()]; !ok { + return fmt.Errorf("未配置系统权限校验: %s", client.GetSysCode()) + } else if utils.Contains(v.WhiteList, pointTask.Index) { + return nil } - // 发送请求 - res, err := request.Send() - if err != nil { - return err - } - - // 检查响应状态码 - if res.StatusCode != http.StatusOK { - return fmt.Errorf("unexpected status code: %d", res.StatusCode) - } - - type resp struct { - Codes []string `json:"codes"` - } - // 解析响应体 - var respBody resp - err = json.Unmarshal([]byte(res.Text), &respBody) - if err != nil { - return err - } - - // 检查权限 - if !utils.Contains(respBody.Codes, pointTask.Index) { + // 授权检查权限 + if !utils.Contains(client.GetCodes(), pointTask.Index) { return fmt.Errorf("用户权限不足: %s", pointTask.Name) } diff --git a/internal/biz/router.go b/internal/biz/router.go index 287d87b..70a069e 100644 --- a/internal/biz/router.go +++ b/internal/biz/router.go @@ -2,11 +2,11 @@ package biz import ( "ai_scheduler/internal/biz/do" + "ai_scheduler/internal/gateway" "ai_scheduler/internal/entitys" "github.com/gofiber/fiber/v2/log" - "github.com/gofiber/websocket/v2" ) // AiRouterBiz 智能路由服务 @@ -26,28 +26,48 @@ func NewAiRouterBiz( } } -func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRequest) (err error) { - //必要数据验证和获取 - dos := r.do.InitCtx(req) +// 路由处理WebSocket请求 +// +// 参数: +// - client: 网关客户端 +// - req: 聊天请求结构体 +// +// 返回: +// - err: 错误信息 +func (r *AiRouterBiz) RouteWithSocket(client *gateway.Client, req *entitys.ChatSockRequest) (err error) { + // 创建请求上下文数据 + requireData := &entitys.RequireData{ + Req: req, + } + // 获取WebSocket连接 + conn := client.GetConn() //初始化通道/上下文 - ctx, clearFunc := dos.MakeCh(c) - defer clearFunc() + ctx, clearFunc := r.do.MakeCh(conn, requireData) + defer func() { + if err != nil { + requireData.Ch <- entitys.Response{ + Content: err.Error(), + Type: entitys.ResponseErr, + } + } + clearFunc() + }() //数据验证和收集 - if err = dos.DataAuth(c); err != nil { + if err = r.do.DataAuth(ctx, client, requireData); err != nil { log.Errorf("数据验证和收集失败: %s", err.Error()) return } //意图识别 - if err = r.handle.Recognize(ctx, dos.Ctx); err != nil { + if err = r.handle.Recognize(ctx, requireData); err != nil { log.Errorf("意图识别失败: %s", err.Error()) return } //向下传递 - if err = r.handle.HandleMatch(ctx, dos.Ctx); err != nil { + if err = r.handle.HandleMatch(ctx, client, requireData); err != nil { log.Errorf("任务处理失败: %s", err.Error()) return } diff --git a/internal/config/config.go b/internal/config/config.go index b2350f7..27d46e4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -110,9 +110,18 @@ type LoggingConfig struct { // PermissionConfig 权限校验配置 type PermissionConfig struct { - UnifiedLoginPlatformBaseURL string `mapstructure:"unified_login_platform_base_url"` // 统一登录平台基础URL - // 白名单任务 - WhiteList []string `mapstructure:"white_list"` // 白名单任务列表 + // 不同系统的权限校验配置 + SysPermission map[string]SysWhiteList `mapstructure:"sys_permission"` + // 通用的白名单任务列表,不需要权限校验 + WhiteList []string `mapstructure:"white_list"` +} + +// 细分系统的白名单任务列表 +type SysWhiteList struct { + // 获取权限的地址 + PermissionURL string `mapstructure:"permission_url"` + // 系统的白名单任务列表 + WhiteList []string `mapstructure:"white_list"` } // 权限校验配置 diff --git a/internal/data/error/error_code.go b/internal/data/error/error_code.go index e9cc67d..9c28865 100644 --- a/internal/data/error/error_code.go +++ b/internal/data/error/error_code.go @@ -13,6 +13,7 @@ var ( AuthNotFound = &BusinessErr{code: 408, message: "身份验证失败"} KeyNotFound = &BusinessErr{code: 409, message: "身份验证失败"} SysNotFound = &BusinessErr{code: 410, message: "未找到系统信息"} + SysCodeNotFound = &BusinessErr{code: 411, message: "未找到系统编码"} InvalidParam = &BusinessErr{code: InvalidParamCode, message: "无效参数"} ) diff --git a/internal/entitys/response.go b/internal/entitys/response.go index 73bd581..5262102 100644 --- a/internal/entitys/response.go +++ b/internal/entitys/response.go @@ -2,7 +2,6 @@ package entitys import ( "encoding/json" - "github.com/gofiber/websocket/v2" ) diff --git a/internal/gateway/client.go b/internal/gateway/client.go new file mode 100644 index 0000000..b49bf45 --- /dev/null +++ b/internal/gateway/client.go @@ -0,0 +1,138 @@ +package gateway + +import ( + errors "ai_scheduler/internal/data/error" + "ai_scheduler/internal/data/model" + "encoding/hex" + "fmt" + "github.com/gofiber/websocket/v2" + "math/rand" + "time" +) + +var ( + ErrConnClosed = errors.SysErr("连接不存在或已关闭") +) + +type Client struct { + id string // 客户端唯一ID + conn *websocket.Conn // WebSocket 连接 + session string // 会话ID + key string // 应用密钥 + auth string // 用户凭证token + codes []string // 用户权限code + sysInfo *model.AiSy // 系统信息 + tasks []model.AiTask // 任务列表 + sysCode string // 系统编码 +} + +func NewClient(conn *websocket.Conn) *Client { + return &Client{ + id: generateClientID(), + conn: conn, + } +} + +// GetID 获取客户端的唯一ID +func (c *Client) GetID() string { + return c.id +} + +// GetConn 获取客户端的 WebSocket 连接 +func (c *Client) GetConn() *websocket.Conn { + return c.conn +} + +// GetSession 获取会话ID +func (c *Client) GetSession() string { + return c.session +} + +// GetKey 获取应用密钥 +func (c *Client) GetKey() string { + return c.key +} + +// GetAuth 获取用户凭证token +func (c *Client) GetAuth() string { + return c.auth +} + +// GetCodes 获取用户权限code +func (c *Client) GetCodes() []string { + return c.codes +} + +// GetSysCode 获取系统编码 +func (c *Client) GetSysCode() string { + return c.sysCode +} + +// GetSysInfo 获取系统信息 +func (c *Client) GetSysInfo() *model.AiSy { + return c.sysInfo +} + +// SetSysInfo 设置系统信息 +func (c *Client) SetSysInfo(sysInfo *model.AiSy) { + c.sysInfo = sysInfo +} + +// GetTasks 获取任务列表 +func (c *Client) GetTasks() []model.AiTask { + return c.tasks +} + +// SetTasks 设置任务列表 +func (c *Client) SetTasks(tasks []model.AiTask) { + c.tasks = tasks +} + +// 设置用户权限code +func (c *Client) SetCodes(codes []string) { + c.codes = codes +} + +// SendFunc 发送消息到客户端 +func (c *Client) SendFunc(msg []byte) error { + if c.conn != nil { + return c.conn.WriteMessage(websocket.TextMessage, msg) + } + return ErrConnClosed +} + +// 生成唯一的客户端ID +func generateClientID() string { + // 使用时间戳+随机数确保唯一性 + timestamp := time.Now().UnixNano() + randomBytes := make([]byte, 4) + rand.Read(randomBytes) + randomStr := hex.EncodeToString(randomBytes) + return fmt.Sprintf("%d%s", timestamp, randomStr) +} + +// 连接数据验证和收集 +func (c *Client) DataAuth() (err error) { + c.session = c.conn.Query("x-session", "") + if len(c.session) == 0 { + err = errors.SessionNotFound + return + } + c.auth = c.conn.Query("x-authorization", "") + if len(c.auth) == 0 { + err = errors.AuthNotFound + return + } + c.key = c.conn.Query("x-app-key", "") + if len(c.key) == 0 { + err = errors.KeyNotFound + return + } + // 系统编码 + c.sysCode = c.conn.Query("x-sys-code", "") + if len(c.sysCode) == 0 { + err = errors.SysCodeNotFound + return + } + return +} diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index f04ed3a..0f0e6f3 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -5,11 +5,6 @@ import ( "sync" ) -type Client struct { - ID string - SendFunc func(data []byte) error -} - type Gateway struct { mu sync.RWMutex clients map[string]*Client // clientID -> Client @@ -26,7 +21,7 @@ func NewGateway() *Gateway { func (g *Gateway) AddClient(c *Client) { g.mu.Lock() defer g.mu.Unlock() - g.clients[c.ID] = c + g.clients[c.GetID()] = c } func (g *Gateway) RemoveClient(clientID string) { diff --git a/internal/services/chat.go b/internal/services/chat.go index 95cd130..bb28412 100644 --- a/internal/services/chat.go +++ b/internal/services/chat.go @@ -2,19 +2,18 @@ package services import ( "ai_scheduler/internal/biz" + "ai_scheduler/internal/config" "ai_scheduler/internal/data/constants" + errors "ai_scheduler/internal/data/error" "ai_scheduler/internal/entitys" "ai_scheduler/internal/gateway" - "encoding/hex" + "ai_scheduler/internal/pkg/l_request" "encoding/json" - "fmt" - "log" - "math/rand" - "sync" - "time" - "github.com/gofiber/fiber/v2" "github.com/gofiber/websocket/v2" + "log" + "net/http" + "sync" ) // ChatHandler 聊天处理器 @@ -23,6 +22,7 @@ type ChatService struct { Gw *gateway.Gateway mu sync.Mutex ChatHis *biz.ChatHistoryBiz + cfg *config.Config } // NewChatHandler 创建聊天处理器 @@ -30,11 +30,13 @@ func NewChatService( routerService *biz.AiRouterBiz, chatHis *biz.ChatHistoryBiz, gw *gateway.Gateway, + cfg *config.Config, ) *ChatService { return &ChatService{ routerBiz: routerService, Gw: gw, ChatHis: chatHis, + cfg: cfg, } } @@ -60,36 +62,61 @@ func (h *ChatService) ChatFail(c *websocket.Conn, content string) { _ = c.Close() } -func generateClientID() string { - // 使用时间戳+随机数确保唯一性 - timestamp := time.Now().UnixNano() - randomBytes := make([]byte, 4) - rand.Read(randomBytes) - randomStr := hex.EncodeToString(randomBytes) - return fmt.Sprintf("%d%s", timestamp, randomStr) -} +// Chat 处理WebSocket聊天连接 +// 这是WebSocket处理的主入口函数 func (h *ChatService) Chat(c *websocket.Conn) { + // 创建新的客户端实例 h.mu.Lock() - clientID := generateClientID() + client := gateway.NewClient(c) h.mu.Unlock() - client := &gateway.Client{ - ID: clientID, - SendFunc: func(data []byte) error { - return c.WriteMessage(websocket.TextMessage, data) - }, - } + + // 将客户端添加到网关管理 h.Gw.AddClient(client) - log.Println("client connected:", clientID) + log.Println("client connected:", client.GetID()) log.Println("客户端已连接") + // 绑定会话ID + uid := c.Query("x-session") + if uid != "" { + if err := h.Gw.BindUid(client.GetID(), uid); err != nil { + log.Println("绑定UID错误:", err) + } + log.Printf("bind %s -> uid:%s\n", client.GetID(), uid) + } + + // 验证并收集连接数据,后续对话中会使用 + if err := client.DataAuth(); err != nil { + log.Println("数据验证错误:", err) + h.ChatFail(c, err.Error()) + return + } + + // 获取用户权限 + codes, err := h.GetUserPermission(client) + if err != nil { + log.Println("获取用户权限错误:", err) + h.ChatFail(c, err.Error()) + return + } + client.SetCodes(codes) + + // 确保在函数返回时移除客户端并关闭连接 + defer func() { + h.Gw.RemoveClient(client.GetID()) + _ = c.Close() + log.Println("client disconnected:", client.GetID()) + }() + // 循环读取客户端消息 for { + // 读取消息 messageType, message, err := c.ReadMessage() if err != nil { log.Println("读取错误:", err) break } + // 处理消息 msg, chatType := h.handleMessageToString(c, messageType, message) if chatType == constants.ConnStatusClosed { break @@ -99,39 +126,31 @@ func (h *ChatService) Chat(c *websocket.Conn) { } log.Printf("收到消息: %s", string(msg)) + + // 解析请求 var req entitys.ChatSockRequest - if err := json.Unmarshal(msg, &req); err != nil { + if err = json.Unmarshal(msg, &req); err != nil { log.Println("JSON parse error:", err) continue } - //简单协议:bind: - // 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) - } - - err = h.routerBiz.RouteWithSocket(c, &req) + // 路由处理请求 + err = h.routerBiz.RouteWithSocket(client, &req) if err != nil { log.Println("处理失败:", err) - entitys.MsgSend(c, entitys.Response{ - Content: err.Error(), - Type: entitys.ResponseText, - }) } - } - h.Gw.RemoveClient(clientID) - _ = c.Close() - log.Println("client disconnected:", clientID) } +// handleMessageToString 处理不同类型的WebSocket消息 +// 参数: +// - c: WebSocket连接 +// - msgType: 消息类型 +// - msg: 消息内容 +// +// 返回: +// - text: 处理后的文本内容 +// - chatType: 连接状态 func (h *ChatService) handleMessageToString(c *websocket.Conn, msgType int, msg any) (text []byte, chatType constants.ConnStatus) { switch msgType { case websocket.TextMessage: @@ -172,3 +191,52 @@ func (s *ChatService) UsefulList(c *fiber.Ctx) error { return c.JSON(constants.UseFulMap) } + +// 从统一登录平台获取用户权限 +func (s *ChatService) GetUserPermission(client *gateway.Client) (codes []string, err error) { + var ( + request l_request.Request + ) + + // 系统编码 + systemCode := client.GetSysCode() + + // 检查系统编码是否配置 + if v, ok := s.cfg.PermissionConfig.SysPermission[systemCode]; !ok { + err = errors.SysErr("系统编码 %s 未配置", systemCode) + return + } else { + request.Url = v.PermissionURL + } + + request.Method = "GET" + request.Headers = map[string]string{ + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", + "Accept": "application/json, text/plain, */*", + "Authorization": "Bearer " + client.GetAuth(), + } + + // 发送请求 + res, err := request.Send() + if err != nil { + return + } + + // 检查响应状态码 + if res.StatusCode != http.StatusOK { + err = errors.SysErr("获取用户权限失败") + return + } + + type resp struct { + Codes []string `json:"codes"` + } + // 解析响应体 + var respBody resp + err = json.Unmarshal([]byte(res.Text), &respBody) + if err != nil { + return + } + + return respBody.Codes, nil +} From 2cd19e5fdfbd381ddc06db2c74aadff3034fc1c9 Mon Sep 17 00:00:00 2001 From: wolter <11@gmail> Date: Fri, 21 Nov 2025 15:25:01 +0800 Subject: [PATCH 08/19] feat: chat --- internal/biz/router.go | 5 +---- internal/entitys/response.go | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/biz/router.go b/internal/biz/router.go index 70a069e..6dcc233 100644 --- a/internal/biz/router.go +++ b/internal/biz/router.go @@ -46,10 +46,7 @@ func (r *AiRouterBiz) RouteWithSocket(client *gateway.Client, req *entitys.ChatS ctx, clearFunc := r.do.MakeCh(conn, requireData) defer func() { if err != nil { - requireData.Ch <- entitys.Response{ - Content: err.Error(), - Type: entitys.ResponseErr, - } + entitys.ResError(requireData.Ch, "", err.Error()) } clearFunc() }() diff --git a/internal/entitys/response.go b/internal/entitys/response.go index 5262102..cdadc98 100644 --- a/internal/entitys/response.go +++ b/internal/entitys/response.go @@ -67,6 +67,13 @@ func ResLoading(ch chan Response, index string, content string) { Type: ResponseLoading, } } +func ResError(ch chan Response, index string, content string) { + ch <- Response{ + Index: index, + Content: content, + Type: ResponseErr, + } +} type ResponseData struct { Done bool From baff6ef5731c386a8a1ce2a436e37c02ac78cf60 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 09:47:23 +0800 Subject: [PATCH 09/19] feat: add --- internal/tools/zltx_order_after_supplier.go | 95 ++++++++++----------- 1 file changed, 44 insertions(+), 51 deletions(-) diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index 5b311de..3767b40 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -61,26 +61,25 @@ type ZltxOrderAfterSaleSupplierRequest struct { } type ZltxOrderAfterSaleSupplierResponse struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data []CheckResult2 `json:"data"` + Code int `json:"code"` + Msg string `json:"msg"` + Data []ZltxOrderAfterSaleSupplierData `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"` +type ZltxOrderAfterSaleSupplierData struct { + SerialNumber string `json:"serialNumber"` + PlatformName string `json:"platformName"` + SignCompany int `json:"signCompany"` + PlatformProductName string `json:"platformProductName"` + PlatformPrice float64 `json:"platformPrice"` + TerminalAccount string `json:"terminalAccount"` + Status int `json:"status"` + PlatformProductID int `json:"platformProductId"` + PlatformID int `json:"platformId"` + SignCompanyName string `json:"signCompanyName"` + ExecuteTime int `json:"executeTime"` + AfterSalesReason string `json:"afterSalesReason"` + AfterSalesPrice float64 `json:"afterSalesPrice"` } func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { @@ -121,42 +120,36 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu resp := ZltxOrderAfterSaleSupplierResponse{ Code: 0, Msg: "success", - Data: []CheckResult2{ + Data: []ZltxOrderAfterSaleSupplierData{ { - 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", - }, + SerialNumber: "123456", + PlatformName: "测试平台", + SignCompany: 1, + PlatformProductName: "测试商品", + PlatformPrice: 100, + TerminalAccount: "123456", + Status: 1, + PlatformProductID: 1, + PlatformID: 1, + SignCompanyName: "测试公司", + ExecuteTime: 1694560000, + AfterSalesReason: "测试售后", + AfterSalesPrice: 50, }, { - 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", - }, + SerialNumber: "123457", + PlatformName: "测试平台2", + SignCompany: 1, + PlatformProductName: "测试商品2", + PlatformPrice: 100, + TerminalAccount: "123456", + Status: 1, + PlatformProductID: 1, + PlatformID: 1, + SignCompanyName: "测试公司2", + ExecuteTime: 1694570000, + AfterSalesReason: "测试售后2", + AfterSalesPrice: 30, }, }, } From 65aa6ca411129fd620556b8f2864dabe0fffcbfd Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 09:53:10 +0800 Subject: [PATCH 10/19] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0UseCase?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/model/ai_task.gen.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/data/model/ai_task.gen.go b/internal/data/model/ai_task.gen.go index 8e04c3b..a5caca3 100644 --- a/internal/data/model/ai_task.gen.go +++ b/internal/data/model/ai_task.gen.go @@ -23,6 +23,7 @@ type AiTask struct { UpdateAt time.Time `gorm:"column:update_at;default:CURRENT_TIMESTAMP" json:"update_at"` Status int32 `gorm:"column:status;not null;default:1" json:"status"` DeleteAt time.Time `gorm:"column:delete_at" json:"delete_at"` + UseCase string `gorm:"column:use_case;not null" json:"use_case"` // 适用场景 } // TableName AiTask's table name From 57788c990868a104bcd506d0fc94a44796ee38a8 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 11:16:01 +0800 Subject: [PATCH 11/19] =?UTF-8?q?feat:=20=E5=B7=A5=E5=85=B7=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E8=BE=93=E5=87=BA=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config_test.yaml | 3 + internal/biz/do/handle.go | 12 +- internal/config/config.go | 2 + internal/services/chat.go | 5 +- internal/tools/manager.go | 5 + internal/tools/zltx_order_after_reseller.go | 176 ++++++++++++++++++++ internal/tools/zltx_order_after_supplier.go | 42 +++-- 7 files changed, 219 insertions(+), 26 deletions(-) create mode 100644 internal/tools/zltx_order_after_reseller.go diff --git a/config/config_test.yaml b/config/config_test.yaml index ba26040..c5c8451 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -58,6 +58,9 @@ tools: zltxOrderAfterSaleSupplier: enabled: true base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier" + zltxOrderAfterSaleReseller: + enabled: true + base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier" default_prompt: img_recognize: diff --git a/internal/biz/do/handle.go b/internal/biz/do/handle.go index 828e443..e3fe794 100644 --- a/internal/biz/do/handle.go +++ b/internal/biz/do/handle.go @@ -17,9 +17,9 @@ import ( "context" "encoding/json" "fmt" - "github.com/gofiber/fiber/v2/log" - "gorm.io/gorm/utils" "strings" + + "gorm.io/gorm/utils" ) type Handle struct { @@ -95,10 +95,10 @@ func (r *Handle) HandleMatch(ctx context.Context, client *gateway.Client, requir } // 校验用户权限 - if err = r.PermissionAuth(client, pointTask); err != nil { - log.Errorf("权限验证失败: %s", err.Error()) - return - } + // if err = r.PermissionAuth(client, pointTask); err != nil { + // log.Errorf("权限验证失败: %s", err.Error()) + // return + // } switch constants.TaskType(pointTask.Type) { case constants.TaskTypeApi: diff --git a/internal/config/config.go b/internal/config/config.go index 8241987..6002a36 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -96,6 +96,8 @@ type ToolsConfig struct { ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"` // 上游订单售后 ZltxOrderAfterSaleSupplier ToolConfig `mapstructure:"zltxOrderAfterSaleSupplier"` + // 下游订单售后 + ZltxOrderAfterSaleReseller ToolConfig `mapstructure:"zltxOrderAfterSaleReseller"` } // ToolConfig 单个工具配置 diff --git a/internal/services/chat.go b/internal/services/chat.go index bb28412..5dc0cf5 100644 --- a/internal/services/chat.go +++ b/internal/services/chat.go @@ -9,11 +9,12 @@ import ( "ai_scheduler/internal/gateway" "ai_scheduler/internal/pkg/l_request" "encoding/json" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/websocket/v2" "log" "net/http" "sync" + + "github.com/gofiber/fiber/v2" + "github.com/gofiber/websocket/v2" ) // ChatHandler 聊天处理器 diff --git a/internal/tools/manager.go b/internal/tools/manager.go index 148d8fd..36ea74d 100644 --- a/internal/tools/manager.go +++ b/internal/tools/manager.go @@ -86,6 +86,11 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager { zltxOrderAfterSaleSupplierTool := NewZltxOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier) m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool } + // 注册直连天下下游售后订单工具 + if config.Tools.ZltxOrderAfterSaleReseller.Enabled { + zltxOrderAfterSaleResellerTool := NewZltxOrderAfterSaleResellerTool(config.Tools.ZltxOrderAfterSaleReseller) + m.tools[zltxOrderAfterSaleResellerTool.Name()] = zltxOrderAfterSaleResellerTool + } // 普通对话 chat := NewNormalChatTool(m.llm, config) diff --git a/internal/tools/zltx_order_after_reseller.go b/internal/tools/zltx_order_after_reseller.go new file mode 100644 index 0000000..8a1a68d --- /dev/null +++ b/internal/tools/zltx_order_after_reseller.go @@ -0,0 +1,176 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "context" + "encoding/json" + "fmt" +) + +type ZltxOrderAfterSaleResellerTool struct { + config config.ToolConfig +} + +// NewZltxOrderAfterSaleResellerTool 创建售后订单预检工具 +func NewZltxOrderAfterSaleResellerTool(config config.ToolConfig) *ZltxOrderAfterSaleResellerTool { + return &ZltxOrderAfterSaleResellerTool{config: config} +} + +// Name 返回工具名称 +func (t *ZltxOrderAfterSaleResellerTool) Name() string { + return "zltxOrderAfterSaleReseller" +} + +func (t *ZltxOrderAfterSaleResellerTool) Description() string { + return "直连天下上游供应商售后工具" +} + +func (t *ZltxOrderAfterSaleResellerTool) 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 ZltxOrderAfterSaleResellerRequest 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 ZltxOrderAfterSaleResellerResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data []ZltxOrderAfterSaleResellerData `json:"data"` +} + +type ZltxOrderAfterSaleResellerData 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 map[int]string `json:"platforms"` + AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 + Remark string `json:"remark"` // 售后原因 + AfterAmount float64 `json:"afterAmount"` // 售后金额 + ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 + ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 +} + +func (t *ZltxOrderAfterSaleResellerTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSaleResellerRequest + 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.checkZltxOrderAfterSaleReseller(req.OrderNumber, requireData) +} + +func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(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 ZltxOrderAfterSaleResellerResponse + // if err := json.Unmarshal(res.Content, &resp); err != nil { + // return err + // } + // if resp.Code != 0 { + // return fmt.Errorf("check failed: %s", resp.Msg) + // } + resp := ZltxOrderAfterSaleResellerResponse{ + Code: 0, + Msg: "success", + Data: []ZltxOrderAfterSaleResellerData{ + // 为我生成两条不一样的数据 + { + OrderType: 1, + OrderNumber: orderNumber, + OrderAmount: 100, + OrderPrice: 100, + SignCompany: 1, + OrderQuantity: 1, + ResellerID: 1, + ResellerName: "测试供应商", + OurProductID: 1, + OurProductTitle: "测试商品", + Account: []string{"123456"}, + Platforms: map[int]string{4: "测试平台"}, + AfterType: 1, + Remark: "测试售后", + AfterAmount: 50, + ResponsibleType: 1, + IsExistsAfterSale: true, + }, + { + OrderType: 1, + OrderNumber: orderNumber, + OrderAmount: 100, + OrderPrice: 100, + SignCompany: 1, + OrderQuantity: 1, + ResellerID: 1, + ResellerName: "测试供应商2", + OurProductID: 1, + OurProductTitle: "测试商品2", + Account: []string{"123456"}, + Platforms: map[int]string{4: "测试平台2"}, + AfterType: 2, + Remark: "测试售后2", + AfterAmount: 30, + ResponsibleType: 2, + IsExistsAfterSale: false, + }, + }, + } + 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/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index 3767b40..a258a56 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -23,7 +23,7 @@ func (t *ZltxOrderAfterSaleSupplierTool) Name() string { } func (t *ZltxOrderAfterSaleSupplierTool) Description() string { - return "直连天下售后订单供应商工具" + return "直连天下上游供应商售后工具" } func (t *ZltxOrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition { @@ -67,19 +67,21 @@ type ZltxOrderAfterSaleSupplierResponse struct { } type ZltxOrderAfterSaleSupplierData struct { - SerialNumber string `json:"serialNumber"` - PlatformName string `json:"platformName"` - SignCompany int `json:"signCompany"` - PlatformProductName string `json:"platformProductName"` - PlatformPrice float64 `json:"platformPrice"` - TerminalAccount string `json:"terminalAccount"` - Status int `json:"status"` - PlatformProductID int `json:"platformProductId"` - PlatformID int `json:"platformId"` - SignCompanyName string `json:"signCompanyName"` - ExecuteTime int `json:"executeTime"` - AfterSalesReason string `json:"afterSalesReason"` - AfterSalesPrice float64 `json:"afterSalesPrice"` + SerialNumber string `json:"serialNumber"` // 流水号 + PlatformName string `json:"platformName"` // 供应商名称 + SignCompany int `json:"signCompany"` // 签约主体 + PlatformProductName string `json:"platformProductName"` // 商品名称 + PlatformPrice float64 `json:"platformPrice"` // 上游价格 + TerminalAccount string `json:"terminalAccount"` // 充值账号 + Status int `json:"status"` // 充值状态 + PlatformProductID int `json:"platformProductId"` // 上有商品id + PlatformID int `json:"platformId"` // 上游平台id + SignCompanyName string `json:"signCompanyName"` // 签约主体名称 + ExecuteTime int `json:"executeTime"` // 订单执行时间 + Reason string `json:"reason"` // 售后原因 + SalePrice float64 `json:"salePrice"` // 售后金额 + SaleType int `json:"saleType"` // 处理方式 1.加款 2.扣款 + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 } func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { @@ -133,8 +135,10 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu PlatformID: 1, SignCompanyName: "测试公司", ExecuteTime: 1694560000, - AfterSalesReason: "测试售后", - AfterSalesPrice: 50, + Reason: "测试售后", + SalePrice: 50, + SaleType: 1, + IsExistsAfterSale: true, }, { SerialNumber: "123457", @@ -148,8 +152,10 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu PlatformID: 1, SignCompanyName: "测试公司2", ExecuteTime: 1694570000, - AfterSalesReason: "测试售后2", - AfterSalesPrice: 30, + Reason: "测试售后2", + SalePrice: 30, + SaleType: 2, + IsExistsAfterSale: false, }, }, } From af54224504a9219dbee72658ab27ada6b4d9a522 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 13:38:30 +0800 Subject: [PATCH 12/19] =?UTF-8?q?fix:=20mock=E6=95=B0=E6=8D=AE=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/tools/zltx_order_after_reseller.go | 41 ++++++++------- internal/tools/zltx_order_after_supplier.go | 55 +++++++++++++-------- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/internal/tools/zltx_order_after_reseller.go b/internal/tools/zltx_order_after_reseller.go index 8a1a68d..f08beb3 100644 --- a/internal/tools/zltx_order_after_reseller.go +++ b/internal/tools/zltx_order_after_reseller.go @@ -126,39 +126,38 @@ func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(orderNu Code: 0, Msg: "success", Data: []ZltxOrderAfterSaleResellerData{ - // 为我生成两条不一样的数据 { OrderType: 1, - OrderNumber: orderNumber, - OrderAmount: 100, - OrderPrice: 100, + OrderNumber: "846784115378364417", + OrderAmount: 0.1, + OrderPrice: 0.1, SignCompany: 1, OrderQuantity: 1, - ResellerID: 1, - ResellerName: "测试供应商", - OurProductID: 1, - OurProductTitle: "测试商品", - Account: []string{"123456"}, - Platforms: map[int]string{4: "测试平台"}, + ResellerID: 23329, + ResellerName: "分销商23329", + OurProductID: 106, + OurProductTitle: "爱奇艺黄金会员周卡", + Account: []string{"15516353308"}, + Platforms: map[int]string{4: "爱奇艺"}, AfterType: 1, Remark: "测试售后", AfterAmount: 50, ResponsibleType: 1, - IsExistsAfterSale: true, + IsExistsAfterSale: false, }, { - OrderType: 1, - OrderNumber: orderNumber, - OrderAmount: 100, - OrderPrice: 100, + OrderType: 101, + OrderNumber: "846052057729867777", + OrderAmount: 23, + OrderPrice: 23, SignCompany: 1, OrderQuantity: 1, - ResellerID: 1, - ResellerName: "测试供应商2", - OurProductID: 1, - OurProductTitle: "测试商品2", - Account: []string{"123456"}, - Platforms: map[int]string{4: "测试平台2"}, + ResellerID: 25629, + ResellerName: "二期财务分销商简称", + OurProductID: 104, + OurProductTitle: "优酷年卡", + Account: []string{"18380416326"}, + Platforms: map[int]string{1: "爱瓦力"}, AfterType: 2, Remark: "测试售后2", AfterAmount: 30, diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index a258a56..ec5e129 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -123,39 +123,52 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu Code: 0, Msg: "success", Data: []ZltxOrderAfterSaleSupplierData{ + // { + // "serialNumber": "847465394004430849", + // "platformName": "爱奇艺", + // "signCompany": 1, + // "platformProductName": "爱奇艺官方周卡", + // "platformPrice": 6, + // "terminalAccount": "15516353308", + // "status": 1, + // "platformProductId": 2, + // "platformId": 4, + // "signCompanyName": "成都蓝色兄弟网络科技有限公司", + // "executeTime": 1763961931 + // } { - SerialNumber: "123456", - PlatformName: "测试平台", + SerialNumber: "847465394004430849", + PlatformName: "爱奇艺", SignCompany: 1, - PlatformProductName: "测试商品", - PlatformPrice: 100, - TerminalAccount: "123456", + PlatformProductName: "爱奇艺官方周卡", + PlatformPrice: 6, + TerminalAccount: "15516353308", Status: 1, - PlatformProductID: 1, - PlatformID: 1, - SignCompanyName: "测试公司", - ExecuteTime: 1694560000, + PlatformProductID: 2, + PlatformID: 4, + SignCompanyName: "成都蓝色兄弟网络科技有限公司", + ExecuteTime: 1763961931, Reason: "测试售后", SalePrice: 50, SaleType: 1, - IsExistsAfterSale: true, + IsExistsAfterSale: false, }, { - SerialNumber: "123457", - PlatformName: "测试平台2", + SerialNumber: "843493448012140545", + PlatformName: "卓望别名1", SignCompany: 1, - PlatformProductName: "测试商品2", - PlatformPrice: 100, - TerminalAccount: "123456", - Status: 1, - PlatformProductID: 1, - PlatformID: 1, - SignCompanyName: "测试公司2", - ExecuteTime: 1694570000, + PlatformProductName: "卓望--别名商品1", + PlatformPrice: 897.7765, + TerminalAccount: "18380416326", + Status: -1, + PlatformProductID: 7497, + PlatformID: 15, + SignCompanyName: "成都蓝色兄弟网络科技有限公司", + ExecuteTime: 1763014914, Reason: "测试售后2", SalePrice: 30, SaleType: 2, - IsExistsAfterSale: false, + IsExistsAfterSale: true, }, }, } From 3eaba6004a92c8ab51566181ab8472f496052c84 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 14:46:00 +0800 Subject: [PATCH 13/19] =?UTF-8?q?fix:=20mock=E6=8E=A5=E5=8F=A3=E5=81=9C?= =?UTF-8?q?=E7=94=A8=E5=8F=82=E6=95=B0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/constants/bot.go | 5 +---- internal/tools/zltx_order_after_reseller.go | 9 ++++----- internal/tools/zltx_order_after_supplier.go | 9 ++++----- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/internal/data/constants/bot.go b/internal/data/constants/bot.go index 0863cb8..6dc6680 100644 --- a/internal/data/constants/bot.go +++ b/internal/data/constants/bot.go @@ -3,8 +3,5 @@ package constants type BotTools string const ( - BotToolsBugOptimizationSubmit = "bug_optimization_submit" // 系统的bug/优化建议 - BotToolsAfterSalesSupplier = "after_sales_supplier" // 供应商售后 - BotToolsAfterSalesResellerSingle = "after_sales_reseller_single" // 分销商单条售后 - BotToolsAfterSalesResellerBatch = "after_sales_reseller_batch" // 分销商批量售后 + BotToolsBugOptimizationSubmit = "bug_optimization_submit" // 系统的bug/优化建议 ) diff --git a/internal/tools/zltx_order_after_reseller.go b/internal/tools/zltx_order_after_reseller.go index f08beb3..b4da6cf 100644 --- a/internal/tools/zltx_order_after_reseller.go +++ b/internal/tools/zltx_order_after_reseller.go @@ -5,7 +5,6 @@ import ( "ai_scheduler/internal/entitys" "context" "encoding/json" - "fmt" ) type ZltxOrderAfterSaleResellerTool struct { @@ -44,7 +43,7 @@ func (t *ZltxOrderAfterSaleResellerTool) Definition() entitys.ToolDefinition { "description": "售后订单号", }, }, - "required": []string{"orderType", "orderNumber"}, + // "required": []string{"orderType", "orderNumber"}, }, }, } @@ -92,9 +91,9 @@ func (t *ZltxOrderAfterSaleResellerTool) Execute(ctx context.Context, requireDat if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { return err } - if req.OrderNumber == "" { - return fmt.Errorf("orderType and orderNumber are required") - } + // if req.OrderNumber == "" { + // return fmt.Errorf("orderType and orderNumber are required") + // } return t.checkZltxOrderAfterSaleReseller(req.OrderNumber, requireData) } diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index ec5e129..af7aba1 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -5,7 +5,6 @@ import ( "ai_scheduler/internal/entitys" "context" "encoding/json" - "fmt" ) type ZltxOrderAfterSaleSupplierTool struct { @@ -44,7 +43,7 @@ func (t *ZltxOrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition { "description": "售后订单号", }, }, - "required": []string{"orderType", "orderNumber"}, + // "required": []string{"orderType", "orderNumber"}, }, }, } @@ -89,9 +88,9 @@ func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireDat if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { return err } - if req.OrderNumber == "" { - return fmt.Errorf("orderType and orderNumber are required") - } + // if req.OrderNumber == "" { + // return fmt.Errorf("orderType and orderNumber are required") + // } return t.checkZltxOrderAfterSaleSupplier(req.OrderNumber, requireData) } From bf0fa441d942498b97dbe1ad9f67ee9ce01078c2 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 15:30:32 +0800 Subject: [PATCH 14/19] =?UTF-8?q?fix=EF=BC=9A=20=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/tools/zltx_order_after_reseller.go | 25 ++++++++++++--------- internal/tools/zltx_order_after_supplier.go | 7 +++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/internal/tools/zltx_order_after_reseller.go b/internal/tools/zltx_order_after_reseller.go index b4da6cf..26891be 100644 --- a/internal/tools/zltx_order_after_reseller.go +++ b/internal/tools/zltx_order_after_reseller.go @@ -5,6 +5,7 @@ import ( "ai_scheduler/internal/entitys" "context" "encoding/json" + "fmt" ) type ZltxOrderAfterSaleResellerTool struct { @@ -50,13 +51,15 @@ func (t *ZltxOrderAfterSaleResellerTool) Definition() entitys.ToolDefinition { } type ZltxOrderAfterSaleResellerRequest 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"` // 售后金额 + OrderNumber []string `json:"orderNumber"` // 订单号 + Account []string `json:"account"` // 充值账号 + OrderTimeStart string `json:"orderTimeStart"` // 订单执行开始时间 + OrderTimeEnd string `json:"orderTimeEnd"` // 订单执行结束时间 + AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 + AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 + AfterSalesReason string `json:"afterSalesReason"` // 售后原因 + ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 + ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 } type ZltxOrderAfterSaleResellerResponse struct { @@ -91,10 +94,10 @@ func (t *ZltxOrderAfterSaleResellerTool) Execute(ctx context.Context, requireDat 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.checkZltxOrderAfterSaleReseller(req.OrderNumber, requireData) + if len(req.OrderNumber) == 0 && len(req.Account) == 0 { + return fmt.Errorf("orderNumber or account are required") + } + return t.checkZltxOrderAfterSaleReseller(req.OrderNumber[0], requireData) } func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(orderNumber string, requireData *entitys.RequireData) error { diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index af7aba1..2fca4cf 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -5,6 +5,7 @@ import ( "ai_scheduler/internal/entitys" "context" "encoding/json" + "fmt" ) type ZltxOrderAfterSaleSupplierTool struct { @@ -88,9 +89,9 @@ func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireDat if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { return err } - // if req.OrderNumber == "" { - // return fmt.Errorf("orderType and orderNumber are required") - // } + if req.OrderNumber == "" { + return fmt.Errorf("orderType and orderNumber are required") + } return t.checkZltxOrderAfterSaleSupplier(req.OrderNumber, requireData) } From e2b6454d29e3367777023ddc454f6677c284b935 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 24 Nov 2025 15:33:10 +0800 Subject: [PATCH 15/19] =?UTF-8?q?feat=EF=BC=9A=20=E5=A2=9E=E5=8A=A0=20tag?= =?UTF-8?q?=5Ftype=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/model/ai_task.gen.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/data/model/ai_task.gen.go b/internal/data/model/ai_task.gen.go index a5caca3..5599d78 100644 --- a/internal/data/model/ai_task.gen.go +++ b/internal/data/model/ai_task.gen.go @@ -23,7 +23,8 @@ type AiTask struct { UpdateAt time.Time `gorm:"column:update_at;default:CURRENT_TIMESTAMP" json:"update_at"` Status int32 `gorm:"column:status;not null;default:1" json:"status"` DeleteAt time.Time `gorm:"column:delete_at" json:"delete_at"` - UseCase string `gorm:"column:use_case;not null" json:"use_case"` // 适用场景 + UseCase string `gorm:"column:use_case;not null" json:"use_case"` // 适用场景 + TagType int32 `gorm:"column:tag_type;not null;default:1" json:"tag_type"` // 标签类型 1.AI日常 2.AI查询 3.AI执行 } // TableName AiTask's table name From cae16fbae25055d9bf8244238c384c61902aff07 Mon Sep 17 00:00:00 2001 From: wolter <11@gmail> Date: Mon, 24 Nov 2025 18:11:20 +0800 Subject: [PATCH 16/19] =?UTF-8?q?feat:=20chat=E6=9D=83=E9=99=90=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E8=B0=83=E6=95=B4=EF=BC=8Ctasklist=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=E8=BF=94=E5=9B=9E=E5=88=97=E8=A1=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config_test.yaml | 12 +------- internal/biz/do/ctx.go | 55 +++++++++++++++++++++++++++++++++ internal/biz/do/handle.go | 15 +-------- internal/biz/task.go | 64 +++++++++++++++++++++++++++++++++++++-- internal/config/config.go | 12 -------- internal/services/chat.go | 61 ------------------------------------- internal/services/task.go | 11 +++++-- 7 files changed, 128 insertions(+), 102 deletions(-) diff --git a/config/config_test.yaml b/config/config_test.yaml index c5c8451..21e44fc 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -73,14 +73,4 @@ default_prompt: user_prompt: '识别图片内容' # 权限配置 permissionConfig: - # 不同系统的权限校验配置 - sys_permission: - # 直连天下系统 - zltx: - permission_url: "https://gateway.dev.cdlsxd.cn/zltx_api/test/v1/menu/myCodes?systemCode=zltx" - white_list: - - "knowledge_qa" # 知识问答 - # 通用的白名单接口 - white_list: - - "chat" # 聊天接口 - - "bug_optimization_submit" # 优化建议提交接口 + permission_url: "http://api.test.user.1688sup.cn:8001/v1/menu/myCodes?systemId=" diff --git a/internal/biz/do/ctx.go b/internal/biz/do/ctx.go index b0e7299..ed8749d 100644 --- a/internal/biz/do/ctx.go +++ b/internal/biz/do/ctx.go @@ -10,7 +10,9 @@ import ( "ai_scheduler/internal/pkg" "ai_scheduler/tmpl/dataTemp" "context" + "encoding/json" "fmt" + "net/http" "strconv" "strings" "time" @@ -71,6 +73,11 @@ func (d *Do) DataAuth(ctx context.Context, client *gateway.Client, requireData * return err } + // 6. 加载用户权限 + if _, err = d.LoadUserPermission(client, requireData); err != nil { + return fmt.Errorf("获取用户权限失败: %w", err) + } + return nil } @@ -298,3 +305,51 @@ func sendWithTimeout(c *websocket.Conn, data entitys.Response, timeout time.Dura return sendCtx.Err() } } + +// 从统一登录平台获取用户权限 +func (d *Do) LoadUserPermission(client *gateway.Client, requireData *entitys.RequireData) (codes []string, err error) { + if len(client.GetCodes()) > 0 { + return client.GetCodes(), nil + } + + var ( + request l_request.Request + ) + + // 构建请求URL + request.Url = d.conf.PermissionConfig.PermissionURL + strconv.Itoa(int(requireData.Sys.SysID)) + + request.Method = "GET" + request.Headers = map[string]string{ + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", + "Accept": "application/json, text/plain, */*", + "Authorization": "Bearer " + client.GetAuth(), + } + + // 发送请求 + res, err := request.Send() + if err != nil { + return + } + + // 检查响应状态码 + if res.StatusCode != http.StatusOK { + err = errors.SysErr("获取用户权限失败") + return + } + + type resp struct { + Codes []string `json:"codes"` + } + // 解析响应体 + var respBody resp + err = json.Unmarshal([]byte(res.Text), &respBody) + if err != nil { + return + } + + // 设置客户端权限 + client.SetCodes(respBody.Codes) + + return respBody.Codes, nil +} diff --git a/internal/biz/do/handle.go b/internal/biz/do/handle.go index e3fe794..e014d25 100644 --- a/internal/biz/do/handle.go +++ b/internal/biz/do/handle.go @@ -17,9 +17,8 @@ import ( "context" "encoding/json" "fmt" - "strings" - "gorm.io/gorm/utils" + "strings" ) type Handle struct { @@ -265,18 +264,6 @@ func (r *Handle) handleApiTask(ctx context.Context, requireData *entitys.Require // 权限验证 func (r *Handle) PermissionAuth(client *gateway.Client, pointTask *model.AiTask) (err error) { - // 通用权限校验 - if utils.Contains(r.conf.PermissionConfig.WhiteList, pointTask.Index) { - return nil - } - - // 系统权限校验 - if v, ok := r.conf.PermissionConfig.SysPermission[client.GetSysCode()]; !ok { - return fmt.Errorf("未配置系统权限校验: %s", client.GetSysCode()) - } else if utils.Contains(v.WhiteList, pointTask.Index) { - return nil - } - // 授权检查权限 if !utils.Contains(client.GetCodes(), pointTask.Index) { return fmt.Errorf("用户权限不足: %s", pointTask.Name) diff --git a/internal/biz/task.go b/internal/biz/task.go index 2c67591..e1a8689 100644 --- a/internal/biz/task.go +++ b/internal/biz/task.go @@ -1,10 +1,16 @@ package biz import ( + errors "ai_scheduler/internal/data/error" "ai_scheduler/internal/data/impl" "ai_scheduler/internal/data/model" "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg/l_request" "context" + "encoding/json" + "gorm.io/gorm/utils" + "net/http" + "strconv" "xorm.io/builder" @@ -24,12 +30,66 @@ func NewTaskBiz(conf *config.Config, taskRepo *impl.TaskImpl) *TaskBiz { } // taskList 功能列表 -func (t *TaskBiz) TaskList(ctx context.Context, req *entitys.TaskRequest) (list []model.AiTask, err error) { +func (t *TaskBiz) TaskList(ctx context.Context, req *entitys.TaskRequest, auth string) (list []model.AiTask, err error) { + tasks := make([]model.AiTask, 0) cond := builder.NewCond() cond = cond.And(builder.Eq{"status": 1}) cond = cond.And(builder.Eq{"sys_id": req.SysId}) - err = t.taskRepo.GetRangeToMapStruct(&cond, &list) + err = t.taskRepo.GetRangeToMapStruct(&cond, &tasks) + + codes, err := t.GetUserPermission(req, auth) + if err != nil { + return + } + + // 检查用户是否有权限 + for _, task := range tasks { + if utils.Contains(codes, task.Index) { + list = append(list, task) + } + } return } + +// 从统一登录平台获取用户权限 +func (t *TaskBiz) GetUserPermission(req *entitys.TaskRequest, auth string) (codes []string, err error) { + var ( + request l_request.Request + ) + + // 构建请求URL + request.Url = t.conf.PermissionConfig.PermissionURL + strconv.Itoa(int(req.SysId)) + + request.Method = "GET" + request.Headers = map[string]string{ + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", + "Accept": "application/json, text/plain, */*", + "Authorization": auth, + } + + // 发送请求 + res, err := request.Send() + if err != nil { + return + } + + // 检查响应状态码 + if res.StatusCode != http.StatusOK { + err = errors.SysErr("获取用户权限失败") + return + } + + type resp struct { + Codes []string `json:"codes"` + } + // 解析响应体 + var respBody resp + err = json.Unmarshal([]byte(res.Text), &respBody) + if err != nil { + return + } + + return respBody.Codes, nil +} diff --git a/internal/config/config.go b/internal/config/config.go index 6002a36..32710ff 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -118,22 +118,10 @@ type LoggingConfig struct { // PermissionConfig 权限校验配置 type PermissionConfig struct { - // 不同系统的权限校验配置 - SysPermission map[string]SysWhiteList `mapstructure:"sys_permission"` - // 通用的白名单任务列表,不需要权限校验 - WhiteList []string `mapstructure:"white_list"` -} - -// 细分系统的白名单任务列表 -type SysWhiteList struct { // 获取权限的地址 PermissionURL string `mapstructure:"permission_url"` - // 系统的白名单任务列表 - WhiteList []string `mapstructure:"white_list"` } -// 权限校验配置 - // LoadConfig 加载配置 func LoadConfig(configPath string) (*Config, error) { viper.SetConfigFile(configPath) diff --git a/internal/services/chat.go b/internal/services/chat.go index 5dc0cf5..ff75bee 100644 --- a/internal/services/chat.go +++ b/internal/services/chat.go @@ -4,13 +4,10 @@ import ( "ai_scheduler/internal/biz" "ai_scheduler/internal/config" "ai_scheduler/internal/data/constants" - errors "ai_scheduler/internal/data/error" "ai_scheduler/internal/entitys" "ai_scheduler/internal/gateway" - "ai_scheduler/internal/pkg/l_request" "encoding/json" "log" - "net/http" "sync" "github.com/gofiber/fiber/v2" @@ -92,15 +89,6 @@ func (h *ChatService) Chat(c *websocket.Conn) { return } - // 获取用户权限 - codes, err := h.GetUserPermission(client) - if err != nil { - log.Println("获取用户权限错误:", err) - h.ChatFail(c, err.Error()) - return - } - client.SetCodes(codes) - // 确保在函数返回时移除客户端并关闭连接 defer func() { h.Gw.RemoveClient(client.GetID()) @@ -192,52 +180,3 @@ func (s *ChatService) UsefulList(c *fiber.Ctx) error { return c.JSON(constants.UseFulMap) } - -// 从统一登录平台获取用户权限 -func (s *ChatService) GetUserPermission(client *gateway.Client) (codes []string, err error) { - var ( - request l_request.Request - ) - - // 系统编码 - systemCode := client.GetSysCode() - - // 检查系统编码是否配置 - if v, ok := s.cfg.PermissionConfig.SysPermission[systemCode]; !ok { - err = errors.SysErr("系统编码 %s 未配置", systemCode) - return - } else { - request.Url = v.PermissionURL - } - - request.Method = "GET" - request.Headers = map[string]string{ - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", - "Accept": "application/json, text/plain, */*", - "Authorization": "Bearer " + client.GetAuth(), - } - - // 发送请求 - res, err := request.Send() - if err != nil { - return - } - - // 检查响应状态码 - if res.StatusCode != http.StatusOK { - err = errors.SysErr("获取用户权限失败") - return - } - - type resp struct { - Codes []string `json:"codes"` - } - // 解析响应体 - var respBody resp - err = json.Unmarshal([]byte(res.Text), &respBody) - if err != nil { - return - } - - return respBody.Codes, nil -} diff --git a/internal/services/task.go b/internal/services/task.go index 380f027..3ace0d5 100644 --- a/internal/services/task.go +++ b/internal/services/task.go @@ -3,7 +3,6 @@ package services import ( "ai_scheduler/internal/biz" "ai_scheduler/internal/entitys" - "github.com/gofiber/fiber/v2" ) @@ -25,7 +24,15 @@ func (s *TaskService) Tasks(c *fiber.Ctx) error { return err } - result, err := s.taskBiz.TaskList(c.Context(), req) + auth := "" + if auths := c.GetReqHeaders()["Authorization"]; len(auths) > 0 { + auth = auths[0] + } + if auth == "" { + return fiber.ErrUnauthorized + } + + result, err := s.taskBiz.TaskList(c.Context(), req, auth) if err != nil { return err From 2cc897507a5e1ede23ee4d67fa768c03a6a001f8 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Tue, 25 Nov 2025 11:37:31 +0800 Subject: [PATCH 17/19] =?UTF-8?q?fix:=201.=20=E7=B3=BB=E7=BB=9F=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=8D=E8=B0=83=E6=95=B4=202.=203=E7=A7=8D=E5=94=AE?= =?UTF-8?q?=E5=90=8E=E5=8F=82=E6=95=B0=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/tools/zltx_order_after_reseller.go | 44 +++-- .../tools/zltx_order_after_reseller_batch.go | 182 ++++++++++++++++++ internal/tools/zltx_order_after_supplier.go | 43 ++--- 3 files changed, 227 insertions(+), 42 deletions(-) create mode 100644 internal/tools/zltx_order_after_reseller_batch.go diff --git a/internal/tools/zltx_order_after_reseller.go b/internal/tools/zltx_order_after_reseller.go index 26891be..612675e 100644 --- a/internal/tools/zltx_order_after_reseller.go +++ b/internal/tools/zltx_order_after_reseller.go @@ -23,7 +23,7 @@ func (t *ZltxOrderAfterSaleResellerTool) Name() string { } func (t *ZltxOrderAfterSaleResellerTool) Description() string { - return "直连天下上游供应商售后工具" + return "直连天下下游分销商普充订单售后工具" } func (t *ZltxOrderAfterSaleResellerTool) Definition() entitys.ToolDefinition { @@ -32,18 +32,18 @@ func (t *ZltxOrderAfterSaleResellerTool) Definition() entitys.ToolDefinition { 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": "售后订单号", - }, - }, + 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"}, }, }, @@ -52,7 +52,7 @@ func (t *ZltxOrderAfterSaleResellerTool) Definition() entitys.ToolDefinition { type ZltxOrderAfterSaleResellerRequest struct { OrderNumber []string `json:"orderNumber"` // 订单号 - Account []string `json:"account"` // 充值账号 + Account string `json:"account"` // 充值账号 OrderTimeStart string `json:"orderTimeStart"` // 订单执行开始时间 OrderTimeEnd string `json:"orderTimeEnd"` // 订单执行结束时间 AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 @@ -94,13 +94,13 @@ func (t *ZltxOrderAfterSaleResellerTool) Execute(ctx context.Context, requireDat if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { return err } - if len(req.OrderNumber) == 0 && len(req.Account) == 0 { - return fmt.Errorf("orderNumber or account are required") + if len(req.OrderNumber) == 0 && (req.Account == "" || req.OrderTimeStart == "") { + return fmt.Errorf("订单号 和 充值账号&订单执行时间 不能同时为空") } - return t.checkZltxOrderAfterSaleReseller(req.OrderNumber[0], requireData) + return t.checkZltxOrderAfterSaleReseller(req, requireData) } -func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(orderNumber string, requireData *entitys.RequireData) error { +func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(req ZltxOrderAfterSaleResellerRequest, requireData *entitys.RequireData) error { // req := l_request.Request{ // Url: t.config.BaseURL, // Headers: map[string]string{ @@ -124,6 +124,8 @@ func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(orderNu // if resp.Code != 0 { // return fmt.Errorf("check failed: %s", resp.Msg) // } + + // === mock start === resp := ZltxOrderAfterSaleResellerResponse{ Code: 0, Msg: "success", @@ -168,6 +170,12 @@ func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(orderNu }, }, } + + if len(req.OrderNumber) == 1 { + resp.Data = resp.Data[:1] + } + // === mock end === + jsonByte, err := json.Marshal(resp) if err != nil { return err diff --git a/internal/tools/zltx_order_after_reseller_batch.go b/internal/tools/zltx_order_after_reseller_batch.go new file mode 100644 index 0000000..ca5f1d6 --- /dev/null +++ b/internal/tools/zltx_order_after_reseller_batch.go @@ -0,0 +1,182 @@ +package tools + +import ( + "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" + "context" + "encoding/json" + "fmt" +) + +type ZltxOrderAfterSaleResellerBatchTool struct { + config config.ToolConfig +} + +// NewZltxOrderAfterSaleResellerBatchTool 创建售后订单预检工具 +func NewZltxOrderAfterSaleResellerBatchTool(config config.ToolConfig) *ZltxOrderAfterSaleResellerBatchTool { + return &ZltxOrderAfterSaleResellerBatchTool{config: config} +} + +// Name 返回工具名称 +func (t *ZltxOrderAfterSaleResellerBatchTool) Name() string { + return "zltxOrderAfterSaleResellerBatch" +} + +func (t *ZltxOrderAfterSaleResellerBatchTool) Description() string { + return "直连天下下游分销商批充订单售后工具" +} + +func (t *ZltxOrderAfterSaleResellerBatchTool) 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 ZltxOrderAfterSaleResellerBatchRequest struct { + OrderNumber []string `json:"orderNumber"` // 订单号 + AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 + AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 + AfterSalesReason string `json:"afterSalesReason"` // 售后原因 + ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 + ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 +} + +type ZltxOrderAfterSaleResellerBatchResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data []ZltxOrderAfterSaleResellerBatchData `json:"data"` +} + +type ZltxOrderAfterSaleResellerBatchData 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 map[int]string `json:"platforms"` + AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款 + Remark string `json:"remark"` // 售后原因 + AfterAmount float64 `json:"afterAmount"` // 售后金额 + ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无 + ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商 + IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后 +} + +func (t *ZltxOrderAfterSaleResellerBatchTool) Execute(ctx context.Context, requireData *entitys.RequireData) error { + var req ZltxOrderAfterSaleResellerBatchRequest + if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { + return err + } + if len(req.OrderNumber) == 0 { + return fmt.Errorf("批充订单号不能为空") + } + return t.checkZltxOrderAfterSaleResellerBatch(req, requireData) +} + +func (t *ZltxOrderAfterSaleResellerBatchTool) checkZltxOrderAfterSaleResellerBatch(req ZltxOrderAfterSaleResellerBatchRequest, 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 ZltxOrderAfterSaleResellerBatchResponse + // if err := json.Unmarshal(res.Content, &resp); err != nil { + // return err + // } + // if resp.Code != 0 { + // return fmt.Errorf("check failed: %s", resp.Msg) + // } + + // === mock start === + resp := ZltxOrderAfterSaleResellerBatchResponse{ + Code: 0, + Msg: "success", + Data: []ZltxOrderAfterSaleResellerBatchData{ + { + OrderType: 1, + OrderNumber: "846784115378364417", + OrderAmount: 0.1, + OrderPrice: 0.1, + SignCompany: 1, + OrderQuantity: 1, + ResellerID: 23329, + ResellerName: "分销商23329", + OurProductID: 106, + OurProductTitle: "爱奇艺黄金会员周卡", + Account: []string{"15516353308"}, + Platforms: map[int]string{4: "爱奇艺"}, + AfterType: 1, + Remark: "测试售后", + AfterAmount: 50, + ResponsibleType: 1, + IsExistsAfterSale: false, + }, + { + OrderType: 101, + OrderNumber: "846052057729867777", + OrderAmount: 23, + OrderPrice: 23, + SignCompany: 1, + OrderQuantity: 1, + ResellerID: 25629, + ResellerName: "二期财务分销商简称", + OurProductID: 104, + OurProductTitle: "优酷年卡", + Account: []string{"18380416326"}, + Platforms: map[int]string{1: "爱瓦力"}, + AfterType: 2, + Remark: "测试售后2", + AfterAmount: 30, + ResponsibleType: 2, + IsExistsAfterSale: false, + }, + }, + } + + if len(req.OrderNumber) == 1 { + resp.Data = resp.Data[:1] + } + // === mock end === + + 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/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index 2fca4cf..8c83ed0 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -51,13 +51,13 @@ func (t *ZltxOrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition { } 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"` // 售后金额 + SerialNumber []string `json:"serialNumber"` // 流水号 + Account string `json:"account"` // 充值账号 + OrderTimeStart string `json:"orderTimeStart"` // 订单执行开始时间 + OrderTimeEnd string `json:"orderTimeEnd"` // 订单执行结束时间 + AfterSalesReason string `json:"afterSalesReason"` // 售后原因 + AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额 + AfterType int `json:"afterType"` // 售后类型 1.加款 2.扣款 } type ZltxOrderAfterSaleSupplierResponse struct { @@ -89,13 +89,13 @@ func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireDat if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil { return err } - if req.OrderNumber == "" { - return fmt.Errorf("orderType and orderNumber are required") + if len(req.SerialNumber) == 0 && (req.Account == "" || req.OrderTimeStart == "") { + return fmt.Errorf("充值流水号 和 充值账号&订单执行时间 不能同时为空") } - return t.checkZltxOrderAfterSaleSupplier(req.OrderNumber, requireData) + return t.checkZltxOrderAfterSaleSupplier(req, requireData) } -func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNumber string, requireData *entitys.RequireData) error { +func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(req ZltxOrderAfterSaleSupplierRequest, requireData *entitys.RequireData) error { // req := l_request.Request{ // Url: t.config.BaseURL, // Headers: map[string]string{ @@ -119,23 +119,12 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu // if resp.Code != 0 { // return fmt.Errorf("check failed: %s", resp.Msg) // } + + // === mock start === resp := ZltxOrderAfterSaleSupplierResponse{ Code: 0, Msg: "success", Data: []ZltxOrderAfterSaleSupplierData{ - // { - // "serialNumber": "847465394004430849", - // "platformName": "爱奇艺", - // "signCompany": 1, - // "platformProductName": "爱奇艺官方周卡", - // "platformPrice": 6, - // "terminalAccount": "15516353308", - // "status": 1, - // "platformProductId": 2, - // "platformId": 4, - // "signCompanyName": "成都蓝色兄弟网络科技有限公司", - // "executeTime": 1763961931 - // } { SerialNumber: "847465394004430849", PlatformName: "爱奇艺", @@ -172,6 +161,12 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu }, }, } + + if len(req.SerialNumber) == 1 { + resp.Data = resp.Data[:1] + } + // === mock end === + jsonByte, err := json.Marshal(resp) if err != nil { return err From 2c46dcacaaaf5e3f481793db7b031c9613f1c3c0 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Tue, 25 Nov 2025 11:47:35 +0800 Subject: [PATCH 18/19] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/tools/zltx_order_after_reseller.go | 5 +++++ internal/tools/zltx_order_after_reseller_batch.go | 5 +++++ internal/tools/zltx_order_after_supplier.go | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/internal/tools/zltx_order_after_reseller.go b/internal/tools/zltx_order_after_reseller.go index 612675e..24c9781 100644 --- a/internal/tools/zltx_order_after_reseller.go +++ b/internal/tools/zltx_order_after_reseller.go @@ -97,6 +97,9 @@ func (t *ZltxOrderAfterSaleResellerTool) Execute(ctx context.Context, requireDat if len(req.OrderNumber) == 0 && (req.Account == "" || req.OrderTimeStart == "") { return fmt.Errorf("订单号 和 充值账号&订单执行时间 不能同时为空") } + + entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") + return t.checkZltxOrderAfterSaleReseller(req, requireData) } @@ -180,6 +183,8 @@ func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(req Zlt if err != nil { return err } + + entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) return nil } diff --git a/internal/tools/zltx_order_after_reseller_batch.go b/internal/tools/zltx_order_after_reseller_batch.go index ca5f1d6..73a75ca 100644 --- a/internal/tools/zltx_order_after_reseller_batch.go +++ b/internal/tools/zltx_order_after_reseller_batch.go @@ -94,6 +94,9 @@ func (t *ZltxOrderAfterSaleResellerBatchTool) Execute(ctx context.Context, requi if len(req.OrderNumber) == 0 { return fmt.Errorf("批充订单号不能为空") } + + entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") + return t.checkZltxOrderAfterSaleResellerBatch(req, requireData) } @@ -177,6 +180,8 @@ func (t *ZltxOrderAfterSaleResellerBatchTool) checkZltxOrderAfterSaleResellerBat if err != nil { return err } + + entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) return nil } diff --git a/internal/tools/zltx_order_after_supplier.go b/internal/tools/zltx_order_after_supplier.go index 8c83ed0..cbd4066 100644 --- a/internal/tools/zltx_order_after_supplier.go +++ b/internal/tools/zltx_order_after_supplier.go @@ -92,6 +92,9 @@ func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireDat if len(req.SerialNumber) == 0 && (req.Account == "" || req.OrderTimeStart == "") { return fmt.Errorf("充值流水号 和 充值账号&订单执行时间 不能同时为空") } + + entitys.ResLog(requireData.Ch, t.Name(), "正在拉取售后订单信息") + return t.checkZltxOrderAfterSaleSupplier(req, requireData) } @@ -171,6 +174,8 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(req Zlt if err != nil { return err } + + entitys.ResLog(requireData.Ch, t.Name(), "售后订单信息拉取完成") entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte)) return nil } From 33965dae4785b5023d65c0a3965b6f7e5538b55d Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Wed, 26 Nov 2025 10:51:10 +0800 Subject: [PATCH 19/19] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=A8=A1=E5=9E=8B=E4=B8=8E=E6=9D=83=E9=99=90=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/task.go | 30 ++++++++++++++---------------- internal/data/constants/task.go | 11 +++++++++++ internal/data/model/ai_task.gen.go | 28 +++++++++++++++------------- 3 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 internal/data/constants/task.go diff --git a/internal/biz/task.go b/internal/biz/task.go index e1a8689..1c9a39f 100644 --- a/internal/biz/task.go +++ b/internal/biz/task.go @@ -1,6 +1,7 @@ package biz import ( + "ai_scheduler/internal/data/constants" errors "ai_scheduler/internal/data/error" "ai_scheduler/internal/data/impl" "ai_scheduler/internal/data/model" @@ -8,10 +9,11 @@ import ( "ai_scheduler/internal/pkg/l_request" "context" "encoding/json" - "gorm.io/gorm/utils" "net/http" "strconv" + "gorm.io/gorm/utils" + "xorm.io/builder" "ai_scheduler/internal/config" @@ -33,9 +35,9 @@ func NewTaskBiz(conf *config.Config, taskRepo *impl.TaskImpl) *TaskBiz { func (t *TaskBiz) TaskList(ctx context.Context, req *entitys.TaskRequest, auth string) (list []model.AiTask, err error) { tasks := make([]model.AiTask, 0) cond := builder.NewCond() - cond = cond.And(builder.Eq{"status": 1}) - + cond = cond.And(builder.Eq{"status": constants.Enable}) cond = cond.And(builder.Eq{"sys_id": req.SysId}) + cond = cond.And(builder.Eq{"is_show": constants.IsSHOW}) err = t.taskRepo.GetRangeToMapStruct(&cond, &tasks) codes, err := t.GetUserPermission(req, auth) @@ -55,20 +57,16 @@ func (t *TaskBiz) TaskList(ctx context.Context, req *entitys.TaskRequest, auth s // 从统一登录平台获取用户权限 func (t *TaskBiz) GetUserPermission(req *entitys.TaskRequest, auth string) (codes []string, err error) { - var ( - request l_request.Request - ) - // 构建请求URL - request.Url = t.conf.PermissionConfig.PermissionURL + strconv.Itoa(int(req.SysId)) - - request.Method = "GET" - request.Headers = map[string]string{ - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", - "Accept": "application/json, text/plain, */*", - "Authorization": auth, + request := l_request.Request{ + Method: "GET", + Url: t.conf.PermissionConfig.PermissionURL + strconv.Itoa(int(req.SysId)), + Headers: map[string]string{ + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", + "Accept": "application/json, text/plain, */*", + "Authorization": auth, + }, } - // 发送请求 res, err := request.Send() if err != nil { @@ -84,7 +82,7 @@ func (t *TaskBiz) GetUserPermission(req *entitys.TaskRequest, auth string) (code type resp struct { Codes []string `json:"codes"` } - // 解析响应体 + // 解析响应体s var respBody resp err = json.Unmarshal([]byte(res.Text), &respBody) if err != nil { diff --git a/internal/data/constants/task.go b/internal/data/constants/task.go new file mode 100644 index 0000000..8ba18a9 --- /dev/null +++ b/internal/data/constants/task.go @@ -0,0 +1,11 @@ +package constants + +const ( + IsSHOW = 1 + NotShow = 2 +) + +const ( + Enable = 1 + Disable = 2 +) diff --git a/internal/data/model/ai_task.gen.go b/internal/data/model/ai_task.gen.go index 5599d78..e45f408 100644 --- a/internal/data/model/ai_task.gen.go +++ b/internal/data/model/ai_task.gen.go @@ -12,19 +12,21 @@ const TableNameAiTask = "ai_task" // AiTask mapped from table type AiTask struct { - TaskID int32 `gorm:"column:task_id;primaryKey" json:"task_id"` - SysID int32 `gorm:"column:sys_id;not null" json:"sys_id"` - Name string `gorm:"column:name;not null" json:"name"` - Index string `gorm:"column:index;not null" json:"index"` - Desc string `gorm:"column:desc;not null" json:"desc"` - Type int32 `gorm:"column:type;not null;comment:类型,1:api,2:知识库" json:"type"` // 类型,1:api,2:知识库 - Config string `gorm:"column:config" json:"config"` - CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"` - UpdateAt time.Time `gorm:"column:update_at;default:CURRENT_TIMESTAMP" json:"update_at"` - Status int32 `gorm:"column:status;not null;default:1" json:"status"` - DeleteAt time.Time `gorm:"column:delete_at" json:"delete_at"` - UseCase string `gorm:"column:use_case;not null" json:"use_case"` // 适用场景 - TagType int32 `gorm:"column:tag_type;not null;default:1" json:"tag_type"` // 标签类型 1.AI日常 2.AI查询 3.AI执行 + TaskID int32 `gorm:"column:task_id;primaryKey;autoIncrement:true" json:"task_id"` + SysID int32 `gorm:"column:sys_id;not null" json:"sys_id"` + Name string `gorm:"column:name;not null" json:"name"` + Index string `gorm:"column:index;not null" json:"index"` + Desc string `gorm:"column:desc;not null" json:"desc"` + UseCase string `gorm:"column:use_case;not null;comment:适用场景" json:"use_case"` // 适用场景 + TempPrompt string `gorm:"column:temp_prompt;not null;comment:提示词模板" json:"temp_prompt"` // 提示词模板 + Type int32 `gorm:"column:type;not null;default:1;comment:类型,1:api,2:知识库" json:"type"` // 类型,1:api,2:知识库 + Config string `gorm:"column:config" json:"config"` + TagType int32 `gorm:"column:tag_type;comment:标签类型:1.AI日常 2.AI查询 3.AI执行" json:"tag_type"` // 标签类型:1.AI日常 2.AI查询 3.AI执行 + CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"` + UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"` + IsShow int32 `gorm:"column:is_show;not null;default:1;comment:是否展示,1为展示,2为不展示" json:"is_show"` // 是否展示,1为展示,2为不展示 + Status int32 `gorm:"column:status;not null;default:1" json:"status"` + DeleteAt time.Time `gorm:"column:delete_at" json:"delete_at"` } // TableName AiTask's table name