|
|
@@ -1,5 +1,6 @@
|
|
|
package com.yingpai.gupiao.service.impl;
|
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yingpai.gupiao.domain.vo.StockInfoVO;
|
|
|
@@ -9,11 +10,6 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-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.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -28,10 +24,6 @@ public class StockDataServiceImpl implements StockDataService {
|
|
|
//指数数据接口
|
|
|
private static final String INDEX_URL = "https://web.ifzq.gtimg.cn/appstock/app/fqkline/get";
|
|
|
|
|
|
- private final HttpClient httpClient = HttpClient.newBuilder()
|
|
|
- .connectTimeout(Duration.ofSeconds(3))
|
|
|
- .build();
|
|
|
-
|
|
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
@Override
|
|
|
@@ -62,17 +54,12 @@ public class StockDataServiceImpl implements StockDataService {
|
|
|
}
|
|
|
|
|
|
String fullUrl = BASE_URL + queryBuilder.toString();
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(URI.create(fullUrl))
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
|
|
|
try {
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
- log.debug("[批量查询] 响应: {}", response.body());
|
|
|
+ String body = HttpUtil.get(fullUrl);
|
|
|
+ log.debug("[批量查询] 响应: {}", body);
|
|
|
|
|
|
- if (response.statusCode() == 200) {
|
|
|
- String body = response.body();
|
|
|
+ if (body != null && !body.isEmpty()) {
|
|
|
String[] lines = body.split(";");
|
|
|
|
|
|
for (String line : lines) {
|
|
|
@@ -103,16 +90,11 @@ public class StockDataServiceImpl implements StockDataService {
|
|
|
String today = java.time.LocalDate.now().toString();
|
|
|
String fullUrl = INDEX_URL + "?param=sh" + code + ",day," + today + ",,640,qfq";
|
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(URI.create(fullUrl))
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
- log.debug("[指数查询] 响应: {}", response.body());
|
|
|
+ String body = HttpUtil.get(fullUrl);
|
|
|
+ log.debug("[指数查询] 响应: {}", body);
|
|
|
|
|
|
- if (response.statusCode() == 200) {
|
|
|
- JsonNode root = objectMapper.readTree(response.body());
|
|
|
+ if (body != null && !body.isEmpty()) {
|
|
|
+ JsonNode root = objectMapper.readTree(body);
|
|
|
JsonNode qtData = root.path("data").path("sh" + code).path("qt").path("sh" + code);
|
|
|
|
|
|
if (qtData != null && qtData.isArray() && qtData.size() > 32) {
|
|
|
@@ -189,15 +171,10 @@ public class StockDataServiceImpl implements StockDataService {
|
|
|
|
|
|
String fullUrl = TREND_URL + "?code=" + marketPrefix + stockCode;
|
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(URI.create(fullUrl))
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
+ String body = HttpUtil.get(fullUrl);
|
|
|
|
|
|
- if (response.statusCode() == 200) {
|
|
|
- JsonNode root = objectMapper.readTree(response.body());
|
|
|
+ if (body != null && !body.isEmpty()) {
|
|
|
+ JsonNode root = objectMapper.readTree(body);
|
|
|
JsonNode data = root.path("data").path(marketPrefix + stockCode).path("data").path("data");
|
|
|
|
|
|
if (data != null && data.isArray()) {
|