init: 条件流引擎初始提交
This commit is contained in:
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
package fixtures
|
||||
|
||||
import (
|
||||
"git.fsdpf.net/go/condflow"
|
||||
"git.fsdpf.net/go/reflux"
|
||||
"git.fsdpf.net/go/reflux/valuex"
|
||||
"git.fsdpf.net/go/req"
|
||||
)
|
||||
|
||||
// ApproveExecutor 审批执行器
|
||||
type ApproveExecutor struct {
|
||||
res req.Resource
|
||||
}
|
||||
|
||||
// NewApproveExecutor 创建审批执行器
|
||||
func NewApproveExecutor(res req.Resource) *ApproveExecutor {
|
||||
return &ApproveExecutor{res: res}
|
||||
}
|
||||
|
||||
func (ae *ApproveExecutor) Res() req.Resource {
|
||||
return ae.res
|
||||
}
|
||||
|
||||
// AutoApprove 自动审批
|
||||
func (ae *ApproveExecutor) AutoApprove(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{
|
||||
"status": "approved",
|
||||
"method": "auto",
|
||||
}), nil
|
||||
}
|
||||
|
||||
// Manager 经理审批
|
||||
func (ae *ApproveExecutor) Manager(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{
|
||||
"status": "pending",
|
||||
"approver": "manager",
|
||||
}), nil
|
||||
}
|
||||
|
||||
// Director 总监审批
|
||||
func (ae *ApproveExecutor) Director(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{
|
||||
"status": "pending",
|
||||
"approver": "director",
|
||||
}), nil
|
||||
}
|
||||
|
||||
// Reject 拒绝
|
||||
func (ae *ApproveExecutor) Reject(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
reason, _ := cfg.Lookup("reason")
|
||||
return reflux.New(map[string]any{
|
||||
"status": "rejected",
|
||||
"reason": reason.String(),
|
||||
}), nil
|
||||
}
|
||||
Vendored
+114
@@ -0,0 +1,114 @@
|
||||
package fixtures
|
||||
|
||||
import (
|
||||
"git.fsdpf.net/go/condflow"
|
||||
"git.fsdpf.net/go/reflux"
|
||||
"git.fsdpf.net/go/reflux/valuex"
|
||||
"git.fsdpf.net/go/req"
|
||||
)
|
||||
|
||||
// ExampleExecutor 示例执行器
|
||||
type ExampleExecutor struct {
|
||||
res req.Resource
|
||||
}
|
||||
|
||||
// NewExampleExecutor 创建示例执行器
|
||||
func NewExampleExecutor(res req.Resource) *ExampleExecutor {
|
||||
return &ExampleExecutor{res: res}
|
||||
}
|
||||
|
||||
func (ee *ExampleExecutor) Res() req.Resource {
|
||||
return ee.res
|
||||
}
|
||||
|
||||
// AutoApprove 自动审批
|
||||
func (ee *ExampleExecutor) AutoApprove(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"status": "approved", "method": "auto"}), nil
|
||||
}
|
||||
|
||||
// ManagerApproval 经理审批
|
||||
func (ee *ExampleExecutor) ManagerApproval(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"status": "pending", "approver": "manager"}), nil
|
||||
}
|
||||
|
||||
// DirectorApproval 总监审批
|
||||
func (ee *ExampleExecutor) DirectorApproval(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"status": "pending", "approver": "director"}), nil
|
||||
}
|
||||
|
||||
// Reject 拒绝
|
||||
func (ee *ExampleExecutor) Reject(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
reason, _ := cfg.Lookup("reason")
|
||||
return reflux.New(map[string]any{"status": "rejected", "reason": reason.String()}), nil
|
||||
}
|
||||
|
||||
// VIPEmail 处理VIP邮件
|
||||
func (ee *ExampleExecutor) VIPEmail(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
template, _ := cfg.Lookup("template")
|
||||
return reflux.New(map[string]any{"sent": true, "template": template.String()}), nil
|
||||
}
|
||||
|
||||
// RegularEmail 处理普通邮件
|
||||
func (ee *ExampleExecutor) RegularEmail(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
template, _ := cfg.Lookup("template")
|
||||
return reflux.New(map[string]any{"sent": true, "template": template.String()}), nil
|
||||
}
|
||||
|
||||
// WelcomeEmail 处理欢迎邮件
|
||||
func (ee *ExampleExecutor) WelcomeEmail(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
template, _ := cfg.Lookup("template")
|
||||
return reflux.New(map[string]any{"sent": true, "template": template.String()}), nil
|
||||
}
|
||||
|
||||
// Skip 跳过处理
|
||||
func (ee *ExampleExecutor) Skip(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
reason, _ := cfg.Lookup("reason")
|
||||
return reflux.New(map[string]any{"skipped": true, "reason": reason.String()}), nil
|
||||
}
|
||||
|
||||
// ExpressShipping 处理快递配送
|
||||
func (ee *ExampleExecutor) ExpressShipping(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
fee, _ := cfg.Lookup("shipping_fee")
|
||||
return reflux.New(map[string]any{"shipping": "express", "fee": fee.Int()}), nil
|
||||
}
|
||||
|
||||
// StandardShipping 处理标准配送
|
||||
func (ee *ExampleExecutor) StandardShipping(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"shipping": "standard"}), nil
|
||||
}
|
||||
|
||||
// WarehouseTransfer 处理仓库调配
|
||||
func (ee *ExampleExecutor) WarehouseTransfer(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"transfer": true}), nil
|
||||
}
|
||||
|
||||
// NotifyCustomer 通知客户
|
||||
func (ee *ExampleExecutor) NotifyCustomer(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"notified": true}), nil
|
||||
}
|
||||
|
||||
// SendVerification 发送验证
|
||||
func (ee *ExampleExecutor) SendVerification(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"verification_sent": true}), nil
|
||||
}
|
||||
|
||||
// WaitVerification 等待验证
|
||||
func (ee *ExampleExecutor) WaitVerification(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"waiting": true}), nil
|
||||
}
|
||||
|
||||
// CreateCoupon 创建优惠券
|
||||
func (ee *ExampleExecutor) CreateCoupon(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
discount, _ := cfg.Lookup("discount")
|
||||
return reflux.New(map[string]any{"coupon_created": true, "discount": discount.Int()}), nil
|
||||
}
|
||||
|
||||
// GrantPoints 授予积分
|
||||
func (ee *ExampleExecutor) GrantPoints(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"points_granted": true}), nil
|
||||
}
|
||||
|
||||
// CreateUser 创建用户
|
||||
func (ee *ExampleExecutor) CreateUser(ctx condflow.Context, cfg valuex.Accessor) (reflux.R, error) {
|
||||
return reflux.New(map[string]any{"user_created": true}), nil
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package fixtures
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
|
||||
// "git.fsdpf.net/go/contracts"
|
||||
"git.fsdpf.net/go/contracts/base"
|
||||
// "git.fsdpf.net/go/db"
|
||||
"github.com/samber/do"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caches = append(caches, _ResCache{injector: func(app *do.Injector) {
|
||||
do.Provide(app, GetCondflowServiceProvider)
|
||||
|
||||
// 缓存 Condflow
|
||||
do.Provide(app, func(i *do.Injector) ([]base.Condflow, error) {
|
||||
defer useRefreshCache(i, "Condflow", func() error {
|
||||
do.Override(i, GetCondflowServiceProvider)
|
||||
do.Override(i, func(i *do.Injector) ([]base.Condflow, error) {
|
||||
return getCondflowCaches(i)
|
||||
})
|
||||
return nil
|
||||
})
|
||||
return getCondflowCaches(i)
|
||||
})
|
||||
}, priority: 0})
|
||||
}
|
||||
|
||||
func GetCondflowServiceProvider(container *do.Injector) (base.GetCondflow, error) {
|
||||
caches := do.MustInvoke[[]base.Condflow](container)
|
||||
|
||||
return func(code string) (base.Condflow, bool) {
|
||||
item, flag := lo.Find(caches, func(i base.Condflow) bool {
|
||||
return i.Code == code || i.Uuid == code
|
||||
})
|
||||
return item, flag
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getCondflowCaches(app *do.Injector) (items []base.Condflow, err error) {
|
||||
// TODO: 临时测试数据,等待资源表创建后从数据库读取
|
||||
// if res, ok := do.MustInvoke[contracts.GetResource](app)("Condflow"); !ok {
|
||||
// return items, fmt.Errorf("获取 Condflow 资源失败")
|
||||
// } else {
|
||||
// items = []base.Condflow{}
|
||||
// if e := res.GetDBTable(base.GetSystemUser()).
|
||||
// Select(
|
||||
// db.T("Condflow").All(),
|
||||
// ).
|
||||
// Order(db.I("Condflow.id").Asc()).
|
||||
// ScanStructs(&items); e != nil {
|
||||
// err = fmt.Errorf("获取 Condflow 资源失败, %w", e)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
items = []base.Condflow{
|
||||
{
|
||||
Uuid: "550e8400-e29b-41d4-a716-446655440001",
|
||||
Name: "用户审批流程",
|
||||
Code: "user-approval-flow",
|
||||
Comment: "处理用户申请的审批流程,根据金额和信用评分自动分配审批策略",
|
||||
Params: []base.CondflowParam{
|
||||
{Name: "申请金额", Code: "amount", DataType: "decimal", IsRequired: true, Comment: "申请的金额"},
|
||||
{Name: "用户信息", Code: "user", DataType: "json", IsRequired: true, Comment: "用户详细信息"},
|
||||
},
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "550e8400-e29b-41d4-a716-446655440002",
|
||||
Name: "邮件营销活动流程",
|
||||
Code: "email-campaign-flow",
|
||||
Comment: "根据用户等级和活跃度自动发送不同类型的营销邮件",
|
||||
Params: []base.CondflowParam{
|
||||
{Name: "用户信息", Code: "user", DataType: "json", IsRequired: true, Comment: "用户详细信息"},
|
||||
},
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "550e8400-e29b-41d4-a716-446655440003",
|
||||
Name: "订单处理流程",
|
||||
Code: "order-processing-flow",
|
||||
Comment: "订单自动化处理流程,包括配送方式选择和客户通知",
|
||||
Params: []base.CondflowParam{
|
||||
{Name: "订单信息", Code: "order", DataType: "json", IsRequired: true, Comment: "订单详细信息"},
|
||||
{Name: "用户信息", Code: "user", DataType: "json", IsRequired: true, Comment: "下单用户信息"},
|
||||
},
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
package fixtures
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
|
||||
// "git.fsdpf.net/go/contracts"
|
||||
"git.fsdpf.net/go/contracts/base"
|
||||
// "git.fsdpf.net/go/db"
|
||||
"github.com/samber/do"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caches = append(caches, _ResCache{injector: func(app *do.Injector) {
|
||||
do.Provide(app, GetCondflowCasesServiceProvider)
|
||||
|
||||
// 缓存 CondflowCase
|
||||
do.Provide(app, func(i *do.Injector) ([]base.CondflowCase, error) {
|
||||
defer useRefreshCache(i, "CondflowCase", func() error {
|
||||
do.Override(i, GetCondflowCasesServiceProvider)
|
||||
do.Override(i, func(i *do.Injector) ([]base.CondflowCase, error) {
|
||||
return getCondflowCaseCaches(i)
|
||||
})
|
||||
return nil
|
||||
})
|
||||
return getCondflowCaseCaches(i)
|
||||
})
|
||||
}, priority: 0})
|
||||
}
|
||||
|
||||
func GetCondflowCasesServiceProvider(container *do.Injector) (base.GetCondflowCases, error) {
|
||||
caches := do.MustInvoke[[]base.CondflowCase](container)
|
||||
|
||||
return func(uuid string) []base.CondflowCase {
|
||||
items := lo.Filter(caches, func(item base.CondflowCase, _ int) bool {
|
||||
return item.CondflowUuid == uuid
|
||||
})
|
||||
|
||||
return items
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getCondflowCaseCaches(app *do.Injector) (items []base.CondflowCase, err error) {
|
||||
// TODO: 临时测试数据,等待资源表创建后从数据库读取
|
||||
// if res, ok := do.MustInvoke[contracts.GetResource](app)("CondflowCase"); !ok {
|
||||
// return items, fmt.Errorf("获取 CondflowCase 资源失败")
|
||||
// } else {
|
||||
// items = []base.CondflowCase{}
|
||||
// if e := res.GetDBTable(base.GetSystemUser()).
|
||||
// Select(
|
||||
// db.T("CondflowCase").All(),
|
||||
// ).
|
||||
// Order(db.I("CondflowCase.priority").Desc(), db.I("CondflowCase.id").Asc()).
|
||||
// ScanStructs(&items); e != nil {
|
||||
// err = fmt.Errorf("获取 CondflowCase 资源失败, %w", e)
|
||||
// }
|
||||
// }
|
||||
items = []base.CondflowCase{
|
||||
// 用户审批流程的 cases
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440001",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440001",
|
||||
Name: "低信用拒绝",
|
||||
Code: "reject-low-credit",
|
||||
Priority: 200,
|
||||
Action: "Approval/ApproveExecutor@Reject",
|
||||
Config: map[string]any{"reason": "信用评分不足", "notify": true, "suggest_retry": false},
|
||||
NextCaseOnSuccess: false,
|
||||
NextFlowUuid: "",
|
||||
Comment: "信用评分低于60,直接拒绝",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440002",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440001",
|
||||
Name: "小额自动审批",
|
||||
Code: "auto-approve-small",
|
||||
Priority: 100,
|
||||
Action: "Approval/ApproveExecutor@AutoApprove",
|
||||
Config: map[string]any{"notify": true, "message": "申请已自动通过"},
|
||||
NextCaseOnSuccess: false,
|
||||
NextFlowUuid: "",
|
||||
Comment: "金额 <= 1000,自动通过",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440003",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440001",
|
||||
Name: "经理审批",
|
||||
Code: "manager-approval",
|
||||
Priority: 90,
|
||||
Action: "Approval/ApproveExecutor@Manager",
|
||||
Config: map[string]any{"approver_role": "manager", "timeout_hours": 24, "notify": true},
|
||||
NextCaseOnSuccess: false,
|
||||
NextFlowUuid: "",
|
||||
Comment: "1000 < 金额 <= 10000,需要经理审批",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440004",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440001",
|
||||
Name: "总监审批",
|
||||
Code: "director-approval",
|
||||
Priority: 80,
|
||||
Action: "Approval/ApproveExecutor@Director",
|
||||
Config: map[string]any{"approver_role": "director", "timeout_hours": 48, "notify": true, "cc_roles": []string{"manager", "ceo"}},
|
||||
NextCaseOnSuccess: false,
|
||||
NextFlowUuid: "",
|
||||
Comment: "金额 > 10000,需要总监审批",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
|
||||
// 邮件营销活动流程的 cases
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440005",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440002",
|
||||
Name: "跳过未订阅用户",
|
||||
Code: "skip-unsubscribed",
|
||||
Priority: 200,
|
||||
Action: "Marketing/EmailExecutor@Skip",
|
||||
Config: map[string]any{"reason": "用户未订阅营销邮件", "log": true},
|
||||
NextCaseOnSuccess: false,
|
||||
NextFlowUuid: "",
|
||||
Comment: "未订阅营销邮件的用户跳过",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440006",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440002",
|
||||
Name: "VIP 用户营销",
|
||||
Code: "vip-campaign",
|
||||
Priority: 100,
|
||||
Action: "Marketing/EmailExecutor@VIP",
|
||||
Config: map[string]any{"template": "vip-exclusive-offer", "discount": 30, "valid_days": 30, "priority": "high"},
|
||||
NextCaseOnSuccess: false,
|
||||
NextFlowUuid: "",
|
||||
Comment: "VIP 用户发送专属优惠",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440007",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440002",
|
||||
Name: "新用户欢迎",
|
||||
Code: "new-user-welcome",
|
||||
Priority: 90,
|
||||
Action: "Marketing/EmailExecutor@Welcome",
|
||||
Config: map[string]any{"template": "welcome-new-user", "coupon_code": "WELCOME2024", "discount": 10},
|
||||
NextCaseOnSuccess: false,
|
||||
NextFlowUuid: "",
|
||||
Comment: "新注册用户发送欢迎邮件",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
|
||||
// 订单处理流程的 cases
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440008",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440003",
|
||||
Name: "VIP 订单优先处理",
|
||||
Code: "premium-order",
|
||||
Priority: 100,
|
||||
Action: "Order/ShippingExecutor@Express",
|
||||
Config: map[string]any{"shipping_method": "express", "shipping_fee": 0, "priority": "high", "gift_wrapping": true},
|
||||
NextCaseOnSuccess: true, // 继续执行通知客户
|
||||
NextFlowUuid: "",
|
||||
Comment: "高价值 VIP 订单加急处理",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440009",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440003",
|
||||
Name: "标准配送",
|
||||
Code: "standard-order",
|
||||
Priority: 50,
|
||||
Action: "Order/ShippingExecutor@Standard",
|
||||
Config: map[string]any{"shipping_method": "standard", "estimated_days": 3},
|
||||
NextCaseOnSuccess: false,
|
||||
NextFlowUuid: "",
|
||||
Comment: "普通订单标准配送",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "case-550e8400-e29b-41d4-a716-446655440010",
|
||||
CondflowUuid: "550e8400-e29b-41d4-a716-446655440003",
|
||||
Name: "通知客户",
|
||||
Code: "notify-customer",
|
||||
Priority: 40,
|
||||
Action: "Order/NotificationExecutor@Notify",
|
||||
Config: map[string]any{"channels": []string{"email", "sms"}, "template": "order-confirmed", "immediate": true},
|
||||
NextCaseOnSuccess: false,
|
||||
NextFlowUuid: "",
|
||||
Comment: "订单确认后通知客户",
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
package fixtures
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
|
||||
// "git.fsdpf.net/go/contracts"
|
||||
|
||||
"git.fsdpf.net/go/contracts/base"
|
||||
// "git.fsdpf.net/go/db"
|
||||
"github.com/samber/do"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caches = append(caches, _ResCache{injector: func(app *do.Injector) {
|
||||
do.Provide(app, GetCondflowDecisionServiceProvider)
|
||||
|
||||
// 缓存 CondflowDecision
|
||||
do.Provide(app, func(i *do.Injector) ([]base.CondflowDecision, error) {
|
||||
defer useRefreshCache(i, "CondflowDecision", func() error {
|
||||
do.Override(i, GetCondflowDecisionServiceProvider)
|
||||
do.Override(i, func(i *do.Injector) ([]base.CondflowDecision, error) {
|
||||
return getCondflowDecisionCaches(i)
|
||||
})
|
||||
return nil
|
||||
})
|
||||
return getCondflowDecisionCaches(i)
|
||||
})
|
||||
}, priority: 0})
|
||||
}
|
||||
|
||||
func GetCondflowDecisionServiceProvider(container *do.Injector) (base.GetCondflowDecision, error) {
|
||||
caches := do.MustInvoke[[]base.CondflowDecision](container)
|
||||
|
||||
return func(code string) (base.CondflowDecision, bool) {
|
||||
item, flag := lo.Find(caches, func(i base.CondflowDecision) bool {
|
||||
return i.Code == code || i.Uuid == code
|
||||
})
|
||||
return item, flag
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getCondflowDecisionCaches(app *do.Injector) (items []base.CondflowDecision, err error) {
|
||||
// TODO: 临时测试数据,等待资源表创建后从数据库读取
|
||||
// if res, ok := do.MustInvoke[contracts.GetResource](app)("CondflowDecision"); !ok {
|
||||
// return items, fmt.Errorf("获取 CondflowDecision 资源失败")
|
||||
// } else {
|
||||
// items = []base.CondflowDecision{}
|
||||
// if e := res.GetDBTable(base.GetSystemUser()).
|
||||
// Select(
|
||||
// db.T("CondflowDecision").All(),
|
||||
// ).
|
||||
// Order(db.I("CondflowDecision.id").Asc()).
|
||||
// ScanStructs(&items); e != nil {
|
||||
// err = fmt.Errorf("获取 CondflowDecision 资源失败, %w", e)
|
||||
// }
|
||||
// }
|
||||
items = []base.CondflowDecision{
|
||||
{
|
||||
Uuid: "exec-550e8400-e29b-41d4-a716-446655440001",
|
||||
ResourceUuid: "550e8400-e29b-41d4-a716-446655440100", // Approval 资源 UUID
|
||||
Name: "审批执行器",
|
||||
Code: "ApproveDecision",
|
||||
Comment: "处理各类审批操作的执行器",
|
||||
Actions: []base.CondflowDecisionAction{
|
||||
{
|
||||
Name: "自动审批",
|
||||
Code: "AutoApprove",
|
||||
ConfigSchema: map[string]any{
|
||||
"notify": map[string]any{"type": "boolean", "default": true, "description": "是否发送通知"},
|
||||
"message": map[string]any{"type": "string", "description": "通知消息内容"},
|
||||
},
|
||||
Comment: "小额申请自动审批通过",
|
||||
},
|
||||
{
|
||||
Name: "经理审批",
|
||||
Code: "Manager",
|
||||
ConfigSchema: map[string]any{
|
||||
"approver_role": map[string]any{"type": "string", "default": "manager", "description": "审批人角色"},
|
||||
"timeout_hours": map[string]any{"type": "integer", "default": 24, "description": "审批超时时间(小时)"},
|
||||
"notify": map[string]any{"type": "boolean", "default": true, "description": "是否发送通知"},
|
||||
},
|
||||
Comment: "中额申请需要经理审批",
|
||||
},
|
||||
{
|
||||
Name: "总监审批",
|
||||
Code: "Director",
|
||||
ConfigSchema: map[string]any{
|
||||
"approver_role": map[string]any{"type": "string", "default": "director", "description": "审批人角色"},
|
||||
"timeout_hours": map[string]any{"type": "integer", "default": 48, "description": "审批超时时间(小时)"},
|
||||
"notify": map[string]any{"type": "boolean", "default": true, "description": "是否发送通知"},
|
||||
"cc_roles": map[string]any{"type": "array", "description": "抄送角色列表"},
|
||||
},
|
||||
Comment: "大额申请需要总监审批",
|
||||
},
|
||||
{
|
||||
Name: "拒绝",
|
||||
Code: "Reject",
|
||||
ConfigSchema: map[string]any{
|
||||
"reason": map[string]any{"type": "string", "required": true, "description": "拒绝原因"},
|
||||
"notify": map[string]any{"type": "boolean", "default": true, "description": "是否发送通知"},
|
||||
"suggest_retry": map[string]any{"type": "boolean", "default": false, "description": "是否建议重试"},
|
||||
},
|
||||
Comment: "拒绝申请",
|
||||
},
|
||||
},
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "exec-550e8400-e29b-41d4-a716-446655440002",
|
||||
ResourceUuid: "550e8400-e29b-41d4-a716-446655440200", // Marketing 资源 UUID
|
||||
Name: "邮件营销执行器",
|
||||
Code: "EmailDecision",
|
||||
Comment: "处理邮件营销活动的执行器",
|
||||
Actions: []base.CondflowDecisionAction{
|
||||
{
|
||||
Name: "VIP 邮件",
|
||||
Code: "VIP",
|
||||
ConfigSchema: map[string]any{
|
||||
"template": map[string]any{"type": "string", "required": true, "description": "邮件模板"},
|
||||
"subject": map[string]any{"type": "string", "description": "邮件主题"},
|
||||
"discount": map[string]any{"type": "integer", "description": "折扣百分比"},
|
||||
"valid_days": map[string]any{"type": "integer", "description": "有效天数"},
|
||||
"priority": map[string]any{"type": "string", "enum": []string{"low", "normal", "high"}, "description": "优先级"},
|
||||
"attachments": map[string]any{"type": "array", "description": "附件列表"},
|
||||
},
|
||||
Comment: "发送 VIP 专属营销邮件",
|
||||
},
|
||||
{
|
||||
Name: "欢迎邮件",
|
||||
Code: "Welcome",
|
||||
ConfigSchema: map[string]any{
|
||||
"template": map[string]any{"type": "string", "required": true, "description": "邮件模板"},
|
||||
"subject": map[string]any{"type": "string", "description": "邮件主题"},
|
||||
"coupon_code": map[string]any{"type": "string", "description": "优惠券代码"},
|
||||
"discount": map[string]any{"type": "integer", "description": "折扣百分比"},
|
||||
"trigger_delay": map[string]any{"type": "string", "description": "延迟发送时间"},
|
||||
},
|
||||
Comment: "发送新用户欢迎邮件",
|
||||
},
|
||||
{
|
||||
Name: "跳过",
|
||||
Code: "Skip",
|
||||
ConfigSchema: map[string]any{
|
||||
"reason": map[string]any{"type": "string", "description": "跳过原因"},
|
||||
"log": map[string]any{"type": "boolean", "default": true, "description": "是否记录日志"},
|
||||
},
|
||||
Comment: "跳过邮件发送",
|
||||
},
|
||||
},
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "exec-550e8400-e29b-41d4-a716-446655440003",
|
||||
ResourceUuid: "550e8400-e29b-41d4-a716-446655440300", // Order 资源 UUID
|
||||
Name: "配送执行器",
|
||||
Code: "ShippingDecision",
|
||||
Comment: "处理订单配送的执行器",
|
||||
Actions: []base.CondflowDecisionAction{
|
||||
{
|
||||
Name: "加急配送",
|
||||
Code: "Express",
|
||||
ConfigSchema: map[string]any{
|
||||
"shipping_method": map[string]any{"type": "string", "default": "express", "description": "配送方式"},
|
||||
"shipping_fee": map[string]any{"type": "number", "description": "配送费用"},
|
||||
"priority": map[string]any{"type": "string", "enum": []string{"normal", "high", "urgent"}, "description": "优先级"},
|
||||
"gift_wrapping": map[string]any{"type": "boolean", "default": false, "description": "是否礼品包装"},
|
||||
"insurance": map[string]any{"type": "boolean", "default": false, "description": "是否购买保险"},
|
||||
},
|
||||
Comment: "加急配送服务",
|
||||
},
|
||||
{
|
||||
Name: "标准配送",
|
||||
Code: "Standard",
|
||||
ConfigSchema: map[string]any{
|
||||
"shipping_method": map[string]any{"type": "string", "default": "standard", "description": "配送方式"},
|
||||
"estimated_days": map[string]any{"type": "integer", "default": 3, "description": "预计送达天数"},
|
||||
},
|
||||
Comment: "标准配送服务",
|
||||
},
|
||||
},
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
{
|
||||
Uuid: "exec-550e8400-e29b-41d4-a716-446655440004",
|
||||
ResourceUuid: "550e8400-e29b-41d4-a716-446655440300", // Order 资源 UUID
|
||||
Name: "通知执行器",
|
||||
Code: "NotificationDecision",
|
||||
Comment: "处理客户通知的执行器",
|
||||
Actions: []base.CondflowDecisionAction{
|
||||
{
|
||||
Name: "发送通知",
|
||||
Code: "Notify",
|
||||
ConfigSchema: map[string]any{
|
||||
"channels": map[string]any{"type": "array", "required": true, "description": "通知渠道列表"},
|
||||
"template": map[string]any{"type": "string", "required": true, "description": "通知模板"},
|
||||
"immediate": map[string]any{"type": "boolean", "default": true, "description": "是否立即发送"},
|
||||
},
|
||||
Comment: "向客户发送通知",
|
||||
},
|
||||
},
|
||||
CreatedAt: "2024-01-01 00:00:00",
|
||||
UpdatedAt: "2024-01-01 00:00:00",
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user