From d5514b32f4a0a42ad5508b7be14790299ca46c8e Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 29 May 2026 16:22:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=88=8F=E9=97=AE=E9=A2=98=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/ranking/GameRankingQryExe.java | 24 ---------- .../service/game/common/GameEventService.java | 1 + .../domain/game/GameRankingIncrementCmd.java | 5 +++ .../mongo/entity/game/rank/GameRanking.java | 5 +++ .../gateway/game/GameRankingGatewayImpl.java | 2 + .../SysGameListConfigClientServiceImpl.java | 44 +++++++++++++++---- 6 files changed, 49 insertions(+), 32 deletions(-) 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 9ac67fe5..5aefff7b 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 @@ -1,7 +1,6 @@ package com.red.circle.other.app.command.game.ranking; import com.alibaba.fastjson.JSON; -import com.red.circle.component.redis.RedisKeys; import com.red.circle.component.redis.service.RedisService; import com.red.circle.framework.dto.PageResult; import com.red.circle.other.app.convertor.game.GameRankingConvertor; @@ -11,14 +10,11 @@ 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.infra.database.cache.key.GameRankingKeys; -import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig; -import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import java.util.List; -import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -35,11 +31,7 @@ public class GameRankingQryExe { private final GameRankingGateway gameRankingGateway; private final GameRankingConvertor gameRankingConvertor; private final RedisService redisService; - private final GameListConfigService gameListConfigService; - /** - * 缓存过期时间:30秒 - */ private static final long CACHE_EXPIRE_SECONDS = 300; public PageResult execute(GameRankingQry qry) { @@ -67,17 +59,8 @@ public class GameRankingQryExe { }) .collect(Collectors.toList()); - Set showcaseGameIds = gameListConfigService.query() - .in(GameListConfig::getGameId, coList.stream().map(GameRankingCO::getGameId).collect(Collectors.toSet())) - .eq(GameListConfig::getShowcase, Boolean.TRUE) - .list() - .stream() - .map(GameListConfig::getGameId) - .collect(Collectors.toSet()); - // latest 排前,非 latest 保持原 totalPrizeAmount 排序 List sorted = coList.stream() - .filter(co -> showcaseGameIds.contains(co.getGameId())) .sorted((a, b) -> { boolean aLatest = a.isLatest(); boolean bLatest = b.isLatest(); @@ -87,7 +70,6 @@ public class GameRankingQryExe { return a.getRank() - b.getRank(); }) .collect(Collectors.toList()); - // 重新赋排名 for (int i = 0; i < sorted.size(); i++) { sorted.get(i).setRank(startRank + i); } @@ -103,9 +85,6 @@ public class GameRankingQryExe { return result; } - /** - * 根据 periodType 计算当前 periodKey - */ private String resolvePeriodKey(String periodType) { if (GameRankingPeriodType.WEEK.getCode().equals(periodType)) { return ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString(); @@ -117,9 +96,6 @@ public class GameRankingQryExe { return null; } - /** - * 构建缓存 Key. - */ private String buildCacheKey(String periodType, String periodKey, Integer pageNum, Integer pageSize) { return GameRankingKeys.RANKING_PAGE.getKey(periodType, periodKey, pageNum, pageSize); } 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 d3f84480..bfeb740d 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 @@ -166,6 +166,7 @@ public class GameEventService { .gameUrl(gameConfig.getGameCode()) .sysOrigin(gameConfig.getSysOrigin()) .amount(gold) + .showcase(gameConfig.getShowcase()) .periodType(GameRankingPeriodType.WEEK.getCode()) .periodKey(ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString()) .gameCreateTime(gameConfig.getCreateTime()) 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 e233f5d0..1dffe433 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 @@ -66,4 +66,9 @@ public class GameRankingIncrementCmd { * 中奖金额(单位:分) */ private Long amount; + + /** + * 是否上架 + */ + private Boolean showcase; } 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 9949b55b..da8b9bd2 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 @@ -77,6 +77,11 @@ public class GameRanking { */ private Long totalPrizeAmount; + /** + * 是否上架 + */ + private Boolean showcase; + /** * 游戏创建时间 */ 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 86b1b0b0..d3dca52f 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 @@ -42,6 +42,7 @@ public class GameRankingGatewayImpl implements GameRankingGateway { Query query = new Query(); query.addCriteria(Criteria.where("periodType").is(periodType)); + query.addCriteria(Criteria.where("showcase").is(Boolean.TRUE)); if (periodKey != null) { query.addCriteria(Criteria.where("periodKey").is(periodKey)); } @@ -80,6 +81,7 @@ public class GameRankingGatewayImpl implements GameRankingGateway { Update update = new Update(); update.inc("totalPrizeAmount", cmd.getAmount()); update.set("updateTime", LocalDateTime.now()); + update.set("showcase", cmd.getShowcase()); update.setOnInsert("createTime", LocalDateTime.now()); update.setOnInsert("sysOrigin", cmd.getSysOrigin()); update.setOnInsert("gameOrigin", cmd.getGameOrigin()); 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 44e5cb78..10a0180f 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 @@ -1,9 +1,14 @@ package com.red.circle.other.app.inner.service.sys.impl; +import com.red.circle.component.redis.service.RedisService; import com.red.circle.framework.dto.PageResult; import com.red.circle.other.app.inner.service.sys.SysGameListConfigClientService; +import com.red.circle.other.domain.game.GameRankingIncrementCmd; +import com.red.circle.other.domain.game.GameRankingPeriodType; +import com.red.circle.other.domain.gateway.game.GameRankingGateway; import com.red.circle.other.infra.convertor.sys.SysGameListConfigInnerConvertor; import com.red.circle.other.infra.database.cache.service.other.GameListCacheService; +import com.red.circle.other.infra.database.cache.key.GameRankingKeys; import com.red.circle.other.infra.database.mongo.service.sys.GameMatchModelConfigService; import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig; import com.red.circle.other.infra.database.rds.entity.user.user.BaseInfo; @@ -12,6 +17,7 @@ import com.red.circle.other.infra.database.rds.service.game.GameUserLotteryRecor import com.red.circle.other.infra.database.rds.service.game.GameUserShardsExchangeRecordService; import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService; import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService; +import com.red.circle.other.infra.utils.RedisUtils; import com.red.circle.other.inner.model.cmd.game.GameEggQryCmd; import com.red.circle.other.inner.model.cmd.sys.SysGameListConfigParamCmd; import com.red.circle.other.inner.model.cmd.sys.SysGameListQryCmd; @@ -24,6 +30,7 @@ import com.red.circle.other.inner.model.dto.sys.GameModelDTO; import com.red.circle.other.inner.model.dto.sys.SysGameListConfigDTO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.TimestampUtils; +import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.num.NumUtils; import com.red.circle.tool.core.sequence.IdWorkerUtils; import com.red.circle.tool.core.text.StringUtils; @@ -53,12 +60,13 @@ public class SysGameListConfigClientServiceImpl implements SysGameListConfigClie private final GameUserLotteryRecordService gameUserLotteryRecordService; private final GameUserShardsExchangeRecordService gameUserShardsExchangeRecordService; private final GameUserLotteryDetailsRecordService gameUserLotteryDetailsRecordService; + private final GameRankingGateway gameRankingGateway; + private final RedisService redisService; @Override public PageResult pageQuery(SysGameListQryCmd query) { PageResult pageResult = gameListConfigService.pageQuery(query); - return pageResult.convert( - gameListConfigAppConvertor::toSysGameListConfigDTO); + return pageResult.convert(gameListConfigAppConvertor::toSysGameListConfigDTO); } @Override @@ -70,10 +78,34 @@ public class SysGameListConfigClientServiceImpl implements SysGameListConfigClie if (Objects.isNull(param.getId())) { gameListConfig.setId(IdWorkerUtils.getId()); gameListConfigService.save(gameListConfig); + } else { + gameListConfigService.updateSelectiveById(gameListConfig); + gameListConfig = gameListConfigService.getById(param.getId()); + } + syncGameRanking(gameListConfig); + RedisUtils.redisScan(redisService.redisTemplate(), GameRankingKeys.RANKING_PAGE.getKey()) + .forEach(redisService::delete); + } + + private void syncGameRanking(GameListConfig config) { + if (config == null) { return; } - gameListConfigService.updateSelectiveById(gameListConfig); - + gameRankingGateway.incrementPrizeAmount( + GameRankingIncrementCmd.builder() + .sysOrigin(config.getSysOrigin()) + .gameOrigin(config.getGameOrigin()) + .gameId(config.getId().toString()) + .gameName(config.getName()) + .gameCover(config.getCover()) + .gameUrl(config.getGameCode()) + .gameCreateTime(config.getCreateTime()) + .showcase(config.getShowcase()) + .periodType(GameRankingPeriodType.WEEK.getCode()) + .periodKey(ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString()) + .amount(0L) + .build() + ); } @Override @@ -92,11 +124,9 @@ public class SysGameListConfigClientServiceImpl implements SysGameListConfigClie public void addOrUpdateMatchConfig(GameMatchModelConfigDTO param) { if (Objects.isNull(param.getId())) { param.setId(IdWorkerUtils.getId()); - param.setModels(param.getModels().stream() .peek(model -> model.setOnlinePlayers(NumUtils.randomBetween(10, 999))) .collect(Collectors.toList())); - List userBaseInfos = baseInfoService.listVest(4); if (CollectionUtils.isNotEmpty(userBaseInfos)) { param.setOnlinePlayersUsers( @@ -129,14 +159,12 @@ public class SysGameListConfigClientServiceImpl implements SysGameListConfigClie return gameUserLotteryDetailsRecordService.mapByLotteryIds(lotteryIds); } - @Override public PageResult pageUserShardsExchange(GameEggQryCmd query) { return gameUserShardsExchangeRecordService.pageRecord( query).convert(gameListConfigAppConvertor::toGameUserShardsExchangeRecordDTO); } - @Override public SysGameListConfigDTO getByGameCode(String gameCode, String sysOrigin) { return gameListConfigAppConvertor.toSysGameListConfigDTO(