From f1228d27a813f7869eb06d604ae7b73f8c6587a4 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Mon, 2 Feb 2026 20:28:57 +0800 Subject: [PATCH] =?UTF-8?q?azizi=E7=AD=BE=E5=88=B0=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../other/inner/asserts/GameErrorCode.java | 5 +++++ .../other/app/command/task/CheckInExe.java | 22 +++++++++++++++---- .../task/query/CheckInRewardQryExe.java | 12 +++++++++- .../task/query/SevenCheckInGetQryExe.java | 2 +- .../infra/database/cache/key/CheckInKeys.java | 5 +++++ .../service/other/CheckInCacheService.java | 4 ++-- .../other/impl/CheckInCacheServiceImpl.java | 13 ++--------- 7 files changed, 44 insertions(+), 19 deletions(-) diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/GameErrorCode.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/GameErrorCode.java index b58c5a3a..d17e9d1d 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/GameErrorCode.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/GameErrorCode.java @@ -208,6 +208,11 @@ public enum GameErrorCode implements IResponseErrorCode { */ USER_ALREADY_EXISTS(8139, "User already exists"), + /** + * 已达到最大签到数量 + */ + MAX_CHECK_IN(8140, "Max check in."), + ; private final Integer code; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/CheckInExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/CheckInExe.java index 1a9a21b5..e51d7b06 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/CheckInExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/CheckInExe.java @@ -67,10 +67,17 @@ public class CheckInExe { checkInCacheService.checkDailyCheckIn(cmd.getReqUserId(), cmd.getDailyKey())); ResponseAssert.isFalse(GameErrorCode.CHECKED_IN, - Objects.equals(checkInCacheService.getCheckInDays(cmd.getReqUserId()), 7)); + Objects.equals(checkInCacheService.getCheckInDays(buildKey(cmd)), 7)); // 累计打卡天数 - Long inDays = checkInCacheService.incrCheckInDays(cmd.getReqUserId(), getExpiredTime(cmd)); + Long inDays; + if (StringUtils.isBlank(cmd.getDailyKey())) { + inDays = checkInCacheService.incrCheckInDays(CheckInKeys.SEVEN_CHECK_IN.getKey(cmd.getReqUserId()), getExpiredTime(cmd)); + } else { + inDays = checkInCacheService.incrCheckInDays(CheckInKeys.AZIZI_SEVEN_CHECK_IN.getKey(cmd.getReqUserId()), getExpiredTime(cmd)); + ResponseAssert.isTrue(GameErrorCode.MAX_CHECK_IN, inDays <= 7); + } + checkInCacheService.markDailyCheckIn(cmd.getReqUserId(), cmd.getDailyKey()); /* 不再根据资源组发,根据资源组顺序一个一个发 @@ -106,17 +113,24 @@ public class CheckInExe { ); - return checkInCacheService.getCheckInDays(cmd.getReqUserId()); + return checkInCacheService.getCheckInDays(buildKey(cmd)); } finally { redisService.unlock(lockKey); } } + private String buildKey(CheckInRewardCmd cmd) { + if (StringUtils.isBlank(cmd.getDailyKey())) { + return CheckInKeys.SEVEN_CHECK_IN.getKey(cmd.getReqUserId()); + } + return CheckInKeys.AZIZI_SEVEN_CHECK_IN.getKey(cmd.getReqUserId()); + } + private long getExpiredTime(CheckInRewardCmd cmd) { Duration duration = getDuration(); long expiredTime = duration.plusDays(1).toMillis(); - if (Objects.equals(6, checkInCacheService.getCheckInDays(cmd.getReqUserId()))) { + if (Objects.equals(6, checkInCacheService.getCheckInDays(buildKey(cmd)))) { expiredTime = duration.toMillis(); } return expiredTime; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/query/CheckInRewardQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/query/CheckInRewardQryExe.java index 04894738..4e3229b2 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/query/CheckInRewardQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/query/CheckInRewardQryExe.java @@ -1,10 +1,13 @@ package com.red.circle.other.app.command.task.query; +import com.alibaba.nacos.common.utils.StringUtils; import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.other.app.convertor.material.PropsMaterialAppConvertor; import com.red.circle.other.app.dto.clientobject.activity.ActivityResourceCO; import com.red.circle.other.app.dto.clientobject.task.CheckInRewardListCO; +import com.red.circle.other.app.dto.cmd.task.CheckInRewardCmd; import com.red.circle.other.domain.gateway.props.ActivitySourceGroupGateway; +import com.red.circle.other.infra.database.cache.key.CheckInKeys; import com.red.circle.other.infra.database.cache.service.other.CheckInCacheService; import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum; import java.util.List; @@ -33,9 +36,16 @@ public class CheckInRewardQryExe { activityType)); return new CheckInRewardListCO() - .setDays(Optional.ofNullable(checkInCacheService.getCheckInDays(cmd.getReqUserId())) + .setDays(Optional.ofNullable(checkInCacheService.getCheckInDays(buildKey(cmd.getReqUserId(), activityType.name()))) .orElse(0)) .setRewards(rewards); } + private String buildKey(Long userId, String activityType) { + if (PropsActivityTypeEnum.DAILY_REGISTER_AZIZI.name().equals(activityType)) { + return CheckInKeys.AZIZI_SEVEN_CHECK_IN.getKey(userId); + } + return CheckInKeys.SEVEN_CHECK_IN.getKey(userId); + } + } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/query/SevenCheckInGetQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/query/SevenCheckInGetQryExe.java index f7dd980e..f4a231e0 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/query/SevenCheckInGetQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/task/query/SevenCheckInGetQryExe.java @@ -33,7 +33,7 @@ public class SevenCheckInGetQryExe { return new CheckInCO() .setType(getType(nobleVip)) .setClockedIn(checkInCacheService.getMarkDaySevenCheckIn(cmd.getReqUserId())) - .setConsecutiveDays(checkInCacheService.getCheckInDays(cmd.getReqUserId())) + .setConsecutiveDays(checkInCacheService.getCheckInDays("cmd.getReqUserId()")) .putNobleRewardQuantity(Optional.ofNullable(nobleVip) .map(nobleVipCache -> enumConfigCacheService .goldsToDiamondQuantity(nobleVipCache.getLoginRewardsAmount(), diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/key/CheckInKeys.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/key/CheckInKeys.java index 18d3e510..562bca3f 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/key/CheckInKeys.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/key/CheckInKeys.java @@ -28,6 +28,11 @@ public enum CheckInKeys implements RedisKeys { */ AZIZI_CHECK_IN, + /** + * azizi七日签到 + */ + AZIZI_SEVEN_CHECK_IN, + ; @Override diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/other/CheckInCacheService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/other/CheckInCacheService.java index bdb28b67..a6b48b7b 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/other/CheckInCacheService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/other/CheckInCacheService.java @@ -13,7 +13,7 @@ public interface CheckInCacheService { * @param userId 用户id * @param timeoutMilliseconds 过期时间 */ - Long incrCheckInDays(Long userId, long timeoutMilliseconds); + Long incrCheckInDays(String key, long timeoutMilliseconds); /** * 缓存用户打卡天数. @@ -21,7 +21,7 @@ public interface CheckInCacheService { * @param userId 用户id * @return ignore */ - Integer getCheckInDays(Long userId); + Integer getCheckInDays(String key); /** * 标记用户已打卡. diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/other/impl/CheckInCacheServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/other/impl/CheckInCacheServiceImpl.java index 052602ca..36540637 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/other/impl/CheckInCacheServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/other/impl/CheckInCacheServiceImpl.java @@ -23,23 +23,14 @@ public class CheckInCacheServiceImpl implements CheckInCacheService { private final RedisService redisService; @Override - public Long incrCheckInDays(Long userId, long timeoutMilliseconds) { - return incrCheckInDays(CheckInKeys.SEVEN_CHECK_IN.getKey(userId), - timeoutMilliseconds); - } - - private Long incrCheckInDays(String key, long timeoutMilliseconds) { + public Long incrCheckInDays(String key, long timeoutMilliseconds) { Long size = Optional.ofNullable(redisService.increment(key)).orElse(0L); redisService.expire(key, timeoutMilliseconds, TimeUnit.MILLISECONDS); return size; } @Override - public Integer getCheckInDays(Long userId) { - return getCheckInDays(CheckInKeys.SEVEN_CHECK_IN.getKey(userId)); - } - - private Integer getCheckInDays(String key) { + public Integer getCheckInDays(String key) { return Optional.ofNullable(redisService.getStringToInteger(key)).orElse(null); }