feat(contribution): 为 HEADQUARTERS 未分配算力创建明细记录

- 每笔未分配算力都创建 HEADQUARTERS 的明细记录
- 发布 SystemContributionRecordCreatedEvent 事件同步到 mining-admin-service
- 明细记录包含来源用户ID (sourceAccountSequence)
This commit is contained in:
hailin 2026-01-21 02:20:36 -08:00
parent 97e974b6da
commit 974b45554d
1 changed files with 34 additions and 0 deletions

View File

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