fix(admin-service): 用户详情查询改用 accountSequence

- 钱包/认种查询从 userId 改为 accountSequence 作为关联键
- 修复用户详情页钱包数据显示为0的问题
- accountSequence 是全局唯一业务标识,关联更可靠

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-07 20:43:36 -08:00
parent b49776fadb
commit f15bdeaef8
3 changed files with 30 additions and 22 deletions

View File

@ -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,
{

View File

@ -203,13 +203,13 @@ export interface IUserDetailQueryRepository {
/**
*
*/
getPlantingSummary(userId: bigint): Promise<PlantingSummary | null>;
getPlantingSummary(accountSequence: string): Promise<PlantingSummary | null>;
/**
*
*/
getPlantingLedger(
userId: bigint,
accountSequence: string,
page: number,
pageSize: number,
startDate?: Date,
@ -219,13 +219,13 @@ export interface IUserDetailQueryRepository {
/**
*
*/
getWalletSummary(userId: bigint): Promise<WalletSummary | null>;
getWalletSummary(accountSequence: string): Promise<WalletSummary | null>;
/**
*
*/
getWalletLedger(
userId: bigint,
accountSequence: string,
page: number,
pageSize: number,
filters?: WalletLedgerFilters,

View File

@ -159,16 +159,24 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository
// 认种相关
// ============================================================================
async getPlantingSummary(userId: bigint): Promise<PlantingSummary | null> {
// 获取持仓信息
const position = await this.prisma.plantingPositionQueryView.findUnique({
where: { userId },
async getPlantingSummary(accountSequence: string): Promise<PlantingSummary | null> {
// 先获取用户的 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<PlantingLedgerResult> {
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<WalletSummary | null> {
async getWalletSummary(accountSequence: string): Promise<WalletSummary | null> {
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<WalletLedgerResult> {
const where: any = { userId };
const where: any = { accountSequence };
if (filters?.assetType) {
where.assetType = filters.assetType;