diff --git a/internal/biz/system/actor.go b/internal/biz/system/actor.go deleted file mode 100644 index 0ddf910..0000000 --- a/internal/biz/system/actor.go +++ /dev/null @@ -1,19 +0,0 @@ -package system - -import "context" - -type actorContextKey struct{} - -type Actor struct { - UserID uint - AuthorityID uint -} - -func NewActorContext(ctx context.Context, actor Actor) context.Context { - return context.WithValue(ctx, actorContextKey{}, actor) -} - -func ActorFromContext(ctx context.Context) (Actor, bool) { - actor, ok := ctx.Value(actorContextKey{}).(Actor) - return actor, ok -} diff --git a/internal/biz/system/data_scope.go b/internal/biz/system/context.go similarity index 61% rename from internal/biz/system/data_scope.go rename to internal/biz/system/context.go index a4d5a93..fb6fb69 100644 --- a/internal/biz/system/data_scope.go +++ b/internal/biz/system/context.go @@ -2,6 +2,22 @@ package system import "context" +type actorContextKey struct{} + +type Actor struct { + UserID uint + AuthorityID uint +} + +func NewActorContext(ctx context.Context, actor Actor) context.Context { + return context.WithValue(ctx, actorContextKey{}, actor) +} + +func ActorFromContext(ctx context.Context) (Actor, bool) { + actor, ok := ctx.Value(actorContextKey{}).(Actor) + return actor, ok +} + type DataScope struct { All bool Scope int diff --git a/internal/data/payment/payment.go b/internal/data/payment/payment.go index 8264855..5aae2e4 100644 --- a/internal/data/payment/payment.go +++ b/internal/data/payment/payment.go @@ -29,6 +29,10 @@ func NewPaymentRepo(data Provider, config integrationbiz.PaymentConfigReader, fa } func (r *paymentRepo) values(ctx context.Context, provider string) (map[string]any, error) { + return r.readValues(ctx, provider, true) +} + +func (r *paymentRepo) readValues(ctx context.Context, provider string, requireEnabled bool) (map[string]any, error) { if r == nil || r.config == nil { return nil, errors.New("支付配置仓储未接入") } @@ -39,7 +43,10 @@ func (r *paymentRepo) values(ctx context.Context, provider string) (map[string]a } return nil, err } - if config == nil || !config.Enabled { + if config == nil { + return nil, errors.New("支付配置为空") + } + if requireEnabled && !config.Enabled { return nil, fmt.Errorf("支付渠道 %s 未启用", provider) } values := map[string]any{} @@ -284,24 +291,7 @@ func recordPaymentTestError(ctx context.Context, data Provider, provider, tradeN } func (r *paymentRepo) testRow(ctx context.Context, provider string) (map[string]any, error) { - if r == nil || r.config == nil { - return nil, errors.New("支付配置仓储未接入") - } - config, err := r.config.ReadPaymentConfig(ctx, provider) - if err != nil { - if errors.Is(err, integrationbiz.ErrPaymentConfigNotFound) { - return nil, bizpayment.ErrPaymentProviderNotFound - } - return nil, err - } - if config == nil { - return nil, errors.New("支付配置为空") - } - values := map[string]any{} - if err := json.Unmarshal(config.Values, &values); err != nil || values == nil { - return nil, errors.New("支付配置格式错误") - } - return values, nil + return r.readValues(ctx, provider, false) } func paymentTestRequest(provider string, values map[string]any) *bizpayment.PaymentRequest { diff --git a/internal/server/router/routes.go b/internal/server/router/routes.go index ffa87f0..fa75454 100644 --- a/internal/server/router/routes.go +++ b/internal/server/router/routes.go @@ -19,26 +19,31 @@ func (r *Routes) RegisterRoutes(public, private *gin.RouterGroup, engine *gin.En if r == nil || r.handlers == nil { return } - RegisterPublic(public, engine, r.handlers.Public) - RegisterUser(private, r.handlers.User) - RegisterNavigation(private, r.handlers.Navigation) - RegisterSession(private, r.handlers.Session) - RegisterAuthority(private, r.handlers.Authority) - RegisterMenu(private, r.handlers.Menu) - RegisterAPI(private, public, engine, r.handlers.API) - RegisterPermission(private, r.handlers.Permission) - RegisterOrganization(private, r.handlers.Organization) - RegisterDictionary(private, r.handlers.Dictionary) - RegisterParameter(private, r.handlers.Parameter) - RegisterAPIToken(private, r.handlers.APIToken) - RegisterSystemConfig(private, r.handlers.SystemConfig) - RegisterVersion(private, r.handlers.Version) - RegisterExport(private, public, r.handlers.Export) - RegisterAudit(private, public, r.handlers.Audit) - RegisterTask(private, r.handlers.Task) - RegisterMedia(private, r.handlers.Media) - RegisterAnnouncement(private, public, r.handlers.Announcement) - RegisterEmail(private, r.handlers.Email) - RegisterIntegrationConfig(private, r.handlers.IntegrationConfig) - RegisterPayment(private, public, r.handlers.Payment) + registrations := []func(){ + func() { RegisterPublic(public, engine, r.handlers.Public) }, + func() { RegisterUser(private, r.handlers.User) }, + func() { RegisterNavigation(private, r.handlers.Navigation) }, + func() { RegisterSession(private, r.handlers.Session) }, + func() { RegisterAuthority(private, r.handlers.Authority) }, + func() { RegisterMenu(private, r.handlers.Menu) }, + func() { RegisterAPI(private, public, engine, r.handlers.API) }, + func() { RegisterPermission(private, r.handlers.Permission) }, + func() { RegisterOrganization(private, r.handlers.Organization) }, + func() { RegisterDictionary(private, r.handlers.Dictionary) }, + func() { RegisterParameter(private, r.handlers.Parameter) }, + func() { RegisterAPIToken(private, r.handlers.APIToken) }, + func() { RegisterSystemConfig(private, r.handlers.SystemConfig) }, + func() { RegisterVersion(private, r.handlers.Version) }, + func() { RegisterExport(private, public, r.handlers.Export) }, + func() { RegisterAudit(private, public, r.handlers.Audit) }, + func() { RegisterTask(private, r.handlers.Task) }, + func() { RegisterMedia(private, r.handlers.Media) }, + func() { RegisterAnnouncement(private, public, r.handlers.Announcement) }, + func() { RegisterEmail(private, r.handlers.Email) }, + func() { RegisterIntegrationConfig(private, r.handlers.IntegrationConfig) }, + func() { RegisterPayment(private, public, r.handlers.Payment) }, + } + for _, register := range registrations { + register() + } }