diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftAnchorCountStrategy.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftAnchorCountStrategy.java index 987c6644..58c80a90 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftAnchorCountStrategy.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftAnchorCountStrategy.java @@ -156,8 +156,8 @@ public class GiftAnchorCountStrategy implements GiftStrategy { teamIds.add(teamMember.getTeamId()); // 团队内 -> 代理主播活动(永久活动) -// activityAgentAnchorCount(acceptAnchorUser.getTargetAmount().longValue(), -// acceptAnchorUser.getAcceptUserId(), teamMember.getTeamId()); + activityAgentAnchorCount(acceptAnchorUser.getTargetAmount().longValue(), + acceptAnchorUser.getAcceptUserId(), teamMember.getTeamId()); // 代理活动(永久活动) // agentActivityCount(acceptAnchorUser, teamMember.getTeamId()); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/ActivityAgentAnchorCountServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/ActivityAgentAnchorCountServiceImpl.java index 70da0065..282ffaef 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/ActivityAgentAnchorCountServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/ActivityAgentAnchorCountServiceImpl.java @@ -6,6 +6,7 @@ import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.sequence.IdWorkerUtils; +import java.time.ZonedDateTime; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -64,6 +65,10 @@ public class ActivityAgentAnchorCountServiceImpl implements ActivityAgentAnchorC @Override public void initZero(Long acceptUserId, Long teamId) { + if (!isMonthEndResetDay()) { + return; + } + // 主播月收礼,永久活动 Long quantity1 = getCountQuantity(acceptUserId, "ACTIVE_ANCHOR_MONTH_TARGET_REWARD", getThisMonthDate()); @@ -87,6 +92,10 @@ public class ActivityAgentAnchorCountServiceImpl implements ActivityAgentAnchorC @Override public void initZeroTeam(Long teamId) { + if (!isMonthEndResetDay()) { + return; + } + mongoTemplate.updateFirst(Query.query(Criteria.where("businessId").is(teamId) .and("group").is("ACTIVE_AGENT_MONTH_TARGET_REWARD") .and("dateNumber").is(getThisMonthDate())), @@ -97,6 +106,10 @@ public class ActivityAgentAnchorCountServiceImpl implements ActivityAgentAnchorC @Override public void initZeroMember(Set acceptUserIds) { + if (!isMonthEndResetDay()) { + return; + } + if (CollectionUtils.isEmpty(acceptUserIds)) { return; } @@ -121,4 +134,10 @@ public class ActivityAgentAnchorCountServiceImpl implements ActivityAgentAnchorC return ZonedDateTimeAsiaRiyadhUtils.nowDateToInt(); } + protected boolean isMonthEndResetDay() { + ZonedDateTime now = ZonedDateTimeAsiaRiyadhUtils.now(); + return Objects.equals(ZonedDateTimeAsiaRiyadhUtils.nowDateToInt(), + ZonedDateTimeAsiaRiyadhUtils.getLastDayOfMonthToInt(now)); + } + } diff --git a/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/database/mongo/service/activity/impl/ActivityAgentAnchorCountServiceImplTest.java b/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/database/mongo/service/activity/impl/ActivityAgentAnchorCountServiceImplTest.java new file mode 100644 index 00000000..95fa012d --- /dev/null +++ b/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/database/mongo/service/activity/impl/ActivityAgentAnchorCountServiceImplTest.java @@ -0,0 +1,59 @@ +package com.red.circle.other.infra.database.mongo.service.activity.impl; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verifyNoInteractions; + +import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.data.mongodb.core.MongoTemplate; + +class ActivityAgentAnchorCountServiceImplTest { + + private MongoTemplate mongoTemplate; + private ActivityAgentAnchorCountServiceImpl service; + + @BeforeEach + void setUp() { + mongoTemplate = mock(MongoTemplate.class); + service = new TestableActivityAgentAnchorCountService(mongoTemplate, false); + } + + @Test + void initZeroSkipsBeforeMonthEnd() { + service.initZero(10001L, 20001L); + + verifyNoInteractions(mongoTemplate); + } + + @Test + void initZeroTeamSkipsBeforeMonthEnd() { + service.initZeroTeam(20001L); + + verifyNoInteractions(mongoTemplate); + } + + @Test + void initZeroMemberSkipsBeforeMonthEnd() { + service.initZeroMember(Set.of(10001L, 10002L)); + + verifyNoInteractions(mongoTemplate); + } + + private static class TestableActivityAgentAnchorCountService + extends ActivityAgentAnchorCountServiceImpl { + + private final boolean monthEndResetDay; + + private TestableActivityAgentAnchorCountService(MongoTemplate mongoTemplate, + boolean monthEndResetDay) { + super(mongoTemplate); + this.monthEndResetDay = monthEndResetDay; + } + + @Override + protected boolean isMonthEndResetDay() { + return monthEndResetDay; + } + } +}