Commit 70ea2b67 authored by hanbing's avatar hanbing

[update] 微观大数据平台-路段行程时间改为根据轨迹计算

parent 7f781dc0
package net.wanji.opt.common;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.wanji.opt.dto.CrossEventDTO;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;
......@@ -22,14 +25,20 @@ public class RedisUtils {
/**
* 7号库获取最大 score zset 元素
*/
public Object getMaxScoreElement(String redisKey) {
public Object getMaxScoreElement(String redisKey) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
ZSetOperations<String, Object> zSetOps = redis7Template.opsForZSet();
Set<Object> result = zSetOps.reverseRange(redisKey, 0, 0);
if (result != null && !result.isEmpty()) {
return result.iterator().next();
} else {
return null;
for (Object o : result) {
CrossEventDTO dto = objectMapper.readValue(o.toString(), CrossEventDTO.class);
String msgType = dto.getMsgType();
if (msgType.startsWith("50")) {
return o;
}
}
}
return null;
}
}
......@@ -1076,8 +1076,11 @@ public class TrendServiceImpl implements TrendService {
String redisKey = crossId + ":" + inDir;
Object element = redisUtils.getMaxScoreElement(redisKey);
ObjectMapper objectMapper = new ObjectMapper();
CrossEventDTO dto = objectMapper.readValue(element.toString(), CrossEventDTO.class);
return dto.getTransitTime().intValue();
if (element != null) {
CrossEventDTO dto = objectMapper.readValue(element.toString(), CrossEventDTO.class);
return dto.getTransitTime().intValue();
}
return 0;
}
private Integer calcUncoordinatePhaseQueue(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment