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 3c83888e..5ab3ab89 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 @@ -45,12 +45,14 @@ public class CheckInExe { private final PropsSendCommon propsSendCommon; public Integer execute(CheckInRewardCmd cmd) { - boolean inrAzizi = false; - if (StringUtils.isBlank(cmd.getDailyKey())) { - cmd.setDailyKey(CheckInKeys.DAILY_CHECK_IN.getKey("DAILY_CHECK_IN_" + cmd.getReqUserId() + ZonedDateTimeAsiaRiyadhUtils.nowDateToInt())); - } else { - inrAzizi = true; + // 判断是否为Azizi签到(根据dailyKey是否为空) + boolean isAziziCheckIn = StringUtils.isNotBlank(cmd.getDailyKey()); + + // 设置每日签到key + if (isAziziCheckIn) { cmd.setDailyKey(CheckInKeys.AZIZI_CHECK_IN.getKey("AZIZI_CHECK_IN" + cmd.getReqUserId() + ZonedDateTimeAsiaRiyadhUtils.nowDateToInt())); + } else { + cmd.setDailyKey(CheckInKeys.DAILY_CHECK_IN.getKey("DAILY_CHECK_IN_" + cmd.getReqUserId() + ZonedDateTimeAsiaRiyadhUtils.nowDateToInt())); } @@ -69,14 +71,14 @@ public class CheckInExe { checkInCacheService.checkDailyCheckIn(cmd.getReqUserId(), cmd.getDailyKey())); ResponseAssert.isFalse(GameErrorCode.CHECKED_IN, - Objects.equals(checkInCacheService.getCheckInDays(buildKey(cmd)), 7)); + Objects.equals(checkInCacheService.getCheckInDays(buildSevenCheckInKey(isAziziCheckIn, cmd.getReqUserId())), 7)); // 累计打卡天数 - Long inDays; - if (!inrAzizi) { - 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)); + String sevenCheckInKey = buildSevenCheckInKey(isAziziCheckIn, cmd.getReqUserId()); + Long inDays = checkInCacheService.incrCheckInDays(sevenCheckInKey, getExpiredTime(isAziziCheckIn, cmd.getReqUserId())); + + // Azizi签到需要检查最大天数限制 + if (isAziziCheckIn) { ResponseAssert.isTrue(GameErrorCode.MAX_CHECK_IN, inDays <= 7); } @@ -115,24 +117,39 @@ public class CheckInExe { ); - return checkInCacheService.getCheckInDays(buildKey(cmd)); + return checkInCacheService.getCheckInDays(sevenCheckInKey); } 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()); - } + /** + * 构建7日签到统计key + * @param isAziziCheckIn 是否为Azizi签到 + * @param userId 用户ID + * @return 签到统计key + */ + private String buildSevenCheckInKey(boolean isAziziCheckIn, Long userId) { + return isAziziCheckIn + ? CheckInKeys.AZIZI_SEVEN_CHECK_IN.getKey(userId) + : CheckInKeys.SEVEN_CHECK_IN.getKey(userId); + } - private long getExpiredTime(CheckInRewardCmd cmd) { + /** + * 获取过期时间 + * @param isAziziCheckIn 是否为Azizi签到 + * @param userId 用户ID + * @return 过期时间(毫秒) + */ + private long getExpiredTime(boolean isAziziCheckIn, Long userId) { Duration duration = getDuration(); long expiredTime = duration.plusDays(1).toMillis(); - if (Objects.equals(6, checkInCacheService.getCheckInDays(buildKey(cmd)))) { + + String sevenCheckInKey = buildSevenCheckInKey(isAziziCheckIn, userId); + Integer checkInDays = checkInCacheService.getCheckInDays(sevenCheckInKey); + // 第6天及以上(包括脏数据)都在今天结束时过期,准备开始新周期 + if (checkInDays != null && checkInDays >= 6) { expiredTime = duration.toMillis(); } return expiredTime;