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) {