diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/activity/SpringFestivalRechargeRewardTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/activity/SpringFestivalRechargeRewardTask.java new file mode 100644 index 00000000..3a6fe258 --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/activity/SpringFestivalRechargeRewardTask.java @@ -0,0 +1,89 @@ +package com.red.circle.other.app.scheduler.activity; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; +import com.red.circle.common.business.enums.SendPropsOrigin; +import com.red.circle.component.redis.annotation.TaskCacheLock; +import com.red.circle.other.infra.database.rds.dao.activity.UserActivityRechargeDAO; +import com.red.circle.other.infra.database.rds.dto.activity.ActivityRechargeRankDTO; +import com.red.circle.other.inner.model.cmd.activity.SendActivityRewardCmd; +import com.red.circle.other.inner.endpoint.activity.PropsActivityClient; +import com.red.circle.tool.core.collection.CollectionUtils; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 2026 Spring Festival 充值活动奖励发放. + * + * @author tf + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class SpringFestivalRechargeRewardTask { + + private static final Long ACTIVITY_ID = 2007771533988204877L; + private static final String RECHARGE_TYPE = "LUCKY_WIN"; + + // TOP1~TOP3 各自独立奖励组,TOP4~10 共用同一个 + private static final long REWARD_TOP1 = 2021175644056657922L; + private static final long REWARD_TOP2 = 2021175937418862593L; + private static final long REWARD_TOP3 = 2021176242588033025L; + private static final long REWARD_TOP4_10 = 2021176565687853057L; + + private final UserActivityRechargeDAO userActivityRechargeDAO; + private final PropsActivityClient propsActivityClient; + + /** + * Asia/Riyadh 周六 0点执行,只执行一次. + */ + @Scheduled(cron = "0 0 0 ? * SAT", zone = "Asia/Riyadh") + @TaskCacheLock(key = "SPRING_FESTIVAL_RECHARGE_REWARD_TASK", expireSecond = 86400) + public void sendRechargeReward() { + log.warn("[SpringFestival] 充值活动奖励发放 start"); + try { + Page page = new Page<>(1, 10); + List top10 = userActivityRechargeDAO.pageRechargeRank(page, ACTIVITY_ID, RECHARGE_TYPE) + .getRecords(); + + if (CollectionUtils.isEmpty(top10)) { + log.warn("[SpringFestival] 排行榜为空,跳过奖励发放"); + return; + } + + for (int i = 0; i < top10.size(); i++) { + int rank = i + 1; + Long userId = top10.get(i).getUserId(); + long rewardGroupId = resolveRewardGroupId(rank); + try { + propsActivityClient.sendActivityReward(new SendActivityRewardCmd() + .setTrackId(ACTIVITY_ID) + .setOrigin(SendPropsOrigin.RANKING_ACTIVITY) + .setSysOrigin(SysOriginPlatformEnum.LIKEI) + .setSourceGroupId(rewardGroupId) + .setAcceptUserId(userId) + ); + log.info("[SpringFestival] 奖励发放成功 rank={} userId={} rewardGroupId={}", rank, userId, rewardGroupId); + } catch (Exception e) { + log.error("[SpringFestival] 奖励发放失败 rank={} userId={}", rank, userId, e); + } + } + } catch (Exception e) { + log.error("[SpringFestival] 充值活动奖励发放异常", e); + } + log.warn("[SpringFestival] 充值活动奖励发放 end"); + } + + private long resolveRewardGroupId(int rank) { + switch (rank) { + case 1: return REWARD_TOP1; + case 2: return REWARD_TOP2; + case 3: return REWARD_TOP3; + default: return REWARD_TOP4_10; + } + } +} diff --git a/rc-service/rc-service-other/other-start/src/test/java/DailTaskTest.java b/rc-service/rc-service-other/other-start/src/test/java/DailTaskTest.java index be8f12db..eb7ca0e3 100644 --- a/rc-service/rc-service-other/other-start/src/test/java/DailTaskTest.java +++ b/rc-service/rc-service-other/other-start/src/test/java/DailTaskTest.java @@ -6,6 +6,7 @@ import com.red.circle.mq.rocket.business.producer.UserMqMessageService; import com.red.circle.other.app.scheduler.RankingActivityRewardTask; import com.red.circle.other.app.scheduler.RocketStatusSyncTask; import com.red.circle.other.app.scheduler.activity.RamadanRankingBadgeTask; +import com.red.circle.other.app.scheduler.activity.SpringFestivalRechargeRewardTask; import com.red.circle.other.app.scheduler.cp.CleanExpiredDismissingCpTask; import com.red.circle.other.infra.database.rds.entity.badge.BadgeBackpack; import com.red.circle.other.infra.database.rds.service.badge.BadgeBackpackService; @@ -43,6 +44,8 @@ public class DailTaskTest { // private GameKingRewardTask gameKingRewardTask; @Autowired private BadgeBackpackService badgeBackpackService; + @Autowired + private SpringFestivalRechargeRewardTask springFestivalRechargeRewardTask; private final static Long[] BADGE_IDS = new Long[]{ 2021136719126454273L, // 第一名 @@ -54,7 +57,7 @@ public class DailTaskTest { @Test public void testGameKing() { -// gameKingRewardTask.executeGameKingReward(); + springFestivalRechargeRewardTask.sendRechargeReward(); } @Test