From c10b7dc378e2cffff0e6ea4e7f1d69ee95bdcaf1 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 28 May 2026 17:58:38 +0800 Subject: [PATCH] =?UTF-8?q?baishun=20=E5=92=8C=20=E7=81=B5=E4=BB=99?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/party3rd/GameHkysRestController.java | 131 +----------------- .../service/game/GameBaishunServiceImpl.java | 123 +--------------- 2 files changed, 11 insertions(+), 243 deletions(-) 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 5d24f3b7..16f19f39 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 @@ -1,7 +1,6 @@ package com.red.circle.other.adapter.app.game.party3rd; import com.alibaba.fastjson.JSONObject; -import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; import com.red.circle.component.game.hkys.GameHkysService; import com.red.circle.component.game.hkys.props.GameHkysProperties; import com.red.circle.component.game.hkys.request.HkysUserCoinUpdate; @@ -11,47 +10,21 @@ import com.red.circle.component.game.hkys.response.HkysUserProfileResponse; import com.red.circle.component.game.hkys.response.HyksErrorEnum; import com.red.circle.component.game.hkys.response.UpdateUserCoinResponse; import com.red.circle.component.redis.service.RedisService; -import com.red.circle.external.inner.endpoint.message.ImGroupClient; -import com.red.circle.external.inner.model.cmd.message.BroadcastGroupMsgBodyCmd; -import com.red.circle.external.inner.model.enums.message.GroupMessageTypeEnum; -import com.red.circle.framework.core.dto.ReqSysOrigin; import com.red.circle.framework.core.security.UserCredential; import com.red.circle.framework.web.annotation.IgnoreResultResponse; -import com.red.circle.mq.rocket.business.producer.TaskMqMessage; -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.task.RoomDailyTaskProgressUpdateCmd; import com.red.circle.other.app.enums.violation.GameOriginEnum; -import com.red.circle.other.app.service.activity.ActivityRechargeTicketService; -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.task.RoomDailyTaskProgressService; -import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils; -import com.red.circle.other.app.util.OfficialNoticeUtils; -import com.red.circle.other.domain.game.GameRankingIncrementCmd; -import com.red.circle.other.domain.gateway.game.GameRankingGateway; -import com.red.circle.other.domain.gateway.user.UserProfileGateway; -import com.red.circle.other.domain.ranking.RankingActivityType; -import com.red.circle.other.domain.ranking.RankingCycleType; -import com.red.circle.other.domain.ranking.RankingDimension; -import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService; +import com.red.circle.other.app.service.game.common.GameEventService; import com.red.circle.other.infra.database.cache.service.other.GameListCacheService; 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.other.inner.enums.config.EnumConfigKey; -import com.red.circle.other.inner.enums.task.RoomDailyTaskCode; -import com.red.circle.other.inner.model.dto.user.UserProfileDTO; -import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.parse.DataTypeUtils; import com.red.circle.tool.core.text.StringUtils; import com.red.circle.tool.crypto.SecurityUtils; -import java.math.BigDecimal; -import java.util.Map; import java.util.Objects; -import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -75,19 +48,11 @@ public class GameHkysRestController { private final GameHkysService gameHkysService; private final GameHkysProperties gameHkysProperties; - private final TaskMqMessage taskMqMessage; - private final EnumConfigCacheService enumConfigCacheService; - private final UserProfileGateway userProfileGateway; - private final UserProfileAppConvertor userProfileAppConvertor; private final GameListConfigService gameListConfigService; - private final ImGroupClient imGroupClient; - private final GameRankingGateway gameRankingGateway; private final GameListCacheService gameListCacheService; - private final RankingActivityService rankingActivityService; private final GameActivityService gameActivityService; private final RedisService redisService; - private final ActivityRechargeTicketService activityRechargeTicketService; - private final RoomDailyTaskProgressService roomDailyTaskProgressService; + private final GameEventService gameEventService; @IgnoreResultResponse @PostMapping("/getUserInfo") @@ -148,53 +113,19 @@ public class GameHkysRestController { String sysOrigin = UserCredential.parseToken(cmd.getToken()).getSysOrigin(); - BigDecimal cost = enumConfigCacheService - .getValueBigDecimal(EnumConfigKey.GAME_BROADCAST_AMOUNT, sysOrigin) ; - if (cost == null || cost.compareTo(BigDecimal.ZERO) <= 0) { - cost = BigDecimal.valueOf(5000L); - } - GameListConfig gameListConfig = gameListCacheService.getByGameIdWithCache( cmd.getGameId(), GameOriginEnum.LINGXIAN.name(), sysOrigin, () -> gameListConfigService.getByGameId(cmd.getGameId(), GameOriginEnum.LINGXIAN.name(), sysOrigin) ); - if (cmd.getType() != null && cmd.getType() == 2 && cmd.getCoin() >= cost.longValue()) { - UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO( - userProfileGateway.getByUserId(userId)); - if (Objects.nonNull(gameListConfig)) { - Map build = OfficialNoticeUtils.buildUserProfile(userProfile); - build.put("gameUrl", gameListConfig.getCover()); - build.put("currencyDiff", cmd.getCoin()); - - imGroupClient.sendMessageBroadcast( - BroadcastGroupMsgBodyCmd.builder() - .toPlatform(SysOriginPlatformEnum.ATYOU) - .type(GroupMessageTypeEnum.GAME_BAISHUN_WIN) - .data(build) - .build() - ); - } - } - // type = 1 是支出 type = 2 是收入 - - //游戏参与打榜活动 - incGameRankingActivity(cmd); - - //累计游戏排行榜 - incGameRankingRecord(cmd, gameListConfig); - - //处理游戏获得任务 - if (cmd.getType() == 2) { + if (cmd.getType() != null && cmd.getType() == 2) { + gameEventService.onWinEvent(userId, cmd.getCoin(), GameOriginEnum.LINGXIAN.name(), gameListConfig); gameActivityService.handleGameSpendTask(userId, cmd.getCoin()); - - // 累加用户获得的金币并发送抽奖券 -// activityRechargeTicketService.accumulatedRechargeAndAddTicket(userId, Math.abs(cmd.getCoin()), MonthlyRechargeType.UNDEFINED); + gameActivityService.incKingGameDaily(userId, cmd.getCoin(), cmd.getGameId()); } else { - - updateRoomDailyTask(cmd.getCoin(), userId); + gameEventService.onBetEvent(userId, cmd.getCoin()); } @@ -203,56 +134,6 @@ public class GameHkysRestController { .setData(jsonObject); } - private void updateRoomDailyTask(Long coins, Long userId) { - RoomDailyTaskCode taskType = RoomDailyTaskCode.PERSONAL_GAME_CONSUME; - String redisKey = "room:daily:task:progress:" + taskType.name() + ":" + userId + ":" + ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate(); - Long total = redisService.increment(redisKey, Math.abs(coins.intValue())); - redisService.expire(redisKey, DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(), TimeUnit.SECONDS); - roomDailyTaskProgressService.updateTaskProgress( - new RoomDailyTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode(taskType.name()) - .setProgressValue(total.intValue()) - ); - } - - private void incGameRankingRecord(GameLxwlUpdateBalanceCmd request, GameListConfig gameListConfig) { - if (request.getType() != 2 || gameListConfig == null || request.getCoin() <= 0) { - return; - } - - GameRankingIncrementCmd build = GameRankingIncrementCmd.builder() - .gameOrigin(GameOriginEnum.LINGXIAN.name()) - .gameId(gameListConfig.getGameId()) - .gameName(gameListConfig.getName()) - .gameCover(gameListConfig.getCover()) - .gameUrl(gameListConfig.getGameCode()) - .sysOrigin(gameListConfig.getSysOrigin()) - .amount(request.getCoin()) - .periodType("ALL") - .build(); - gameRankingGateway.incrementPrizeAmount(build); - } - - private void incGameRankingActivity(GameLxwlUpdateBalanceCmd request) { - if (request.getType() != null && request.getType() == 2 && request.getCoin() > 0) { - RankingDataUpdateCmd receiverCmd = new RankingDataUpdateCmd(); - receiverCmd.setUserId(DataTypeUtils.toLong(request.getUid())); - receiverCmd.setUserSex(1); - receiverCmd.setActivityType(RankingActivityType.KING_GAMES.getCode()); - receiverCmd.setCycleType(RankingCycleType.WEEKLY.getCode()); - receiverCmd.setCycleKey(ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString()); - receiverCmd.setDimension(RankingDimension.GAME_WIN.getCode()); - receiverCmd.setIncrementQuantity(request.getCoin()); - receiverCmd.setBizNo(request.getGameId()); - receiverCmd.setReqSysOrigin(ReqSysOrigin.of(SysOriginPlatformEnum.ATYOU.name())); - rankingActivityService.accumulateRankingData(receiverCmd); - - //游戏王日榜 - gameActivityService.incKingGameDaily(DataTypeUtils.toLong(request.getUid()), request.getCoin(), request.getGameId()); - } - } - @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/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 b7856057..01e048ba 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 @@ -1,7 +1,6 @@ package com.red.circle.other.app.service.game; import com.red.circle.auth.inner.endpoint.AuthClient; -import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; import com.red.circle.component.game.baishun.GameBaishunService; import com.red.circle.component.game.baishun.error.BaishunErrorCode; import com.red.circle.component.game.baishun.props.GameBaishunProperties; @@ -14,41 +13,23 @@ import com.red.circle.component.game.baishun.response.BaishunResponse; import com.red.circle.component.game.baishun.response.BaishunTokenResponse; import com.red.circle.component.game.baishun.response.BaishunUserProfileResponse; import com.red.circle.component.redis.service.RedisService; -import com.red.circle.external.inner.endpoint.message.ImGroupClient; -import com.red.circle.external.inner.model.cmd.message.BroadcastGroupMsgBodyCmd; -import com.red.circle.external.inner.model.enums.message.GroupMessageTypeEnum; import com.red.circle.framework.core.asserts.ResponseAssert; -import com.red.circle.framework.core.dto.ReqSysOrigin; import com.red.circle.framework.core.exception.ResponseException; import com.red.circle.framework.core.security.UserCredential; import com.red.circle.mq.business.model.event.task.TaskApprovalEvent; import com.red.circle.mq.rocket.business.producer.TaskMqMessage; 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.task.RoomDailyTaskProgressUpdateCmd; import com.red.circle.other.app.enums.violation.GameOriginEnum; -import com.red.circle.other.app.service.activity.ActivityRechargeTicketService; -import com.red.circle.other.app.service.activity.RankingActivityService; -import com.red.circle.other.app.service.task.RoomDailyTaskProgressService; +import com.red.circle.other.app.service.game.common.GameEventService; import com.red.circle.other.app.service.task.TaskService; -import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils; -import com.red.circle.other.app.util.OfficialNoticeUtils; -import com.red.circle.other.domain.game.GameRankingIncrementCmd; -import com.red.circle.other.domain.gateway.game.GameRankingGateway; import com.red.circle.other.domain.gateway.user.UserProfileGateway; -import com.red.circle.other.domain.ranking.RankingActivityType; -import com.red.circle.other.domain.ranking.RankingCycleType; -import com.red.circle.other.domain.ranking.RankingDimension; import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService; import com.red.circle.other.infra.database.cache.service.other.GameListCacheService; 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.other.inner.enums.config.EnumConfigKey; -import com.red.circle.other.inner.enums.task.RoomDailyTaskCode; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.tool.core.date.DateUtils; import com.red.circle.tool.core.date.LocalDateTimeUtils; -import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.json.JacksonUtils; import com.red.circle.tool.core.parse.DataTypeUtils; import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient; @@ -57,7 +38,6 @@ import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd.GoldReceiptCmdBuilde import com.red.circle.wallet.inner.model.dto.WalletReceiptResDTO; import com.red.circle.wallet.inner.model.enums.GoldOrigin; import java.math.BigDecimal; -import java.util.Map; import java.util.Objects; import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; @@ -84,14 +64,10 @@ public class GameBaishunServiceImpl implements GameBaishunService { private final UserProfileAppConvertor userProfileAppConvertor; private final EnumConfigCacheService enumConfigCacheService; private final GameListConfigService gameListConfigService; - private final ImGroupClient imGroupClient; - private final RankingActivityService rankingActivityService; - private final GameRankingGateway gameRankingGateway; private final GameListCacheService gameListCacheService; private final TaskService taskService; private final GameActivityService gameActivityService; - private final ActivityRechargeTicketService activityRechargeTicketService; - private final RoomDailyTaskProgressService roomDailyTaskProgressService; + private final GameEventService gameEventService; @Value("${red-circle.game-rank.gameid}") private String gameId; @@ -213,22 +189,12 @@ public class GameBaishunServiceImpl implements GameBaishunService { // request.getCurrencyDiff() > 0 是收入 request.getCurrencyDiff() < 0 是支出 if (Objects.nonNull(gameListConfig)) { - sendBroadcast(request, gameListConfig); - - //游戏参与打榜活动 - incGameRankingActivity(request); - - //累计游戏排行榜 - incGameRankingRecord(request, gameListConfig); - - //处理游戏获得任务 if (request.getCurrencyDiff() > 0) { + gameEventService.onWinEvent(userId, request.getCurrencyDiff(), GameOriginEnum.BAISHUN.name(), gameListConfig); gameActivityService.handleGameSpendTask(userId, Math.abs(request.getCurrencyDiff())); - - // 累加用户获得的金币并发送抽奖券 -// activityRechargeTicketService.accumulatedRechargeAndAddTicket(userId, request.getCurrencyDiff(), MonthlyRechargeType.UNDEFINED); + gameActivityService.incKingGameDaily(userId, request.getCurrencyDiff(), request.getGameId()); } else { - updateRoomDailyTask(request.getCurrencyDiff(), userId); + gameEventService.onBetEvent(userId, request.getCurrencyDiff()); } } @@ -250,85 +216,6 @@ public class GameBaishunServiceImpl implements GameBaishunService { return BaishunResponse.fail(BaishunErrorCode.SERVER_ERROR); } - private void updateRoomDailyTask(Long coins, Long userId) { - RoomDailyTaskCode taskType = RoomDailyTaskCode.PERSONAL_GAME_CONSUME; - String redisKey = "room:daily:task:progress:" + taskType.name() + ":" + userId + ":" + ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate(); - Long total = redisService.increment(redisKey, Math.abs(coins.intValue())); - redisService.expire(redisKey, DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(), TimeUnit.SECONDS); - roomDailyTaskProgressService.updateTaskProgress( - new RoomDailyTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode(taskType.name()) - .setProgressValue(total.intValue()) - ); - } - - private void sendBroadcast(BaishunChangeCurrencyRequest request, GameListConfig gameListConfig) { - if (gameListConfig == null) { - return; - } - - BigDecimal cost = enumConfigCacheService - .getValueBigDecimal(EnumConfigKey.GAME_BROADCAST_AMOUNT, gameListConfig.getSysOrigin()) ; - if (cost == null || cost.compareTo(BigDecimal.ZERO) <= 0) { - cost = BigDecimal.valueOf(5000L); - } - - if (request.getCurrencyDiff() >= cost.longValue()) { - UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO( - userProfileGateway.getByUserId(DataTypeUtils.toLong(request.getUserId()))); - - Map build = OfficialNoticeUtils.buildUserProfile(userProfile); - build.put("gameUrl", gameListConfig.getCover()); - build.put("currencyDiff", request.getCurrencyDiff()); - - imGroupClient.sendMessageBroadcast( - BroadcastGroupMsgBodyCmd.builder() - .toPlatform(SysOriginPlatformEnum.ATYOU) - .type(GroupMessageTypeEnum.GAME_BAISHUN_WIN) - .data(build) - .build() - ); - } - } - - private void incGameRankingRecord(BaishunChangeCurrencyRequest request, GameListConfig gameListConfig) { - if (gameListConfig == null || request.getCurrencyDiff() <= 0) { - return; - } - - GameRankingIncrementCmd build = GameRankingIncrementCmd.builder() - .gameOrigin(GameOriginEnum.BAISHUN.name()) - .gameId(gameListConfig.getGameId()) - .gameName(gameListConfig.getName()) - .gameCover(gameListConfig.getCover()) - .gameUrl(gameListConfig.getGameCode()) - .sysOrigin(gameListConfig.getSysOrigin()) - .amount(request.getCurrencyDiff()) - .periodType("ALL") - .build(); - gameRankingGateway.incrementPrizeAmount(build); - } - - private void incGameRankingActivity(BaishunChangeCurrencyRequest request) { - if (request.getCurrencyDiff() > 0) { - RankingDataUpdateCmd receiverCmd = new RankingDataUpdateCmd(); - receiverCmd.setUserId(DataTypeUtils.toLong(request.getUserId())); - receiverCmd.setUserSex(1); - receiverCmd.setActivityType(RankingActivityType.KING_GAMES.getCode()); - receiverCmd.setCycleType(RankingCycleType.WEEKLY.getCode()); - receiverCmd.setCycleKey(ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString()); - receiverCmd.setDimension(RankingDimension.GAME_WIN.getCode()); - receiverCmd.setIncrementQuantity(request.getCurrencyDiff()); - receiverCmd.setBizNo(request.getGameRoundId()); - receiverCmd.setReqSysOrigin(ReqSysOrigin.of(SysOriginPlatformEnum.ATYOU.name())); - rankingActivityService.accumulateRankingData(receiverCmd); - - //游戏王日榜 - gameActivityService.incKingGameDaily(DataTypeUtils.toLong(request.getUserId()), request.getCurrencyDiff(), request.getGameId()); - } - } - private GoldReceiptCmd createReceipt(BaishunChangeCurrencyRequest param) { UserCredential userCredential = UserCredential.parseToken(param.getToken()); return createGoldReceiptCmdBuilder(param.getCurrencyDiff())