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 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-16 09:22:59 -08:00
parent 1f0bd15946
commit b645621c81
2 changed files with 29 additions and 1 deletions

View File

@ -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": []

View File

@ -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<void> {
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 -
*/