diff --git a/internal/data/error/error_code.go b/internal/data/error/error_code.go index 9d907e7..85abd88 100644 --- a/internal/data/error/error_code.go +++ b/internal/data/error/error_code.go @@ -15,6 +15,7 @@ var ( SysNotFound = &BusinessErr{code: 410, message: "未找到系统信息"} SysCodeNotFound = &BusinessErr{code: 411, message: "未找到系统编码"} InvalidParam = &BusinessErr{code: InvalidParamCode, message: "无效参数"} + WorkflowError = &BusinessErr{code: 501, message: "工作流过程错误"} ) const ( @@ -58,3 +59,7 @@ func (e *BusinessErr) Wrap(err error) *BusinessErr { func KeyErr() *BusinessErr { return &BusinessErr{code: KeyNotFound.code, message: KeyNotFound.message} } + +func WorkflowErr(message string) *BusinessErr { + return NewBusinessErr(WorkflowError.code, message) +} diff --git a/internal/domain/workflow/hyt/product_upload.go b/internal/domain/workflow/hyt/product_upload.go index 0a93ce1..de74977 100644 --- a/internal/domain/workflow/hyt/product_upload.go +++ b/internal/domain/workflow/hyt/product_upload.go @@ -2,6 +2,7 @@ package hyt import ( "ai_scheduler/internal/config" + errorcode "ai_scheduler/internal/data/error" toolManager "ai_scheduler/internal/domain/tools" toolPu "ai_scheduler/internal/domain/tools/hyt/product_upload" "ai_scheduler/internal/domain/workflow/runtime" @@ -50,7 +51,11 @@ func (o *productUpload) Invoke(ctx context.Context, rec *entitys.Recognize) (map // 工作流过程调用 output, err := runnable.Invoke(ctx, o.data) if err != nil { - return nil, err + errStr := err.Error() + if u := errors.Unwrap(err); u != nil { + errStr = u.Error() + } + return nil, errorcode.WorkflowErr(errStr) } fmt.Printf("workflow output: %v\n", output) @@ -235,10 +240,13 @@ func (o *productUpload) buildWorkflow(ctx context.Context) (compose.Runnable[*Pr // 4. 合并/同步节点 g.AddLambdaNode("merge_node", compose.InvokableLambda(func(ctx context.Context, state *ProductUploadContext) (*ProductUploadContext, error) { - // 可以在这里做最终校验,例如必须有 SupplierId + // 最终校验 if state.UploadReq.SupplierId == 0 { return nil, fmt.Errorf("供应商获取失败") } + if state.UploadReq.WarehouseId == 0 { + return nil, fmt.Errorf("仓库获取失败") + } return state, nil })) diff --git a/internal/domain/workflow/zltx/order_after_reseller_batch.go b/internal/domain/workflow/zltx/order_after_reseller_batch.go index 5e5fa51..ff21d84 100644 --- a/internal/domain/workflow/zltx/order_after_reseller_batch.go +++ b/internal/domain/workflow/zltx/order_after_reseller_batch.go @@ -78,15 +78,6 @@ type OrderAfterSaleResellerBatchData struct { // ID 返回工作流唯一标识 func (o *orderAfterSaleResellerBatch) ID() string { return "zltx.orderAfterSaleResellerBatch" } -// Schema 返回入参约束(用于校验/表单生成) -// func (o *orderAfterSaleResellerBatch) Schema() map[string]any { -// return map[string]any{ -// "type": "object", -// "properties": map[string]any{"orderNumber": map[string]any{"type": "array", "items": map[string]any{"type": "string"}}}, -// "required": []string{"orderNumber"}, -// } -// } - // Invoke 调用原有编排工作流并规范化输出 func (o *orderAfterSaleResellerBatch) Invoke(ctx context.Context, rec *entitys.Recognize) (map[string]any, error) { // 构建工作流 diff --git a/internal/server/router/router.go b/internal/server/router/router.go index 15e1554..091c85f 100644 --- a/internal/server/router/router.go +++ b/internal/server/router/router.go @@ -52,7 +52,6 @@ func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionServi r := app.Group("api/v1/") registerResponse(r) - // 注册 CORS 中间件 r.Get("/health", func(c *fiber.Ctx) error { c.Response().SetBody([]byte("1")) return nil