|
|
@@ -1,7 +1,6 @@
|
|
|
package com.yingpai.stock.service.impl;
|
|
|
|
|
|
-import com.fasterxml.jackson.databind.JsonNode;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.yingpai.stock.domain.StockQuoteData;
|
|
|
import com.yingpai.stock.service.IStockQuoteService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -11,11 +10,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.net.URI;
|
|
|
-import java.net.http.HttpClient;
|
|
|
-import java.net.http.HttpRequest;
|
|
|
-import java.net.http.HttpResponse;
|
|
|
-import java.time.Duration;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
@@ -29,11 +23,6 @@ import java.util.stream.Collectors;
|
|
|
public class StockQuoteServiceImpl implements IStockQuoteService {
|
|
|
|
|
|
private final ThreadPoolTaskExecutor executor;
|
|
|
- private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
-
|
|
|
- private final HttpClient httpClient = HttpClient.newBuilder()
|
|
|
- .connectTimeout(Duration.ofSeconds(10))
|
|
|
- .build();
|
|
|
|
|
|
private static final int BATCH_SIZE = 50;
|
|
|
// 腾讯股票行情接口
|
|
|
@@ -103,15 +92,12 @@ public class StockQuoteServiceImpl implements IStockQuoteService {
|
|
|
|
|
|
if (codes.isEmpty()) return result;
|
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(URI.create(String.format(BATCH_QUOTE_URL, codes)))
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ String body = HttpUtil.createGet(String.format(BATCH_QUOTE_URL, codes))
|
|
|
+ .timeout(10000)
|
|
|
+ .execute()
|
|
|
+ .body();
|
|
|
|
|
|
- if (response.statusCode() == 200) {
|
|
|
- String body = response.body();
|
|
|
+ if (body != null && !body.isEmpty()) {
|
|
|
String[] lines = body.split(";");
|
|
|
|
|
|
for (String line : lines) {
|