DeviceLatestLocationManager.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.zy.omp.common.redis;
  2. import com.alibaba.fastjson.JSON;
  3. import com.zy.omp.common.Constant;
  4. import com.zy.omp.model.Location;
  5. import org.springframework.data.redis.core.RedisTemplate;
  6. import javax.annotation.Resource;
  7. /**
  8. * 设备最新的位置信息,存储在Redis缓存中
  9. * 弃用
  10. *
  11. * @author yang xiao kun
  12. * create on 2021/2/8
  13. */
  14. //@Component
  15. @Deprecated
  16. public class DeviceLatestLocationManager {
  17. @Resource
  18. private RedisTemplate<String, String> redisTemplate;
  19. /**
  20. * 将最新位置信息保存至redis中
  21. *
  22. * @param entity 位置信息
  23. */
  24. public void saveLocation(Location entity) {
  25. redisTemplate.boundHashOps(Constant.REDIS_LOCATION).put(entity.getDeviceId(), JSON.toJSONString(entity));
  26. }
  27. /**
  28. * 获取设备最新位置信息
  29. *
  30. * @param deviceId 设备ID
  31. */
  32. public Location getLocation(String deviceId) {
  33. Object json = redisTemplate.boundHashOps(Constant.REDIS_LOCATION).get(deviceId);
  34. if (json == null) return null;
  35. return JSON.parseObject(json.toString(), Location.class);
  36. }
  37. }