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:
parent
b49776fadb
commit
f15bdeaef8
|
|
@ -194,9 +194,9 @@ export class UserDetailController {
|
||||||
}
|
}
|
||||||
|
|
||||||
const [summary, ledger] = await Promise.all([
|
const [summary, ledger] = await Promise.all([
|
||||||
this.userDetailRepository.getPlantingSummary(user.userId),
|
this.userDetailRepository.getPlantingSummary(accountSequence),
|
||||||
this.userDetailRepository.getPlantingLedger(
|
this.userDetailRepository.getPlantingLedger(
|
||||||
user.userId,
|
accountSequence,
|
||||||
query.page || 1,
|
query.page || 1,
|
||||||
query.pageSize || 20,
|
query.pageSize || 20,
|
||||||
query.startDate ? new Date(query.startDate) : undefined,
|
query.startDate ? new Date(query.startDate) : undefined,
|
||||||
|
|
@ -250,9 +250,9 @@ export class UserDetailController {
|
||||||
}
|
}
|
||||||
|
|
||||||
const [summary, ledger] = await Promise.all([
|
const [summary, ledger] = await Promise.all([
|
||||||
this.userDetailRepository.getWalletSummary(user.userId),
|
this.userDetailRepository.getWalletSummary(accountSequence),
|
||||||
this.userDetailRepository.getWalletLedger(
|
this.userDetailRepository.getWalletLedger(
|
||||||
user.userId,
|
accountSequence,
|
||||||
query.page || 1,
|
query.page || 1,
|
||||||
query.pageSize || 20,
|
query.pageSize || 20,
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -203,13 +203,13 @@ export interface IUserDetailQueryRepository {
|
||||||
/**
|
/**
|
||||||
* 获取认种汇总
|
* 获取认种汇总
|
||||||
*/
|
*/
|
||||||
getPlantingSummary(userId: bigint): Promise<PlantingSummary | null>;
|
getPlantingSummary(accountSequence: string): Promise<PlantingSummary | null>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取认种分类账
|
* 获取认种分类账
|
||||||
*/
|
*/
|
||||||
getPlantingLedger(
|
getPlantingLedger(
|
||||||
userId: bigint,
|
accountSequence: string,
|
||||||
page: number,
|
page: number,
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
startDate?: Date,
|
startDate?: Date,
|
||||||
|
|
@ -219,13 +219,13 @@ export interface IUserDetailQueryRepository {
|
||||||
/**
|
/**
|
||||||
* 获取钱包汇总
|
* 获取钱包汇总
|
||||||
*/
|
*/
|
||||||
getWalletSummary(userId: bigint): Promise<WalletSummary | null>;
|
getWalletSummary(accountSequence: string): Promise<WalletSummary | null>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取钱包分类账
|
* 获取钱包分类账
|
||||||
*/
|
*/
|
||||||
getWalletLedger(
|
getWalletLedger(
|
||||||
userId: bigint,
|
accountSequence: string,
|
||||||
page: number,
|
page: number,
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
filters?: WalletLedgerFilters,
|
filters?: WalletLedgerFilters,
|
||||||
|
|
|
||||||
|
|
@ -159,16 +159,24 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository
|
||||||
// 认种相关
|
// 认种相关
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
async getPlantingSummary(userId: bigint): Promise<PlantingSummary | null> {
|
async getPlantingSummary(accountSequence: string): Promise<PlantingSummary | null> {
|
||||||
// 获取持仓信息
|
// 先获取用户的 userId 用于查询持仓
|
||||||
const position = await this.prisma.plantingPositionQueryView.findUnique({
|
const user = await this.prisma.userQueryView.findUnique({
|
||||||
where: { userId },
|
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([
|
const [orderStats, firstOrder, lastOrder] = await Promise.all([
|
||||||
this.prisma.plantingOrderQueryView.aggregate({
|
this.prisma.plantingOrderQueryView.aggregate({
|
||||||
where: { userId },
|
where: { accountSequence },
|
||||||
_count: true,
|
_count: true,
|
||||||
_sum: {
|
_sum: {
|
||||||
treeCount: true,
|
treeCount: true,
|
||||||
|
|
@ -176,12 +184,12 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
this.prisma.plantingOrderQueryView.findFirst({
|
this.prisma.plantingOrderQueryView.findFirst({
|
||||||
where: { userId, paidAt: { not: null } },
|
where: { accountSequence, paidAt: { not: null } },
|
||||||
orderBy: { paidAt: 'asc' },
|
orderBy: { paidAt: 'asc' },
|
||||||
select: { paidAt: true },
|
select: { paidAt: true },
|
||||||
}),
|
}),
|
||||||
this.prisma.plantingOrderQueryView.findFirst({
|
this.prisma.plantingOrderQueryView.findFirst({
|
||||||
where: { userId, paidAt: { not: null } },
|
where: { accountSequence, paidAt: { not: null } },
|
||||||
orderBy: { paidAt: 'desc' },
|
orderBy: { paidAt: 'desc' },
|
||||||
select: { paidAt: true },
|
select: { paidAt: true },
|
||||||
}),
|
}),
|
||||||
|
|
@ -199,13 +207,13 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPlantingLedger(
|
async getPlantingLedger(
|
||||||
userId: bigint,
|
accountSequence: string,
|
||||||
page: number,
|
page: number,
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
startDate?: Date,
|
startDate?: Date,
|
||||||
endDate?: Date,
|
endDate?: Date,
|
||||||
): Promise<PlantingLedgerResult> {
|
): Promise<PlantingLedgerResult> {
|
||||||
const where: any = { userId };
|
const where: any = { accountSequence };
|
||||||
|
|
||||||
if (startDate || endDate) {
|
if (startDate || endDate) {
|
||||||
where.createdAt = {};
|
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({
|
const wallet = await this.prisma.walletAccountQueryView.findUnique({
|
||||||
where: { userId },
|
where: { accountSequence },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!wallet) return null;
|
if (!wallet) return null;
|
||||||
|
|
@ -279,12 +287,12 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
async getWalletLedger(
|
async getWalletLedger(
|
||||||
userId: bigint,
|
accountSequence: string,
|
||||||
page: number,
|
page: number,
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
filters?: WalletLedgerFilters,
|
filters?: WalletLedgerFilters,
|
||||||
): Promise<WalletLedgerResult> {
|
): Promise<WalletLedgerResult> {
|
||||||
const where: any = { userId };
|
const where: any = { accountSequence };
|
||||||
|
|
||||||
if (filters?.assetType) {
|
if (filters?.assetType) {
|
||||||
where.assetType = filters.assetType;
|
where.assetType = filters.assetType;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue