fix(biz): 更新响应通道类型并优化-商品查询逻辑 将 handleTask 中的 ResponseData通道统一修改为 Response

- 在商品查询工具中增加对空数据的判断并返回错误- 修改测试用例中的参数以匹配实际接口需求
- 初始化 AiRouterBiz时新增 client 参数传递
This commit is contained in:
wuchao 2025-09-29 10:21:46 +08:00
parent 3f1a8a3c4c
commit e48ec38a96
2 changed files with 10 additions and 7 deletions

View File

@ -33,7 +33,7 @@ type configData struct {
func Test_Order(t *testing.T) {
routerBiz := in()
ch := make(chan entitys.ResponseData, 5)
ch := make(chan entitys.Response, 5)
defer close(ch)
err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"order_number":"822895927188791297"}`}, &model.AiTask{Config: `{"tool": "zltxOrderDetail", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`})
select {
@ -47,7 +47,7 @@ func Test_Order(t *testing.T) {
func Test_OrderLog(t *testing.T) {
routerBiz := in()
ch := make(chan entitys.ResponseData, 5)
ch := make(chan entitys.Response, 5)
defer close(ch)
err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"order_number":"822979421673758721","serial_number":"822979421979938817"}`}, &model.AiTask{Config: `{"tool": "zltxOrderDirectLog", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`})
t.Log(err)
@ -55,17 +55,17 @@ func Test_OrderLog(t *testing.T) {
func Test_ProductLog(t *testing.T) {
routerBiz := in()
ch := make(chan entitys.ResponseData, 5)
ch := make(chan entitys.Response, 5)
defer close(ch)
err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"id":"101","serial_number":"822979421979938817"}`}, &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":"李瑞上游测试20250918002"}`}, &model.AiTask{Config: `{"tool": "zltxProduct", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`})
t.Log(err)
}
func Test_ZltxStatistics(t *testing.T) {
routerBiz := in()
ch := make(chan entitys.ResponseData, 5)
ch := make(chan entitys.Response, 5)
defer close(ch)
err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"number":"15583730896"}`}, &model.AiTask{Config: `{"tool": "zltxOrderStatistics", "param": {"type": "object", "optional": [], "required": ["number"], "properties": {"number": {"type": "string", "description": "充值账号/分销商ID"}}}}`})
err := routerBiz.handleTask(ch, nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"number":"13737882067"}`}, &model.AiTask{Config: `{"tool": "zltxOrderStatistics", "param": {"type": "object", "optional": [], "required": ["number"], "properties": {"number": {"type": "string", "description": "充值账号/分销商ID"}}}}`})
t.Log(err)
}
@ -93,7 +93,7 @@ func in() *AiRouterBiz {
taskImpl := impl.NewTaskImpl(db)
chatImpl := impl.NewChatImpl(db)
safeChannelPool, _ := pkg.NewSafeChannelPool(configConfig)
routerBiz := NewAiRouterBiz(manager, sessionImpl, sysImpl, taskImpl, chatImpl, configConfig, utilOllama, safeChannelPool)
routerBiz := NewAiRouterBiz(manager, sessionImpl, sysImpl, taskImpl, chatImpl, configConfig, utilOllama, safeChannelPool, client)
return routerBiz
}

View File

@ -179,6 +179,9 @@ func (z ZltxProductTool) getZltxProduct(channel chan entitys.Response, c *websoc
if err := json.Unmarshal(res.Content, &respData); err != nil {
return fmt.Errorf("解析商品数据失败:%w", err)
}
if respData.Data.ID == 0 {
return fmt.Errorf("商品查询失败:暂无数据")
}
resp.Data.List = []ZltxProductData{respData.Data}
resp.Data.DataCount = 1
}