This commit is contained in:
2025-12-19 17:05:09 +08:00
parent cc3472ff40
commit 39c46937ea
307 changed files with 87686 additions and 129 deletions

View File

@@ -55,6 +55,7 @@ import (
asynq "tyapi-server/internal/infrastructure/task/implementations/asynq"
task_interfaces "tyapi-server/internal/infrastructure/task/interfaces"
task_repositories "tyapi-server/internal/infrastructure/task/repositories"
component_report "tyapi-server/internal/shared/component_report"
shared_database "tyapi-server/internal/shared/database"
"tyapi-server/internal/shared/esign"
shared_events "tyapi-server/internal/shared/events"
@@ -565,6 +566,21 @@ func NewContainer() *Container {
product_repo.NewGormProductDocumentationRepository,
fx.As(new(domain_product_repo.ProductDocumentationRepository)),
),
// 组件报告下载记录仓储
fx.Annotate(
product_repo.NewGormComponentReportRepository,
fx.As(new(domain_product_repo.ComponentReportRepository)),
),
// UI组件仓储 - 同时注册具体类型和接口类型
fx.Annotate(
product_repo.NewGormUIComponentRepository,
fx.As(new(domain_product_repo.UIComponentRepository)),
),
// 产品UI组件关联仓储 - 同时注册具体类型和接口类型
fx.Annotate(
product_repo.NewGormProductUIComponentRepository,
fx.As(new(domain_product_repo.ProductUIComponentRepository)),
),
),
// 仓储层 - 文章域
@@ -882,6 +898,7 @@ func NewContainer() *Container {
logger *zap.Logger,
config *config.Config,
exportManager *export.ExportManager,
componentReportRepo domain_product_repo.ComponentReportRepository,
) finance.FinanceApplicationService {
return finance.NewFinanceApplicationService(
aliPayClient,
@@ -892,6 +909,7 @@ func NewContainer() *Container {
alipayOrderRepo,
wechatOrderRepo,
rechargeRecordRepo,
componentReportRepo,
userRepo,
txManager,
logger,
@@ -1028,6 +1046,27 @@ func NewContainer() *Container {
},
fx.As(new(statistics.StatisticsApplicationService)),
),
// UI组件应用服务 - 绑定到接口
fx.Annotate(
func(
uiComponentRepo domain_product_repo.UIComponentRepository,
productUIComponentRepo domain_product_repo.ProductUIComponentRepository,
fileStorageService *storage.LocalFileStorageService,
logger *zap.Logger,
) product.UIComponentApplicationService {
// 创建UI组件文件服务
basePath := "resources/Pure Component/src/ui"
fileService := product.NewUIComponentFileService(basePath, logger)
return product.NewUIComponentApplicationService(
uiComponentRepo,
productUIComponentRepo,
fileStorageService,
fileService,
)
},
fx.As(new(product.UIComponentApplicationService)),
),
),
// PDF查找服务
@@ -1086,6 +1125,24 @@ func NewContainer() *Container {
return cacheManager, nil
},
),
// 本地文件存储服务
fx.Provide(
func(logger *zap.Logger) *storage.LocalFileStorageService {
// 使用默认配置基础存储目录在项目根目录下的storage目录
basePath := "storage"
// 可以通过环境变量覆盖
if envBasePath := os.Getenv("FILE_STORAGE_BASE_PATH"); envBasePath != "" {
basePath = envBasePath
}
logger.Info("本地文件存储服务已初始化",
zap.String("base_path", basePath),
)
return storage.NewLocalFileStorageService(basePath, logger)
},
),
// HTTP处理器
fx.Provide(
// 用户HTTP处理器
@@ -1120,6 +1177,30 @@ func NewContainer() *Container {
) *handlers.AnnouncementHandler {
return handlers.NewAnnouncementHandler(appService, responseBuilder, validator, logger)
},
// 组件报告处理器
func(
productRepo domain_product_repo.ProductRepository,
docRepo domain_product_repo.ProductDocumentationRepository,
apiConfigRepo domain_product_repo.ProductApiConfigRepository,
componentReportRepo domain_product_repo.ComponentReportRepository,
rechargeRecordRepo domain_finance_repo.RechargeRecordRepository,
alipayOrderRepo domain_finance_repo.AlipayOrderRepository,
wechatOrderRepo domain_finance_repo.WechatOrderRepository,
aliPayService *payment.AliPayService,
wechatPayService *payment.WechatPayService,
logger *zap.Logger,
) *component_report.ComponentReportHandler {
return component_report.NewComponentReportHandler(productRepo, docRepo, apiConfigRepo, componentReportRepo, rechargeRecordRepo, alipayOrderRepo, wechatOrderRepo, aliPayService, wechatPayService, logger)
},
// UI组件HTTP处理器
func(
uiComponentAppService product.UIComponentApplicationService,
responseBuilder interfaces.ResponseBuilder,
validator interfaces.RequestValidator,
logger *zap.Logger,
) *handlers.UIComponentHandler {
return handlers.NewUIComponentHandler(uiComponentAppService, responseBuilder, validator, logger)
},
),
// 路由注册
@@ -1134,6 +1215,8 @@ func NewContainer() *Container {
routes.NewProductRoutes,
// 产品管理员路由
routes.NewProductAdminRoutes,
// UI组件路由
routes.NewUIComponentRoutes,
// 文章路由
routes.NewArticleRoutes,
// 公告路由
@@ -1248,10 +1331,13 @@ func RegisterRoutes(
financeRoutes *routes.FinanceRoutes,
productRoutes *routes.ProductRoutes,
productAdminRoutes *routes.ProductAdminRoutes,
uiComponentRoutes *routes.UIComponentRoutes,
articleRoutes *routes.ArticleRoutes,
announcementRoutes *routes.AnnouncementRoutes,
apiRoutes *routes.ApiRoutes,
statisticsRoutes *routes.StatisticsRoutes,
jwtAuth *middleware.JWTAuthMiddleware,
adminAuth *middleware.AdminAuthMiddleware,
cfg *config.Config,
logger *zap.Logger,
) {
@@ -1266,6 +1352,13 @@ func RegisterRoutes(
financeRoutes.Register(router)
productRoutes.Register(router)
productAdminRoutes.Register(router)
// UI组件路由需要特殊处理因为它需要管理员中间件
engine := router.GetEngine()
adminGroup := engine.Group("/api/v1/admin")
adminGroup.Use(adminAuth.Handle())
uiComponentRoutes.RegisterRoutes(adminGroup, adminAuth)
articleRoutes.Register(router)
announcementRoutes.Register(router)
statisticsRoutes.Register(router)