refactor(admin-service): 团队认种量改用 PlantingOrderQueryView
统一使用 PlantingOrderQueryView 计算团队认种量, 与个人认种量保持一致的数据源,避免 CDC 同步不一致问题 🤖 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
97bcaa2dfc
commit
bab30dbeba
|
|
@ -529,18 +529,25 @@ export class UserDetailQueryRepositoryImpl implements IUserDetailQueryRepository
|
||||||
|
|
||||||
const teamAddressCount = teamMembers.length;
|
const teamAddressCount = teamMembers.length;
|
||||||
|
|
||||||
// 2. 获取团队认种量:汇总所有团队成员的有效认种树数
|
// 2. 获取团队认种量:汇总所有团队成员的有效认种订单数
|
||||||
|
// 使用 PlantingOrderQueryView 而不是 PlantingPositionQueryView,保持与个人认种量一致
|
||||||
let teamAdoptionCount = 0;
|
let teamAdoptionCount = 0;
|
||||||
if (teamMembers.length > 0) {
|
if (teamMembers.length > 0) {
|
||||||
const teamUserIds = teamMembers.map((m) => m.userId);
|
const teamAccountSequences = await this.prisma.referralQueryView.findMany({
|
||||||
const positions = await this.prisma.plantingPositionQueryView.findMany({
|
|
||||||
where: {
|
where: {
|
||||||
userId: { in: teamUserIds },
|
userId: { in: teamMembers.map((m) => m.userId) },
|
||||||
},
|
},
|
||||||
select: { effectiveTreeCount: true },
|
select: { accountSequence: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
teamAdoptionCount = positions.reduce((sum, p) => sum + p.effectiveTreeCount, 0);
|
const count = await this.prisma.plantingOrderQueryView.count({
|
||||||
|
where: {
|
||||||
|
accountSequence: { in: teamAccountSequences.map((t) => t.accountSequence) },
|
||||||
|
status: 'MINING_ENABLED',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
teamAdoptionCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { teamAddressCount, teamAdoptionCount };
|
return { teamAddressCount, teamAdoptionCount };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue