forked from dyf/fys-Multi-tenant
全局控制
This commit is contained in:
@ -1,14 +1,17 @@
|
||||
package com.fuyuanshen.app.service.device.status.jbq;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.app.service.device.status.DeviceStatusRule;
|
||||
import com.fuyuanshen.app.service.device.status.constants.DeviceTypeConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
@ -30,21 +33,23 @@ public class AlarmStatusRule implements DeviceStatusRule {
|
||||
public Map<String, Object> getStatus(AppRealTimeStatusDto dto) {
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
String functionAccess = RedisUtils.getCacheObject(
|
||||
|
||||
FUNCTION_ACCESS_KEY + dto.getDeviceImei());
|
||||
if(functionAccess==null){
|
||||
FUNCTION_ACCESS_KEY + dto.getBatchId());
|
||||
if(StringUtils.isBlank(functionAccess)){
|
||||
status.put("functionAccess", "OK");
|
||||
return status;
|
||||
}
|
||||
JSONObject jsonObj = new JSONObject(functionAccess);
|
||||
AtomicBoolean isActive = new AtomicBoolean(false);
|
||||
jsonObj.forEach((key, value) -> {
|
||||
if(value.equals("ACTIVE")){
|
||||
isActive.set(true);
|
||||
}
|
||||
});
|
||||
if(!isActive.get()){
|
||||
status.put("functionAccess", "OK");
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
//
|
||||
|
||||
// String alarmStatus = RedisUtils.getCacheObject(
|
||||
// GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + dto.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
//
|
||||
// if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
// status.put("alarmStatus", alarmStatus);
|
||||
// }
|
||||
return status;
|
||||
}
|
||||
}
|
@ -36,14 +36,6 @@ public class BootLogoStatusRule implements DeviceStatusRule {
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
// String location = RedisUtils.getCacheObject(
|
||||
// GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + dto.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX);
|
||||
//
|
||||
// if (StringUtils.isNotBlank(location)) {
|
||||
// JSONObject jsonObject = JSONObject.parseObject(location);
|
||||
// status.put("latitude", jsonObject.getString("latitude"));
|
||||
// status.put("longitude", jsonObject.getString("longitude"));
|
||||
// }
|
||||
return status;
|
||||
}
|
||||
}
|
@ -40,9 +40,6 @@ public class LaserModeSettingsStatusRule implements DeviceStatusRule {
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
// String onlineStatus = RedisUtils.getCacheObject(
|
||||
// GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + dto.getDeviceImei() + DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
// status.put("onlineStatus", StringUtils.isNotBlank(onlineStatus) ? 1 : 0);
|
||||
return status;
|
||||
}
|
||||
}
|
@ -32,16 +32,11 @@ public class ModeStatusRule implements DeviceStatusRule {
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
String functionAccess = RedisUtils.getCacheObject(
|
||||
FUNCTION_ACCESS_KEY + dto.getDeviceImei());
|
||||
status.put("functionAccess", functionAccess);
|
||||
// String deviceStatus = RedisUtils.getCacheObject(
|
||||
// GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + dto.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
//
|
||||
// if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
// JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
// status.put("battery", jsonObject.getString("batteryPercentage"));
|
||||
// } else {
|
||||
// status.put("battery", "0");
|
||||
// }
|
||||
if(functionAccess==null){
|
||||
status.put("functionAccess", "OK");
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
@ -36,12 +36,6 @@ public class RegisterPersonInfoStatusRule implements DeviceStatusRule {
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
// String alarmStatus = RedisUtils.getCacheObject(
|
||||
// GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + dto.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
//
|
||||
// if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
// status.put("alarmStatus", alarmStatus);
|
||||
// }
|
||||
return status;
|
||||
}
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
package com.fuyuanshen.app.service.device.status.jbq;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.app.service.device.status.DeviceStatusRule;
|
||||
import com.fuyuanshen.app.service.device.status.constants.DeviceTypeConstants;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
@ -30,19 +32,24 @@ public class SendMessageStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public Map<String, Object> getStatus(AppRealTimeStatusDto dto) {
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
List<String> functionAccess = RedisUtils.getCacheObject(
|
||||
String functionAccess = RedisUtils.getCacheObject(
|
||||
FUNCTION_ACCESS_KEY + dto.getBatchId());
|
||||
if(functionAccess==null){
|
||||
if(StringUtils.isBlank(functionAccess)){
|
||||
status.put("functionAccess", "OK");
|
||||
return status;
|
||||
}
|
||||
JSONObject jsonObj = new JSONObject(functionAccess);
|
||||
AtomicBoolean isActive = new AtomicBoolean(false);
|
||||
jsonObj.forEach((key, value) -> {
|
||||
if(value.equals("ACTIVE")){
|
||||
isActive.set(true);
|
||||
}
|
||||
});
|
||||
if(!isActive.get()){
|
||||
status.put("functionAccess", "OK");
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
// String alarmStatus = RedisUtils.getCacheObject(
|
||||
// GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + dto.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
//
|
||||
// if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
// status.put("alarmStatus", alarmStatus);
|
||||
// }
|
||||
return status;
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ public class FunctionAccessAspect {
|
||||
throw new ServiceException("设备已存在访问限制,请稍后再试", 500);
|
||||
}
|
||||
// 存储到Redis中,设置过期时间
|
||||
RedisUtils.setCacheObject(redisKey, "ACTIVE", Duration.ofMinutes(30));
|
||||
RedisUtils.setCacheObject(redisKey, "ACTIVE", Duration.ofSeconds(30));
|
||||
log.info("设备Redis key已添加: {}", redisKey);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONObject;
|
||||
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;
|
||||
@ -14,9 +15,7 @@ import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
@ -43,8 +42,15 @@ 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(deviceImeiList), Duration.ofMinutes(30));
|
||||
RedisUtils.setCacheObject(redisKey, JSONUtil.toJsonStr(deviceImeiMap), Duration.ofSeconds(15));
|
||||
log.info("设备Redis key已添加: {}", redisKey);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user