feat: 在用户链接状态查询中添加异步调用逻辑,首次调用立即执行,第二次调用延迟30秒,优化日志记录以便于调试

This commit is contained in:
yahaozhang
2025-10-11 16:36:29 +08:00
parent 951b9ba2f1
commit 314eecb211

View File

@@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
@@ -1159,9 +1160,19 @@ private UserLinkStatusResponse doGetUserLinkStatus_DEPRECATED(Long linkId, Strin
try {
LinkBatch linkBatch = linkBatchMapper.findById(linkTask.getBatchId());
log.info("=============================================");
// 第一次立即调用
scriptClient.saveTotalTimes(deviceId,linkBatch.getTimes()).block();
// saveTotalTimes方法已经包含了详细的日志记录
log.info("codeNo:{},deviceId:{}",linkTask.getCodeNo(),deviceId);
log.info("第一次调用saveTotalTimes成功 - codeNo:{},deviceId:{}",linkTask.getCodeNo(),deviceId);
// 30秒后异步调用第二次不阻塞当前线程
Mono.delay(Duration.ofSeconds(30))
.flatMap(tick -> scriptClient.saveTotalTimes(deviceId, linkBatch.getTimes()))
.subscribe(
result -> log.info("第二次调用saveTotalTimes成功(30秒后) - codeNo:{},deviceId:{}", linkTask.getCodeNo(), deviceId),
error -> log.warn("第二次调用saveTotalTimes失败(30秒后) - codeNo:{},deviceId:{}, error:{}", linkTask.getCodeNo(), deviceId, error.getMessage())
);
log.info("=============================================");
} catch (Exception e) {