From 7a700909a746f16d3219c369b39e4d439daa3df9 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 28 Nov 2025 14:58:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E6=AF=8F=E5=A4=A9?= =?UTF-8?q?=E6=9C=80=E5=A4=9A=E4=B8=A4=E4=B8=AA=E5=B0=8F=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../other/app/listener/task/TaskListener.java | 52 +++++++------------ 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java index 14544b5a..cb2b55e4 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java @@ -381,8 +381,8 @@ public class TaskListener implements MessageListener { String redisKey = "admin:heartbeat:" + userId; String incValue = redisService.getString(redisKey); - // 计算当前半月周期的过期时间 - long expireSeconds = calculateHalfMonthExpireSeconds(); + // 计算到第二天0点的过期时间 + long expireSeconds = calculateDailyExpireSeconds(); // 心跳计数:每次心跳+1 if (StringUtils.isEmpty(incValue)) { @@ -392,6 +392,13 @@ public class TaskListener implements MessageListener { } else { // 递增心跳计数 long currentCount = redisService.increment(redisKey, 1, expireSeconds, TimeUnit.SECONDS); + + // 每天最多2小时 = 120次心跳 + if (currentCount > 120) { + log.info("管理员麦克风使用时长已达今日上限(2小时),跳过记录, userId={}, currentCount={}", userId, currentCount); + return; + } + if (currentCount % 60 != 0) { return; } @@ -489,46 +496,23 @@ public class TaskListener implements MessageListener { } } - /** - * 计算当前半月周期的过期时间(秒) - *
- * 规则: - * - 上半月(1-15日):过期时间到16号0点0分0秒 - * - 下半月(16日-月末):过期时间到下月1号0点0分0秒 - *
- * - * @return 距离当前周期结束的秒数 - */ - private long calculateHalfMonthExpireSeconds() { + private long calculateDailyExpireSeconds() { // 使用沙特时区 ZoneId riyadhZone = ZoneId.of("Asia/Riyadh"); ZonedDateTime now = ZonedDateTime.now(riyadhZone); - int currentDay = now.getDayOfMonth(); - ZonedDateTime expireTime; - - if (currentDay <= 15) { - // 上半月:过期到当月16号0点 - expireTime = now.withDayOfMonth(16) - .withHour(0) - .withMinute(0) - .withSecond(0) - .withNano(0); - } else { - // 下半月:过期到下月1号0点 - expireTime = now.plusMonths(1) - .withDayOfMonth(1) - .withHour(0) - .withMinute(0) - .withSecond(0) - .withNano(0); - } + // 过期到第二天0点 + ZonedDateTime expireTime = now.plusDays(1) + .withHour(0) + .withMinute(0) + .withSecond(0) + .withNano(0); // 计算秒数差 long expireSeconds = Duration.between(now, expireTime).getSeconds(); - log.debug("计算半月周期过期时间, currentDay={}, expireTime={}, expireSeconds={}", - currentDay, expireTime, expireSeconds); + log.debug("计算每日过期时间, currentTime={}, expireTime={}, expireSeconds={}", + now, expireTime, expireSeconds); return expireSeconds; }