优化结构
This commit is contained in:
@@ -3,6 +3,8 @@ package integration
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"kra/internal/integration/runtimeconfig"
|
||||
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
// Provider is the minimal database/runtime seam for integration configuration.
|
||||
@@ -10,3 +12,5 @@ type Provider interface {
|
||||
DB() *gorm.DB
|
||||
IntegrationRuntime() *runtimeconfig.Store
|
||||
}
|
||||
|
||||
var ProviderSet = wire.NewSet(NewIntegrationConfigRepo, NewPaymentConfigReader)
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package integration
|
||||
|
||||
import "github.com/google/wire"
|
||||
|
||||
var ProviderSet = wire.NewSet(NewIntegrationConfigRepo, NewPaymentConfigReader)
|
||||
@@ -424,15 +424,15 @@ func paymentCreateRequiresNotifyURL(provider string, extra, config map[string]an
|
||||
normalized := strings.NewReplacer(".", "_", "-", "_", " ", "_").Replace(strings.ToLower(strings.TrimSpace(value)))
|
||||
switch provider {
|
||||
case bizpayment.PaymentAlipay, bizpayment.PaymentAlipayV3:
|
||||
return !contains([]string{"pay", "trade_pay", "alipay_trade_pay", "barcode", "barcode_pay", "micropay", "face_to_face"}, normalized)
|
||||
return !paymentkit.ContainsFold([]string{"pay", "trade_pay", "alipay_trade_pay", "barcode", "barcode_pay", "micropay", "face_to_face"}, normalized)
|
||||
case bizpayment.PaymentWechatV2:
|
||||
return !contains([]string{"micropay", "micro_pay", "barcode", "barcode_pay", "pay_code", "payment_code"}, normalized)
|
||||
return !paymentkit.ContainsFold([]string{"micropay", "micro_pay", "barcode", "barcode_pay", "pay_code", "payment_code"}, normalized)
|
||||
case bizpayment.PaymentWechatV3:
|
||||
return !contains([]string{"micropay", "micro_pay", "codepay", "code_pay", "barcode", "barcode_pay", "facepay", "face_pay"}, normalized)
|
||||
return !paymentkit.ContainsFold([]string{"micropay", "micro_pay", "codepay", "code_pay", "barcode", "barcode_pay", "facepay", "face_pay"}, normalized)
|
||||
case bizpayment.PaymentQQ:
|
||||
return !contains([]string{"micropay", "micro_pay", "barcode", "barcode_pay"}, normalized)
|
||||
return !paymentkit.ContainsFold([]string{"micropay", "micro_pay", "barcode", "barcode_pay"}, normalized)
|
||||
case bizpayment.PaymentLakala:
|
||||
return !contains([]string{"retail", "retail_pay", "micropay", "barcode"}, normalized)
|
||||
return !paymentkit.ContainsFold([]string{"retail", "retail_pay", "micropay", "barcode"}, normalized)
|
||||
default:
|
||||
return true
|
||||
}
|
||||
@@ -516,12 +516,3 @@ func paymentCallbackAck(provider string, values map[string]any, success bool) bi
|
||||
}
|
||||
return ack
|
||||
}
|
||||
|
||||
func contains(values []string, value string) bool {
|
||||
for _, item := range values {
|
||||
if item == value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
package payment
|
||||
|
||||
import "gorm.io/gorm"
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
// Provider is the narrow persistence seam required by payment repositories.
|
||||
// Keeping it here lets payment remain an independent data module.
|
||||
type Provider interface {
|
||||
DB() *gorm.DB
|
||||
}
|
||||
|
||||
// ProviderSet wires payment persistence repositories.
|
||||
var ProviderSet = wire.NewSet(NewPaymentRepo, NewPaymentOrderRepo)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package payment
|
||||
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSet wires payment persistence repositories.
|
||||
var ProviderSet = wire.NewSet(NewPaymentRepo, NewPaymentOrderRepo)
|
||||
@@ -71,7 +71,7 @@ func (r *announcementRepo) List(ctx context.Context, filter system.AnnouncementF
|
||||
if filter.StartCreatedAt != nil && filter.EndCreatedAt != nil {
|
||||
db = db.Where("created_at BETWEEN ? AND ?", filter.StartCreatedAt, filter.EndCreatedAt)
|
||||
}
|
||||
return listRows(db, filter.Page, filter.PageSize, filter.PageSize > 0, func(po announcementPO) *system.Announcement {
|
||||
return listRows(db.Order("id desc"), filter.Page, filter.PageSize, filter.PageSize > 0, func(po announcementPO) *system.Announcement {
|
||||
return announcementToBiz(po)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -21,12 +21,10 @@ type DataAccessLogPO struct {
|
||||
|
||||
func (DataAccessLogPO) TableName() string { return "sys_data_access_logs" }
|
||||
|
||||
func (r *auditRecorderRepo) RecordDataAccess(ctx context.Context, v *system.DataAccessLog) error {
|
||||
return r.data.DB().WithContext(ctx).Create(&DataAccessLogPO{EventType: v.EventType, TargetTable: v.TargetTable, Operation: v.Operation, UserID: v.UserID, AuthorityID: v.AuthorityID, Scope: v.Scope, RequestID: v.RequestID, Method: v.Method, Path: v.Path, Detail: v.Detail}).Error
|
||||
}
|
||||
func dataAccessFromPO(v DataAccessLogPO) *system.DataAccessLog {
|
||||
return &system.DataAccessLog{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, EventType: v.EventType, TargetTable: v.TargetTable, Operation: v.Operation, UserID: v.UserID, AuthorityID: v.AuthorityID, Scope: v.Scope, RequestID: v.RequestID, Method: v.Method, Path: v.Path, Detail: v.Detail}
|
||||
}
|
||||
|
||||
func (r *auditQueryRepo) ListDataAccess(ctx context.Context, page, size int, q *system.DataAccessLog) ([]*system.DataAccessLog, int64, error) {
|
||||
db := r.data.DB().WithContext(ctx).Model(&DataAccessLogPO{})
|
||||
if q != nil {
|
||||
@@ -47,6 +45,7 @@ func (r *auditQueryRepo) ListDataAccess(ctx context.Context, page, size int, q *
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
|
||||
func (r *auditQueryRepo) DeleteDataAccess(ctx context.Context, ids []uint) error {
|
||||
return r.data.DB().WithContext(ctx).Delete(&DataAccessLogPO{}, "id IN ?", ids).Error
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (r *parameterRepo) ListParameters(ctx context.Context, page, size int, q *s
|
||||
db = db.Where(clause.Like{Column: clause.Column{Name: "key"}, Value: "%" + q.Key + "%"})
|
||||
}
|
||||
}
|
||||
return listRows(db, page, size, true, func(po parameterPO) *system.SystemParameter {
|
||||
return listRows(db.Order("id desc"), page, size, true, func(po parameterPO) *system.SystemParameter {
|
||||
return parameterFromPO(po)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package system
|
||||
import (
|
||||
"kra/internal/config"
|
||||
|
||||
"github.com/google/wire"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -14,3 +15,28 @@ type Provider interface {
|
||||
DatabaseReady() bool
|
||||
Runtime() *config.Store
|
||||
}
|
||||
|
||||
// ProviderSet wires system repositories and their runtime-backed adapters.
|
||||
var ProviderSet = wire.NewSet(
|
||||
NewRuntimeSettings,
|
||||
NewTokenIssuer,
|
||||
NewUserRepo,
|
||||
NewAuthorityAccessRepo,
|
||||
NewAPIRepo,
|
||||
NewPermissionRepo,
|
||||
NewMenuRepo,
|
||||
NewDepartmentRepo,
|
||||
NewPositionRepo,
|
||||
NewDictionaryRepo,
|
||||
NewParameterRepo,
|
||||
NewAPITokenRepo,
|
||||
NewSecurityRepo,
|
||||
NewVersionRepo,
|
||||
NewExportRepo,
|
||||
NewAuditRepo,
|
||||
NewAuditRecorderRepo,
|
||||
NewLogFileRepo,
|
||||
NewMediaRepo,
|
||||
NewAnnouncementRepo,
|
||||
NewMaintenanceRepo,
|
||||
)
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package system
|
||||
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSet wires system repositories and their runtime-backed adapters.
|
||||
var ProviderSet = wire.NewSet(
|
||||
NewRuntimeSettings,
|
||||
NewTokenIssuer,
|
||||
NewUserRepo,
|
||||
NewAuthorityAccessRepo,
|
||||
NewAPIRepo,
|
||||
NewPermissionRepo,
|
||||
NewMenuRepo,
|
||||
NewDepartmentRepo,
|
||||
NewPositionRepo,
|
||||
NewDictionaryRepo,
|
||||
NewParameterRepo,
|
||||
NewAPITokenRepo,
|
||||
NewSecurityRepo,
|
||||
NewVersionRepo,
|
||||
NewExportRepo,
|
||||
NewAuditRepo,
|
||||
NewAuditRecorderRepo,
|
||||
NewLogFileRepo,
|
||||
NewMediaRepo,
|
||||
NewAnnouncementRepo,
|
||||
NewMaintenanceRepo,
|
||||
)
|
||||
@@ -59,6 +59,7 @@ func (r *versionRepo) ListVersions(ctx context.Context, page, size int, name, co
|
||||
if code != "" {
|
||||
db = db.Where("version_code = ?", code)
|
||||
}
|
||||
db = db.Order("id desc")
|
||||
var total int64
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package task
|
||||
|
||||
import dataprovider "kra/internal/data/provider"
|
||||
import (
|
||||
dataprovider "kra/internal/data/provider"
|
||||
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
// Provider is the minimal database seam required by the task tables.
|
||||
// Task persistence must not depend on the full data runtime or system repos.
|
||||
type Provider = dataprovider.Database
|
||||
|
||||
var ProviderSet = wire.NewSet(NewTaskRepo)
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package task
|
||||
|
||||
import "github.com/google/wire"
|
||||
|
||||
var ProviderSet = wire.NewSet(NewTaskRepo)
|
||||
Reference in New Issue
Block a user