访问控制
This commit is contained in:
@ -39,4 +39,6 @@ public interface GlobalConstants {
|
||||
|
||||
|
||||
String FUNCTION_ACCESS_KEY = GLOBAL_REDIS_KEY + "device:function_access:";
|
||||
|
||||
String FUNCTION_ACCESS_TIMEOUT_KEY = GLOBAL_REDIS_KEY + "device:function_access_timeout:";
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.time.Duration;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_TIMEOUT_KEY;
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@ -35,9 +36,8 @@ public class FunctionAccessAspect {
|
||||
if(StringUtils.isNotBlank(cacheKey) && "ACTIVE".equals(cacheKey)){
|
||||
throw new ServiceException("设备已存在访问限制,请稍后再试", 500);
|
||||
}
|
||||
// 存储到Redis中,设置过期时间
|
||||
//
|
||||
RedisUtils.setCacheObject(redisKey, "ACTIVE", Duration.ofSeconds(30));
|
||||
log.info("设备Redis key已添加: {}", redisKey);
|
||||
}
|
||||
|
||||
// 执行原方法
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.fuyuanshen.common.ratelimiter.aspectj;// DeviceRedisKeyAspect.java
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONObject;
|
||||
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.ObjectUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -15,7 +13,7 @@ import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
@ -42,16 +40,11 @@ public class FunctionAccessBatchAspect {
|
||||
if(StringUtils.isNotBlank(cacheKey) && "ACTIVE".equals(cacheKey)){
|
||||
throw new ServiceException("设备已存在访问限制,请稍后再试", 500);
|
||||
}
|
||||
Map<String, String> deviceImeiMap = new HashMap<>();
|
||||
if(ObjectUtils.length(deviceImeiList)>0){
|
||||
deviceImeiList.forEach(item->{
|
||||
deviceImeiMap.put(item, "ACTIVE");
|
||||
});
|
||||
}
|
||||
|
||||
// 存储到Redis中,设置过期时间
|
||||
RedisUtils.setCacheObject(redisKey, JSONUtil.toJsonStr(deviceImeiMap), Duration.ofSeconds(15));
|
||||
log.info("设备Redis key已添加: {}", redisKey);
|
||||
deviceImeiList.forEach(item->{
|
||||
RedisUtils.setCacheObject(FUNCTION_ACCESS_KEY + item, "ACTIVE", Duration.ofSeconds(30));
|
||||
});
|
||||
String deviceImeiListStr = JSONUtil.toJsonStr(deviceImeiList);
|
||||
RedisUtils.setCacheObject(redisKey, deviceImeiListStr , Duration.ofSeconds(40));
|
||||
}
|
||||
|
||||
// 执行原方法
|
||||
|
Reference in New Issue
Block a user