| | |
| | | package com.lf.server.service.sys; |
| | | |
| | | import com.lf.server.entity.all.RedisCacheKey; |
| | | import com.lf.server.entity.all.SettingData; |
| | | import com.lf.server.entity.sys.BlacklistEntity; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.sys.BlacklistMapper; |
| | | import com.lf.server.service.all.RedisService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 黑名单 |
| | |
| | | @Autowired |
| | | BlacklistMapper blacklistMapper; |
| | | |
| | | @Override |
| | | public Integer selectCount(String ip) { |
| | | ip = "%" + (StringHelper.isNull(ip) ? "" : ip.trim()) + "%"; |
| | | @Autowired |
| | | RedisService redisService; |
| | | |
| | | return blacklistMapper.selectCount(ip); |
| | | private final static int TWO = 2; |
| | | |
| | | @Override |
| | | public Integer selectCount(String ip, Integer type) { |
| | | ip = StringHelper.getLikeUpperStr(ip); |
| | | |
| | | return blacklistMapper.selectCount(ip, type); |
| | | } |
| | | |
| | | @Override |
| | | public List<BlacklistEntity> selectByPage(String ip, Integer limit, Integer offset) { |
| | | ip = "%" + (StringHelper.isNull(ip) ? "" : ip.trim()) + "%"; |
| | | public List<BlacklistEntity> selectByPage(String ip, Integer type, Integer limit, Integer offset) { |
| | | ip = StringHelper.getLikeUpperStr(ip); |
| | | |
| | | return blacklistMapper.selectByPage(ip, limit, offset); |
| | | return blacklistMapper.selectByPage(ip, type, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectIpList(Integer type) { |
| | | if (type == null || type < 1 || type > TWO) { |
| | | return null; |
| | | } |
| | | |
| | | String key = RedisCacheKey.blacklistKey(type.toString()); |
| | | Object obj = redisService.get(key); |
| | | if (obj instanceof List<?>) { |
| | | return (List<String>) obj; |
| | | } |
| | | |
| | | List<String> list = blacklistMapper.selectIpList(type); |
| | | if (list != null && list.size() > 0) { |
| | | redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 清空缓存 |
| | | */ |
| | | public void clearCache() { |
| | | redisService.clearKeys(RedisCacheKey.blacklistKey("")); |
| | | } |
| | | |
| | | @Override |
| | | public Integer insert(BlacklistEntity entity) { |
| | | return blacklistMapper.insert(entity); |
| | | } |