fix: 注册佣金计算任务 Handler 到队列处理器
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m19s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m19s
佣金计算任务 (commission:calculate) 的 Handler 已实现但未在队列处理器中注册, 导致支付成功后入队的佣金计算任务永远不会被消费执行。 变更内容: - 在 pkg/queue/handler.go 中添加 registerCommissionCalculationHandler() 方法 - 创建所有需要的 Store 和 Service 依赖 - 在 RegisterHandlers() 中调用注册方法 修复后,订单支付成功将正确触发佣金计算和发放。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/service/commission_calculation"
|
||||
"github.com/break/junhong_cmp_fiber/internal/service/commission_stats"
|
||||
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
"github.com/break/junhong_cmp_fiber/internal/task"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
@@ -47,6 +49,7 @@ func (h *Handler) RegisterHandlers() *asynq.ServeMux {
|
||||
h.registerIotCardImportHandler()
|
||||
h.registerDeviceImportHandler()
|
||||
h.registerCommissionStatsHandlers()
|
||||
h.registerCommissionCalculationHandler()
|
||||
|
||||
h.logger.Info("所有任务处理器注册完成")
|
||||
return h.mux
|
||||
@@ -90,6 +93,51 @@ func (h *Handler) registerCommissionStatsHandlers() {
|
||||
h.logger.Info("注册佣金统计归档任务处理器", zap.String("task_type", constants.TaskTypeCommissionStatsArchive))
|
||||
}
|
||||
|
||||
func (h *Handler) registerCommissionCalculationHandler() {
|
||||
// 创建所有需要的 Store 实例
|
||||
commissionRecordStore := postgres.NewCommissionRecordStore(h.db, h.redis)
|
||||
shopStore := postgres.NewShopStore(h.db, h.redis)
|
||||
shopPackageAllocationStore := postgres.NewShopPackageAllocationStore(h.db)
|
||||
shopSeriesAllocationStore := postgres.NewShopSeriesAllocationStore(h.db)
|
||||
packageSeriesStore := postgres.NewPackageSeriesStore(h.db)
|
||||
iotCardStore := postgres.NewIotCardStore(h.db, h.redis)
|
||||
deviceStore := postgres.NewDeviceStore(h.db, h.redis)
|
||||
walletStore := postgres.NewWalletStore(h.db, h.redis)
|
||||
walletTransactionStore := postgres.NewWalletTransactionStore(h.db, h.redis)
|
||||
orderStore := postgres.NewOrderStore(h.db, h.redis)
|
||||
orderItemStore := postgres.NewOrderItemStore(h.db, h.redis)
|
||||
packageStore := postgres.NewPackageStore(h.db)
|
||||
commissionStatsStore := postgres.NewShopSeriesCommissionStatsStore(h.db)
|
||||
|
||||
// 创建 commission_stats.Service
|
||||
commissionStatsService := commission_stats.New(commissionStatsStore)
|
||||
|
||||
// 创建 commission_calculation.Service
|
||||
commissionCalculationService := commission_calculation.New(
|
||||
h.db,
|
||||
commissionRecordStore,
|
||||
shopStore,
|
||||
shopPackageAllocationStore,
|
||||
shopSeriesAllocationStore,
|
||||
packageSeriesStore,
|
||||
iotCardStore,
|
||||
deviceStore,
|
||||
walletStore,
|
||||
walletTransactionStore,
|
||||
orderStore,
|
||||
orderItemStore,
|
||||
packageStore,
|
||||
commissionStatsStore,
|
||||
commissionStatsService,
|
||||
h.logger,
|
||||
)
|
||||
|
||||
// 创建并注册 Handler
|
||||
commissionCalculationHandler := task.NewCommissionCalculationHandler(h.db, commissionCalculationService, h.logger)
|
||||
h.mux.HandleFunc(constants.TaskTypeCommission, commissionCalculationHandler.HandleCommissionCalculation)
|
||||
h.logger.Info("注册佣金计算任务处理器", zap.String("task_type", constants.TaskTypeCommission))
|
||||
}
|
||||
|
||||
// GetMux 获取 ServeMux(用于启动 Worker 服务器)
|
||||
func (h *Handler) GetMux() *asynq.ServeMux {
|
||||
return h.mux
|
||||
|
||||
Reference in New Issue
Block a user