fix(mining-admin): use CDC synced tables for system accounts API

Change SystemAccountsService to read from syncedWalletSystemAccount and
syncedWalletPoolAccount tables instead of local tables. This fixes the
issue where the frontend shows "暂无数据" despite data being synced.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-14 01:44:22 -08:00
parent eff71a6b22
commit fa6826dde3
1 changed files with 61 additions and 53 deletions

View File

@ -7,55 +7,53 @@ export class SystemAccountsService {
/** /**
* *
* CDC
*/ */
async getSystemAccounts() { async getSystemAccounts() {
// 先从本地 SystemAccount 表获取 // 从 CDC 同步的 SyncedWalletSystemAccount 表获取数据
const localAccounts = await this.prisma.systemAccount.findMany({ const syncedAccounts = await this.prisma.syncedWalletSystemAccount.findMany({
orderBy: { accountType: 'asc' }, orderBy: { accountType: 'asc' },
}); });
// 从 CDC 同步的 SyncedSystemContribution 获取算力数据 // 从 CDC 同步的 SyncedSystemContribution 获取算力数据
const syncedContributions = const syncedContributions =
await this.prisma.syncedSystemContribution.findMany(); await this.prisma.syncedSystemContribution.findMany();
// 合并数据 // 构建算力数据映射
const accountsMap = new Map<string, any>(); const contributionMap = new Map<string, any>();
for (const contrib of syncedContributions) {
contributionMap.set(contrib.accountType, contrib);
}
// 添加本地账户 // 构建返回数据
for (const account of localAccounts) { const accounts = syncedAccounts.map((account) => {
accountsMap.set(account.accountType, { const contrib = contributionMap.get(account.accountType);
return {
id: account.originalId,
accountType: account.accountType, accountType: account.accountType,
name: account.name, name: account.name,
description: account.description, code: account.code,
totalContribution: account.totalContribution.toString(), provinceId: account.provinceId,
createdAt: account.createdAt, cityId: account.cityId,
source: 'local', shareBalance: account.shareBalance.toString(),
}); usdtBalance: account.usdtBalance.toString(),
} greenPointBalance: account.greenPointBalance.toString(),
frozenShare: account.frozenShare.toString(),
// 更新或添加同步的算力数据 frozenUsdt: account.frozenUsdt.toString(),
for (const contrib of syncedContributions) { totalInflow: account.totalInflow.toString(),
const existing = accountsMap.get(contrib.accountType); totalOutflow: account.totalOutflow.toString(),
if (existing) { blockchainAddress: account.blockchainAddress,
existing.contributionBalance = contrib.contributionBalance.toString(); isActive: account.isActive,
existing.contributionNeverExpires = contrib.contributionNeverExpires; contributionBalance: contrib?.contributionBalance?.toString() || '0',
existing.syncedAt = contrib.syncedAt; contributionNeverExpires: contrib?.contributionNeverExpires || false,
existing.source = 'synced'; syncedAt: account.syncedAt,
} else { source: 'cdc',
accountsMap.set(contrib.accountType, { };
accountType: contrib.accountType, });
name: contrib.name,
contributionBalance: contrib.contributionBalance.toString(),
contributionNeverExpires: contrib.contributionNeverExpires,
syncedAt: contrib.syncedAt,
source: 'synced',
});
}
}
return { return {
accounts: Array.from(accountsMap.values()), accounts,
total: accountsMap.size, total: accounts.length,
}; };
} }
@ -63,22 +61,21 @@ export class SystemAccountsService {
* *
*/ */
async getSystemAccountsSummary() { async getSystemAccountsSummary() {
const [localAccounts, syncedContributions, miningConfig, circulationPool] = const [
await Promise.all([ syncedSystemAccounts,
this.prisma.systemAccount.findMany(), syncedPoolAccounts,
this.prisma.syncedSystemContribution.findMany(), syncedContributions,
this.prisma.syncedMiningConfig.findFirst(), miningConfig,
this.prisma.syncedCirculationPool.findFirst(), circulationPool,
]); ] = await Promise.all([
this.prisma.syncedWalletSystemAccount.findMany(),
this.prisma.syncedWalletPoolAccount.findMany(),
this.prisma.syncedSystemContribution.findMany(),
this.prisma.syncedMiningConfig.findFirst(),
this.prisma.syncedCirculationPool.findFirst(),
]);
// 计算总算力 // 计算总算力
let totalSystemContribution = 0n;
for (const account of localAccounts) {
totalSystemContribution += BigInt(
account.totalContribution.toString().replace('.', ''),
);
}
let totalSyncedContribution = 0n; let totalSyncedContribution = 0n;
for (const contrib of syncedContributions) { for (const contrib of syncedContributions) {
totalSyncedContribution += BigInt( totalSyncedContribution += BigInt(
@ -88,11 +85,22 @@ export class SystemAccountsService {
return { return {
systemAccounts: { systemAccounts: {
count: localAccounts.length, count: syncedSystemAccounts.length,
totalContribution: ( totalBalance: syncedSystemAccounts.reduce(
Number(totalSystemContribution) / 100000000 (sum, acc) => sum + Number(acc.shareBalance),
0,
).toFixed(8), ).toFixed(8),
}, },
poolAccounts: {
count: syncedPoolAccounts.length,
pools: syncedPoolAccounts.map((pool) => ({
poolType: pool.poolType,
name: pool.name,
balance: pool.balance.toString(),
targetBurn: pool.targetBurn?.toString(),
remainingBurn: pool.remainingBurn?.toString(),
})),
},
syncedContributions: { syncedContributions: {
count: syncedContributions.length, count: syncedContributions.length,
totalBalance: (Number(totalSyncedContribution) / 100000000).toFixed(8), totalBalance: (Number(totalSyncedContribution) / 100000000).toFixed(8),