Prechádzať zdrojové kódy

添加缓存工具类

gao.qiang 2 rokov pred
rodič
commit
5bb0656cfe

+ 59 - 0
base-common/src/main/java/com/ozs/common/utils/HeartbeatUtils.java

@@ -0,0 +1,59 @@
+package com.ozs.common.utils;
+
+
+import com.ozs.common.core.redis.RedisCache;
+import com.ozs.common.utils.uuid.IdUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 车载心跳机制交互缓存工具类
+ *
+ * @author Administrator
+ */
+@Component
+public class HeartbeatUtils {
+
+    @Autowired
+    private RedisCache redisCache;
+
+
+    /**
+     * 获取信息
+     *
+     * @return Redis存储的key
+     */
+    public String getHeartbeat(String code) {
+        // 获取请求携带的令牌
+        if (StringUtils.isNotEmpty(code)) {
+            try {
+                // 解析对应的权限
+                return redisCache.getCacheObject(code);
+            } catch (Exception e) {
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * 存储信息
+     *
+     * @return
+     */
+    public void createHeartbeat(String code, Map<String,Object> site) {
+        redisCache.setCacheObject(code, site, 10, TimeUnit.MINUTES);
+    }
+
+    /**
+     * 删除信息
+     * @param code
+     * @return
+     */
+    public boolean deleteHeartbeat(String code) {
+        return redisCache.deleteObject(code);
+    }
+}

+ 1 - 1
base-common/src/main/java/com/ozs/common/utils/HttpClientUtil.java

@@ -96,7 +96,7 @@ public class HttpClientUtil {
                 .get()
                 .build();
         Response response = client.newCall(request).execute();
-        return response.body() != null ? response.body().string() : null;
+        return String.valueOf(response.code());
     }
 
     public static InputStream download(String url) throws Exception {

+ 58 - 0
base-common/src/main/java/com/ozs/common/utils/IgnoreUtils.java

@@ -0,0 +1,58 @@
+package com.ozs.common.utils;
+
+
+import com.ozs.common.core.redis.RedisCache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 车载心跳机制交互缓存工具类
+ *
+ * @author Administrator
+ */
+@Component
+public class IgnoreUtils {
+
+    @Autowired
+    private RedisCache redisCache;
+
+
+    /**
+     * 获取信息
+     *
+     * @return Redis存储的key
+     */
+    public String getIgnore(String code) {
+        // 获取请求携带的令牌
+        if (StringUtils.isNotEmpty(code)) {
+            try {
+                // 解析对应的权限
+                return redisCache.getCacheObject(code);
+            } catch (Exception e) {
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * 存储信息
+     *
+     * @return
+     */
+    public void createIgnore(String code, String uuid) {
+        redisCache.setCacheObject(code, uuid, 10, TimeUnit.MINUTES);
+    }
+
+    /**
+     * 删除信息
+     * @param code
+     * @return
+     */
+    public boolean deleteIgnore(String code) {
+        return redisCache.deleteObject(code);
+    }
+}