Files
condflow/tests/fixtures/example_executor.go

115 lines
4.2 KiB
Go

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
}