feat: 移除NEW状态链接的过期时间设置,调整过期状态逻辑

This commit is contained in:
zyh
2025-08-30 00:46:43 +08:00
parent cc69ac1fee
commit 63e42368cb
3 changed files with 23 additions and 13 deletions

View File

@@ -72,11 +72,11 @@ public class LinkGenerationService {
// 从配置表获取每次副本的奖励点数
int perTimeQuantity = systemConfigService.getDefaultQuantity();
long needPoints = (long) times; // 只扣times不乘以perTimeQuantity
int expireHours = systemConfigService.getConfigValueAsInt("link.expire-hours", 2);
// 移除expireHours配置因为NEW状态不设置过期时间
if (log.isDebugEnabled()) {
log.debug("generateLinks operatorId={} operatorType={} times={} linkCount={} perTimeQuantity={} needPoints={} expireHours={}",
operatorId, operatorType, times, linkCount, perTimeQuantity, needPoints, expireHours);
log.debug("generateLinks operatorId={} operatorType={} times={} linkCount={} perTimeQuantity={} needPoints={}",
operatorId, operatorType, times, linkCount, perTimeQuantity, needPoints);
}
if (!isAdminOperator) {
@@ -94,7 +94,7 @@ public class LinkGenerationService {
batch.setOperatorId(operatorId);
linkBatchMapper.insert(batch);
LocalDateTime expireAt = LocalDateTime.now().plusHours(expireHours);
// NEW状态的链接不设置过期时间只有激活使用时才设置过期时间
List<LinkTask> tasks = new ArrayList<>();
for (int i = 0; i < linkCount; i++) { // 生成linkCount个链接
LinkTask t = new LinkTask();
@@ -102,7 +102,7 @@ public class LinkGenerationService {
t.setAgentId(operator.getId());
t.setCodeNo(generateCodeNo());
t.setTokenHash(DigestUtils.sha256Hex(generateToken()));
t.setExpireAt(expireAt);
t.setExpireAt(null); // NEW状态不设置过期时间
t.setStatus("NEW");
linkTaskMapper.insert(t);
tasks.add(t);
@@ -133,7 +133,7 @@ public class LinkGenerationService {
GenerateResult result = new GenerateResult();
result.setBatchId(batch.getId());
result.setNeedPoints(needPoints);
result.setExpireAt(expireAt);
result.setExpireAt(null); // NEW状态无过期时间
result.setCodeNos(tasks.stream().map(LinkTask::getCodeNo).toList());
return result;
}

View File

@@ -155,17 +155,22 @@ public class LinkListService {
item.setUpdatedAt(task.getUpdatedAt());
// 计算是否过期和剩余时间
// expire_at字段只在状态为EXPIRED时才有值表示过期时间戳
LocalDateTime now = LocalDateTime.now();
boolean isExpired = task.getExpireAt().isBefore(now);
item.setIsExpired(isExpired);
boolean isExpired = "EXPIRED".equals(task.getStatus());
long remainingSeconds = 0L;
// 根据不同状态计算剩余时间
if (isExpired) {
item.setRemainingSeconds(0L);
remainingSeconds = 0L;
} else {
long remainingSeconds = ChronoUnit.SECONDS.between(now, task.getExpireAt());
item.setRemainingSeconds(Math.max(0, remainingSeconds));
// 非过期状态显示为永不过期
remainingSeconds = Long.MAX_VALUE;
}
item.setIsExpired(isExpired);
item.setRemainingSeconds(remainingSeconds);
// 从批次信息中获取任务详情
if (batch != null) {
item.setQuantity(batch.getQuantity());

View File

@@ -464,8 +464,10 @@ public class LinkStatusService {
// 2. 检查链接任务是否过期
if (linkTask.getExpireAt() != null && linkTask.getExpireAt().isBefore(LocalDateTime.now())) {
log.warn("链接任务已过期: expireAt={}", linkTask.getExpireAt());
LocalDateTime now = LocalDateTime.now();
linkTask.setStatus("EXPIRED");
linkTask.setUpdatedAt(LocalDateTime.now());
linkTask.setExpireAt(now); // 设置过期时间戳
linkTask.setUpdatedAt(now);
linkTaskMapper.update(linkTask);
UserLinkStatusResponse response = new UserLinkStatusResponse();
@@ -479,8 +481,10 @@ public class LinkStatusService {
if (linkTask.getQrCreatedAt() != null &&
linkTask.getQrCreatedAt().isBefore(LocalDateTime.now().minusMinutes(10))) {
log.warn("选择设备已超过10分钟未登录链接过期: qrCreatedAt={}", linkTask.getQrCreatedAt());
LocalDateTime now = LocalDateTime.now();
linkTask.setStatus("EXPIRED");
linkTask.setUpdatedAt(LocalDateTime.now());
linkTask.setExpireAt(now); // 设置过期时间戳
linkTask.setUpdatedAt(now);
linkTaskMapper.update(linkTask);
UserLinkStatusResponse response = new UserLinkStatusResponse();
@@ -633,6 +637,7 @@ public class LinkStatusService {
// 将链接状态设置为过期
linkTask.setStatus("EXPIRED");
linkTask.setExpireAt(now); // 设置过期时间戳
linkTask.setUpdatedAt(now);
linkTaskMapper.updateById(linkTask);
log.info("链接状态已更新为EXPIRED: linkTaskId={}, 更新时间={}", linkTask.getId(), now);