新增云协议设备实时数据功能
This commit is contained in:
@@ -1,15 +1,8 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.AskDeviceDataClientFallbackFactory;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -41,4 +34,7 @@ public interface AskDeviceDataFeignClient {
|
||||
@PostMapping("/askRealData")
|
||||
HttpResult<String> askRealData(@RequestParam("nDid") String nDid, @RequestParam("idx") Integer idx, @RequestParam("clDId") Integer clDId);
|
||||
|
||||
@PostMapping("/askCldRealData")
|
||||
HttpResult<String> askCldRealData(@RequestParam("devId") String devId, @RequestParam("lineId") String lineId);
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +73,12 @@ public class AskDeviceDataClientFallbackFactory implements FallbackFactory<AskDe
|
||||
log.error("{}异常,降级处理,异常为:{}","询问装置实时数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> askCldRealData(String devId, String lineId) {
|
||||
log.error("{}异常,降级处理,异常为:{}","询问云前置实时数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author 徐扬
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RedisSetUtil {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 向Redis Set中添加元素
|
||||
*/
|
||||
public void addToSet(String key, String value, long expireSeconds) {
|
||||
try {
|
||||
Object existing = redisUtil.getObjectByKey(key);
|
||||
Set<String> set = convertToSet(existing);
|
||||
set.add(value);
|
||||
redisUtil.saveByKeyWithExpire(key, set, expireSeconds);
|
||||
} catch (Exception e) {
|
||||
log.error("向Redis Set添加元素失败,key: {}", key, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Redis Set中移除元素
|
||||
*/
|
||||
public void removeFromSet(String key, String value) {
|
||||
try {
|
||||
Object existing = redisUtil.getObjectByKey(key);
|
||||
if (existing != null) {
|
||||
Set<String> set = convertToSet(existing);
|
||||
set.remove(value);
|
||||
redisUtil.saveByKey(key, set);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("从Redis Set移除元素失败,key: {}", key, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的对象到Set转换
|
||||
*/
|
||||
public Set<String> convertToSet(Object obj) {
|
||||
if (obj == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
if (obj instanceof Set) {
|
||||
return new HashSet<>((Set<String>) obj);
|
||||
}
|
||||
if (obj instanceof Collection) {
|
||||
return new HashSet<>((Collection<String>) obj);
|
||||
}
|
||||
log.warn("无法转换的对象类型: {}", obj.getClass().getName());
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user