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() {
|
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(),
|
||||||
|
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',
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// 更新或添加同步的算力数据
|
|
||||||
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',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
||||||
|
syncedContributions,
|
||||||
|
miningConfig,
|
||||||
|
circulationPool,
|
||||||
|
] = await Promise.all([
|
||||||
|
this.prisma.syncedWalletSystemAccount.findMany(),
|
||||||
|
this.prisma.syncedWalletPoolAccount.findMany(),
|
||||||
this.prisma.syncedSystemContribution.findMany(),
|
this.prisma.syncedSystemContribution.findMany(),
|
||||||
this.prisma.syncedMiningConfig.findFirst(),
|
this.prisma.syncedMiningConfig.findFirst(),
|
||||||
this.prisma.syncedCirculationPool.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),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue