From 4046be18ed9efe2c09f8b7a791131fc38ccd2254 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 4 Mar 2026 18:34:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E9=97=B4=E9=87=91=E5=B8=81=E5=A4=A7?= =?UTF-8?q?=E6=94=BE=E9=80=81-=E6=AF=8F=E6=97=A5=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E9=BA=A6=E4=BD=8D=E7=BB=9F=E8=AE=A1=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/party3rd/GameHkysRestController.java | 25 ++++++++---- .../redpacket/SendRoomRedPacketCmdExe.java | 27 ++++++++++++- .../app/command/room/RoomEnterCmdExe.java | 39 +++++++++++++++++-- .../team/TeamMemberHeartbeatCmdExe.java | 9 ++++- .../service/game/GameBaishunServiceImpl.java | 22 +++++++---- .../app/service/game/HotGameServiceImpl.java | 22 +++++++---- .../app/service/game/YomiGameServiceImpl.java | 24 ++++++++---- 7 files changed, 133 insertions(+), 35 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 cfcdf5ce..3b401d88 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 @@ -29,6 +29,7 @@ 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; @@ -51,6 +52,7 @@ 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; @@ -193,13 +195,7 @@ public class GameHkysRestController { activityRechargeTicketService.accumulatedRechargeAndAddTicket(userId, Math.abs(cmd.getCoin()), MonthlyRechargeType.UNDEFINED); } else { - RoomDailyTaskCode taskType = RoomDailyTaskCode.PERSONAL_GAME_CONSUME; - roomDailyTaskProgressService.updateTaskProgress( - new RoomDailyTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode(taskType.name()) - .setProgressValue(param.getCoin().intValue()) - ); + updateRoomDailyTask(cmd.getCoin(), userId); } @@ -208,7 +204,20 @@ public class GameHkysRestController { .setData(jsonObject); } - private void incGameRankingRecord(GameLxwlUpdateBalanceCmd request, GameListConfig gameListConfig) { + 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; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/SendRoomRedPacketCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/SendRoomRedPacketCmdExe.java index d6dae72c..e65c65d5 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/SendRoomRedPacketCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/SendRoomRedPacketCmdExe.java @@ -11,7 +11,9 @@ import com.red.circle.other.app.convertor.RoomRedPacketAppConvertor; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.RoomRedPacketCO; import com.red.circle.other.app.dto.cmd.SendRoomRedPacketCmd; +import com.red.circle.other.app.dto.cmd.task.RoomDailyTaskProgressUpdateCmd; import com.red.circle.other.app.enums.RoomRewardLevelEnum; +import com.red.circle.other.app.service.task.RoomDailyTaskProgressService; import com.red.circle.other.app.util.OfficialNoticeUtils; import com.red.circle.other.domain.gateway.RoomRedPacketGateway; import com.red.circle.other.domain.gateway.user.UserProfileGateway; @@ -22,10 +24,12 @@ import com.red.circle.other.domain.redpacket.RoomRedPacketStatus; import com.red.circle.other.domain.redpacket.RoomRedPacketType; import com.red.circle.other.infra.database.cache.service.other.RoomRedPacketCacheService; import com.red.circle.other.infra.database.mongo.entity.activity.RoomContributionActivityCount; +import com.red.circle.other.infra.database.mongo.entity.live.RoomProfileManager; import com.red.circle.other.infra.database.mongo.service.activity.RoomContributionActivityCountService; import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService; import com.red.circle.other.inner.asserts.OtherErrorCode; import com.red.circle.other.inner.asserts.RoomErrorCode; +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.sequence.IdWorkerUtils; @@ -33,7 +37,6 @@ import com.red.circle.tool.core.tuple.PennyAmount; import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient; import com.red.circle.wallet.inner.error.WalletErrorCode; import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd; -import com.red.circle.wallet.inner.model.cmd.WalletReceiptCmd; import com.red.circle.wallet.inner.model.enums.GoldOrigin; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -62,6 +65,7 @@ public class SendRoomRedPacketCmdExe { private final UserProfileAppConvertor userProfileAppConvertor; private final RoomProfileManagerService roomProfileManagerService; private final RoomContributionActivityCountService roomContributionActivityCountService; + private final RoomDailyTaskProgressService roomDailyTaskProgressService; /** * 执行发红包(用户红包) @@ -106,6 +110,8 @@ public class SendRoomRedPacketCmdExe { // 发送飘窗通知 sendMessage(cmd, packetId); + updateRoomDailyTask(cmd.getRoomId(), userId); + log.info("发红包成功 userId={} packetId={} roomId={} type={} amount={} count={}", userId, packetId, cmd.getRoomId(), cmd.getPacketType(), cmd.getTotalAmount(), cmd.getTotalCount()); @@ -113,6 +119,25 @@ public class SendRoomRedPacketCmdExe { return RoomRedPacketAppConvertor.toCO(redPacket); } + private void updateRoomDailyTask(Long roomId, Long userId) { + RoomProfileManager roomProfileManager = roomProfileManagerService.getById(roomId); + if (roomProfileManager == null || !Objects.equals(roomProfileManager.getUserId(), userId)) { + return; + } + + try { + roomDailyTaskProgressService.updateTaskProgress( + new RoomDailyTaskProgressUpdateCmd() + .setUserId(userId) + .setTaskCode(RoomDailyTaskCode.ROOM_OWNER_SEND_RED_PACKET.name()) + .setProgressValue(1) + ); + } catch (Exception e) { + log.error(e .getMessage(), e); + } + } + + /** * 执行发平台红包 */ diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java index de4c91ad..eda1d7c7 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java @@ -1,6 +1,5 @@ package com.red.circle.other.app.command.room; -import com.alibaba.fastjson.JSON; import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; import com.red.circle.external.inner.endpoint.message.TrtcClient; import com.red.circle.framework.core.asserts.ResponseAssert; @@ -18,10 +17,12 @@ import com.red.circle.other.app.dto.clientobject.room.EntryRoomResponseCO; import com.red.circle.other.app.dto.clientobject.room.RoomThemeCO; import com.red.circle.other.app.dto.cmd.room.RoomEntryCmd; import com.red.circle.other.app.dto.cmd.room.UpdateRoomSettingCmd; +import com.red.circle.other.app.dto.cmd.task.RoomDailyTaskProgressUpdateCmd; +import com.red.circle.other.app.service.task.RoomDailyTaskProgressService; +import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; import com.red.circle.other.domain.model.user.NobleAbilityCO; -import com.red.circle.other.domain.model.user.UserProfile; import com.red.circle.other.infra.database.cache.service.other.RoomManagerCacheService; import com.red.circle.other.infra.database.cache.service.user.UserAgoraTokenCacheService; import com.red.circle.other.infra.database.mongo.entity.live.RoomProfile; @@ -39,14 +40,16 @@ import com.red.circle.other.inner.enums.material.PropsCommodityType; import com.red.circle.other.inner.enums.material.PropsVipActualEquityEnum; import com.red.circle.other.inner.enums.room.RoomEventEnum; import com.red.circle.other.inner.enums.room.RoomTakeMicRoleEnum; +import com.red.circle.other.inner.enums.task.RoomDailyTaskCode; import com.red.circle.other.inner.model.dto.live.RoomProfileDTO; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.other.inner.model.dto.user.WealthAndCharmLevelDTO; import com.red.circle.other.inner.model.dto.user.props.UserPropsResourcesDTO; import com.red.circle.other.inner.model.dto.user.props.UserUsePropsDTO; +import com.red.circle.component.redis.service.RedisService; import com.red.circle.tool.core.collection.CollectionUtils; -import com.red.circle.tool.core.date.LocalDateTimeUtils; import com.red.circle.tool.core.date.TimestampUtils; +import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.json.JacksonUtils; import com.red.circle.tool.core.sequence.IdWorkerUtils; import com.red.circle.tool.core.text.StringUtils; @@ -58,6 +61,7 @@ import java.util.concurrent.atomic.AtomicReference; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; /** @@ -85,6 +89,9 @@ public class RoomEnterCmdExe { private final TaskMqMessage taskMqMessage; private final AdministratorAuthService administratorAuthService; private final RocketRewardClaimCmdExe rocketRewardClaimCmdExe; + private final RoomDailyTaskProgressService roomDailyTaskProgressService; + private final RedisService redisService; + private final RedisTemplate redisTemplate; public EntryRoomResponseCO execute(RoomEntryCmd cmd) { //checkEntryUserId(cmd); @@ -127,6 +134,9 @@ public class RoomEnterCmdExe { log.error("进房间添加足迹异常:{}", e.getMessage()); } + // 房间每日任务 + updateRoomDailyTask(cmd.getReqUserId(), manager.getUserId()); + return new EntryRoomResponseCO() .setRoomProfile( new EntryRoomProfileCO() @@ -151,6 +161,29 @@ public class RoomEnterCmdExe { ); } + private void updateRoomDailyTask(Long enterUserId, Long roomOwnerId) { + // 只处理用户进入非自己房间的情况 + if (Objects.equals(enterUserId, roomOwnerId)) { + return; + } + try { + // Redis 去重:同一用户当天进入同一房间只计一次 + String redisKey = "room:daily:task:new_member:" + roomOwnerId + ":" + ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate(); + redisTemplate.opsForSet().add(redisKey, enterUserId); + redisService.expire(redisKey, DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(), TimeUnit.SECONDS); + + long uniqueCount = redisService.setSize(redisKey); + roomDailyTaskProgressService.updateTaskProgress( + new RoomDailyTaskProgressUpdateCmd() + .setUserId(roomOwnerId) + .setTaskCode(RoomDailyTaskCode.ROOM_NEW_MEMBER.name()) + .setProgressValue((int) uniqueCount) + ); + } catch (Exception e) { + log.error("更新房间每日任务失败, roomOwnerId={}, enterUserId={}", roomOwnerId, enterUserId, e); + } + } + /** * 异步拿声网观众token,5分钟拿不到就返回默认一串字符串 * @param cmd diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/TeamMemberHeartbeatCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/TeamMemberHeartbeatCmdExe.java index e229919e..54b8f24d 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/TeamMemberHeartbeatCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/TeamMemberHeartbeatCmdExe.java @@ -8,6 +8,7 @@ import com.red.circle.mq.rocket.business.producer.TaskMqMessage; import com.red.circle.other.app.dto.cmd.task.RoomDailyTaskProgressUpdateCmd; import com.red.circle.other.app.service.task.RoomDailyTaskProgressService; import com.red.circle.other.app.service.task.TaskService; +import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils; import com.red.circle.other.infra.common.team.TeamTargetCommon; import com.red.circle.other.infra.database.mongo.entity.live.RoomProfile; import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMemberTarget; @@ -99,11 +100,15 @@ public class TeamMemberHeartbeatCmdExe { } private void updateDailyTask(AppRoomIdCmd cmd, RoomDailyTaskCode taskType) { + Long userId = cmd.requiredReqUserId(); + String redisKey = "room:daily:task:progress:" + taskType.name() + ":" + userId + ":" + ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate(); + Long total = redisService.increment(redisKey, 1); + redisService.expire(redisKey, DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(), TimeUnit.SECONDS); roomDailyTaskProgressService.updateTaskProgress( new RoomDailyTaskProgressUpdateCmd() - .setUserId(cmd.requiredReqUserId()) + .setUserId(userId) .setTaskCode(taskType.name()) - .setProgressValue(1) + .setProgressValue(total.intValue()) ); } 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 25183291..c5bc26f3 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 @@ -32,6 +32,7 @@ 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.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; @@ -228,13 +229,7 @@ public class GameBaishunServiceImpl implements GameBaishunService { // 累加用户获得的金币并发送抽奖券 activityRechargeTicketService.accumulatedRechargeAndAddTicket(userId, request.getCurrencyDiff(), MonthlyRechargeType.UNDEFINED); } else { - RoomDailyTaskCode taskType = RoomDailyTaskCode.PERSONAL_GAME_CONSUME; - roomDailyTaskProgressService.updateTaskProgress( - new RoomDailyTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode(taskType.name()) - .setProgressValue(Math.abs(request.getCurrencyDiff().intValue())) - ); + updateRoomDailyTask(request.getCurrencyDiff(), userId); } } @@ -256,6 +251,19 @@ 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; 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 39f2c8d8..e545a6a4 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 @@ -26,6 +26,7 @@ import com.red.circle.other.app.service.activity.RankingActivityService; 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.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; @@ -333,13 +334,7 @@ public class HotGameServiceImpl implements HotGameService { // 处理游戏消费人任务 else { - RoomDailyTaskCode taskType = RoomDailyTaskCode.PERSONAL_GAME_CONSUME; - roomDailyTaskProgressService.updateTaskProgress( - new RoomDailyTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode(taskType.name()) - .setProgressValue(param.getCoin().intValue()) - ); + updateRoomDailyTask(param.getCoin(), userId); } return new HotGameResponse() @@ -362,6 +357,19 @@ public class HotGameServiceImpl implements HotGameService { .setErrorCode(HotGameErrorEnum.SERVER_ERROR.getErrorCode()); } + 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 incGameRankingTmpActivity(HotGameUserCoinUpdate request) { if (ZonedDateTimeAsiaRiyadhUtils.now().isAfter(getFinishTime())) { return; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/YomiGameServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/YomiGameServiceImpl.java index 743e7f44..12cc0684 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/YomiGameServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/YomiGameServiceImpl.java @@ -2,6 +2,7 @@ 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.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; @@ -18,6 +19,7 @@ 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.override.service.YomiGameService; 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; @@ -73,6 +75,7 @@ public class YomiGameServiceImpl implements YomiGameService { private final GameRankingGateway gameRankingGateway; private final ActivityRechargeTicketService activityRechargeTicketService; private final RoomDailyTaskProgressService roomDailyTaskProgressService; + private final RedisService redisService; @Override public YomiTokenCO getToken(YomiGetTokenCmd cmd) { @@ -184,13 +187,7 @@ public class YomiGameServiceImpl implements YomiGameService { // 累加用户获得的金币并发送抽奖券 activityRechargeTicketService.accumulatedRechargeAndAddTicket(userId, Math.abs(changeValue.longValue()), MonthlyRechargeType.UNDEFINED); } else { - RoomDailyTaskCode taskType = RoomDailyTaskCode.PERSONAL_GAME_CONSUME; - roomDailyTaskProgressService.updateTaskProgress( - new RoomDailyTaskProgressUpdateCmd() - .setUserId(userId) - .setTaskCode(taskType.name()) - .setProgressValue(cmd.getChangeValue()) - ); + updateRoomDailyTask(changeValue.longValue(), userId); } return new YomiBalanceCO(currentBalance); @@ -202,6 +199,19 @@ public class YomiGameServiceImpl implements YomiGameService { } } + 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 static boolean isConsume(YomiChangeBalanceCmd cmd) { return "bet".equals(cmd.getChangeCause()); }