feat(mining-admin): 系统账户显示具体省市名称
- 根据 regionCode 从 SyncedProvince/SyncedCity 表查找名称 - PROVINCE + 440000 显示为 "广东省公司" - CITY + 440100 显示为 "广州市公司" Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
946978f624
commit
63aba087b6
|
|
@ -81,6 +81,9 @@ export class SystemAccountsService {
|
|||
// 从 mining-service 获取挖矿数据
|
||||
const miningDataMap = await this.fetchMiningServiceSystemAccounts();
|
||||
|
||||
// 获取省市名称映射
|
||||
const regionNameMap = await this.buildRegionNameMap();
|
||||
|
||||
// 构建钱包数据映射
|
||||
const walletMap = new Map<string, any>();
|
||||
for (const wallet of syncedWalletAccounts) {
|
||||
|
|
@ -105,11 +108,14 @@ export class SystemAccountsService {
|
|||
const wallet = walletMap.get(key) || walletMap.get(contrib.accountType);
|
||||
const miningData = miningDataMap.get(key) || miningDataMap.get(contrib.accountType);
|
||||
|
||||
// 获取显示名称
|
||||
const displayName = this.getDisplayName(contrib.accountType, contrib.regionCode, regionNameMap);
|
||||
|
||||
return {
|
||||
id: contrib.id,
|
||||
accountType: contrib.accountType,
|
||||
regionCode: contrib.regionCode,
|
||||
name: contrib.name,
|
||||
name: displayName,
|
||||
code: wallet?.code || null,
|
||||
provinceId: wallet?.provinceId || null,
|
||||
cityId: wallet?.cityId || null,
|
||||
|
|
@ -142,6 +148,59 @@ export class SystemAccountsService {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建区域代码到名称的映射
|
||||
*/
|
||||
private async buildRegionNameMap(): Promise<Map<string, string>> {
|
||||
const [provinces, cities] = await Promise.all([
|
||||
this.prisma.syncedProvince.findMany({ select: { code: true, name: true } }),
|
||||
this.prisma.syncedCity.findMany({ select: { code: true, name: true } }),
|
||||
]);
|
||||
|
||||
const map = new Map<string, string>();
|
||||
for (const province of provinces) {
|
||||
map.set(province.code, province.name);
|
||||
}
|
||||
for (const city of cities) {
|
||||
map.set(city.code, city.name);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据账户类型和区域代码获取显示名称
|
||||
*/
|
||||
private getDisplayName(
|
||||
accountType: string,
|
||||
regionCode: string | null,
|
||||
regionNameMap: Map<string, string>,
|
||||
): string {
|
||||
// 基础账户类型名称
|
||||
const baseNames: Record<string, string> = {
|
||||
OPERATION: '运营账户',
|
||||
HEADQUARTERS: '总部账户',
|
||||
PROVINCE: '省公司账户',
|
||||
CITY: '市公司账户',
|
||||
};
|
||||
|
||||
if (!regionCode) {
|
||||
return baseNames[accountType] || accountType;
|
||||
}
|
||||
|
||||
// 根据区域代码查找名称
|
||||
const regionName = regionNameMap.get(regionCode);
|
||||
if (regionName) {
|
||||
if (accountType === 'PROVINCE') {
|
||||
return `${regionName}省公司`;
|
||||
} else if (accountType === 'CITY') {
|
||||
return `${regionName}市公司`;
|
||||
}
|
||||
}
|
||||
|
||||
// 回退:使用区域代码
|
||||
return `${regionCode}账户`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从钱包账户的 code 提取区域代码
|
||||
* 例如: "CITY-440100" -> "440100", "PROVINCE-440000" -> "440000"
|
||||
|
|
|
|||
Loading…
Reference in New Issue