优化结构
This commit is contained in:
parent
bfb6295153
commit
a16d362bb5
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue