|
@@ -4,32 +4,30 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.zy.bms.common.Constant;
|
|
|
import com.zy.bms.model.DeviceLocation;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
- * 设备信息,存放在缓存中的数据
|
|
|
+ * 设备最新的位置信息,存储在Redis缓存中
|
|
|
+ * 弃用
|
|
|
*
|
|
|
* @author yang xiao kun
|
|
|
* create on 2021/2/8
|
|
|
*/
|
|
|
-@Component
|
|
|
-public class DeviceManager {
|
|
|
+//@Component
|
|
|
+@Deprecated
|
|
|
+public class DeviceLatestLocationManager {
|
|
|
|
|
|
@Resource
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
/**
|
|
|
* 将最新位置信息保存至redis中
|
|
|
- * 24小时过期
|
|
|
*
|
|
|
* @param entity 位置信息
|
|
|
*/
|
|
|
public void saveLocation(DeviceLocation entity) {
|
|
|
- redisTemplate.opsForValue()
|
|
|
- .set(Constant.REDIS_PREFIX_LOCATION + entity.getDeviceId(), JSON.toJSONString(entity), 24, TimeUnit.HOURS);
|
|
|
+ redisTemplate.boundHashOps(Constant.REDIS_LOCATION).put(entity.getDeviceId(), JSON.toJSONString(entity));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -38,8 +36,8 @@ public class DeviceManager {
|
|
|
* @param deviceId 设备ID
|
|
|
*/
|
|
|
public DeviceLocation getLocation(String deviceId) {
|
|
|
- String json = redisTemplate.opsForValue().get(Constant.REDIS_PREFIX_LOCATION + deviceId);
|
|
|
- if (json == null || json.equals("")) return null;
|
|
|
- return JSON.parseObject(json, DeviceLocation.class);
|
|
|
+ Object json = redisTemplate.boundHashOps(Constant.REDIS_LOCATION).get(deviceId);
|
|
|
+ if (json == null) return null;
|
|
|
+ return JSON.parseObject(json.toString(), DeviceLocation.class);
|
|
|
}
|
|
|
}
|