diff --git a/backend/services/admin-service/src/api/controllers/user-detail.controller.ts b/backend/services/admin-service/src/api/controllers/user-detail.controller.ts index 74321e28..96030771 100644 --- a/backend/services/admin-service/src/api/controllers/user-detail.controller.ts +++ b/backend/services/admin-service/src/api/controllers/user-detail.controller.ts @@ -194,9 +194,9 @@ export class UserDetailController { } const [summary, ledger] = await Promise.all([ - this.userDetailRepository.getPlantingSummary(user.userId), + this.userDetailRepository.getPlantingSummary(accountSequence), this.userDetailRepository.getPlantingLedger( - user.userId, + accountSequence, query.page || 1, query.pageSize || 20, query.startDate ? new Date(query.startDate) : undefined, @@ -250,9 +250,9 @@ export class UserDetailController { } const [summary, ledger] = await Promise.all([ - this.userDetailRepository.getWalletSummary(user.userId), + this.userDetailRepository.getWalletSummary(accountSequence), this.userDetailRepository.getWalletLedger( - user.userId, + accountSequence, query.page || 1, query.pageSize || 20, { diff --git a/backend/services/admin-service/src/domain/repositories/user-detail-query.repository.ts b/backend/services/admin-service/src/domain/repositories/user-detail-query.repository.ts index 7d2a8cad..e04198f3 100644 --- a/backend/services/admin-service/src/domain/repositories/user-detail-query.repository.ts +++ b/backend/services/admin-service/src/domain/repositories/user-detail-query.repository.ts @@ -203,13 +203,13 @@ export interface IUserDetailQueryRepository { /** * 获取认种汇总 */ - getPlantingSummary(userId: bigint): Promise; + getPlantingSummary(accountSequence: string): Promise; /** * 获取认种分类账 */ getPlantingLedger( - userId: bigint, + accountSequence: string, page: number, pageSize: number, startDate?: Date, @@ -219,13 +219,13 @@ export interface IUserDetailQueryRepository { /** * 获取钱包汇总 */ - getWalletSummary(userId: bigint): Promise; + getWalletSummary(accountSequence: string): Promise; /** * 获取钱包分类账 */ getWalletLedger( - userId: bigint, + accountSequence: string, page: number, pageSize: number, filters?: WalletLedgerFilters, diff --git a/backend/services/admin-service/src/infrastructure/persistence/repositories/user-detail-query.repository.impl.ts b/backend/services/admin-service/src/infrastructure/persistence/repositories/user-detail-query.repository.impl.ts index 153c2be6..88505135 100644 --- a/backend/services/admin-service/src/infrastructure/persistence/repositories/user-detail-query.repository.impl.ts +++ b/backend/services/admin-service/src/infrastructure/persistence/repositories/user-detail-query.repository.impl.ts @@ -159,16 +159,24 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository // 认种相关 // ============================================================================ - async getPlantingSummary(userId: bigint): Promise { - // 获取持仓信息 - const position = await this.prisma.plantingPositionQueryView.findUnique({ - where: { userId }, + async getPlantingSummary(accountSequence: string): Promise { + // 先获取用户的 userId 用于查询持仓 + const user = await this.prisma.userQueryView.findUnique({ + where: { accountSequence }, + select: { userId: true }, }); - // 获取订单统计 + if (!user) return null; + + // 获取持仓信息 + const position = await this.prisma.plantingPositionQueryView.findUnique({ + where: { userId: user.userId }, + }); + + // 获取订单统计 - 使用 accountSequence const [orderStats, firstOrder, lastOrder] = await Promise.all([ this.prisma.plantingOrderQueryView.aggregate({ - where: { userId }, + where: { accountSequence }, _count: true, _sum: { treeCount: true, @@ -176,12 +184,12 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository }, }), this.prisma.plantingOrderQueryView.findFirst({ - where: { userId, paidAt: { not: null } }, + where: { accountSequence, paidAt: { not: null } }, orderBy: { paidAt: 'asc' }, select: { paidAt: true }, }), this.prisma.plantingOrderQueryView.findFirst({ - where: { userId, paidAt: { not: null } }, + where: { accountSequence, paidAt: { not: null } }, orderBy: { paidAt: 'desc' }, select: { paidAt: true }, }), @@ -199,13 +207,13 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository } async getPlantingLedger( - userId: bigint, + accountSequence: string, page: number, pageSize: number, startDate?: Date, endDate?: Date, ): Promise { - const where: any = { userId }; + const where: any = { accountSequence }; if (startDate || endDate) { where.createdAt = {}; @@ -248,9 +256,9 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository // 钱包相关 // ============================================================================ - async getWalletSummary(userId: bigint): Promise { + async getWalletSummary(accountSequence: string): Promise { const wallet = await this.prisma.walletAccountQueryView.findUnique({ - where: { userId }, + where: { accountSequence }, }); if (!wallet) return null; @@ -279,12 +287,12 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository } async getWalletLedger( - userId: bigint, + accountSequence: string, page: number, pageSize: number, filters?: WalletLedgerFilters, ): Promise { - const where: any = { userId }; + const where: any = { accountSequence }; if (filters?.assetType) { where.assetType = filters.assetType;