邀请码 绑定后更新任务进度值
This commit is contained in:
parent
8e8d2bdc5c
commit
5a75f78165
@ -1,21 +1,28 @@
|
||||
package com.red.circle.other.app.command.activity;
|
||||
|
||||
import com.red.circle.component.redis.service.RedisService;
|
||||
import com.red.circle.other.app.command.user.InviteCodeService;
|
||||
import com.red.circle.other.app.dto.cmd.SpinsTaskProgressUpdateCmd;
|
||||
import com.red.circle.other.app.dto.cmd.activity.BindInviteCodeCmd;
|
||||
import com.red.circle.other.app.service.SpinsUserTaskProgressService;
|
||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||
import com.red.circle.other.domain.model.user.UserProfile;
|
||||
import com.red.circle.other.infra.database.rds.entity.user.user.UserInviteUser;
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.UserInviteUserService;
|
||||
import com.red.circle.other.infra.enums.user.InviteTypeEnum;
|
||||
import com.red.circle.tool.core.date.TimestampUtils;
|
||||
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
|
||||
import com.red.circle.tool.core.sequence.IdWorkerUtils;
|
||||
import com.red.circle.tool.core.text.StringUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 绑定邀请码执行器
|
||||
@ -31,6 +38,8 @@ public class BindInviteCodeExe {
|
||||
private final UserProfileGateway userProfileGateway;
|
||||
private final UserInviteUserService userInviteUserService;
|
||||
private final InviteCodeService inviteCodeService;
|
||||
private final RedisService redisService;
|
||||
private final SpinsUserTaskProgressService spinsUserTaskProgressService;
|
||||
|
||||
/**
|
||||
* 执行绑定邀请码
|
||||
@ -117,5 +126,61 @@ public class BindInviteCodeExe {
|
||||
|
||||
log.info("绑定邀请码成功, userId={}, inviterUserId={}, inviteCode={}, inviteType={}",
|
||||
userId, inviterProfile.getId(), inviteCode, inviteType);
|
||||
|
||||
// 增加用户每日邀请用户数量
|
||||
int inviteCount = incrementDailyInviteCount(inviterProfile.getId());
|
||||
|
||||
// 处理送礁1个礼物任务
|
||||
if (inviteCount >= 1) {
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_INVITE_USER_1")
|
||||
.setProgressValue(inviteCount)
|
||||
);
|
||||
}
|
||||
|
||||
// 处理送出3个礼物任务
|
||||
if (inviteCount >= 3) {
|
||||
spinsUserTaskProgressService.updateTaskProgress(
|
||||
new SpinsTaskProgressUpdateCmd()
|
||||
.setUserId(userId)
|
||||
.setTaskCode("SPINS_INVITE_USER_3")
|
||||
.setProgressValue(inviteCount)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加用户每日邀请用户数量
|
||||
* @param userId 用户ID
|
||||
* @return 当前邀请用户数量
|
||||
*/
|
||||
private int incrementDailyInviteCount(Long userId) {
|
||||
String redisKey = "spins:daily:inviteuser:count:" + userId;
|
||||
String countStr = redisService.getString(redisKey);
|
||||
|
||||
if (StringUtils.isBlank(countStr)) {
|
||||
// 计算到凌晨的过期时间(秒)
|
||||
long expireSeconds = getSecondsUntilMidnight();
|
||||
redisService.setString(redisKey, "1", expireSeconds, TimeUnit.SECONDS);
|
||||
return 1;
|
||||
} else {
|
||||
Long newCount = redisService.increment(redisKey, 1);
|
||||
return newCount.intValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前时间到凌晨的秒数
|
||||
* @return 秒数
|
||||
*/
|
||||
private long getSecondsUntilMidnight() {
|
||||
ZonedDateTime now = ZonedDateTimeAsiaRiyadhUtils.now();
|
||||
ZonedDateTime midnight = now.toLocalDate().plusDays(1).atStartOfDay(now.getZone());
|
||||
return java.time.Duration.between(now, midnight).getSeconds();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user