|
|
@@ -1,11 +1,35 @@
|
|
|
package com.yunfeiyun.agmp.iot.common.service;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
|
|
|
+import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.TosDevicetype;
|
|
|
+import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
/**
|
|
|
* 统一维护type(lv2)的缓存,增删改查
|
|
|
*/
|
|
|
@Service
|
|
|
public class TypeCacheService {
|
|
|
+ @Resource
|
|
|
+ private RedisCacheManager redisCacheManager;
|
|
|
+
|
|
|
+ public void setCache(TosDevicetype tosDevicetype){
|
|
|
+ redisCacheManager.setCacheObject(RedisCacheKey.IOT_DEVICE_TYPE,tosDevicetype.getDevtypeCode(),tosDevicetype);
|
|
|
+ }
|
|
|
+ public void deleteCache(TosDevicetype tosDevicetype){
|
|
|
+ redisCacheManager.deleteObject(RedisCacheKey.IOT_DEVICE_TYPE,tosDevicetype.getDevtypeCode());
|
|
|
+ }
|
|
|
|
|
|
+ public TosDevicetype getCacheObjectByDevTypeCode(String devtypeCode){
|
|
|
+ Object tosDevicetype = redisCacheManager.getCacheObject(RedisCacheKey.IOT_DEVICE_TYPE,devtypeCode);
|
|
|
+ if(null == tosDevicetype){
|
|
|
+ throw new IotBizException(IotErrorCode.CACHE_NOT_FOUNT);
|
|
|
+ }
|
|
|
+ return JSONObject.parseObject(JSONObject.toJSONString(tosDevicetype), TosDevicetype.class);
|
|
|
+ }
|
|
|
}
|