From 48f21a86b339c76369c17c84e227369285d98ccd Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 11 Mar 2026 14:46:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9B=B4=E6=96=B0CP=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E9=A1=B5=E7=94=A8=E6=88=B7=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/UpdateStartPageUserTask.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/UpdateStartPageUserTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/UpdateStartPageUserTask.java index 2b1967c7..3943f0ab 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/UpdateStartPageUserTask.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/UpdateStartPageUserTask.java @@ -5,6 +5,9 @@ import com.red.circle.component.redis.annotation.TaskCacheLock; import com.red.circle.other.domain.ranking.RankingActivityType; import com.red.circle.other.domain.ranking.RankingCycleType; import com.red.circle.other.infra.database.mongo.entity.activity.RankingActivityRecord; +import com.red.circle.other.infra.database.mongo.entity.user.count.WeekCpValueCount; +import com.red.circle.other.infra.database.mongo.service.user.count.WeekCpValueCountService; +import org.apache.commons.lang3.tuple.ImmutablePair; import com.red.circle.other.infra.database.rds.entity.sys.StartPageUser; import com.red.circle.other.infra.database.rds.service.sys.StartPageUserService; import com.red.circle.other.infra.gateway.RankingActivityGateway; @@ -33,8 +36,10 @@ public class UpdateStartPageUserTask { private final RankingActivityGateway rankingActivityGateway; private final StartPageUserService startPageUserService; + private final WeekCpValueCountService weekCpValueCountService; private static final String START_PAGE_TYPE = "KING_GAMES"; + private static final String CP_START_PAGE_TYPE = "CP"; private static final Integer EXPIRE_DAYS = 7; /** @@ -69,6 +74,69 @@ public class UpdateStartPageUserTask { } } + /** + * 每周一 0点10分执行,更新CP启动页用户 + */ + @Scheduled(cron = "0 10 0 ? * MON", zone = "Asia/Riyadh") + @TaskCacheLock(key = "UPDATE_CP_START_PAGE_USER_TASK", expireSecond = 86400) + @Transactional(rollbackFor = Exception.class) + public void updateCpStartPage() { + log.warn("========== 更新CP启动页用户定时任务开始 =========="); + long startTime = System.currentTimeMillis(); + + try { + String sysOrigin = SysOriginPlatformEnum.LIKEI.name(); + + List topList = weekCpValueCountService.listLastWeekTop(sysOrigin, 1); + + if (CollectionUtils.isEmpty(topList)) { + log.warn("上周CP排行榜为空,跳过更新"); + return; + } + + String topId = topList.get(0).getId(); + ImmutablePair userIdPair = weekCpValueCountService.parseUserIdPair(topId); + + if (userIdPair.getLeft() == null || userIdPair.getRight() == null) { + log.warn("CP排行榜第一名ID解析失败: {}", topId); + return; + } + + Long userIdOne = userIdPair.getLeft(); + Long userIdTwo = userIdPair.getRight(); + Timestamp expireTime = calculateExpireTime(); + + updateCpStartPageUser(sysOrigin, 1, userIdOne, expireTime); + updateCpStartPageUser(sysOrigin, 2, userIdTwo, expireTime); + + log.warn("========== 更新CP启动页用户定时任务完成,耗时:{} ms,userId1:{},userId2:{} ==========", + System.currentTimeMillis() - startTime, userIdOne, userIdTwo); + + } catch (Exception e) { + log.error("========== 更新CP启动页用户定时任务异常 ==========", e); + throw e; + } + } + + private void updateCpStartPageUser(String sysOrigin, Integer sort, Long userId, Timestamp expireTime) { + StartPageUser record = startPageUserService.query() + .eq(StartPageUser::getSysOrigin, sysOrigin) + .eq(StartPageUser::getType, CP_START_PAGE_TYPE) + .eq(StartPageUser::getSort, sort) + .last("LIMIT 1") + .getOne(); + + if (record == null) { + log.warn("未找到CP启动页用户记录,sysOrigin={},sort={}", sysOrigin, sort); + return; + } + + record.setUserId(userId); + record.setExpireTime(expireTime); + startPageUserService.updateSelectiveById(record); + log.info("更新CP启动页用户成功,id={},sort={},userId={},expireTime={}", record.getId(), sort, userId, expireTime); + } + /** * 获取上周排名第一的用户 */