From 5f97f550b3fb60ac2142d7ca3c78d6bd04f18b80 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Fri, 11 Oct 2024 17:08:57 +0800
Subject: [PATCH] 1

---
 src/main/java/com/nq/service/impl/StockServiceImpl.java |   42 +++++++++++++++++++++++++++++-------------
 1 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/StockServiceImpl.java b/src/main/java/com/nq/service/impl/StockServiceImpl.java
index cb7f279..d3a6f6a 100644
--- a/src/main/java/com/nq/service/impl/StockServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/StockServiceImpl.java
@@ -19,6 +19,7 @@
 import com.nq.pojo.*;
 import com.nq.pojo.reponse.RPageInfo;
 import com.nq.service.*;
+import com.nq.utils.ConverterUtil;
 import com.nq.utils.http.HttpClientRequest;
 import com.nq.utils.PropertiesUtil;
 import com.nq.utils.redis.RedisKeyUtil;
@@ -184,21 +185,14 @@
             stockListVOS.addAll(Objects.requireNonNull(StockApi.getStockReailTimes(stockList)));
         }
 
-        // Create a list to hold Futures
-        List<CompletableFuture<Void>> futures = new ArrayList<>();
-
-        // Use CompletableFuture to perform asynchronous processing for each stockListVO
         for (StockListVO stockListVO : stockListVOS) {
-            CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
-                stockListVO.setNowPrice(iPriceServices.getNowPrice(stockListVO.getCode(), stockType).toString());
-                Map<String, Object> newStock = iPriceServices.getNewStock(stockListVO.getCode());
-                stockListVO.setHcrateP(newStock.get("pcp").toString());
-            });
-            futures.add(future);
+            Stock stock = new Stock();
+            stock.setStockType(stockListVO.getStock_type());
+            stock.setStockCode(stockListVO.getCode());
+            StockRealTimeBean cacheRealTimeStock = RedisKeyUtil.getCacheRealTimeStock(stock);
+            stockListVO.setNowPrice(cacheRealTimeStock.getLast());
+            stockListVO.setHcrateP(cacheRealTimeStock.getPcp());
         }
-
-        // Wait for all futures to complete
-        CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
 
         RPageInfo pageInfo = new RPageInfo();
         pageInfo.setList(stockListVOS);
@@ -242,6 +236,28 @@
         return ServerResponse.createBySuccess(map);
     }
 
+    public String doGet(String pid, EStockType eStockType) {
+        String apiUrl = eStockType.getStockUrl() + "/indices?country_id="+eStockType.getContryId()+"&key=" + eStockType.getStockKey();
+        try {
+            URL url = new URL(apiUrl);
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+            connection.setRequestMethod("GET");
+
+            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+            String inputLine;
+            StringBuffer response = new StringBuffer();
+
+            while ((inputLine = in.readLine()) != null) {
+                response.append(inputLine);
+            }
+            in.close();
+            return response.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
     public Map getSingleStock(String code) {
         if (StringUtils.isBlank(code))
             return null;

--
Gitblit v1.9.3