forked from dyf/fys-Multi-tenant
访问控制
This commit is contained in:
@ -19,8 +19,8 @@ import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper;
|
||||
import com.fuyuanshen.app.service.device.status.DeviceStatusRule;
|
||||
import com.fuyuanshen.app.service.device.status.RealTimeStatusEngine;
|
||||
import com.fuyuanshen.app.service.device.status.base.DeviceStatusRule;
|
||||
import com.fuyuanshen.app.service.device.status.base.RealTimeStatusEngine;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.*;
|
||||
|
||||
@ -211,7 +211,6 @@ public class AppDeviceBJQBizService {
|
||||
|
||||
}
|
||||
|
||||
@FunctionAccessAnnotation("uploadDeviceLogo")
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
@ -281,7 +280,6 @@ public class AppDeviceBJQBizService {
|
||||
}
|
||||
|
||||
//灯光亮度设置
|
||||
@FunctionAccessAnnotation("lightBrightnessSettings")
|
||||
public void lightBrightnessSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
@ -314,7 +312,6 @@ public class AppDeviceBJQBizService {
|
||||
}
|
||||
|
||||
//激光模式设置
|
||||
@FunctionAccessAnnotation("laserModeSettings")
|
||||
public void laserModeSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
package com.fuyuanshen.app.service.device.status;
|
||||
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.app.service.device.status.base.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 com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_TIMEOUT_KEY;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FunctionAccessBatchStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getStatus(AppRealTimeStatusDto dto) {
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
String functionAccess = RedisUtils.getCacheObject(
|
||||
FUNCTION_ACCESS_KEY + dto.getBatchId());
|
||||
log.info("FunctionAccessBatchStatusRule:{}",functionAccess);
|
||||
if(StringUtils.isBlank(functionAccess)){
|
||||
status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
return status;
|
||||
}
|
||||
List<String> cachedDeviceImeiList = JSONUtil.toList(functionAccess, String.class);
|
||||
if(cachedDeviceImeiList.isEmpty()){
|
||||
status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
return status;
|
||||
}
|
||||
for (String key : cachedDeviceImeiList) {
|
||||
String item = RedisUtils.getCacheObject(FUNCTION_ACCESS_KEY + key);
|
||||
if("ACTIVE".equals(item)){
|
||||
status.put("functionAccess", FunctionAccessStatus.ACTIVE.getCode());
|
||||
break;
|
||||
}else {
|
||||
status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
}
|
||||
// if (StringUtils.isBlank(item)) {
|
||||
// String timeOut = RedisUtils.getCacheObject(FUNCTION_ACCESS_TIMEOUT_KEY + dto.getDeviceImei());
|
||||
// if ("TIMEOUT".equals(timeOut)) {
|
||||
// status.put("functionAccess", FunctionAccessStatus.TIMEOUT.getCode());
|
||||
// break;
|
||||
// } else {
|
||||
// status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
// }
|
||||
// } else {
|
||||
// if (!FunctionAccessStatus.OK.getCode().equals(item)) {
|
||||
// status.put("functionAccess", FunctionAccessStatus.FAILED.getCode());
|
||||
// break;
|
||||
// } else {
|
||||
// status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package com.fuyuanshen.app.service.device.status;
|
||||
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.app.service.device.status.base.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 com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_TIMEOUT_KEY;
|
||||
|
||||
// 上传开机图片
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FunctionAccessStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getStatus(AppRealTimeStatusDto dto) {
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
String functionAccess = RedisUtils.getCacheObject(
|
||||
FUNCTION_ACCESS_KEY + dto.getDeviceImei());
|
||||
log.info("FunctionAccessStatusRule:{}",functionAccess);
|
||||
if(StringUtils.isBlank(functionAccess)){
|
||||
String timeOut = RedisUtils.getCacheObject(FUNCTION_ACCESS_TIMEOUT_KEY + dto.getDeviceImei());
|
||||
if("TIMEOUT".equals(timeOut)){
|
||||
status.put("functionAccess", FunctionAccessStatus.TIMEOUT.getCode());
|
||||
RedisUtils.deleteObject(FUNCTION_ACCESS_TIMEOUT_KEY + dto.getDeviceImei());
|
||||
}else{
|
||||
status.put("functionAccess", FunctionAccessStatus.OK.getCode());
|
||||
}
|
||||
}else{
|
||||
status.put("functionAccess", functionAccess);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
package com.fuyuanshen.app.service.device.status;
|
||||
package com.fuyuanshen.app.service.device.status.base;
|
||||
|
||||
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.fuyuanshen.app.service.device.status;
|
||||
package com.fuyuanshen.app.service.device.status.base;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
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;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AlarmStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_5";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getStatus(AppRealTimeStatusDto dto) {
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
String functionAccess = RedisUtils.getCacheObject(
|
||||
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");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package com.fuyuanshen.app.service.device.status.jbq;
|
||||
|
||||
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.redis.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
// 上传开机图片
|
||||
@Slf4j
|
||||
@Component
|
||||
public class BootLogoStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_3";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
@Override
|
||||
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){
|
||||
status.put("functionAccess", "OK");
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
package com.fuyuanshen.app.service.device.status.jbq;
|
||||
|
||||
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.redis.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
// 激光模式设置
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LaserModeSettingsStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
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){
|
||||
status.put("functionAccess", "OK");
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package com.fuyuanshen.app.service.device.status.jbq;
|
||||
|
||||
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.redis.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
// 灯光状态
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ModeStatusRule implements DeviceStatusRule {
|
||||
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
@Override
|
||||
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){
|
||||
status.put("functionAccess", "OK");
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package com.fuyuanshen.app.service.device.status.jbq;
|
||||
|
||||
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.redis.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RegisterPersonInfoStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_4";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
@Override
|
||||
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){
|
||||
status.put("functionAccess", "OK");
|
||||
}else{
|
||||
status.put("functionAccess", "ACTIVE");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
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;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SendMessageStatusRule implements DeviceStatusRule {
|
||||
@Override
|
||||
public String getCommandType() {
|
||||
return DeviceTypeConstants.TYPE_BJQ6170+"_6";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String deviceType) {
|
||||
return true; // 适用于所有设备类型
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getStatus(AppRealTimeStatusDto dto) {
|
||||
Map<String, Object> status = new HashMap<>();
|
||||
String functionAccess = RedisUtils.getCacheObject(
|
||||
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");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user