diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/WeekKingQueenCountServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/WeekKingQueenCountServiceImpl.java index 956475fd..1bcf26de 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/WeekKingQueenCountServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/WeekKingQueenCountServiceImpl.java @@ -25,6 +25,7 @@ import org.springframework.data.domain.*; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.AggregationResults; +import org.springframework.data.mongodb.core.aggregation.MatchOperation; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; @@ -181,13 +182,21 @@ public class WeekKingQueenCountServiceImpl implements WeekKingQueenCountService List top1List = new ArrayList<>(); for (KingQueenType type : Arrays.asList(KingQueenType.WEALTH, KingQueenType.CHARM)) { + Criteria criteria = Criteria.where("sysOrigin").is(sysOrigin) + .and("type").is(type) + .and("group").in(lastThreeMonthGroups); + + // 如果是财富榜,增加 userSex=1 查询条件 + if (type == KingQueenType.WEALTH) { + criteria.and("userSex").is(1); + } + if (type == KingQueenType.CHARM) { + criteria.and("userSex").is(0); + } + // 聚合查询每周 Top1 Aggregation aggregation = Aggregation.newAggregation( - Aggregation.match( - Criteria.where("sysOrigin").is(sysOrigin) - .and("type").is(type) - .and("group").in(lastThreeMonthGroups) - ), + Aggregation.match(criteria), Aggregation.sort(Sort.by(Sort.Order.desc("quantity"))), // 按数量降序 Aggregation.group("group") // 按周分组 .first(Aggregation.ROOT).as("top1"), // 每组取第一个文档