1.增强拉黑功能,新增拉黑时间
This commit is contained in:
@@ -38,6 +38,12 @@ public class Black implements Serializable {
|
||||
@TableField("target")
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* 截止时间
|
||||
*/
|
||||
@TableField("deadline")
|
||||
private LocalDateTime deadline;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@@ -49,6 +55,4 @@ public class Black implements Serializable {
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.hula.core.user.domain.vo.req.user;
|
||||
import com.hula.domain.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
@@ -12,7 +11,11 @@ import jakarta.validation.constraints.NotNull;
|
||||
@Data
|
||||
public class BlackReq extends BaseEntity {
|
||||
|
||||
@NotNull
|
||||
@NotNull(message = "请选择拉黑用户")
|
||||
@Schema(description = "拉黑用户的uid")
|
||||
private Long uid;
|
||||
|
||||
@NotNull(message = "请输入截止时间")
|
||||
@Schema(description = "截止时间, 分钟")
|
||||
private Long deadline;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hula.core.user.service.cache;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.hula.common.constant.RedisKey;
|
||||
import com.hula.common.domain.vo.req.CursorPageBaseReq;
|
||||
import com.hula.common.domain.vo.res.CursorPageBaseResp;
|
||||
@@ -18,8 +19,10 @@ import com.hula.core.user.domain.entity.UserRole;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -42,6 +45,14 @@ public class UserCache {
|
||||
@Resource
|
||||
private UserSummaryCache userSummaryCache;
|
||||
|
||||
/**
|
||||
* 每小时一执行
|
||||
*/
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void cleanExpiredBlacks() {
|
||||
evictBlackMap();
|
||||
}
|
||||
|
||||
public Long getOnlineNum() {
|
||||
String onlineKey = RedisKey.getKey(RedisKey.ONLINE_UID_ZET);
|
||||
return RedisUtils.zCard(onlineKey);
|
||||
@@ -159,7 +170,8 @@ public class UserCache {
|
||||
|
||||
@Cacheable(cacheNames = "user", key = "'blackList'")
|
||||
public Map<Integer, Set<String>> getBlackMap() {
|
||||
Map<Integer, List<Black>> collect = blackDao.list().stream().collect(Collectors.groupingBy(Black::getType));
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Map<Integer, List<Black>> collect = blackDao.getBaseMapper().selectList(new QueryWrapper<Black>().gt("deadline", now)).stream().collect(Collectors.groupingBy(Black::getType));
|
||||
Map<Integer, Set<String>> result = new HashMap<>(collect.size());
|
||||
for (Map.Entry<Integer, List<Black>> entry : collect.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue().stream().map(Black::getTarget).collect(Collectors.toSet()));
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -48,6 +49,7 @@ import java.util.stream.Collectors;
|
||||
@AllArgsConstructor
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
public static final LocalDateTime MAX_DATE = LocalDateTime.of(2099, 12, 31, 00, 00, 00);
|
||||
private UserCache userCache;
|
||||
private UserBackpackDao userBackpackDao;
|
||||
private UserDao userDao;
|
||||
@@ -143,6 +145,11 @@ public class UserServiceImpl implements UserService {
|
||||
Black user = new Black();
|
||||
user.setTarget(uid.toString());
|
||||
user.setType(BlackTypeEnum.UID.getType());
|
||||
if(ObjectUtil.isNull(req.getDeadline()) || req.getDeadline().equals(0L)){
|
||||
user.setDeadline(MAX_DATE);
|
||||
} else {
|
||||
user.setDeadline(LocalDateTime.now().plusMinutes(req.getDeadline()));
|
||||
}
|
||||
blackDao.save(user);
|
||||
User byId = userDao.getById(uid);
|
||||
blackIp(byId.getIpInfo().getCreateIp());
|
||||
|
||||
Reference in New Issue
Block a user