212 lines
8.3 KiB
Plaintext
212 lines
8.3 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, 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
|
|
}
|