From b645621c8132bb077a046c2e0a8d3ff6e0b75356 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 16 Jan 2026 09:22:59 -0800 Subject: [PATCH] fix(admin): add SystemAccountSynced event handler for system contribution sync The mining-admin-service was only listening for SystemContributionUpdated events, but contribution-service publishes SystemAccountSynced events. Added the missing handler to properly sync system account contribution data. Co-Authored-By: Claude Opus 4.5 --- .claude/settings.local.json | 4 ++- .../infrastructure/kafka/cdc-sync.service.ts | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 44f18707..3b5a89c5 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -779,7 +779,9 @@ "Bash(ssh -o StrictHostKeyChecking=no -J ceshi@103.39.231.231 ceshi@192.168.1.111 \"curl -s http://localhost:3020/api/v1/ | head -100\")", "Bash(ssh -o StrictHostKeyChecking=no -J ceshi@103.39.231.231 ceshi@192.168.1.111:*)", "Bash(bc:*)", - "Bash(DATABASE_URL=\"postgresql://postgres:password@localhost:5432/mining_db?schema=public\" npx prisma migrate diff:*)" + "Bash(DATABASE_URL=\"postgresql://postgres:password@localhost:5432/mining_db?schema=public\" npx prisma migrate diff:*)", + "Bash(git status:*)", + "Bash(xargs cat:*)" ], "deny": [], "ask": [] diff --git a/backend/services/mining-admin-service/src/infrastructure/kafka/cdc-sync.service.ts b/backend/services/mining-admin-service/src/infrastructure/kafka/cdc-sync.service.ts index af4caa03..1e1904d1 100644 --- a/backend/services/mining-admin-service/src/infrastructure/kafka/cdc-sync.service.ts +++ b/backend/services/mining-admin-service/src/infrastructure/kafka/cdc-sync.service.ts @@ -158,6 +158,11 @@ export class CdcSyncService implements OnModuleInit { 'SystemContributionUpdated', this.withIdempotency(this.handleSystemContributionUpdated.bind(this)), ); + // SystemAccountSynced 事件 - 同步系统账户算力(来自 contribution-service) + this.cdcConsumer.registerServiceHandler( + 'SystemAccountSynced', + this.withIdempotency(this.handleSystemAccountSynced.bind(this)), + ); // ReferralSynced 事件 - 同步推荐关系 this.cdcConsumer.registerServiceHandler( 'ReferralSynced', @@ -546,6 +551,27 @@ export class CdcSyncService implements OnModuleInit { }); } + /** + * 处理 SystemAccountSynced 事件 - 同步系统账户算力 + * 来自 contribution-service 的系统账户(运营、省、市、总部)算力同步 + */ + private async handleSystemAccountSynced(event: ServiceEvent, tx: TransactionClient): Promise { + const { payload } = event; + await tx.syncedSystemContribution.upsert({ + where: { accountType: payload.accountType }, + create: { + accountType: payload.accountType, + name: payload.name, + contributionBalance: payload.contributionBalance || 0, + contributionNeverExpires: true, // 系统账户算力永不过期 + }, + update: { + name: payload.name, + contributionBalance: payload.contributionBalance, + }, + }); + } + /** * 处理 ReferralSynced 事件 - 同步推荐关系 */