fix(contribution): 认种记录总贡献值显示用户实际有效算力
后端: - get-planting-ledger.query.ts: 添加effectiveContribution字段 - 从contributionAccount获取用户实际的个人算力(personalContribution) 前端: - planting_record.dart: PlantingSummary添加effectiveContribution字段 - planting_record_model.dart: 解析effectiveContribution字段 - planting_records_page.dart: 总贡献值显示effectiveContribution而非totalAmount Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
613fb33ff9
commit
e8f3c34723
|
|
@ -1,5 +1,6 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { SyncedDataRepository } from '../../infrastructure/persistence/repositories/synced-data.repository';
|
||||
import { ContributionAccountRepository } from '../../infrastructure/persistence/repositories/contribution-account.repository';
|
||||
|
||||
export interface PlantingRecordDto {
|
||||
orderId: string;
|
||||
|
|
@ -18,6 +19,8 @@ export interface PlantingSummaryDto {
|
|||
totalTreeCount: number;
|
||||
totalAmount: string;
|
||||
effectiveTreeCount: number;
|
||||
/** 用户实际的有效贡献值(个人算力) */
|
||||
effectiveContribution: string;
|
||||
firstPlantingAt: string | null;
|
||||
lastPlantingAt: string | null;
|
||||
}
|
||||
|
|
@ -33,24 +36,32 @@ export interface PlantingLedgerDto {
|
|||
|
||||
@Injectable()
|
||||
export class GetPlantingLedgerQuery {
|
||||
constructor(private readonly syncedDataRepository: SyncedDataRepository) {}
|
||||
constructor(
|
||||
private readonly syncedDataRepository: SyncedDataRepository,
|
||||
private readonly contributionAccountRepository: ContributionAccountRepository,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
accountSequence: string,
|
||||
page: number = 1,
|
||||
pageSize: number = 20,
|
||||
): Promise<PlantingLedgerDto> {
|
||||
const [summary, ledger] = await Promise.all([
|
||||
const [summary, ledger, contributionAccount] = await Promise.all([
|
||||
this.syncedDataRepository.getPlantingSummary(accountSequence),
|
||||
this.syncedDataRepository.getPlantingLedger(accountSequence, page, pageSize),
|
||||
this.contributionAccountRepository.findByAccountSequence(accountSequence),
|
||||
]);
|
||||
|
||||
// 获取用户实际的有效贡献值(个人算力)
|
||||
const effectiveContribution = contributionAccount?.personalContribution.toString() || '0';
|
||||
|
||||
return {
|
||||
summary: {
|
||||
totalOrders: summary.totalOrders,
|
||||
totalTreeCount: summary.totalTreeCount,
|
||||
totalAmount: summary.totalAmount,
|
||||
effectiveTreeCount: summary.effectiveTreeCount,
|
||||
effectiveContribution,
|
||||
firstPlantingAt: summary.firstPlantingAt?.toISOString() || null,
|
||||
lastPlantingAt: summary.lastPlantingAt?.toISOString() || null,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ class PlantingSummaryModel extends PlantingSummary {
|
|||
required super.totalTreeCount,
|
||||
required super.totalAmount,
|
||||
required super.effectiveTreeCount,
|
||||
required super.effectiveContribution,
|
||||
super.firstPlantingAt,
|
||||
super.lastPlantingAt,
|
||||
});
|
||||
|
|
@ -67,6 +68,7 @@ class PlantingSummaryModel extends PlantingSummary {
|
|||
totalTreeCount: json['totalTreeCount'] ?? 0,
|
||||
totalAmount: json['totalAmount']?.toString() ?? '0',
|
||||
effectiveTreeCount: json['effectiveTreeCount'] ?? 0,
|
||||
effectiveContribution: json['effectiveContribution']?.toString() ?? '0',
|
||||
firstPlantingAt: json['firstPlantingAt'] != null
|
||||
? DateTime.tryParse(json['firstPlantingAt'])
|
||||
: null,
|
||||
|
|
|
|||
|
|
@ -80,10 +80,12 @@ class PlantingSummary extends Equatable {
|
|||
final int totalOrders;
|
||||
/// 总认种量
|
||||
final int totalTreeCount;
|
||||
/// 总金额
|
||||
/// 总金额(理论贡献值)
|
||||
final String totalAmount;
|
||||
/// 有效认种量
|
||||
final int effectiveTreeCount;
|
||||
/// 有效贡献值(实际个人算力)
|
||||
final String effectiveContribution;
|
||||
/// 首次认种时间
|
||||
final DateTime? firstPlantingAt;
|
||||
/// 最近认种时间
|
||||
|
|
@ -94,6 +96,7 @@ class PlantingSummary extends Equatable {
|
|||
required this.totalTreeCount,
|
||||
required this.totalAmount,
|
||||
required this.effectiveTreeCount,
|
||||
required this.effectiveContribution,
|
||||
this.firstPlantingAt,
|
||||
this.lastPlantingAt,
|
||||
});
|
||||
|
|
@ -104,6 +107,7 @@ class PlantingSummary extends Equatable {
|
|||
totalTreeCount,
|
||||
totalAmount,
|
||||
effectiveTreeCount,
|
||||
effectiveContribution,
|
||||
firstPlantingAt,
|
||||
lastPlantingAt,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ class _PlantingRecordsPageState extends ConsumerState<PlantingRecordsPage> {
|
|||
children: [
|
||||
_buildSummaryItem('总订单数', summary.totalOrders.toString()),
|
||||
_buildSummaryItem('总认种量', summary.totalTreeCount.toString(), color: _green),
|
||||
_buildSummaryItem('总贡献值', formatAmount(summary.totalAmount), color: _orange),
|
||||
_buildSummaryItem('总贡献值', formatAmount(summary.effectiveContribution), color: _orange),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
|
|
|||
Loading…
Reference in New Issue