Commit 79b434e8 authored by duanruiming's avatar duanruiming

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

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