From 974b45554d885b85febb937b7e786aa125e20dfa Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 21 Jan 2026 02:20:36 -0800 Subject: [PATCH] =?UTF-8?q?feat(contribution):=20=E4=B8=BA=20HEADQUARTERS?= =?UTF-8?q?=20=E6=9C=AA=E5=88=86=E9=85=8D=E7=AE=97=E5=8A=9B=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=98=8E=E7=BB=86=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 每笔未分配算力都创建 HEADQUARTERS 的明细记录 - 发布 SystemContributionRecordCreatedEvent 事件同步到 mining-admin-service - 明细记录包含来源用户ID (sourceAccountSequence) --- .../contribution-calculation.service.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/backend/services/contribution-service/src/application/services/contribution-calculation.service.ts b/backend/services/contribution-service/src/application/services/contribution-calculation.service.ts index 568af828..51b1e138 100644 --- a/backend/services/contribution-service/src/application/services/contribution-calculation.service.ts +++ b/backend/services/contribution-service/src/application/services/contribution-calculation.service.ts @@ -291,6 +291,40 @@ export class ContributionCalculationService { totalUnallocatedAmount, ); + // 为每笔未分配算力创建 HEADQUARTERS 明细记录 + for (const unallocated of result.unallocatedContributions) { + const savedRecord = await this.systemAccountRepository.saveContributionRecord({ + accountType: 'HEADQUARTERS', + regionCode: null, + sourceAdoptionId, + sourceAccountSequence, + distributionRate: 0, // 未分配算力没有固定比例 + amount: unallocated.amount, + effectiveDate, + expireDate: null, + }); + + // 发布 HEADQUARTERS 算力明细事件 + const recordEvent = new SystemContributionRecordCreatedEvent( + savedRecord.id, + 'HEADQUARTERS', + null, + sourceAdoptionId, + sourceAccountSequence, + 0, + unallocated.amount.value.toString(), + effectiveDate, + null, + savedRecord.createdAt, + ); + await this.outboxRepository.save({ + aggregateType: SystemContributionRecordCreatedEvent.AGGREGATE_TYPE, + aggregateId: savedRecord.id.toString(), + eventType: SystemContributionRecordCreatedEvent.EVENT_TYPE, + payload: recordEvent.toPayload(), + }); + } + // 发布 HEADQUARTERS 账户同步事件 const headquartersAccount = await this.systemAccountRepository.findByTypeAndRegion('HEADQUARTERS', null); if (headquartersAccount) {