feat: 移除NEW状态链接的过期时间设置,调整过期状态逻辑
This commit is contained in:
@@ -72,11 +72,11 @@ public class LinkGenerationService {
|
|||||||
// 从配置表获取每次副本的奖励点数
|
// 从配置表获取每次副本的奖励点数
|
||||||
int perTimeQuantity = systemConfigService.getDefaultQuantity();
|
int perTimeQuantity = systemConfigService.getDefaultQuantity();
|
||||||
long needPoints = (long) times; // 只扣times,不乘以perTimeQuantity
|
long needPoints = (long) times; // 只扣times,不乘以perTimeQuantity
|
||||||
int expireHours = systemConfigService.getConfigValueAsInt("link.expire-hours", 2);
|
// 移除expireHours配置,因为NEW状态不设置过期时间
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("generateLinks operatorId={} operatorType={} times={} linkCount={} perTimeQuantity={} needPoints={} expireHours={}",
|
log.debug("generateLinks operatorId={} operatorType={} times={} linkCount={} perTimeQuantity={} needPoints={}",
|
||||||
operatorId, operatorType, times, linkCount, perTimeQuantity, needPoints, expireHours);
|
operatorId, operatorType, times, linkCount, perTimeQuantity, needPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAdminOperator) {
|
if (!isAdminOperator) {
|
||||||
@@ -94,7 +94,7 @@ public class LinkGenerationService {
|
|||||||
batch.setOperatorId(operatorId);
|
batch.setOperatorId(operatorId);
|
||||||
linkBatchMapper.insert(batch);
|
linkBatchMapper.insert(batch);
|
||||||
|
|
||||||
LocalDateTime expireAt = LocalDateTime.now().plusHours(expireHours);
|
// NEW状态的链接不设置过期时间,只有激活使用时才设置过期时间
|
||||||
List<LinkTask> tasks = new ArrayList<>();
|
List<LinkTask> tasks = new ArrayList<>();
|
||||||
for (int i = 0; i < linkCount; i++) { // 生成linkCount个链接
|
for (int i = 0; i < linkCount; i++) { // 生成linkCount个链接
|
||||||
LinkTask t = new LinkTask();
|
LinkTask t = new LinkTask();
|
||||||
@@ -102,7 +102,7 @@ public class LinkGenerationService {
|
|||||||
t.setAgentId(operator.getId());
|
t.setAgentId(operator.getId());
|
||||||
t.setCodeNo(generateCodeNo());
|
t.setCodeNo(generateCodeNo());
|
||||||
t.setTokenHash(DigestUtils.sha256Hex(generateToken()));
|
t.setTokenHash(DigestUtils.sha256Hex(generateToken()));
|
||||||
t.setExpireAt(expireAt);
|
t.setExpireAt(null); // NEW状态不设置过期时间
|
||||||
t.setStatus("NEW");
|
t.setStatus("NEW");
|
||||||
linkTaskMapper.insert(t);
|
linkTaskMapper.insert(t);
|
||||||
tasks.add(t);
|
tasks.add(t);
|
||||||
@@ -133,7 +133,7 @@ public class LinkGenerationService {
|
|||||||
GenerateResult result = new GenerateResult();
|
GenerateResult result = new GenerateResult();
|
||||||
result.setBatchId(batch.getId());
|
result.setBatchId(batch.getId());
|
||||||
result.setNeedPoints(needPoints);
|
result.setNeedPoints(needPoints);
|
||||||
result.setExpireAt(expireAt);
|
result.setExpireAt(null); // NEW状态无过期时间
|
||||||
result.setCodeNos(tasks.stream().map(LinkTask::getCodeNo).toList());
|
result.setCodeNos(tasks.stream().map(LinkTask::getCodeNo).toList());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,17 +155,22 @@ public class LinkListService {
|
|||||||
item.setUpdatedAt(task.getUpdatedAt());
|
item.setUpdatedAt(task.getUpdatedAt());
|
||||||
|
|
||||||
// 计算是否过期和剩余时间
|
// 计算是否过期和剩余时间
|
||||||
|
// expire_at字段只在状态为EXPIRED时才有值,表示过期时间戳
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
boolean isExpired = task.getExpireAt().isBefore(now);
|
boolean isExpired = "EXPIRED".equals(task.getStatus());
|
||||||
item.setIsExpired(isExpired);
|
long remainingSeconds = 0L;
|
||||||
|
|
||||||
|
// 根据不同状态计算剩余时间
|
||||||
if (isExpired) {
|
if (isExpired) {
|
||||||
item.setRemainingSeconds(0L);
|
remainingSeconds = 0L;
|
||||||
} else {
|
} 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) {
|
if (batch != null) {
|
||||||
item.setQuantity(batch.getQuantity());
|
item.setQuantity(batch.getQuantity());
|
||||||
|
|||||||
@@ -464,8 +464,10 @@ public class LinkStatusService {
|
|||||||
// 2. 检查链接任务是否过期
|
// 2. 检查链接任务是否过期
|
||||||
if (linkTask.getExpireAt() != null && linkTask.getExpireAt().isBefore(LocalDateTime.now())) {
|
if (linkTask.getExpireAt() != null && linkTask.getExpireAt().isBefore(LocalDateTime.now())) {
|
||||||
log.warn("链接任务已过期: expireAt={}", linkTask.getExpireAt());
|
log.warn("链接任务已过期: expireAt={}", linkTask.getExpireAt());
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
linkTask.setStatus("EXPIRED");
|
linkTask.setStatus("EXPIRED");
|
||||||
linkTask.setUpdatedAt(LocalDateTime.now());
|
linkTask.setExpireAt(now); // 设置过期时间戳
|
||||||
|
linkTask.setUpdatedAt(now);
|
||||||
linkTaskMapper.update(linkTask);
|
linkTaskMapper.update(linkTask);
|
||||||
|
|
||||||
UserLinkStatusResponse response = new UserLinkStatusResponse();
|
UserLinkStatusResponse response = new UserLinkStatusResponse();
|
||||||
@@ -479,8 +481,10 @@ public class LinkStatusService {
|
|||||||
if (linkTask.getQrCreatedAt() != null &&
|
if (linkTask.getQrCreatedAt() != null &&
|
||||||
linkTask.getQrCreatedAt().isBefore(LocalDateTime.now().minusMinutes(10))) {
|
linkTask.getQrCreatedAt().isBefore(LocalDateTime.now().minusMinutes(10))) {
|
||||||
log.warn("选择设备已超过10分钟未登录,链接过期: qrCreatedAt={}", linkTask.getQrCreatedAt());
|
log.warn("选择设备已超过10分钟未登录,链接过期: qrCreatedAt={}", linkTask.getQrCreatedAt());
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
linkTask.setStatus("EXPIRED");
|
linkTask.setStatus("EXPIRED");
|
||||||
linkTask.setUpdatedAt(LocalDateTime.now());
|
linkTask.setExpireAt(now); // 设置过期时间戳
|
||||||
|
linkTask.setUpdatedAt(now);
|
||||||
linkTaskMapper.update(linkTask);
|
linkTaskMapper.update(linkTask);
|
||||||
|
|
||||||
UserLinkStatusResponse response = new UserLinkStatusResponse();
|
UserLinkStatusResponse response = new UserLinkStatusResponse();
|
||||||
@@ -633,6 +637,7 @@ public class LinkStatusService {
|
|||||||
|
|
||||||
// 将链接状态设置为过期
|
// 将链接状态设置为过期
|
||||||
linkTask.setStatus("EXPIRED");
|
linkTask.setStatus("EXPIRED");
|
||||||
|
linkTask.setExpireAt(now); // 设置过期时间戳
|
||||||
linkTask.setUpdatedAt(now);
|
linkTask.setUpdatedAt(now);
|
||||||
linkTaskMapper.updateById(linkTask);
|
linkTaskMapper.updateById(linkTask);
|
||||||
log.info("链接状态已更新为EXPIRED: linkTaskId={}, 更新时间={}", linkTask.getId(), now);
|
log.info("链接状态已更新为EXPIRED: linkTaskId={}, 更新时间={}", linkTask.getId(), now);
|
||||||
|
|||||||
Reference in New Issue
Block a user