From 5c1e682edc2bc6c89cf0f34f93a438d1da274e64 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Sun, 21 Jul 2024 01:18:56 +0800
Subject: [PATCH] 1

---
 websocketClient/src/main/java/org/example/wsClient/GateClient.java |   49 ++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/websocketClient/src/main/java/org/example/wsClient/GateClient.java b/websocketClient/src/main/java/org/example/wsClient/GateClient.java
index 729bf0f..466b1cb 100644
--- a/websocketClient/src/main/java/org/example/wsClient/GateClient.java
+++ b/websocketClient/src/main/java/org/example/wsClient/GateClient.java
@@ -11,6 +11,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.example.pojo.Currency;
 import org.example.util.RedisUtil;
+import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -18,10 +19,7 @@
 import java.math.BigDecimal;
 import java.net.URI;
 import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -101,12 +99,11 @@
             if (null != resultMap && null != resultMap.get("s")) {
                 HashMap<String,Object> hashMap = new HashMap<>();
                 ObjectMapper mapper = new ObjectMapper();
+
                 hashMap.put("bids",resultMap.get("bids"));
                 hashMap.put("asks",resultMap.get("asks"));
+
                 String key = "gate" + resultMap.get("s");
-                if(resultMap.get("s").toString().replace("_","").equals("BTCUSDT")){
-                    System.out.println(hashMap.toString());
-                }
                 RedisUtil.set(key.replace("_",""), mapper.writeValueAsString(hashMap));
             }
         } catch (JsonSyntaxException e) {
@@ -202,12 +199,38 @@
 
     }
 
-    public static void main(String[] args) {
-        String scientificNotation = "5.0E-5"; // 科学计数法字符串
-        BigDecimal bigDecimal = new BigDecimal(scientificNotation);
+//    public static void main(String[] args) throws JSONException {
+//        // 从 resultMap 中获取 "bids" 对应的 JSON 数组
+//        JSONArray jsonArray = new JSONArray(resultMap.get("bids").toString()); // 将获取的 bids 转换成 JSON 数组
+//        List<List<String>> resultList = new ArrayList<>(); // 存放所有的内层列表
+//
+//        // 遍历 JSON 数组
+//        for (int i = 0; i < jsonArray.length(); i++) {
+//            JSONArray innerArray = jsonArray.getJSONArray(i); // 获取当前内层 JSON 数组
+//            List<String> innerList = new ArrayList<>(); // 存放当前内层数组的元素
+//
+//            // 遍历内层 JSON 数组
+//            for (int j = 0; j < innerArray.length(); j++) {
+//                innerList.add(innerArray.getString(j)); // 将元素添加到内层列表中
+//            }
+//
+//            resultList.add(innerList); // 将内层列表添加到结果列表中
+//        }
+//
+//        // 考虑去掉未使用的 dataList,下面的代码使用 resultList 而不是 dataList
+//        List<Map<String, String>> resultMapList = new ArrayList<>(); // 存放最终的映射结果
+//        for (List<String> entry : resultList) { // 遍历 resultList 中的每个内层列表
+//            // 确保每个内层列表有足够的元素,再进行映射
+//            if (entry.size() >= 2) { // 判断 entry 的大小,避免 IndexOutOfBoundsException
+//                Map<String, String> mapKey = new HashMap<>(); // 新建一个 Map 以存储键值对
+//                mapKey.put("p", entry.get(0)); // 将内层列表的第一个元素作为键 "p"
+//                mapKey.put("v", entry.get(1)); // 将内层列表的第二个元素作为键 "v"
+//                resultMapList.add(mapKey); // 将 map 添加到结果映射列表中
+//            }
+//        }
+//
+//    }
 
-        System.out.println("Scientific Notation: " + scientificNotation);
-        System.out.println("BigDecimal Value: " + bigDecimal);
-    }
+
 
 }

--
Gitblit v1.9.3