From 3c35e37e40ce6dd0ada96f4e7b4d3f45e527f804 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=95=B8=E9=9D=9E?= <13281114856@qq.com>
Date: Fri, 26 Aug 2022 15:20:17 +0800
Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=97=A5=E5=BF=97=E5=89=8D?=
 =?UTF-8?q?=E7=AB=AF=E5=B1=95=E7=A4=BA=E6=B7=BB=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../AccessMessageConsumerListener.java        | 39 ++++++++++---------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/log-manager/src/main/java/com/mortals/xhx/base/framework/listener/AccessMessageConsumerListener.java b/log-manager/src/main/java/com/mortals/xhx/base/framework/listener/AccessMessageConsumerListener.java
index eb4f747..fa2b630 100644
--- a/log-manager/src/main/java/com/mortals/xhx/base/framework/listener/AccessMessageConsumerListener.java
+++ b/log-manager/src/main/java/com/mortals/xhx/base/framework/listener/AccessMessageConsumerListener.java
@@ -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));
 
-- 
2.24.3