fix: 新增工作流业务错误,调整工作流错误时输出
This commit is contained in:
parent
d8df571cce
commit
b87767ea5a
|
|
@ -15,6 +15,7 @@ var (
|
||||||
SysNotFound = &BusinessErr{code: 410, message: "未找到系统信息"}
|
SysNotFound = &BusinessErr{code: 410, message: "未找到系统信息"}
|
||||||
SysCodeNotFound = &BusinessErr{code: 411, message: "未找到系统编码"}
|
SysCodeNotFound = &BusinessErr{code: 411, message: "未找到系统编码"}
|
||||||
InvalidParam = &BusinessErr{code: InvalidParamCode, message: "无效参数"}
|
InvalidParam = &BusinessErr{code: InvalidParamCode, message: "无效参数"}
|
||||||
|
WorkflowError = &BusinessErr{code: 501, message: "工作流过程错误"}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -58,3 +59,7 @@ func (e *BusinessErr) Wrap(err error) *BusinessErr {
|
||||||
func KeyErr() *BusinessErr {
|
func KeyErr() *BusinessErr {
|
||||||
return &BusinessErr{code: KeyNotFound.code, message: KeyNotFound.message}
|
return &BusinessErr{code: KeyNotFound.code, message: KeyNotFound.message}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WorkflowErr(message string) *BusinessErr {
|
||||||
|
return NewBusinessErr(WorkflowError.code, message)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package hyt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ai_scheduler/internal/config"
|
"ai_scheduler/internal/config"
|
||||||
|
errorcode "ai_scheduler/internal/data/error"
|
||||||
toolManager "ai_scheduler/internal/domain/tools"
|
toolManager "ai_scheduler/internal/domain/tools"
|
||||||
toolPu "ai_scheduler/internal/domain/tools/hyt/product_upload"
|
toolPu "ai_scheduler/internal/domain/tools/hyt/product_upload"
|
||||||
"ai_scheduler/internal/domain/workflow/runtime"
|
"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)
|
output, err := runnable.Invoke(ctx, o.data)
|
||||||
if err != nil {
|
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)
|
fmt.Printf("workflow output: %v\n", output)
|
||||||
|
|
@ -235,10 +240,13 @@ func (o *productUpload) buildWorkflow(ctx context.Context) (compose.Runnable[*Pr
|
||||||
|
|
||||||
// 4. 合并/同步节点
|
// 4. 合并/同步节点
|
||||||
g.AddLambdaNode("merge_node", compose.InvokableLambda(func(ctx context.Context, state *ProductUploadContext) (*ProductUploadContext, error) {
|
g.AddLambdaNode("merge_node", compose.InvokableLambda(func(ctx context.Context, state *ProductUploadContext) (*ProductUploadContext, error) {
|
||||||
// 可以在这里做最终校验,例如必须有 SupplierId
|
// 最终校验
|
||||||
if state.UploadReq.SupplierId == 0 {
|
if state.UploadReq.SupplierId == 0 {
|
||||||
return nil, fmt.Errorf("供应商获取失败")
|
return nil, fmt.Errorf("供应商获取失败")
|
||||||
}
|
}
|
||||||
|
if state.UploadReq.WarehouseId == 0 {
|
||||||
|
return nil, fmt.Errorf("仓库获取失败")
|
||||||
|
}
|
||||||
return state, nil
|
return state, nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,15 +78,6 @@ type OrderAfterSaleResellerBatchData struct {
|
||||||
// ID 返回工作流唯一标识
|
// ID 返回工作流唯一标识
|
||||||
func (o *orderAfterSaleResellerBatch) ID() string { return "zltx.orderAfterSaleResellerBatch" }
|
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 调用原有编排工作流并规范化输出
|
// Invoke 调用原有编排工作流并规范化输出
|
||||||
func (o *orderAfterSaleResellerBatch) Invoke(ctx context.Context, rec *entitys.Recognize) (map[string]any, error) {
|
func (o *orderAfterSaleResellerBatch) Invoke(ctx context.Context, rec *entitys.Recognize) (map[string]any, error) {
|
||||||
// 构建工作流
|
// 构建工作流
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,6 @@ func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionServi
|
||||||
|
|
||||||
r := app.Group("api/v1/")
|
r := app.Group("api/v1/")
|
||||||
registerResponse(r)
|
registerResponse(r)
|
||||||
// 注册 CORS 中间件
|
|
||||||
r.Get("/health", func(c *fiber.Ctx) error {
|
r.Get("/health", func(c *fiber.Ctx) error {
|
||||||
c.Response().SetBody([]byte("1"))
|
c.Response().SetBody([]byte("1"))
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue