黑名单
This commit is contained in:
zhongzb
2023-05-22 00:14:35 +08:00
parent db1e49a176
commit 06407062bd
11 changed files with 171 additions and 16 deletions

View File

@@ -21,7 +21,7 @@ public class CacheConfig extends CachingConfigurerSupport {
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
// 方案一(常用)定制化缓存Cache
cacheManager.setCaffeine(Caffeine.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.expireAfterWrite(5, TimeUnit.MINUTES)
.initialCapacity(100)
.maximumSize(200));
return cacheManager;

View File

@@ -81,6 +81,12 @@ public class User implements Serializable {
@TableField("item_id")
private Long itemId;
/**
* 用户状态 0正常 1拉黑
*/
@TableField("status")
private Integer status;
/**
* 创建时间
*/

View File

@@ -0,0 +1,25 @@
package com.abin.mallchat.common.user.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Description: 物品枚举
* Author: <a href="https://github.com/zongzibinbin">abin</a>
* Date: 2023-03-19
*/
@AllArgsConstructor
@Getter
public enum BlackTypeEnum {
IP(1),
UID(2),
;
private final Integer type;
}

View File

@@ -8,15 +8,20 @@ import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
import com.abin.mallchat.common.common.utils.CursorUtils;
import com.abin.mallchat.common.common.utils.RedisUtils;
import com.abin.mallchat.common.user.dao.BlackDao;
import com.abin.mallchat.common.user.dao.UserDao;
import com.abin.mallchat.common.user.domain.entity.Black;
import com.abin.mallchat.common.user.domain.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.security.PublicKey;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -32,6 +37,8 @@ public class UserCache {
private CursorUtils cursorUtils;
@Autowired
private UserDao userDao;
@Autowired
private BlackDao blackDao;
public Long getOnlineNum() {
String onlineKey = RedisKey.getKey(RedisKey.ONLINE_UID_ZET);
@@ -112,4 +119,17 @@ public class UserCache {
RedisUtils.del(key);
}
@Cacheable(cacheNames = "user", key = "'blackList'")
public Map<Integer, Set<String>> getBlackMap() {
Map<Integer, List<Black>> collect = blackDao.list().stream().collect(Collectors.groupingBy(Black::getType));
Map<Integer, Set<String>> result =new HashMap<>();
for (Map.Entry<Integer, List<Black>> entry : collect.entrySet()) {
result.put(entry.getKey(),entry.getValue().stream().map(Black::getTarget).collect(Collectors.toSet()));
}
return result;
}
@CacheEvict(cacheNames = "user", key = "'blackList'")
public Map<Integer, Set<String>> evictBlackMap() {
return null;
}
}