Commit 3c35e37e authored by 赵啸非's avatar 赵啸非

异常日志前端展示添加

parent a7a7732f
......@@ -24,10 +24,7 @@ import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -47,34 +44,40 @@ public class AccessMessageConsumerListener {
private AccessLogService accessLogService;
@RabbitHandler
public void onMessage(@Payload List<String> messages, Channel channel) throws Exception {
log.info("[Access onMessage][线程编号:{} 消息数量:{}]", Thread.currentThread().getName()+Thread.currentThread().getId(), messages.size());
public void onMessage(@Payload List<String> messages) throws Exception {
log.info("[Access onMessage][线程编号:{} 消息数量:{}]", Thread.currentThread().getName() + Thread.currentThread().getId(), messages.size());
// if(messages instanceof ArrayList<String>){
//
// }
if (messages instanceof List && ((List) messages).stream()
.noneMatch((o -> !(o instanceof String)))) {
log.info("1111111111");
}else{
log.info("2222222222222");
}
// messages.forEach(entity -> {
// entity.setId(IdUtil.getSnowflake(0, 1).nextId());
// entity.setCreateUserId(1L);
// entity.setCreateTime(new Date());
// });
// accessLogService.save(messages);
List<AccessLogEntity> collect = messages.stream().map(message -> {
try {
//String json = JSONUtil.formatJsonStr(new String(message, StandardCharsets.UTF_8));
log.info("message:{}",message);
log.info("message:{}", message);
AccessLogEntity entity = JSON.parseObject(message, AccessLogEntity.class);
entity.setId(IdUtil.getSnowflake(0, 1).nextId());
entity.setCreateUserId(1L);
entity.setCreateTime(new Date());
return entity;
}catch (Exception e){
log.info("反序列化异常",e);
} catch (Exception e) {
log.info("反序列化异常", e);
return null;
}
}).filter(f->f!=null).collect(Collectors.toList());
}).filter(f -> f != null).collect(Collectors.toList());
// collect.forEach(accessLogEntity -> accessLogService.save(accessLogEntity));
accessLogService.save(collect);
}
......@@ -82,7 +85,7 @@ public class AccessMessageConsumerListener {
public static void main(String[] args) {
String json="{\n" +
String json = "{\n" +
" \"appName\":\"smart-gateway\",\n" +
" \"deleted\":0,\n" +
" \"duration\":12,\n" +
......@@ -115,7 +118,7 @@ public class AccessMessageConsumerListener {
System.out.println(JSON.toJSONString(accessLogEntity));
JSONObject jsonObject = new JSONObject();
jsonObject.put("111",json);
jsonObject.put("111", json);
System.out.println(JSON.toJSONString(jsonObject));
......
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