azizi签到处理

This commit is contained in:
tianfeng 2026-02-02 20:28:57 +08:00
parent 4faae9b097
commit f1228d27a8
7 changed files with 44 additions and 19 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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(),

View File

@ -28,6 +28,11 @@ public enum CheckInKeys implements RedisKeys {
*/
AZIZI_CHECK_IN,
/**
* azizi七日签到
*/
AZIZI_SEVEN_CHECK_IN,
;
@Override

View File

@ -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);
/**
* 标记用户已打卡.

View File

@ -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);
}