Commit d0728f1f by 杨林龙

更新保存数据逻辑

1 parent 0a5b0145
......@@ -54,10 +54,12 @@ public class TransitHandleService {
deviceLocationMap.put(deviceLocationDto.getSn(), deviceLocationDto);
} else {
// gps时间比缓存中Gps的时间大就更新缓存的时间
Boolean flag = false;
Date lastGpsTime = deviceLocationDto.getLastGpsTime();
Date lastGpsTimeCache = deviceLocationCache.getLastGpsTime();
if (judgeDate(lastGpsTime, lastGpsTimeCache) && lastGpsTime.after(lastGpsTimeCache)) {
deviceLocationCache.setLastGpsTime(lastGpsTime);
flag = true;
}
//基站时间比缓存中基站的时间大就更新缓存的时间
......@@ -65,11 +67,14 @@ public class TransitHandleService {
Date lastBsTimeCache = deviceLocationCache.getLastBsTime();
if (judgeDate(lastBsTime, lastBsTimeCache) && lastBsTime.after(lastBsTimeCache)) {
deviceLocationCache.setLastGpsTime(lastBsTime);
flag = true;
}
// 重新设置回缓存
redisUtils.set(setKey(deviceLocationDto.getSn()), deviceLocationCache);
deviceLocationMap.put(deviceLocationDto.getSn(), deviceLocationCache);
// 判断是否有数据更新 有数据更新重新设置回缓存
if (flag) {
redisUtils.set(setKey(deviceLocationDto.getSn()), deviceLocationCache);
deviceLocationMap.put(deviceLocationDto.getSn(), deviceLocationCache);
}
}
// 当数据大小为500个 或者 时间间隔3秒 的时候 保存一次
......
package cn.com.glsx.kafka.queue.remote;
import cn.hutool.json.JSONUtil;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Yanglinlong
* @date 2021/12/27 10:39
*/
public class MainTest {
public static void main(String[] args) {
ConcurrentHashMap<String, String> hashMap = new ConcurrentHashMap<>();
hashMap.put("123", "123");
hashMap.put("123", "456");
hashMap.put("789", "456");
System.out.println("hashMap = " + JSONUtil.toJsonStr(hashMap));
System.out.println("hashMap = " + JSONUtil.toJsonStr(hashMap.values()));
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!