feat: 封禁用户状态仅更改一次
This commit is contained in:
@@ -19,4 +19,6 @@ public interface RedisService {
|
||||
void recordUrlVisitCountWithIp(long userId, String url, String ip);
|
||||
|
||||
boolean isRecordUserOnLineTime(long userId);
|
||||
|
||||
boolean isSetUserState(long userId);
|
||||
}
|
||||
|
||||
@@ -242,21 +242,18 @@ public class RedisServiceImpl implements RedisService {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 增加跳动次数的记录
|
||||
private void increaseJumpCount(long userId) {
|
||||
String jumpCountKey = "user:" + userId + ":jump_count"; // 跳动次数
|
||||
String jumpCount = redisTemplate.opsForValue().get(jumpCountKey);
|
||||
|
||||
if (jumpCount == null) {
|
||||
redisTemplate.opsForValue().set(jumpCountKey, "1", 1, TimeUnit.MINUTES); // 初始跳动
|
||||
} else {
|
||||
int newJumpCount = Integer.parseInt(jumpCount) + 1;
|
||||
redisTemplate.opsForValue().set(jumpCountKey, String.valueOf(newJumpCount), 1, TimeUnit.MINUTES);
|
||||
@Override
|
||||
public boolean isSetUserState(long userId) {
|
||||
String userKey = "user:" + userId + ":state"; // 存储用户上次的 IP 地址
|
||||
String key = redisUtils.get(userKey);
|
||||
if (StrUtil.isBlank(key)) {
|
||||
DateTime date = DateUtil.date();
|
||||
Date tomorrow = DateUtil.beginOfDay(DateUtil.offsetDay(date, 1));
|
||||
long expire = DateUtil.between(date, tomorrow, DateUnit.SECOND);
|
||||
redisUtils.set(key, userId, expire);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 记录用户访问 URL 的次数和 IP 地址
|
||||
|
||||
Reference in New Issue
Block a user