游戏问题更新

This commit is contained in:
tianfeng 2026-05-29 16:22:47 +08:00
parent 6d4d3308b8
commit d5514b32f4
6 changed files with 49 additions and 32 deletions

View File

@ -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<GameRankingCO> execute(GameRankingQry qry) {
@ -67,17 +59,8 @@ public class GameRankingQryExe {
})
.collect(Collectors.toList());
Set<String> 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<GameRankingCO> 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);
}

View File

@ -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())

View File

@ -66,4 +66,9 @@ public class GameRankingIncrementCmd {
* 中奖金额单位
*/
private Long amount;
/**
* 是否上架
*/
private Boolean showcase;
}

View File

@ -77,6 +77,11 @@ public class GameRanking {
*/
private Long totalPrizeAmount;
/**
* 是否上架
*/
private Boolean showcase;
/**
* 游戏创建时间
*/

View File

@ -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());

View File

@ -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<SysGameListConfigDTO> pageQuery(SysGameListQryCmd query) {
PageResult<GameListConfig> 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<BaseInfo> 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<GameUserShardsExchangeRecordDTO> pageUserShardsExchange(GameEggQryCmd query) {
return gameUserShardsExchangeRecordService.pageRecord(
query).convert(gameListConfigAppConvertor::toGameUserShardsExchangeRecordDTO);
}
@Override
public SysGameListConfigDTO getByGameCode(String gameCode, String sysOrigin) {
return gameListConfigAppConvertor.toSysGameListConfigDTO(