diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/ranking/GameRankingQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/ranking/GameRankingQryExe.java index 5aefff7b..eb7418de 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/ranking/GameRankingQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/game/ranking/GameRankingQryExe.java @@ -9,12 +9,14 @@ import com.red.circle.other.app.dto.cmd.game.GameRankingQry; import com.red.circle.other.domain.game.GameRankingPeriodType; import com.red.circle.other.domain.game.GameRankingRecord; import com.red.circle.other.domain.gateway.game.GameRankingGateway; +import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; import com.red.circle.other.infra.database.cache.key.GameRankingKeys; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import java.util.List; +import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -31,6 +33,7 @@ public class GameRankingQryExe { private final GameRankingGateway gameRankingGateway; private final GameRankingConvertor gameRankingConvertor; private final RedisService redisService; + private final UserRegionGateway userRegionGateway; private static final long CACHE_EXPIRE_SECONDS = 300; @@ -40,7 +43,8 @@ public class GameRankingQryExe { Integer pageNum = qry.getCurrent().intValue(); Integer pageSize = qry.getSize().intValue(); - String cacheKey = buildCacheKey(periodType, periodKey, pageNum, pageSize); + String regionId = userRegionGateway.getRegionId(qry.requiredReqUserId()); + String cacheKey = buildCacheKey(periodType, periodKey, regionId, pageNum, pageSize); PageResult cachedResult = redisService.getStringToObject(cacheKey, PageResult.class); if (cachedResult != null) { @@ -59,8 +63,19 @@ public class GameRankingQryExe { }) .collect(Collectors.toList()); + // 区域过滤:regions 有值时只保留包含当前用户 regionId 的游戏 + List filtered = coList.stream() + .filter(co -> { + String regions = co.getRegions(); + if (regions == null || regions.isBlank()) { + return true; + } + return Objects.nonNull(regionId) && List.of(regions.split(",")).contains(regionId); + }) + .collect(Collectors.toList()); + // latest 排前,非 latest 保持原 totalPrizeAmount 排序 - List sorted = coList.stream() + List sorted = filtered.stream() .sorted((a, b) -> { boolean aLatest = a.isLatest(); boolean bLatest = b.isLatest(); @@ -96,7 +111,7 @@ public class GameRankingQryExe { return null; } - private String buildCacheKey(String periodType, String periodKey, Integer pageNum, Integer pageSize) { - return GameRankingKeys.RANKING_PAGE.getKey(periodType, periodKey, pageNum, pageSize); + private String buildCacheKey(String periodType, String periodKey, String regionId, Integer pageNum, Integer pageSize) { + return GameRankingKeys.RANKING_PAGE.getKey(periodType, periodKey, regionId, pageNum, pageSize); } } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/game/GameRankingConvertor.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/game/GameRankingConvertor.java index 72a019f5..1c6bd6b1 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/game/GameRankingConvertor.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/convertor/game/GameRankingConvertor.java @@ -31,6 +31,7 @@ public class GameRankingConvertor { co.setTotalPrizeAmount(record.getTotalPrizeAmount()); co.setPeriodType(record.getPeriodType()); co.setGameCreateTime(record.getGameCreateTime()); + co.setRegions(record.getRegions()); return co; } } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/GameRankingInitTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/GameRankingInitTask.java index 4b781fe3..93d21447 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/GameRankingInitTask.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/GameRankingInitTask.java @@ -56,6 +56,7 @@ public class GameRankingInitTask { .gameUrl(config.getGameCode()) .gameCreateTime(config.getCreateTime()) .showcase(config.getShowcase()) + .regions(config.getRegions()) .periodType(GameRankingPeriodType.WEEK.getCode()) .periodKey(weekKey) .amount(0L) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/common/GameEventService.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/common/GameEventService.java index bfeb740d..1b25335d 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/common/GameEventService.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/common/GameEventService.java @@ -167,6 +167,7 @@ public class GameEventService { .sysOrigin(gameConfig.getSysOrigin()) .amount(gold) .showcase(gameConfig.getShowcase()) + .regions(gameConfig.getRegions()) .periodType(GameRankingPeriodType.WEEK.getCode()) .periodKey(ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString()) .gameCreateTime(gameConfig.getCreateTime()) diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/game/GameRankingCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/game/GameRankingCO.java index 61f2c88a..2359e452 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/game/GameRankingCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/game/GameRankingCO.java @@ -61,6 +61,11 @@ public class GameRankingCO { */ private Timestamp gameCreateTime; + /** + * 区域ID列表(逗号分隔),为空代表全区域 + */ + private String regions; + public boolean isLatest() { if (gameCreateTime == null) { return false; diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/game/GameRankingIncrementCmd.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/game/GameRankingIncrementCmd.java index 1dffe433..7e4da791 100644 --- a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/game/GameRankingIncrementCmd.java +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/game/GameRankingIncrementCmd.java @@ -71,4 +71,9 @@ public class GameRankingIncrementCmd { * 是否上架 */ private Boolean showcase; + + /** + * 区域ID列表(逗号分隔),为空代表全区域 + */ + private String regions; } diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/game/GameRankingRecord.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/game/GameRankingRecord.java index e838baeb..afefeccb 100644 --- a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/game/GameRankingRecord.java +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/game/GameRankingRecord.java @@ -64,4 +64,9 @@ public class GameRankingRecord { * 游戏创建时间 */ private Timestamp gameCreateTime; + + /** + * 区域ID列表(逗号分隔),为空代表全区域 + */ + private String regions; } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/game/rank/GameRanking.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/game/rank/GameRanking.java index da8b9bd2..f874ed03 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/game/rank/GameRanking.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/game/rank/GameRanking.java @@ -82,6 +82,11 @@ public class GameRanking { */ private Boolean showcase; + /** + * 区域ID列表(逗号分隔),为空代表全区域 + */ + private String regions; + /** * 游戏创建时间 */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/game/GameRankingGatewayImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/game/GameRankingGatewayImpl.java index d3dca52f..0c216997 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/game/GameRankingGatewayImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/game/GameRankingGatewayImpl.java @@ -82,6 +82,7 @@ public class GameRankingGatewayImpl implements GameRankingGateway { update.inc("totalPrizeAmount", cmd.getAmount()); update.set("updateTime", LocalDateTime.now()); update.set("showcase", cmd.getShowcase()); + update.set("regions", cmd.getRegions()); update.setOnInsert("createTime", LocalDateTime.now()); update.setOnInsert("sysOrigin", cmd.getSysOrigin()); update.setOnInsert("gameOrigin", cmd.getGameOrigin()); @@ -111,6 +112,7 @@ public class GameRankingGatewayImpl implements GameRankingGateway { record.setPeriodKey(entity.getPeriodKey()); record.setTotalPrizeAmount(entity.getTotalPrizeAmount()); record.setGameCreateTime(entity.getGameCreateTime()); + record.setRegions(entity.getRegions()); return record; } } diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/impl/SysGameListConfigClientServiceImpl.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/impl/SysGameListConfigClientServiceImpl.java index 10a0180f..e10bfe63 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/impl/SysGameListConfigClientServiceImpl.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/sys/impl/SysGameListConfigClientServiceImpl.java @@ -101,6 +101,7 @@ public class SysGameListConfigClientServiceImpl implements SysGameListConfigClie .gameUrl(config.getGameCode()) .gameCreateTime(config.getCreateTime()) .showcase(config.getShowcase()) + .regions(config.getRegions()) .periodType(GameRankingPeriodType.WEEK.getCode()) .periodKey(ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString()) .amount(0L)