优化结构
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"
|
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 {
|
type DataScope struct {
|
||||||
All bool
|
All bool
|
||||||
Scope int
|
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) {
|
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 {
|
if r == nil || r.config == nil {
|
||||||
return nil, errors.New("支付配置仓储未接入")
|
return nil, errors.New("支付配置仓储未接入")
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +43,10 @@ func (r *paymentRepo) values(ctx context.Context, provider string) (map[string]a
|
||||||
}
|
}
|
||||||
return nil, err
|
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)
|
return nil, fmt.Errorf("支付渠道 %s 未启用", provider)
|
||||||
}
|
}
|
||||||
values := map[string]any{}
|
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) {
|
func (r *paymentRepo) testRow(ctx context.Context, provider string) (map[string]any, error) {
|
||||||
if r == nil || r.config == nil {
|
return r.readValues(ctx, provider, false)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func paymentTestRequest(provider string, values map[string]any) *bizpayment.PaymentRequest {
|
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 {
|
if r == nil || r.handlers == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
RegisterPublic(public, engine, r.handlers.Public)
|
registrations := []func(){
|
||||||
RegisterUser(private, r.handlers.User)
|
func() { RegisterPublic(public, engine, r.handlers.Public) },
|
||||||
RegisterNavigation(private, r.handlers.Navigation)
|
func() { RegisterUser(private, r.handlers.User) },
|
||||||
RegisterSession(private, r.handlers.Session)
|
func() { RegisterNavigation(private, r.handlers.Navigation) },
|
||||||
RegisterAuthority(private, r.handlers.Authority)
|
func() { RegisterSession(private, r.handlers.Session) },
|
||||||
RegisterMenu(private, r.handlers.Menu)
|
func() { RegisterAuthority(private, r.handlers.Authority) },
|
||||||
RegisterAPI(private, public, engine, r.handlers.API)
|
func() { RegisterMenu(private, r.handlers.Menu) },
|
||||||
RegisterPermission(private, r.handlers.Permission)
|
func() { RegisterAPI(private, public, engine, r.handlers.API) },
|
||||||
RegisterOrganization(private, r.handlers.Organization)
|
func() { RegisterPermission(private, r.handlers.Permission) },
|
||||||
RegisterDictionary(private, r.handlers.Dictionary)
|
func() { RegisterOrganization(private, r.handlers.Organization) },
|
||||||
RegisterParameter(private, r.handlers.Parameter)
|
func() { RegisterDictionary(private, r.handlers.Dictionary) },
|
||||||
RegisterAPIToken(private, r.handlers.APIToken)
|
func() { RegisterParameter(private, r.handlers.Parameter) },
|
||||||
RegisterSystemConfig(private, r.handlers.SystemConfig)
|
func() { RegisterAPIToken(private, r.handlers.APIToken) },
|
||||||
RegisterVersion(private, r.handlers.Version)
|
func() { RegisterSystemConfig(private, r.handlers.SystemConfig) },
|
||||||
RegisterExport(private, public, r.handlers.Export)
|
func() { RegisterVersion(private, r.handlers.Version) },
|
||||||
RegisterAudit(private, public, r.handlers.Audit)
|
func() { RegisterExport(private, public, r.handlers.Export) },
|
||||||
RegisterTask(private, r.handlers.Task)
|
func() { RegisterAudit(private, public, r.handlers.Audit) },
|
||||||
RegisterMedia(private, r.handlers.Media)
|
func() { RegisterTask(private, r.handlers.Task) },
|
||||||
RegisterAnnouncement(private, public, r.handlers.Announcement)
|
func() { RegisterMedia(private, r.handlers.Media) },
|
||||||
RegisterEmail(private, r.handlers.Email)
|
func() { RegisterAnnouncement(private, public, r.handlers.Announcement) },
|
||||||
RegisterIntegrationConfig(private, r.handlers.IntegrationConfig)
|
func() { RegisterEmail(private, r.handlers.Email) },
|
||||||
RegisterPayment(private, public, r.handlers.Payment)
|
func() { RegisterIntegrationConfig(private, r.handlers.IntegrationConfig) },
|
||||||
|
func() { RegisterPayment(private, public, r.handlers.Payment) },
|
||||||
|
}
|
||||||
|
for _, register := range registrations {
|
||||||
|
register()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue