fix(biz): 更新响应通道类型并优化-商品查询逻辑 将 handleTask 中的 ResponseData通道统一修改为 Response
- 在商品查询工具中增加对空数据的判断并返回错误- 修改测试用例中的参数以匹配实际接口需求 - 初始化 AiRouterBiz时新增 client 参数传递
This commit is contained in:
parent
f17e10a0b3
commit
a1844bc818
|
@ -42,7 +42,7 @@ tools:
|
|||
zltxProduct:
|
||||
enabled: true
|
||||
base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/oursProduct"
|
||||
add_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/platformProduct/"
|
||||
add_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/platformProduct/getProductsByOfficialProductId"
|
||||
api_key: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ"
|
||||
zltxOrderStatistics:
|
||||
base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/direct/ai/search/"
|
||||
|
|
|
@ -57,7 +57,7 @@ func Test_ProductLog(t *testing.T) {
|
|||
routerBiz := in()
|
||||
ch := make(chan entitys.Response, 5)
|
||||
defer close(ch)
|
||||
err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"name":"李瑞上游测试20250918002"}`}, &model.AiTask{Config: `{"tool": "zltxProduct", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`})
|
||||
err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"name":"利楚测试"}`}, &model.AiTask{Config: `{"tool": "zltxProduct", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`})
|
||||
t.Log(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"ai_scheduler/internal/entitys"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gitea.cdlsxd.cn/self-tools/l_request"
|
||||
|
@ -190,7 +191,7 @@ func (z ZltxProductTool) getZltxProduct(channel chan entitys.Response, c *websoc
|
|||
for i := range resp.Data.List {
|
||||
// 调用 平台商品列表
|
||||
if resp.Data.List[i].AuthProductIds != "" {
|
||||
platformProductList := z.ExecutePlatformProductList(auth, resp.Data.List[i].AuthProductIds)
|
||||
platformProductList := z.ExecutePlatformProductList(auth, resp.Data.List[i].AuthProductIds, resp.Data.List[i].OfficialProductID)
|
||||
resp.Data.List[i].PlatformProductList = platformProductList
|
||||
}
|
||||
}
|
||||
|
@ -207,20 +208,94 @@ func (z ZltxProductTool) getZltxProduct(channel chan entitys.Response, c *websoc
|
|||
return nil
|
||||
}
|
||||
|
||||
func (z ZltxProductTool) ExecutePlatformProductList(auth string, authProductIds string) []map[string]any {
|
||||
type PlatformProductResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data []struct {
|
||||
ID int `json:"id"`
|
||||
PlatformID int `json:"platform_id"`
|
||||
OfficialProductID int `json:"official_product_id"`
|
||||
Weight int `json:"weight"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Discount string `json:"discount"`
|
||||
Price string `json:"price"`
|
||||
Extra string `json:"extra"`
|
||||
AccountType []string `json:"account_type"`
|
||||
Status int `json:"status"`
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
RebatePrice string `json:"rebate_price"`
|
||||
ExchangeType int `json:"exchange_type"`
|
||||
IsReportInfo int `json:"is_report_info"`
|
||||
Describe string `json:"describe"`
|
||||
PlatformAliasID int `json:"platform_alias_id"`
|
||||
Platform struct {
|
||||
ID int `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Name string `json:"name"`
|
||||
Status int `json:"status"`
|
||||
Weight int `json:"weight"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
SearchTime string `json:"search_time"`
|
||||
Balance string `json:"balance"`
|
||||
BalanceWarning string `json:"balance_warning"`
|
||||
StockType int `json:"stock_type"`
|
||||
IsIndependent int `json:"is_independent"`
|
||||
IndependentDeadline string `json:"independent_deadline"`
|
||||
CreateTime string `json:"create_time"`
|
||||
} `json:"platform"`
|
||||
} `json:"data"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
type PlatformData struct {
|
||||
ID int `json:"id"`
|
||||
PlatformID int `json:"platform_id"`
|
||||
OfficialProductID int `json:"official_product_id"`
|
||||
Weight int `json:"weight"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Discount string `json:"discount"`
|
||||
Price string `json:"price"`
|
||||
Extra string `json:"extra"`
|
||||
AccountType []string `json:"account_type"`
|
||||
Status int `json:"status"`
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
RebatePrice string `json:"rebate_price"`
|
||||
ExchangeType int `json:"exchange_type"`
|
||||
IsReportInfo int `json:"is_report_info"`
|
||||
Describe string `json:"describe"`
|
||||
PlatformAliasID int `json:"platform_alias_id"`
|
||||
Platform struct {
|
||||
ID int `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Name string `json:"name"`
|
||||
Status int `json:"status"`
|
||||
Weight int `json:"weight"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
SearchTime string `json:"search_time"`
|
||||
Balance string `json:"balance"`
|
||||
BalanceWarning string `json:"balance_warning"`
|
||||
StockType int `json:"stock_type"`
|
||||
IsIndependent int `json:"is_independent"`
|
||||
IndependentDeadline string `json:"independent_deadline"`
|
||||
CreateTime string `json:"create_time"`
|
||||
} `json:"platform"`
|
||||
}
|
||||
|
||||
func (z ZltxProductTool) ExecutePlatformProductList(auth string, authProductIds string, officialProductID int) []PlatformData {
|
||||
if authProductIds == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
//authProductIds 以逗号分割
|
||||
authProductIdList := strings.Split(authProductIds, ",")
|
||||
var result []map[string]any
|
||||
|
||||
for _, authProductId := range authProductIdList {
|
||||
var platformProductResponse map[string]any
|
||||
var platformProductResponse PlatformProductResponse
|
||||
req := l_request.Request{
|
||||
//https://gateway.dev.cdlsxd.cn/zltx_api/admin/platformProduct/{product_id}?id={product_id}
|
||||
Url: fmt.Sprintf("%s/%s?id=%s", z.config.AddURL, authProductId, authProductId),
|
||||
//https://gateway.dev.cdlsxd.cn/zltx_api/admin/platformProduct/getProductsByOfficialProductId?official_product_id=282&is_all=true
|
||||
Url: fmt.Sprintf("%s?official_product_id=%d&is_all=true", z.config.AddURL, officialProductID),
|
||||
Headers: map[string]string{
|
||||
"Authorization": fmt.Sprintf("Bearer %s", auth),
|
||||
},
|
||||
|
@ -237,16 +312,19 @@ func (z ZltxProductTool) ExecutePlatformProductList(auth string, authProductIds
|
|||
// 可以考虑记录日志而不是直接跳过
|
||||
continue
|
||||
}
|
||||
|
||||
// 只提取 data 部分
|
||||
if data, ok := platformProductResponse["data"]; ok {
|
||||
if dataMap, ok := data.(map[string]any); ok {
|
||||
result = append(result, dataMap)
|
||||
authProductIdInt, err := strconv.Atoi(authProductId)
|
||||
if err != nil {
|
||||
// 可以考虑记录日志而不是直接跳过
|
||||
continue
|
||||
}
|
||||
for _, platformProduct := range platformProductResponse.Data {
|
||||
if platformProduct.ID == authProductIdInt {
|
||||
return []PlatformData{platformProduct}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
return nil
|
||||
}
|
||||
|
||||
type ZltxProductPlatformProductList struct {
|
||||
|
|
Loading…
Reference in New Issue