89 lines
4.2 KiB
TypeScript
89 lines
4.2 KiB
TypeScript
import { Module } from '@nestjs/common';
|
||
import { ScheduleModule } from '@nestjs/schedule';
|
||
import { InfrastructureModule } from '../infrastructure/infrastructure.module';
|
||
|
||
// Pre-planting Prisma (独立 schema)
|
||
import { PrePlantingPrismaModule } from './infrastructure/prisma/pre-planting-prisma.module';
|
||
|
||
// CDC Consumer (独立 Kafka consumer group)
|
||
import { PrePlantingCdcConsumerService } from './infrastructure/kafka/pre-planting-cdc-consumer.service';
|
||
|
||
// CDC Event Handlers
|
||
import { PrePlantingOrderSyncedHandler } from './application/handlers/pre-planting-order-synced.handler';
|
||
import { PrePlantingPositionSyncedHandler } from './application/handlers/pre-planting-position-synced.handler';
|
||
import { PrePlantingCdcDispatcher } from './application/handlers/pre-planting-cdc-dispatcher';
|
||
|
||
// Application Services
|
||
import { PrePlantingContributionService } from './application/services/pre-planting-contribution.service';
|
||
|
||
// Schedulers
|
||
import { PrePlantingFreezeScheduler } from './application/schedulers/pre-planting-freeze.scheduler';
|
||
|
||
// 现有 Application Services(直接提供,不 import ApplicationModule 避免引入现有 CDCEventDispatcher)
|
||
// 这些服务是无状态的,仅依赖 InfrastructureModule 的 providers,重复实例化无副作用。
|
||
import { ContributionRateService } from '../application/services/contribution-rate.service';
|
||
import { ContributionDistributionPublisherService } from '../application/services/contribution-distribution-publisher.service';
|
||
import { BonusClaimService } from '../application/services/bonus-claim.service';
|
||
|
||
/**
|
||
* 预种 CDC 集成模块
|
||
*
|
||
* [2026-02-17] 新增:将预种数据集成到 contribution-service 2.0 算力体系
|
||
*
|
||
* === 功能概述 ===
|
||
* 1. 通过独立 CDC consumer 消费预种表变更(cdc.pre-planting.public.*)
|
||
* 2. 同步预种订单/持仓到独立追踪表(PrePlantingPrismaService)
|
||
* 3. 为每份预种订单计算 1/5 算力(复用现有领域计算器)
|
||
* 4. 在 synced_adoptions 中插入 marker 记录(让现有 unlock 逻辑自然计入预种用户)
|
||
* 5. 每日检查冻结/解冻条件(1 年未满 5 份 → 冻结;满 5 份 → 解冻 + 2 年有效期)
|
||
*
|
||
* === 隔离保证 ===
|
||
* - 独立 Kafka consumer group:contribution-pre-planting-cdc(不影响现有 contribution-service-cdc-group)
|
||
* - 独立 CDC topics:cdc.pre-planting.public.*(不影响现有 cdc.planting.public.* topics)
|
||
* - 独立 Debezium connector / replication slot / publication
|
||
* - 独立 Prisma schema:prisma/pre-planting/schema.prisma(追踪表与现有表完全分离)
|
||
* - 幂等性共用主 PrismaService 的 ProcessedCdcEvent 表(同 DB 事务保证一致性)
|
||
*
|
||
* === 对现有系统的影响 ===
|
||
* - 零修改现有代码文件。本模块是纯新增。
|
||
* - 算力写入现有 contribution_accounts / contribution_records 表(挖矿系统可见)
|
||
* - sourceAdoptionId 使用 10,000,000,000 偏移,永远不会与正常认种 ID 冲突
|
||
* - synced_adoptions 中的 marker 记录设置 contributionDistributed=true + treeCount=0,
|
||
* 现有调度器不会处理,即使误处理也不会产生算力
|
||
* - 不更新 NetworkAdoptionProgress(预种份额不推高全网算力系数)
|
||
*
|
||
* === 依赖关系 ===
|
||
* - InfrastructureModule:提供 PrismaService、Repositories、UnitOfWork、Redis 等
|
||
* - PrePlantingPrismaModule:提供独立的 PrePlantingPrismaService
|
||
* - ScheduleModule:提供 @Cron 装饰器支持(冻结调度器)
|
||
*/
|
||
@Module({
|
||
imports: [
|
||
ScheduleModule.forRoot(),
|
||
InfrastructureModule,
|
||
PrePlantingPrismaModule,
|
||
],
|
||
providers: [
|
||
// CDC Consumer (独立 consumer group)
|
||
PrePlantingCdcConsumerService,
|
||
|
||
// CDC Event Handlers
|
||
PrePlantingOrderSyncedHandler,
|
||
PrePlantingPositionSyncedHandler,
|
||
PrePlantingCdcDispatcher,
|
||
|
||
// Application Services (预种)
|
||
PrePlantingContributionService,
|
||
|
||
// Application Services (现有,直接提供以避免 import ApplicationModule)
|
||
// ApplicationModule 内含 CDCEventDispatcher,import 会导致现有 CDC 被二次注册
|
||
ContributionRateService,
|
||
ContributionDistributionPublisherService,
|
||
BonusClaimService,
|
||
|
||
// Schedulers
|
||
PrePlantingFreezeScheduler,
|
||
],
|
||
})
|
||
export class PrePlantingCdcModule {}
|