diff --git a/backend/services/mining-admin-service/src/application/services/system-accounts.service.ts b/backend/services/mining-admin-service/src/application/services/system-accounts.service.ts index 8ff2abcf..a1238edb 100644 --- a/backend/services/mining-admin-service/src/application/services/system-accounts.service.ts +++ b/backend/services/mining-admin-service/src/application/services/system-accounts.service.ts @@ -81,6 +81,9 @@ export class SystemAccountsService { // 从 mining-service 获取挖矿数据 const miningDataMap = await this.fetchMiningServiceSystemAccounts(); + // 获取省市名称映射 + const regionNameMap = await this.buildRegionNameMap(); + // 构建钱包数据映射 const walletMap = new Map(); 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> { + 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(); + 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 { + // 基础账户类型名称 + const baseNames: Record = { + 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"