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:
parent
eff71a6b22
commit
fa6826dde3
|
|
@ -7,55 +7,53 @@ export class SystemAccountsService {
|
|||
|
||||
/**
|
||||
* 获取系统账户列表
|
||||
* 从 CDC 同步的钱包系统账户表读取数据
|
||||
*/
|
||||
async getSystemAccounts() {
|
||||
// 先从本地 SystemAccount 表获取
|
||||
const localAccounts = await this.prisma.systemAccount.findMany({
|
||||
// 从 CDC 同步的 SyncedWalletSystemAccount 表获取数据
|
||||
const syncedAccounts = await this.prisma.syncedWalletSystemAccount.findMany({
|
||||
orderBy: { accountType: 'asc' },
|
||||
});
|
||||
|
||||
// 再从 CDC 同步的 SyncedSystemContribution 获取算力数据
|
||||
// 从 CDC 同步的 SyncedSystemContribution 获取算力数据
|
||||
const syncedContributions =
|
||||
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) {
|
||||
accountsMap.set(account.accountType, {
|
||||
// 构建返回数据
|
||||
const accounts = syncedAccounts.map((account) => {
|
||||
const contrib = contributionMap.get(account.accountType);
|
||||
return {
|
||||
id: account.originalId,
|
||||
accountType: account.accountType,
|
||||
name: account.name,
|
||||
description: account.description,
|
||||
totalContribution: account.totalContribution.toString(),
|
||||
createdAt: account.createdAt,
|
||||
source: 'local',
|
||||
});
|
||||
}
|
||||
|
||||
// 更新或添加同步的算力数据
|
||||
for (const contrib of syncedContributions) {
|
||||
const existing = accountsMap.get(contrib.accountType);
|
||||
if (existing) {
|
||||
existing.contributionBalance = contrib.contributionBalance.toString();
|
||||
existing.contributionNeverExpires = contrib.contributionNeverExpires;
|
||||
existing.syncedAt = contrib.syncedAt;
|
||||
existing.source = 'synced';
|
||||
} else {
|
||||
accountsMap.set(contrib.accountType, {
|
||||
accountType: contrib.accountType,
|
||||
name: contrib.name,
|
||||
contributionBalance: contrib.contributionBalance.toString(),
|
||||
contributionNeverExpires: contrib.contributionNeverExpires,
|
||||
syncedAt: contrib.syncedAt,
|
||||
source: 'synced',
|
||||
});
|
||||
}
|
||||
}
|
||||
code: account.code,
|
||||
provinceId: account.provinceId,
|
||||
cityId: account.cityId,
|
||||
shareBalance: account.shareBalance.toString(),
|
||||
usdtBalance: account.usdtBalance.toString(),
|
||||
greenPointBalance: account.greenPointBalance.toString(),
|
||||
frozenShare: account.frozenShare.toString(),
|
||||
frozenUsdt: account.frozenUsdt.toString(),
|
||||
totalInflow: account.totalInflow.toString(),
|
||||
totalOutflow: account.totalOutflow.toString(),
|
||||
blockchainAddress: account.blockchainAddress,
|
||||
isActive: account.isActive,
|
||||
contributionBalance: contrib?.contributionBalance?.toString() || '0',
|
||||
contributionNeverExpires: contrib?.contributionNeverExpires || false,
|
||||
syncedAt: account.syncedAt,
|
||||
source: 'cdc',
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
accounts: Array.from(accountsMap.values()),
|
||||
total: accountsMap.size,
|
||||
accounts,
|
||||
total: accounts.length,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -63,22 +61,21 @@ export class SystemAccountsService {
|
|||
* 获取系统账户汇总
|
||||
*/
|
||||
async getSystemAccountsSummary() {
|
||||
const [localAccounts, syncedContributions, miningConfig, circulationPool] =
|
||||
await Promise.all([
|
||||
this.prisma.systemAccount.findMany(),
|
||||
this.prisma.syncedSystemContribution.findMany(),
|
||||
this.prisma.syncedMiningConfig.findFirst(),
|
||||
this.prisma.syncedCirculationPool.findFirst(),
|
||||
]);
|
||||
const [
|
||||
syncedSystemAccounts,
|
||||
syncedPoolAccounts,
|
||||
syncedContributions,
|
||||
miningConfig,
|
||||
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;
|
||||
for (const contrib of syncedContributions) {
|
||||
totalSyncedContribution += BigInt(
|
||||
|
|
@ -88,11 +85,22 @@ export class SystemAccountsService {
|
|||
|
||||
return {
|
||||
systemAccounts: {
|
||||
count: localAccounts.length,
|
||||
totalContribution: (
|
||||
Number(totalSystemContribution) / 100000000
|
||||
count: syncedSystemAccounts.length,
|
||||
totalBalance: syncedSystemAccounts.reduce(
|
||||
(sum, acc) => sum + Number(acc.shareBalance),
|
||||
0,
|
||||
).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: {
|
||||
count: syncedContributions.length,
|
||||
totalBalance: (Number(totalSyncedContribution) / 100000000).toFixed(8),
|
||||
|
|
|
|||
Loading…
Reference in New Issue