From 77cd983ad043f06fab2de8ffdd400e3dd7b31d3d Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 12 Sep 2025 19:48:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=98=AF=E8=B4=A2=E5=AF=8C?= =?UTF-8?q?=E6=A6=9C=EF=BC=8C=E5=A2=9E=E5=8A=A0=20userSex=3D1=20=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/WeekKingQueenCountServiceImpl.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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"), // 每组取第一个文档