Commit dc6b2cd0 by 杨林龙

优化Gps基站消费逻辑

1 parent e7f6ffdd
......@@ -7,12 +7,14 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.glsx.plat.redis.utils.RedisUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
/**
......@@ -118,7 +120,7 @@ public class TransitHandleService {
// 当数据大小为500个 或者 时间间隔3秒 的时候 保存一次
if (System.currentTimeMillis() >= tempTime + STEP) {
List<String> snTempList = Lists.newArrayList();
Set<String> snTempSet = Sets.newHashSet();
log.info("开始插入或者更新Gps和基站的数据大小===" + snSet.size());
snSet.forEach(sn -> {
Integer lockValue = (Integer) redisUtils.get(setKey(sn));
......@@ -126,7 +128,7 @@ public class TransitHandleService {
log.info("设备号:" + sn + "已经在redis中加锁,在此服务器中不消费");
return;
}
snTempList.add(sn);
snTempSet.add(sn);
//消费的设备号进行加锁 保证只在一台机器上处理入库操作
redisUtils.setnx(setKey(sn), 1, 60);
});
......@@ -136,7 +138,7 @@ public class TransitHandleService {
// 通过sn从 redis中获取数据 并入库
List<DeviceLocationDto> deviceLocationList = Lists.newArrayList();
// 合并Gps 基站 停留状态数据
snTempList.forEach(sn -> {
snTempSet.forEach(sn -> {
DeviceLocationDto gpsData = (DeviceLocationDto) redisUtils.get(setKey(sn, Constants.GPS));
// log.info("gpsData===" + JSONUtil.toJsonStr(gpsData));
if (ObjectUtil.isNull(gpsData)) {
......@@ -165,7 +167,7 @@ public class TransitHandleService {
// log.info("deviceLocationList===" + JSONUtil.toJsonStr(deviceLocationList));
remoteDeviceLocationService.saveOrUpdateDeviceLocationData(deviceLocationList);
// 将sn解锁
snTempList.forEach(sn -> {
snTempSet.forEach(sn -> {
//对于已经入库的设备进行解锁
redisUtils.unlock(setKey(sn), 0);
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!