fix(admin-service): 修复祖先节点数据获取依赖 user_query_view 的问题
问题:当祖先用户存在于 referral_query_view 但不存在于 user_query_view 时(CDC 同步延迟),祖先节点的 accountSequence 和统计数据无法正确获取。 修复: - 改用 referralAccountSequences(从 referrals 获取) 替代 userAccountSequences(从 users 获取) - 确保即使用户基本信息未同步,仍能获取正确的认种统计 🤖 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
ca337bcdb7
commit
a86116fef4
|
|
@ -83,13 +83,14 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository
|
|||
]);
|
||||
|
||||
// 实时统计:获取每个祖先的认种数量、团队认种量和直推数量
|
||||
const userAccountSequences = users.map(u => u.accountSequence);
|
||||
// 注意:优先从 referrals 获取 accountSequences,因为用户可能不存在于 user_query_view
|
||||
const referralAccountSequences = referrals.map(r => r.accountSequence);
|
||||
const [adoptionCounts, directReferralCounts, teamStats] = await Promise.all([
|
||||
// 统计每个用户的认种订单数量(状态为 MINING_ENABLED)
|
||||
this.prisma.plantingOrderQueryView.groupBy({
|
||||
by: ['accountSequence'],
|
||||
where: {
|
||||
accountSequence: { in: userAccountSequences },
|
||||
accountSequence: { in: referralAccountSequences },
|
||||
status: 'MINING_ENABLED',
|
||||
},
|
||||
_count: { id: true },
|
||||
|
|
@ -101,7 +102,7 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository
|
|||
_count: { userId: true },
|
||||
}),
|
||||
// 获取团队认种量
|
||||
this.getBatchUserStats(userAccountSequences),
|
||||
this.getBatchUserStats(referralAccountSequences),
|
||||
]);
|
||||
|
||||
const adoptionCountMap = new Map(adoptionCounts.map(a => [a.accountSequence, a._count.id]));
|
||||
|
|
|
|||
Loading…
Reference in New Issue