新增更新CP启动页用户定时任务
This commit is contained in:
parent
e55f3b909a
commit
48f21a86b3
@ -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<WeekCpValueCount> topList = weekCpValueCountService.listLastWeekTop(sysOrigin, 1);
|
||||
|
||||
if (CollectionUtils.isEmpty(topList)) {
|
||||
log.warn("上周CP排行榜为空,跳过更新");
|
||||
return;
|
||||
}
|
||||
|
||||
String topId = topList.get(0).getId();
|
||||
ImmutablePair<Long, Long> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上周排名第一的用户
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user