HeartbeatUtils.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.ozs.common.utils;
  2. import com.ozs.common.core.redis.RedisCache;
  3. import com.ozs.common.utils.uuid.IdUtils;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Component;
  6. import java.util.Map;
  7. import java.util.concurrent.TimeUnit;
  8. /**
  9. * 车载心跳机制交互缓存工具类
  10. *
  11. * @author Administrator
  12. */
  13. @Component
  14. public class HeartbeatUtils {
  15. @Autowired
  16. private RedisCache redisCache;
  17. /**
  18. * 获取信息
  19. *
  20. * @return Redis存储的key
  21. */
  22. public String getHeartbeat(String code) {
  23. // 获取请求携带的令牌
  24. if (StringUtils.isNotEmpty(code)) {
  25. try {
  26. // 解析对应的权限
  27. return redisCache.getCacheObject(code);
  28. } catch (Exception e) {
  29. }
  30. }
  31. return null;
  32. }
  33. /**
  34. * 存储信息
  35. *
  36. * @return
  37. */
  38. public void createHeartbeat(String code, String site) {
  39. redisCache.setCacheObject(code, site, 10, TimeUnit.MINUTES);
  40. }
  41. /**
  42. * 删除信息
  43. * @param code
  44. * @return
  45. */
  46. public boolean deleteHeartbeat(String code) {
  47. return redisCache.deleteObject(code);
  48. }
  49. }