Commit 79b434e8 authored by duanruiming's avatar duanruiming

[update] 微观大数据平台-行程时间日志打印

parent 728f850f
package net.wanji.opt.common;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.opt.dto.CrossEventDTO;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
......@@ -17,6 +17,7 @@ import java.util.Set;
* Created on 2019/4/29 20:34
*/
@Component
@Slf4j
public class RedisUtils {
@Resource
......@@ -25,19 +26,24 @@ public class RedisUtils {
/**
* 7号库获取最大 score zset 元素
*/
public Object getMaxScoreElement(String redisKey) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
ZSetOperations<String, Object> zSetOps = redis7Template.opsForZSet();
Set<Object> result = zSetOps.reverseRange(redisKey, 0, -1);
public Object getMaxScoreElement(String redisKey) throws Exception {
try {
ObjectMapper objectMapper = new ObjectMapper();
ZSetOperations<String, Object> zSetOps = redis7Template.opsForZSet();
Set<Object> result = zSetOps.reverseRange(redisKey, 0, -1);
if (result != null && !result.isEmpty()) {
for (Object o : result) {
CrossEventDTO dto = objectMapper.readValue(o.toString(), CrossEventDTO.class);
String msgType = dto.getMsgType();
if (msgType.startsWith("50")) {
return o;
if (result != null && !result.isEmpty()) {
for (Object o : result) {
CrossEventDTO dto = objectMapper.readValue(o.toString(), CrossEventDTO.class);
String msgType = dto.getMsgType();
if (msgType.startsWith("50")) {
return o;
}
}
}
log.error("redis获取数据key:{}, 获取value:{}", redisKey, result);
} catch (Exception e) {
//throw new RuntimeException(e);
}
return null;
}
......
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