管理员每天最多两个小时任务
This commit is contained in:
parent
fd006517c8
commit
7a700909a7
@ -381,8 +381,8 @@ public class TaskListener implements MessageListener {
|
|||||||
String redisKey = "admin:heartbeat:" + userId;
|
String redisKey = "admin:heartbeat:" + userId;
|
||||||
String incValue = redisService.getString(redisKey);
|
String incValue = redisService.getString(redisKey);
|
||||||
|
|
||||||
// 计算当前半月周期的过期时间
|
// 计算到第二天0点的过期时间
|
||||||
long expireSeconds = calculateHalfMonthExpireSeconds();
|
long expireSeconds = calculateDailyExpireSeconds();
|
||||||
|
|
||||||
// 心跳计数:每次心跳+1
|
// 心跳计数:每次心跳+1
|
||||||
if (StringUtils.isEmpty(incValue)) {
|
if (StringUtils.isEmpty(incValue)) {
|
||||||
@ -392,6 +392,13 @@ public class TaskListener implements MessageListener {
|
|||||||
} else {
|
} else {
|
||||||
// 递增心跳计数
|
// 递增心跳计数
|
||||||
long currentCount = redisService.increment(redisKey, 1, expireSeconds, TimeUnit.SECONDS);
|
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) {
|
if (currentCount % 60 != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -489,46 +496,23 @@ public class TaskListener implements MessageListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private long calculateDailyExpireSeconds() {
|
||||||
* 计算当前半月周期的过期时间(秒)
|
|
||||||
* <p>
|
|
||||||
* 规则:
|
|
||||||
* - 上半月(1-15日):过期时间到16号0点0分0秒
|
|
||||||
* - 下半月(16日-月末):过期时间到下月1号0点0分0秒
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @return 距离当前周期结束的秒数
|
|
||||||
*/
|
|
||||||
private long calculateHalfMonthExpireSeconds() {
|
|
||||||
// 使用沙特时区
|
// 使用沙特时区
|
||||||
ZoneId riyadhZone = ZoneId.of("Asia/Riyadh");
|
ZoneId riyadhZone = ZoneId.of("Asia/Riyadh");
|
||||||
ZonedDateTime now = ZonedDateTime.now(riyadhZone);
|
ZonedDateTime now = ZonedDateTime.now(riyadhZone);
|
||||||
int currentDay = now.getDayOfMonth();
|
|
||||||
|
|
||||||
ZonedDateTime expireTime;
|
// 过期到第二天0点
|
||||||
|
ZonedDateTime expireTime = now.plusDays(1)
|
||||||
if (currentDay <= 15) {
|
.withHour(0)
|
||||||
// 上半月:过期到当月16号0点
|
.withMinute(0)
|
||||||
expireTime = now.withDayOfMonth(16)
|
.withSecond(0)
|
||||||
.withHour(0)
|
.withNano(0);
|
||||||
.withMinute(0)
|
|
||||||
.withSecond(0)
|
|
||||||
.withNano(0);
|
|
||||||
} else {
|
|
||||||
// 下半月:过期到下月1号0点
|
|
||||||
expireTime = now.plusMonths(1)
|
|
||||||
.withDayOfMonth(1)
|
|
||||||
.withHour(0)
|
|
||||||
.withMinute(0)
|
|
||||||
.withSecond(0)
|
|
||||||
.withNano(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算秒数差
|
// 计算秒数差
|
||||||
long expireSeconds = Duration.between(now, expireTime).getSeconds();
|
long expireSeconds = Duration.between(now, expireTime).getSeconds();
|
||||||
|
|
||||||
log.debug("计算半月周期过期时间, currentDay={}, expireTime={}, expireSeconds={}",
|
log.debug("计算每日过期时间, currentTime={}, expireTime={}, expireSeconds={}",
|
||||||
currentDay, expireTime, expireSeconds);
|
now, expireTime, expireSeconds);
|
||||||
|
|
||||||
return expireSeconds;
|
return expireSeconds;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user