208 lines
7.9 KiB
Plaintext
208 lines
7.9 KiB
Plaintext
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
|
|
}
|