From ecb7a83c462ae7e825c25f3b55ace00189c3282d Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Tue, 30 Dec 2025 15:29:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=88=8F=E6=8E=A5=E5=85=A5=E6=8A=BD?= =?UTF-8?q?=E5=A5=96=E5=88=B8=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/party3rd/GameHkysRestController.java | 69 +------------- .../command/SpinsTaskProgressUpdateExe.java | 1 + .../app/service/game/GameActivityService.java | 91 +++++++++++++++++++ .../service/game/GameBaishunServiceImpl.java | 66 +------------- .../app/service/game/HotGameServiceImpl.java | 69 +------------- 5 files changed, 106 insertions(+), 190 deletions(-) create mode 100644 rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameActivityService.java diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/party3rd/GameHkysRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/party3rd/GameHkysRestController.java index 7db33403..fed2f3fb 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/party3rd/GameHkysRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/game/party3rd/GameHkysRestController.java @@ -27,11 +27,10 @@ import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd; import com.red.circle.other.app.dto.cmd.game.GameLxwlUpdateBalanceCmd; import com.red.circle.other.app.dto.cmd.game.GameLxwlUserInfoCmd; -import com.red.circle.other.app.dto.cmd.SpinsTaskProgressUpdateCmd; import com.red.circle.other.app.enums.violation.GameOriginEnum; import com.red.circle.other.app.enums.violation.ViolationTypeEnum; import com.red.circle.other.app.service.activity.RankingActivityService; -import com.red.circle.other.app.service.SpinsUserTaskProgressService; +import com.red.circle.other.app.service.game.GameActivityService; import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils; import com.red.circle.other.app.util.OfficialNoticeUtils; import com.red.circle.other.domain.game.GameRankingIncrementCmd; @@ -90,7 +89,7 @@ public class GameHkysRestController { private final GameRankingGateway gameRankingGateway; private final GameListCacheService gameListCacheService; private final RankingActivityService rankingActivityService; - private final SpinsUserTaskProgressService spinsUserTaskProgressService; + private final GameActivityService gameActivityService; private final RedisService redisService; @IgnoreResultResponse @@ -191,7 +190,9 @@ public class GameHkysRestController { incGameRankingRecord(cmd, gameListConfig); //处理游戏消费任务 - handleGameSpendTask(userId, cmd.getType(), cmd.getCoin()); + if (cmd.getType() == 1) { + gameActivityService.handleGameSpendTask(userId, cmd.getCoin()); + } return new HkysResponse() @@ -233,66 +234,6 @@ public class GameHkysRestController { } } - /** - * 处理游戏消费任务 - */ - private void handleGameSpendTask(Long userId, Integer type, Long amount) { - try { - if (type != 1 || amount <= 0) { - return; - } - - // 累计每日游戏消费金额 - String redisKey = "spins:daily:game:spend:" + userId; - String totalStr = redisService.getString(redisKey); - long totalSpend; - - if (StringUtils.isBlank(totalStr)) { - totalSpend = amount; - long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(); - redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS); - } else { - long currentTotal = Long.parseLong(totalStr); - // 如果已经超过50000,不再处理 - if (currentTotal >= 50000) { - log.info("Spins游戏消费任务已达上限, userId={}, totalSpend={}", userId, currentTotal); - return; - } - totalSpend = currentTotal + amount; - long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(); - redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS); - } - - log.info("Spins游戏消费任务, userId={}, spendAmount={}, totalSpend={}", userId, amount, totalSpend); - - int progressValue = Integer.parseInt(String.valueOf(totalSpend)); - spinsUserTaskProgressService.updateTaskProgress( - new SpinsTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode("SPINS_SPEND_5000") - .setProgressValue(progressValue) - ); - - spinsUserTaskProgressService.updateTaskProgress( - new SpinsTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode("SPINS_SPEND_10000") - .setProgressValue(progressValue) - ); - - spinsUserTaskProgressService.updateTaskProgress( - new SpinsTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode("SPINS_SPEND_50000") - .setProgressValue(progressValue) - ); - - log.info("Spins游戏消费任务处理成功, userId={}, totalSpend={}", userId, totalSpend); - } catch (Exception e) { - log.error("处理Spins游戏消费任务失败, userId={}, amount={}", userId, amount, e); - } - } - @IgnoreResultResponse @PostMapping("/orderCompensation") public HkysResponse orderCompensation(@RequestBody JSONObject object) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/SpinsTaskProgressUpdateExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/SpinsTaskProgressUpdateExe.java index 8aff27b0..8e2e398f 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/SpinsTaskProgressUpdateExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/SpinsTaskProgressUpdateExe.java @@ -50,6 +50,7 @@ public class SpinsTaskProgressUpdateExe { new LambdaQueryWrapper() .eq(SpinsTaskConfig::getTaskCode, taskCode) .eq(SpinsTaskConfig::getStatus, 1) + .last("limit 1") ); if (taskConfigs.isEmpty()) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameActivityService.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameActivityService.java new file mode 100644 index 00000000..e954439d --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameActivityService.java @@ -0,0 +1,91 @@ +package com.red.circle.other.app.service.game; + +import com.red.circle.component.redis.service.RedisService; +import com.red.circle.other.app.dto.cmd.SpinsTaskProgressUpdateCmd; +import com.red.circle.other.app.service.SpinsUserTaskProgressService; +import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.concurrent.TimeUnit; + +/** + * 游戏活动服务 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class GameActivityService { + + private static final long MAX_DAILY_SPEND = 50000L; + private static final String REDIS_KEY_PREFIX = "spins:daily:game:spend:"; + + private final RedisService redisService; + private final SpinsUserTaskProgressService spinsUserTaskProgressService; + + /** + * 处理游戏消费任务 + * + * @param userId 用户ID + * @param spendAmount 本次消费金额 + */ + public void handleGameSpendTask(Long userId, Long spendAmount) { + try { + if (spendAmount <= 0) { + return; + } + + String redisKey = REDIS_KEY_PREFIX + userId; + + Long totalSpend = redisService.increment(redisKey, spendAmount); + + // 首次创建时设置过期时间 + if (totalSpend.equals(spendAmount)) { + long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(); + redisService.expire(redisKey, expireSeconds, TimeUnit.SECONDS); + } + + // 如果累计已经超过50000,不再处理任务 + if (totalSpend - spendAmount >= MAX_DAILY_SPEND) { + log.info("Spins游戏消费任务已达上限, userId={}, totalSpend={}", userId, totalSpend); + return; + } + + log.info("Spins游戏消费任务, userId={}, spendAmount={}, totalSpend={}", userId, spendAmount, totalSpend); + + int progressValue = totalSpend.intValue(); + updateGameSpendProgress(userId, progressValue); + + log.info("Spins游戏消费任务处理成功, userId={}, totalSpend={}", userId, totalSpend); + } catch (Exception e) { + log.error("处理Spins游戏消费任务失败, userId={}, spendAmount={}", userId, spendAmount, e); + } + } + + /** + * 更新游戏消费进度 + */ + private void updateGameSpendProgress(Long userId, int progressValue) { + spinsUserTaskProgressService.updateTaskProgress( + new SpinsTaskProgressUpdateCmd() + .setUserId(userId) + .setTaskCode("SPINS_SPEND_5000") + .setProgressValue(progressValue) + ); + + spinsUserTaskProgressService.updateTaskProgress( + new SpinsTaskProgressUpdateCmd() + .setUserId(userId) + .setTaskCode("SPINS_SPEND_10000") + .setProgressValue(progressValue) + ); + + spinsUserTaskProgressService.updateTaskProgress( + new SpinsTaskProgressUpdateCmd() + .setUserId(userId) + .setTaskCode("SPINS_SPEND_50000") + .setProgressValue(progressValue) + ); + } +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameBaishunServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameBaishunServiceImpl.java index f1343943..f71414f9 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameBaishunServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameBaishunServiceImpl.java @@ -88,7 +88,7 @@ public class GameBaishunServiceImpl implements GameBaishunService { private final GameRankingGateway gameRankingGateway; private final GameListCacheService gameListCacheService; private final TaskService taskService; - private final SpinsUserTaskProgressService spinsUserTaskProgressService; + private final GameActivityService gameActivityService; @Value("${red-circle.game-rank.gameid}") private String gameId; @@ -219,7 +219,9 @@ public class GameBaishunServiceImpl implements GameBaishunService { incGameRankingRecord(request, gameListConfig); //处理游戏消费任务 - handleGameSpendTask(userId, request.getCurrencyDiff()); + if (request.getCurrencyDiff() < 0) { + gameActivityService.handleGameSpendTask(userId, Math.abs(request.getCurrencyDiff())); + } } log.warn("{} 发送游戏获奖通知--金币数量{}", GoldOrigin.BAISHUN_GAME.name(), request.getCurrencyDiff()); @@ -303,66 +305,6 @@ public class GameBaishunServiceImpl implements GameBaishunService { } } - /** - * 处理游戏消费任务 - */ - private void handleGameSpendTask(Long userId, Long amount) { - try { - if (amount >= 0) { - return; - } - - long spendAmount = Math.abs(amount); - - // 累计每日游戏消费金额 - String redisKey = "spins:daily:game:spend:" + userId; - String totalStr = redisService.getString(redisKey); - long totalSpend; - - if (StringUtils.isBlank(totalStr)) { - totalSpend = spendAmount; - long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(); - redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS); - } else { - long currentTotal = Long.parseLong(totalStr); - // 如果已经超过50000,不再处理 - if (currentTotal >= 50000) { - log.info("Spins游戏消费任务已达上限, userId={}, totalSpend={}", userId, currentTotal); - return; - } - totalSpend = currentTotal + spendAmount; - long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(); - redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS); - } - - int progressValue = Integer.parseInt(String.valueOf(totalSpend)); - spinsUserTaskProgressService.updateTaskProgress( - new SpinsTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode("SPINS_SPEND_5000") - .setProgressValue(progressValue) - ); - - spinsUserTaskProgressService.updateTaskProgress( - new SpinsTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode("SPINS_SPEND_10000") - .setProgressValue(progressValue) - ); - - spinsUserTaskProgressService.updateTaskProgress( - new SpinsTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode("SPINS_SPEND_50000") - .setProgressValue(progressValue) - ); - - log.info("Spins游戏消费任务处理成功, userId={}, totalSpend={}", userId, totalSpend); - } catch (Exception e) { - log.error("处理Spins游戏消费任务失败, userId={}, amount={}", userId, amount, e); - } - } - private GoldReceiptCmd createReceipt(BaishunChangeCurrencyRequest param) { UserCredential userCredential = UserCredential.parseToken(param.getToken()); return createGoldReceiptCmdBuilder(param.getCurrencyDiff()) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/HotGameServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/HotGameServiceImpl.java index 02dcb926..10cbe90b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/HotGameServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/HotGameServiceImpl.java @@ -23,12 +23,11 @@ import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.game.HotGameUpdateRequest; import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd; import com.red.circle.other.app.dto.cmd.game.GameLxwlUpdateBalanceCmd; -import com.red.circle.other.app.dto.cmd.SpinsTaskProgressUpdateCmd; import com.red.circle.other.app.enums.violation.GameOriginEnum; import com.red.circle.other.app.service.activity.RankingActivityService; +import com.red.circle.other.app.service.game.GameActivityService; import com.red.circle.other.app.service.game.override.domain.HotGameUserProfile; import com.red.circle.other.app.service.game.override.service.HotGameService; -import com.red.circle.other.app.service.SpinsUserTaskProgressService; import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils; import com.red.circle.other.app.util.OfficialNoticeUtils; import com.red.circle.other.domain.game.GameRankingIncrementCmd; @@ -95,7 +94,7 @@ public class HotGameServiceImpl implements HotGameService { private final GameRankingGateway gameRankingGateway; private final GameListCacheService gameListCacheService; private final RankingActivityService rankingActivityService; - private final SpinsUserTaskProgressService spinsUserTaskProgressService; + private final GameActivityService gameActivityService; @Value("${red-circle.game-rank.gameid}") private String gameId; @Value("${red-circle.game-rank.endTime}") @@ -241,7 +240,9 @@ public class HotGameServiceImpl implements HotGameService { incGameRankingTmpActivity(param); //处理游戏消费任务 - handleGameSpendTask(userId, param.getType(), param.getCoin()); + if (param.getType() == 1) { + gameActivityService.handleGameSpendTask(userId, param.getCoin()); + } return new HotGameResponse() .setData(new HotGameCoin() @@ -376,64 +377,4 @@ public class HotGameServiceImpl implements HotGameService { .build(); } - /** - * 处理游戏消费任务 - */ - private void handleGameSpendTask(Long userId, Integer type, Long amount) { - try { - if (type != 1 || amount <= 0) { - return; - } - - // 累计每日游戏消费金额 - String redisKey = "spins:daily:game:spend:" + userId; - String totalStr = redisService.getString(redisKey); - long totalSpend; - - if (StringUtils.isBlank(totalStr)) { - totalSpend = amount; - long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(); - redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS); - } else { - long currentTotal = Long.parseLong(totalStr); - // 如果已经超过50000,不再处理 - if (currentTotal >= 50000) { - log.info("Spins游戏消费任务已达上限, userId={}, totalSpend={}", userId, currentTotal); - return; - } - totalSpend = currentTotal + amount; - long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(); - redisService.setString(redisKey, String.valueOf(totalSpend), expireSeconds, TimeUnit.SECONDS); - } - - log.info("Spins游戏消费任务, userId={}, spendAmount={}, totalSpend={}", userId, amount, totalSpend); - - int progressValue = Integer.parseInt(String.valueOf(totalSpend)); - spinsUserTaskProgressService.updateTaskProgress( - new SpinsTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode("SPINS_SPEND_5000") - .setProgressValue(progressValue) - ); - - spinsUserTaskProgressService.updateTaskProgress( - new SpinsTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode("SPINS_SPEND_10000") - .setProgressValue(progressValue) - ); - - spinsUserTaskProgressService.updateTaskProgress( - new SpinsTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode("SPINS_SPEND_50000") - .setProgressValue(progressValue) - ); - - log.info("Spins游戏消费任务处理成功, userId={}, totalSpend={}", userId, totalSpend); - } catch (Exception e) { - log.error("处理Spins游戏消费任务失败, userId={}, amount={}", userId, amount, e); - } - } - }