游戏王列表缓存处理
(cherry picked from commit 173dcf83ec6ce3290431c998dd93a148850b06fc)
This commit is contained in:
parent
fcaa54dab5
commit
cc803ca4fb
@ -66,7 +66,8 @@ public class RankingListQryExe {
|
||||
}
|
||||
|
||||
// 查询排行榜列表
|
||||
String regionId = cmd.getReqUserId() != null ? userRegionGateway.getRegionId(cmd.getReqUserId()) : null;
|
||||
String regionId = cmd.getRegionId() != null ? cmd.getRegionId()
|
||||
: (cmd.getReqUserId() != null ? userRegionGateway.getRegionId(cmd.getReqUserId()) : null);
|
||||
List<RankingActivityRecord> records = rankingActivityGateway.getRankingList(
|
||||
cmd.getReqSysOrigin().getOrigin(),
|
||||
activityType,
|
||||
|
||||
@ -9,6 +9,8 @@ import com.red.circle.mq.business.model.event.GameKingRewardEvent;
|
||||
import com.red.circle.mq.rocket.business.producer.UserMqMessageService;
|
||||
import com.red.circle.other.app.command.activity.query.RankingListQryExe;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.RankingListCO;
|
||||
import com.red.circle.other.infra.constant.RegionConstants;
|
||||
import com.red.circle.other.infra.utils.UserIdEncryptUtils;
|
||||
import com.red.circle.other.app.dto.cmd.activity.RankingListQueryCmd;
|
||||
import com.red.circle.other.app.service.activity.RankingActivityService;
|
||||
import com.red.circle.other.domain.ranking.RankingActivityType;
|
||||
@ -48,43 +50,44 @@ public class GameKingRewardTask {
|
||||
public void executeGameKingReward() {
|
||||
try {
|
||||
log.info("开始执行游戏王排名奖励兜底任务");
|
||||
|
||||
RankingListQueryCmd cmd = new RankingListQueryCmd();
|
||||
cmd.setCycleKey(ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString());
|
||||
cmd.setActivityType(RankingActivityType.KING_GAMES.getCode());
|
||||
cmd.setTemplateId("2001207026499137537");
|
||||
cmd.setReqSysOrigin(ReqSysOrigin.of(SysOriginPlatformEnum.ATYOU.name()));
|
||||
|
||||
RankingListQueryCmd top4Cmd = new RankingListQueryCmd();
|
||||
top4Cmd.setActivityType(cmd.getActivityType());
|
||||
top4Cmd.setCycleKey(cmd.getCycleKey());
|
||||
top4Cmd.setCycleType(RankingCycleType.WEEKLY.getCode());
|
||||
top4Cmd.setReqUserId(cmd.getReqUserId());
|
||||
top4Cmd.setReqSysOrigin(cmd.getReqSysOrigin());
|
||||
top4Cmd.setTopN(100);
|
||||
top4Cmd.setTemplateId(cmd.getTemplateId());
|
||||
|
||||
RankingListCO result = rankingListQryExe.execute(top4Cmd);
|
||||
|
||||
String cacheKey = buildRankingListCacheKey(cmd);
|
||||
if (result != null && CollectionUtils.isNotEmpty(result.getRankingList())) {
|
||||
redisService.setString(cacheKey, JSON.toJSONString(result), CACHE_EXPIRE_MINUTES, TimeUnit.MINUTES);
|
||||
|
||||
result.setRankingList(result.getRankingList().stream().limit(10).toList());
|
||||
sendGameKingRewardEvent(cmd, result);
|
||||
}
|
||||
|
||||
String cycleKey = ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString();
|
||||
executeAndCache(cycleKey, RegionConstants.AR_REGION_IDS.iterator().next(), "AR");
|
||||
executeAndCache(cycleKey, RegionConstants.OTHER_REGION_PLACEHOLDER, "OTHER");
|
||||
log.info("游戏王排名奖励兜底任务执行完成");
|
||||
} catch (Exception e) {
|
||||
log.error("游戏王排名奖励兜底任务执行失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建排行榜缓存Key.
|
||||
*/
|
||||
private String buildRankingListCacheKey(RankingListQueryCmd cmd) {
|
||||
return RANKING_LIST_CACHE_KEY_PREFIX + RankingActivityType.getByCode(cmd.getActivityType()).name() + ":" + cmd.getCycleKey();
|
||||
private void executeAndCache(String cycleKey, String regionId, String regionSuffix) {
|
||||
try {
|
||||
RankingListQueryCmd cmd = new RankingListQueryCmd();
|
||||
cmd.setCycleKey(cycleKey);
|
||||
cmd.setActivityType(RankingActivityType.KING_GAMES.getCode());
|
||||
cmd.setTemplateId("2001207026499137537");
|
||||
cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI"));
|
||||
cmd.setRegionId(regionId);
|
||||
|
||||
RankingListQueryCmd top4Cmd = new RankingListQueryCmd();
|
||||
top4Cmd.setActivityType(cmd.getActivityType());
|
||||
top4Cmd.setCycleKey(cmd.getCycleKey());
|
||||
top4Cmd.setCycleType(RankingCycleType.WEEKLY.getCode());
|
||||
top4Cmd.setReqSysOrigin(cmd.getReqSysOrigin());
|
||||
top4Cmd.setTopN(100);
|
||||
top4Cmd.setTemplateId(cmd.getTemplateId());
|
||||
top4Cmd.setRegionId(regionId);
|
||||
|
||||
RankingListCO result = rankingListQryExe.execute(top4Cmd);
|
||||
|
||||
String cacheKey = RANKING_LIST_CACHE_KEY_PREFIX + RankingActivityType.KING_GAMES.name() + ":" + cycleKey + ":" + regionSuffix;
|
||||
if (result != null && CollectionUtils.isNotEmpty(result.getRankingList())) {
|
||||
redisService.setString(cacheKey, JSON.toJSONString(result), CACHE_EXPIRE_MINUTES, TimeUnit.MINUTES);
|
||||
result.setRankingList(result.getRankingList().stream().limit(10).toList());
|
||||
sendGameKingRewardEvent(cmd, result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("游戏王排名兜底任务执行失败, regionSuffix={}", regionSuffix, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,9 +104,14 @@ public class GameKingRewardTask {
|
||||
.setCycleKey(cmd.getCycleKey())
|
||||
.setTemplateId(cmd.getTemplateId())
|
||||
.setRankingUsers(result.getRankingList().stream()
|
||||
.map(user -> new GameKingRewardEvent.RankingUser()
|
||||
.setUserId(user.getUserId())
|
||||
.setRank(user.getRank()))
|
||||
.map(user -> {
|
||||
Long userId = user.getUserId() != null ? user.getUserId()
|
||||
: (user.getEncryptedId() != null ? UserIdEncryptUtils.decrypt(user.getEncryptedId()) : null);
|
||||
return new GameKingRewardEvent.RankingUser()
|
||||
.setUserId(userId)
|
||||
.setRank(user.getRank());
|
||||
})
|
||||
.filter(user -> user.getUserId() != null)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
userMqMessageService.sendGameKingRewardEvent(event);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.red.circle.other.app.service.activity;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
|
||||
import com.red.circle.component.redis.service.RedisService;
|
||||
import com.red.circle.mq.business.model.event.GameKingRewardEvent;
|
||||
import com.red.circle.other.app.command.activity.query.HistoricalTop1QryExe;
|
||||
@ -17,22 +18,25 @@ import com.red.circle.mq.rocket.business.producer.UserMqMessageService;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import com.red.circle.other.domain.enums.VipAbilityType;
|
||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||
import com.red.circle.other.domain.model.user.UserProfile;
|
||||
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
|
||||
import com.red.circle.other.domain.ranking.RankingActivityType;
|
||||
import com.red.circle.other.domain.ranking.RankingCycleType;
|
||||
import com.red.circle.other.infra.database.cache.service.other.ActivityConfigCacheService;
|
||||
import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService;
|
||||
import com.red.circle.other.infra.database.mongo.entity.activity.RankingActivityRecord;
|
||||
import com.red.circle.other.infra.database.mongo.entity.sys.ActivityConfig;
|
||||
import com.red.circle.other.infra.constant.RegionConstants;
|
||||
import com.red.circle.other.infra.gateway.RankingActivityGateway;
|
||||
import com.red.circle.other.infra.utils.UserIdEncryptUtils;
|
||||
import com.red.circle.other.inner.enums.config.EnumConfigKey;
|
||||
import com.red.circle.tool.core.collection.CollectionUtils;
|
||||
import com.red.circle.tool.core.date.DateFormatConstant;
|
||||
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
|
||||
@ -59,6 +63,8 @@ public class RankingActivityServiceImpl implements RankingActivityService {
|
||||
private final UserProfileGateway userProfileGateway;
|
||||
private final RankingActivityGateway rankingActivityGateway;
|
||||
private final ActivityConfigCacheService activityConfigCacheService;
|
||||
private final EnumConfigCacheService enumConfigCacheService;
|
||||
private final UserRegionGateway userRegionGateway;
|
||||
|
||||
private static final String RANKING_LIST_CACHE_KEY_PREFIX = "ranking_list:";
|
||||
private static final int CACHE_EXPIRE_MINUTES = 10;
|
||||
@ -76,7 +82,9 @@ public class RankingActivityServiceImpl implements RankingActivityService {
|
||||
return rankingListQryExe.execute(cmd);
|
||||
}
|
||||
|
||||
String cacheKey = buildRankingListCacheKey(cmd);
|
||||
String regionId = cmd.getReqUserId() != null ? userRegionGateway.getRegionId(cmd.getReqUserId()) : null;
|
||||
cmd.setRegionId(regionId);
|
||||
String cacheKey = buildRankingListCacheKey(cmd, regionId);
|
||||
RankingListCO cachedResult = redisService.getStringToObject(cacheKey, RankingListCO.class);
|
||||
if (cachedResult != null) {
|
||||
fillCurrentUserRank(cachedResult, cmd.getReqUserId());
|
||||
@ -134,7 +142,8 @@ public class RankingActivityServiceImpl implements RankingActivityService {
|
||||
|
||||
@Override
|
||||
public List<RankingUserVO> getTopFourRankingWithReward(RankingListQueryCmd cmd) {
|
||||
String cacheKey = buildRankingListCacheKey(cmd);
|
||||
String regionId = cmd.getReqUserId() != null ? userRegionGateway.getRegionId(cmd.getReqUserId()) : null;
|
||||
String cacheKey = buildRankingListCacheKey(cmd, regionId);
|
||||
|
||||
RankingListCO cachedResult = redisService.getStringToObject(cacheKey, RankingListCO.class);
|
||||
if (cachedResult != null) {
|
||||
@ -214,12 +223,26 @@ public class RankingActivityServiceImpl implements RankingActivityService {
|
||||
Set<Long> userIds = top4Users.stream()
|
||||
.map(RankingActivityRecordCO::getUserId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
|
||||
Set<Long> encryptedIds = top4Users.stream()
|
||||
.map(RankingActivityRecordCO::getEncryptedId)
|
||||
.filter(Objects::nonNull)
|
||||
.map(UserIdEncryptUtils::decrypt)
|
||||
.collect(Collectors.toSet());
|
||||
userIds.addAll(encryptedIds);
|
||||
|
||||
Set<Long> sets = new HashSet<>(userIds);
|
||||
Set<Long> invisibleUserIds = userProfileGateway.filterUsersByVipAbility(sets, VipAbilityType.MYSTERIOUS_INVISIBILITY);
|
||||
|
||||
Map<Long, UserProfile> userProfileMap = userProfileGateway.mapByUserIds(userIds);
|
||||
|
||||
|
||||
return top4Users.stream()
|
||||
.map(user -> {
|
||||
UserProfile profile = userProfileMap.get(user.getUserId());
|
||||
if (profile == null) {
|
||||
profile = userProfileMap.get(UserIdEncryptUtils.decrypt(user.getEncryptedId()));
|
||||
}
|
||||
|
||||
RankingUserVO vo = new RankingUserVO();
|
||||
vo.setUserId(user.getUserId());
|
||||
vo.setRank(user.getRank());
|
||||
@ -230,6 +253,13 @@ public class RankingActivityServiceImpl implements RankingActivityService {
|
||||
vo.setNickname(profile.getUserNickname());
|
||||
vo.setAvatar(profile.getUserAvatar());
|
||||
}
|
||||
|
||||
if (profile != null && invisibleUserIds.contains(profile.getId())) {
|
||||
vo.setUserId(null);
|
||||
vo.setAccount(null);
|
||||
vo.setNickname("****");
|
||||
vo.setAvatar(enumConfigCacheService.getValue(EnumConfigKey.USER_YINSHEN_COVER, SysOriginPlatformEnum.LIKEI.getSysOrigin()));
|
||||
}
|
||||
|
||||
return vo;
|
||||
})
|
||||
@ -261,8 +291,9 @@ public class RankingActivityServiceImpl implements RankingActivityService {
|
||||
/**
|
||||
* 构建排行榜缓存Key.
|
||||
*/
|
||||
private String buildRankingListCacheKey(RankingListQueryCmd cmd) {
|
||||
return RANKING_LIST_CACHE_KEY_PREFIX + RankingActivityType.getByCode(cmd.getActivityType()).name() + ":" + cmd.getCycleKey();
|
||||
private String buildRankingListCacheKey(RankingListQueryCmd cmd, String regionId) {
|
||||
String regionSuffix = RegionConstants.AR_REGION_IDS.contains(regionId) ? "AR" : "OTHER";
|
||||
return RANKING_LIST_CACHE_KEY_PREFIX + RankingActivityType.getByCode(cmd.getActivityType()).name() + ":" + cmd.getCycleKey() + ":" + regionSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -62,4 +62,14 @@ public class RankingListQueryCmd extends AppExtCommand {
|
||||
* 模板ID
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 排行榜是否隐身
|
||||
*/
|
||||
private Boolean invisible = true;
|
||||
|
||||
/**
|
||||
* 区域ID,内部使用,不需要前端传入
|
||||
*/
|
||||
private String regionId;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user