fix
This commit is contained in:
@@ -14,6 +14,12 @@ import (
|
||||
|
||||
// SetupGormCache 设置GORM缓存插件
|
||||
func SetupGormCache(db *gorm.DB, cacheService interfaces.CacheService, cfg *config.Config, logger *zap.Logger) error {
|
||||
// 缓存功能已完全禁用
|
||||
logger.Info("GORM缓存插件已禁用 - 所有查询将直接访问数据库")
|
||||
return nil
|
||||
|
||||
// 以下是原有的缓存配置代码,已注释掉
|
||||
/*
|
||||
// 创建缓存配置
|
||||
cacheConfig := cache.CacheConfig{
|
||||
DefaultTTL: 30 * time.Minute,
|
||||
@@ -29,16 +35,16 @@ func SetupGormCache(db *gorm.DB, cacheService interfaces.CacheService, cfg *conf
|
||||
|
||||
// 配置启用缓存的表
|
||||
EnabledTables: []string{
|
||||
"product",
|
||||
"product_category",
|
||||
"enterprise_info_submit_records",
|
||||
"sms_codes",
|
||||
"wallets",
|
||||
"subscription",
|
||||
"product_category",
|
||||
"product_documentation",
|
||||
"enterprise_infos",
|
||||
"api_users",
|
||||
// "product",
|
||||
// "product_category",
|
||||
// "enterprise_info_submit_records",
|
||||
// "sms_codes",
|
||||
// "wallets",
|
||||
// "subscription",
|
||||
// "product_category",
|
||||
// "product_documentation",
|
||||
// "enterprise_infos",
|
||||
// "api_users",
|
||||
// 添加更多需要缓存的表
|
||||
},
|
||||
|
||||
@@ -68,8 +74,9 @@ func SetupGormCache(db *gorm.DB, cacheService interfaces.CacheService, cfg *conf
|
||||
zap.Strings("enabled_tables", cacheConfig.EnabledTables),
|
||||
zap.Strings("disabled_tables", cacheConfig.DisabledTables),
|
||||
)
|
||||
*/
|
||||
|
||||
return nil
|
||||
// return nil
|
||||
}
|
||||
|
||||
// GetCacheConfig 根据环境获取缓存配置
|
||||
@@ -89,10 +96,10 @@ func GetCacheConfig(cfg *config.Config) cache.CacheConfig {
|
||||
InvalidateDelay: 50 * time.Millisecond,
|
||||
|
||||
EnabledTables: []string{
|
||||
"product",
|
||||
"product_category",
|
||||
"enterprise_info_submit_records",
|
||||
"sms_codes",
|
||||
// "product",
|
||||
// "product_category",
|
||||
// "enterprise_info_submit_records",
|
||||
// "sms_codes",
|
||||
},
|
||||
|
||||
DisabledTables: []string{
|
||||
@@ -120,10 +127,10 @@ func GetCacheConfig(cfg *config.Config) cache.CacheConfig {
|
||||
InvalidateDelay: 200 * time.Millisecond,
|
||||
|
||||
EnabledTables: []string{
|
||||
"product",
|
||||
"product_category",
|
||||
"enterprise_info_submit_records",
|
||||
"sms_codes",
|
||||
// "product",
|
||||
// "product_category",
|
||||
// "enterprise_info_submit_records",
|
||||
// "sms_codes",
|
||||
},
|
||||
|
||||
DisabledTables: []string{
|
||||
|
||||
@@ -77,12 +77,29 @@ func NewContainer() *Container {
|
||||
|
||||
// 基础设施模块
|
||||
fx.Provide(
|
||||
// 日志器 - 提供自定义Logger和*zap.Logger
|
||||
func(cfg *config.Config) (logger.Logger, error) {
|
||||
if cfg.Logger.EnableLevelSeparation {
|
||||
// 使用按级别分文件的日志器
|
||||
levelConfig := logger.LevelLoggerConfig{
|
||||
BaseConfig: logger.Config{
|
||||
// 日志器 - 提供自定义Logger和*zap.Logger
|
||||
func(cfg *config.Config) (logger.Logger, error) {
|
||||
if cfg.Logger.EnableLevelSeparation {
|
||||
// 使用按级别分文件的日志器
|
||||
levelConfig := logger.LevelLoggerConfig{
|
||||
BaseConfig: logger.Config{
|
||||
Level: cfg.Logger.Level,
|
||||
Format: cfg.Logger.Format,
|
||||
Output: cfg.Logger.Output,
|
||||
LogDir: cfg.Logger.LogDir,
|
||||
MaxSize: cfg.Logger.MaxSize,
|
||||
MaxBackups: cfg.Logger.MaxBackups,
|
||||
MaxAge: cfg.Logger.MaxAge,
|
||||
Compress: cfg.Logger.Compress,
|
||||
UseDaily: cfg.Logger.UseDaily,
|
||||
},
|
||||
EnableLevelSeparation: true,
|
||||
LevelConfigs: convertLevelConfigs(cfg.Logger.LevelConfigs),
|
||||
}
|
||||
return logger.NewLevelLogger(levelConfig)
|
||||
} else {
|
||||
// 使用普通日志器
|
||||
logCfg := logger.Config{
|
||||
Level: cfg.Logger.Level,
|
||||
Format: cfg.Logger.Format,
|
||||
Output: cfg.Logger.Output,
|
||||
@@ -92,44 +109,27 @@ func NewContainer() *Container {
|
||||
MaxAge: cfg.Logger.MaxAge,
|
||||
Compress: cfg.Logger.Compress,
|
||||
UseDaily: cfg.Logger.UseDaily,
|
||||
},
|
||||
EnableLevelSeparation: true,
|
||||
LevelConfigs: convertLevelConfigs(cfg.Logger.LevelConfigs),
|
||||
}
|
||||
return logger.NewLogger(logCfg)
|
||||
}
|
||||
return logger.NewLevelLogger(levelConfig)
|
||||
} else {
|
||||
// 使用普通日志器
|
||||
logCfg := logger.Config{
|
||||
Level: cfg.Logger.Level,
|
||||
Format: cfg.Logger.Format,
|
||||
Output: cfg.Logger.Output,
|
||||
LogDir: cfg.Logger.LogDir,
|
||||
MaxSize: cfg.Logger.MaxSize,
|
||||
MaxBackups: cfg.Logger.MaxBackups,
|
||||
MaxAge: cfg.Logger.MaxAge,
|
||||
Compress: cfg.Logger.Compress,
|
||||
UseDaily: cfg.Logger.UseDaily,
|
||||
},
|
||||
// 提供普通的*zap.Logger(用于大多数场景)
|
||||
func(log logger.Logger) *zap.Logger {
|
||||
// 尝试转换为ZapLogger
|
||||
if zapLogger, ok := log.(*logger.ZapLogger); ok {
|
||||
return zapLogger.GetZapLogger()
|
||||
}
|
||||
return logger.NewLogger(logCfg)
|
||||
}
|
||||
},
|
||||
// 提供普通的*zap.Logger(用于大多数场景)
|
||||
func(log logger.Logger) *zap.Logger {
|
||||
// 尝试转换为ZapLogger
|
||||
if zapLogger, ok := log.(*logger.ZapLogger); ok {
|
||||
return zapLogger.GetZapLogger()
|
||||
}
|
||||
// 尝试转换为LevelLogger
|
||||
if levelLogger, ok := log.(*logger.LevelLogger); ok {
|
||||
// 获取Info级别的日志器作为默认
|
||||
if infoLogger := levelLogger.GetLevelLogger(zapcore.InfoLevel); infoLogger != nil {
|
||||
return infoLogger
|
||||
// 尝试转换为LevelLogger
|
||||
if levelLogger, ok := log.(*logger.LevelLogger); ok {
|
||||
// 获取Info级别的日志器作为默认
|
||||
if infoLogger := levelLogger.GetLevelLogger(zapcore.InfoLevel); infoLogger != nil {
|
||||
return infoLogger
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果类型转换失败,创建一个默认的zap logger
|
||||
defaultLogger, _ := zap.NewProduction()
|
||||
return defaultLogger
|
||||
},
|
||||
// 如果类型转换失败,创建一个默认的zap logger
|
||||
defaultLogger, _ := zap.NewProduction()
|
||||
return defaultLogger
|
||||
},
|
||||
|
||||
// 数据库连接
|
||||
func(cfg *config.Config, cacheService interfaces.CacheService, logger *zap.Logger) (*gorm.DB, error) {
|
||||
@@ -147,7 +147,7 @@ func NewContainer() *Container {
|
||||
}
|
||||
db, err := database.NewConnection(dbCfg)
|
||||
if err != nil {
|
||||
logger.Error("数据库连接失败",
|
||||
logger.Error("数据库连接失败",
|
||||
zap.String("host", cfg.Database.Host),
|
||||
zap.String("port", cfg.Database.Port),
|
||||
zap.String("database", cfg.Database.Name),
|
||||
@@ -155,8 +155,8 @@ func NewContainer() *Container {
|
||||
zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logger.Info("数据库连接成功",
|
||||
|
||||
logger.Info("数据库连接成功",
|
||||
zap.String("host", cfg.Database.Host),
|
||||
zap.String("port", cfg.Database.Port),
|
||||
zap.String("database", cfg.Database.Name))
|
||||
@@ -445,6 +445,10 @@ func NewContainer() *Container {
|
||||
product_repo.NewGormProductApiConfigRepository,
|
||||
fx.As(new(domain_product_repo.ProductApiConfigRepository)),
|
||||
),
|
||||
fx.Annotate(
|
||||
product_repo.NewGormProductDocumentationRepository,
|
||||
fx.As(new(domain_product_repo.ProductDocumentationRepository)),
|
||||
),
|
||||
),
|
||||
|
||||
// API域仓储层
|
||||
@@ -468,6 +472,7 @@ func NewContainer() *Container {
|
||||
product_service.NewProductManagementService,
|
||||
product_service.NewProductSubscriptionService,
|
||||
product_service.NewProductApiConfigService,
|
||||
product_service.NewProductDocumentationService,
|
||||
finance_service.NewWalletAggregateService,
|
||||
finance_service.NewRechargeRecordService,
|
||||
certification_service.NewCertificationAggregateService,
|
||||
@@ -518,6 +523,10 @@ func NewContainer() *Container {
|
||||
product.NewCategoryApplicationService,
|
||||
fx.As(new(product.CategoryApplicationService)),
|
||||
),
|
||||
fx.Annotate(
|
||||
product.NewDocumentationApplicationService,
|
||||
fx.As(new(product.DocumentationApplicationServiceInterface)),
|
||||
),
|
||||
// 订阅应用服务 - 绑定到接口
|
||||
fx.Annotate(
|
||||
product.NewSubscriptionApplicationService,
|
||||
@@ -670,7 +679,7 @@ func RegisterRoutes(
|
||||
logger.Info("HTTP服务器启动成功", zap.String("addr", addr))
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
logger.Info("路由注册完成,HTTP服务器启动中...")
|
||||
}
|
||||
|
||||
@@ -691,7 +700,7 @@ func NewRequestBodyLoggerMiddlewareWrapper(logger *zap.Logger, cfg *config.Confi
|
||||
// convertLevelConfigs 转换级别配置
|
||||
func convertLevelConfigs(configs map[string]config.LevelFileConfig) map[zapcore.Level]logger.LevelFileConfig {
|
||||
result := make(map[zapcore.Level]logger.LevelFileConfig)
|
||||
|
||||
|
||||
levelMap := map[string]zapcore.Level{
|
||||
"debug": zapcore.DebugLevel,
|
||||
"info": zapcore.InfoLevel,
|
||||
@@ -700,7 +709,7 @@ func convertLevelConfigs(configs map[string]config.LevelFileConfig) map[zapcore.
|
||||
"fatal": zapcore.FatalLevel,
|
||||
"panic": zapcore.PanicLevel,
|
||||
}
|
||||
|
||||
|
||||
for levelStr, config := range configs {
|
||||
if level, exists := levelMap[levelStr]; exists {
|
||||
result[level] = logger.LevelFileConfig{
|
||||
@@ -711,7 +720,7 @@ func convertLevelConfigs(configs map[string]config.LevelFileConfig) map[zapcore.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user