From 15c3febe76c681f605903cc7ece074f12324ba6c Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Thu, 11 Dec 2025 16:41:46 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/do/handle.go | 26 ++++++++++- internal/data/constants/const.go | 9 ++-- internal/domain/workflow/manager.go | 1 + .../zltx/order_after_reseller_batch.go | 5 -- .../zltx/order_after_reseller_batch_test.go | 46 +++++++++++++++++++ 5 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 internal/domain/workflow/manager.go create mode 100644 internal/domain/workflow/zltx/order_after_reseller_batch_test.go diff --git a/internal/biz/do/handle.go b/internal/biz/do/handle.go index 2e2a313..fa7b3c5 100644 --- a/internal/biz/do/handle.go +++ b/internal/biz/do/handle.go @@ -7,10 +7,12 @@ import ( errors "ai_scheduler/internal/data/error" "ai_scheduler/internal/data/impl" "ai_scheduler/internal/data/model" + "ai_scheduler/internal/domain/workflow/zltx" "ai_scheduler/internal/entitys" "ai_scheduler/internal/gateway" "ai_scheduler/internal/pkg/l_request" "ai_scheduler/internal/pkg/mapstructure" + "ai_scheduler/internal/pkg/util" "ai_scheduler/internal/tools" "ai_scheduler/internal/tools_bot" "context" @@ -110,6 +112,8 @@ func (r *Handle) HandleMatch(ctx context.Context, client *gateway.Client, requir return r.handleKnowle(ctx, requireData, pointTask) case constants.TaskTypeBot: return r.handleBot(ctx, requireData, pointTask) + case constants.TaskTypeEinoWorkflow: + return r.handleEinoWorkflow(ctx, requireData, pointTask) default: return r.handleOtherTask(ctx, requireData) } @@ -265,11 +269,31 @@ func (r *Handle) handleApiTask(ctx context.Context, requireData *entitys.Require err = errors.NewBusinessErr(422, "api地址获取失败") return } + + entitys.ResLoading(requireData.Ch, requireData.Task.Index, "正在请求数据") + res, err := request.Send() if err != nil { return } - entitys.ResJson(requireData.Ch, "", res.Text) + entitys.ResJson(requireData.Ch, requireData.Task.Index, res.Text) + + return +} + +// eino 工作流 +func (r *Handle) handleEinoWorkflow(ctx context.Context, requireData *entitys.RequireData, task *model.AiTask) (err error) { + // token 写入ctx + ctx = util.SetTokenToContext(ctx, requireData.Auth) + + // 构建工作流 - todo 示例,后续抽象出来 + zltxWorkflow, err := zltx.BuildOrderAfterResellerBatchWorkflow(ctx, r.conf.Tools.ZltxOrderAfterSaleResellerBatch) + if err != nil { + return + } + + // 工作流执行 + _, err = zltxWorkflow.Invoke(ctx, zltx.OrderAfterSaleResellerBatchWorkflowInput{}) return } diff --git a/internal/data/constants/const.go b/internal/data/constants/const.go index f06e906..151d259 100644 --- a/internal/data/constants/const.go +++ b/internal/data/constants/const.go @@ -11,10 +11,11 @@ const ( type TaskType int32 const ( - TaskTypeApi TaskType = 1 - TaskTypeKnowle TaskType = 2 - TaskTypeFunc TaskType = 3 - TaskTypeBot TaskType = 4 + TaskTypeApi TaskType = 1 + TaskTypeKnowle TaskType = 2 + TaskTypeFunc TaskType = 3 + TaskTypeBot TaskType = 4 + TaskTypeEinoWorkflow TaskType = 5 // eino 工作流 ) type UseFul int32 diff --git a/internal/domain/workflow/manager.go b/internal/domain/workflow/manager.go new file mode 100644 index 0000000..0e59ea2 --- /dev/null +++ b/internal/domain/workflow/manager.go @@ -0,0 +1 @@ +package workflow diff --git a/internal/domain/workflow/zltx/order_after_reseller_batch.go b/internal/domain/workflow/zltx/order_after_reseller_batch.go index af41488..5c3081a 100644 --- a/internal/domain/workflow/zltx/order_after_reseller_batch.go +++ b/internal/domain/workflow/zltx/order_after_reseller_batch.go @@ -10,12 +10,10 @@ import ( ) type OrderAfterSaleResellerBatchWorkflowInput struct { - Token string `json:"token"` OrderNumber []string `json:"orderNumber"` } var ErrInvalidOrderNumbers = errors.New("orderNumber 不能为空") -var ErrMissingToken = errors.New("token 不能为空") func BuildOrderAfterResellerBatchWorkflow(ctx context.Context, cfg config.ToolConfig) (compose.Runnable[OrderAfterSaleResellerBatchWorkflowInput, toolZoarb.OrderAfterSaleResellerBatchData], error) { // 定义工作流、出入参 @@ -26,9 +24,6 @@ func BuildOrderAfterResellerBatchWorkflow(ctx context.Context, cfg config.ToolCo if len(in.OrderNumber) == 0 { return OrderAfterSaleResellerBatchWorkflowInput{}, ErrInvalidOrderNumbers } - if in.Token == "" { - return OrderAfterSaleResellerBatchWorkflowInput{}, ErrMissingToken - } return in, nil })) diff --git a/internal/domain/workflow/zltx/order_after_reseller_batch_test.go b/internal/domain/workflow/zltx/order_after_reseller_batch_test.go new file mode 100644 index 0000000..be56786 --- /dev/null +++ b/internal/domain/workflow/zltx/order_after_reseller_batch_test.go @@ -0,0 +1,46 @@ +package zltx + +import ( + "ai_scheduler/internal/config" + "context" + "errors" + "strings" + "testing" +) + +func TestOrderAfterResellerBatch_InvalidOrderNumbers(t *testing.T) { + ctx := context.Background() + cfg := config.ToolConfig{} + + run, err := BuildOrderAfterResellerBatchWorkflow(ctx, cfg) + if err != nil { + t.Fatalf("build workflow error: %v", err) + } + + _, err = run.Invoke(ctx, OrderAfterSaleResellerBatchWorkflowInput{}) + if err == nil { + t.Fatalf("expected error, got nil") + } + if !errors.Is(err, ErrInvalidOrderNumbers) { + t.Fatalf("expected ErrInvalidOrderNumbers, got %v", err) + } +} + +func TestOrderAfterResellerBatch_ContextTokenRequired(t *testing.T) { + ctx := context.Background() + cfg := config.ToolConfig{} + + run, err := BuildOrderAfterResellerBatchWorkflow(ctx, cfg) + if err != nil { + t.Fatalf("build workflow error: %v", err) + } + + in := OrderAfterSaleResellerBatchWorkflowInput{OrderNumber: []string{"123"}} + _, err = run.Invoke(ctx, in) + if err == nil { + t.Fatalf("expected error, got nil") + } + if !strings.Contains(err.Error(), "token 未注入") { + t.Fatalf("expected contains 'token 未注入', got %v", err) + } +}