fix(planting-records): filter only MINING_ENABLED records and fix UI overflow
- Backend: Add status filter to getPlantingLedger and getPlantingSummary - Frontend: Change Row to Wrap for info items to prevent width overflow Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
8ae9e217ff
commit
1f15daa6c5
|
|
@ -373,16 +373,18 @@ export class SyncedDataRepository implements ISyncedDataRepository {
|
||||||
totalPages: number;
|
totalPages: number;
|
||||||
}> {
|
}> {
|
||||||
const skip = (page - 1) * pageSize;
|
const skip = (page - 1) * pageSize;
|
||||||
|
// 只返回 MINING_ENABLED 状态的认种记录
|
||||||
|
const whereClause = { accountSequence, status: 'MINING_ENABLED' };
|
||||||
|
|
||||||
const [items, total] = await Promise.all([
|
const [items, total] = await Promise.all([
|
||||||
this.client.syncedAdoption.findMany({
|
this.client.syncedAdoption.findMany({
|
||||||
where: { accountSequence },
|
where: whereClause,
|
||||||
orderBy: { adoptionDate: 'desc' },
|
orderBy: { adoptionDate: 'desc' },
|
||||||
skip,
|
skip,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
}),
|
}),
|
||||||
this.client.syncedAdoption.count({
|
this.client.syncedAdoption.count({
|
||||||
where: { accountSequence },
|
where: whereClause,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -403,8 +405,9 @@ export class SyncedDataRepository implements ISyncedDataRepository {
|
||||||
firstPlantingAt: Date | null;
|
firstPlantingAt: Date | null;
|
||||||
lastPlantingAt: Date | null;
|
lastPlantingAt: Date | null;
|
||||||
}> {
|
}> {
|
||||||
|
// 只统计 MINING_ENABLED 状态的认种记录
|
||||||
const adoptions = await this.client.syncedAdoption.findMany({
|
const adoptions = await this.client.syncedAdoption.findMany({
|
||||||
where: { accountSequence },
|
where: { accountSequence, status: 'MINING_ENABLED' },
|
||||||
orderBy: { adoptionDate: 'asc' },
|
orderBy: { adoptionDate: 'asc' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -421,11 +424,8 @@ export class SyncedDataRepository implements ISyncedDataRepository {
|
||||||
|
|
||||||
const totalOrders = adoptions.length;
|
const totalOrders = adoptions.length;
|
||||||
const totalTreeCount = adoptions.reduce((sum, a) => sum + a.treeCount, 0);
|
const totalTreeCount = adoptions.reduce((sum, a) => sum + a.treeCount, 0);
|
||||||
const effectiveTreeCount = adoptions
|
|
||||||
.filter((a) => a.status === 'MINING_ENABLED')
|
|
||||||
.reduce((sum, a) => sum + a.treeCount, 0);
|
|
||||||
|
|
||||||
// 计算总金额:treeCount * contributionPerTree (假设每棵树价格等于算力值)
|
// 计算总金额:treeCount * contributionPerTree
|
||||||
let totalAmount = new Decimal(0);
|
let totalAmount = new Decimal(0);
|
||||||
for (const adoption of adoptions) {
|
for (const adoption of adoptions) {
|
||||||
const amount = new Decimal(adoption.contributionPerTree).mul(adoption.treeCount);
|
const amount = new Decimal(adoption.contributionPerTree).mul(adoption.treeCount);
|
||||||
|
|
@ -436,7 +436,7 @@ export class SyncedDataRepository implements ISyncedDataRepository {
|
||||||
totalOrders,
|
totalOrders,
|
||||||
totalTreeCount,
|
totalTreeCount,
|
||||||
totalAmount: totalAmount.toString(),
|
totalAmount: totalAmount.toString(),
|
||||||
effectiveTreeCount,
|
effectiveTreeCount: totalTreeCount, // 全部都是有效的 MINING_ENABLED
|
||||||
firstPlantingAt: adoptions[0]?.adoptionDate || null,
|
firstPlantingAt: adoptions[0]?.adoptionDate || null,
|
||||||
lastPlantingAt: adoptions[adoptions.length - 1]?.adoptionDate || null,
|
lastPlantingAt: adoptions[adoptions.length - 1]?.adoptionDate || null,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -342,12 +342,12 @@ class _PlantingRecordsPageState extends ConsumerState<PlantingRecordsPage> {
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
// 第二行:认种数量 + 单棵算力 + 总算力
|
// 第二行:认种数量 + 单棵算力 + 总算力
|
||||||
Row(
|
Wrap(
|
||||||
|
spacing: 12,
|
||||||
|
runSpacing: 8,
|
||||||
children: [
|
children: [
|
||||||
_buildInfoItem('认种数量', '${record.treeCount}棵'),
|
_buildInfoItem('认种数量', '${record.treeCount}棵'),
|
||||||
const SizedBox(width: 16),
|
|
||||||
_buildInfoItem('单棵算力', formatAmount(record.contributionPerTree)),
|
_buildInfoItem('单棵算力', formatAmount(record.contributionPerTree)),
|
||||||
const SizedBox(width: 16),
|
|
||||||
_buildInfoItem('总算力', formatAmount(record.totalContribution), isHighlight: true),
|
_buildInfoItem('总算力', formatAmount(record.totalContribution), isHighlight: true),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue