|
|
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yingpai.gupiao.domain.vo.Result;
|
|
|
import com.yingpai.gupiao.domain.vo.StockInfoVO;
|
|
|
import com.yingpai.gupiao.util.StockUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
@@ -19,6 +20,7 @@ import java.time.Duration;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/api/stock")
|
|
|
public class StockDataController {
|
|
|
@@ -46,7 +48,7 @@ public class StockDataController {
|
|
|
*/
|
|
|
@GetMapping("/fetch")
|
|
|
public Result<List<StockInfoVO>> fetchStockData(@RequestParam("codes") String codes) {
|
|
|
- System.out.println("[股票查询] 请求参数: " + codes);
|
|
|
+ log.info("[股票查询] 请求参数: {}", codes);
|
|
|
|
|
|
List<StockInfoVO> dataList = new ArrayList<>();
|
|
|
String[] codeArray = codes.split(",");
|
|
|
@@ -63,7 +65,7 @@ public class StockDataController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- System.out.println("[股票查询] 返回结果: " + dataList);
|
|
|
+ log.debug("[股票查询] 返回结果: {}", dataList);
|
|
|
return Result.success(dataList);
|
|
|
}
|
|
|
|
|
|
@@ -79,11 +81,11 @@ public class StockDataController {
|
|
|
*/
|
|
|
@GetMapping("/index")
|
|
|
public Result<StockInfoVO> fetchIndexData(@RequestParam("code") String code) {
|
|
|
- System.out.println("[指数查询] 请求参数: " + code);
|
|
|
+ log.info("[指数查询] 请求参数: {}", code);
|
|
|
|
|
|
StockInfoVO indexInfo = fetchIndexInfo(code);
|
|
|
|
|
|
- System.out.println("[指数查询] 返回结果: " + indexInfo);
|
|
|
+ log.debug("[指数查询] 返回结果: {}", indexInfo);
|
|
|
return Result.success(indexInfo);
|
|
|
}
|
|
|
|
|
|
@@ -108,7 +110,7 @@ public class StockDataController {
|
|
|
|
|
|
try {
|
|
|
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
- System.out.println("[指数 " + code + "] 响应: " + response.body());
|
|
|
+ log.debug("[指数 {}] 响应: {}", code, response.body());
|
|
|
|
|
|
if (response.statusCode() == 200) {
|
|
|
JsonNode root = objectMapper.readTree(response.body());
|
|
|
@@ -133,7 +135,7 @@ public class StockDataController {
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- System.err.println("[指数 " + code + "] 异常: " + e.getMessage());
|
|
|
+ log.error("[指数 {}] 异常: {}", code, e.getMessage());
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
@@ -164,7 +166,7 @@ public class StockDataController {
|
|
|
|
|
|
try {
|
|
|
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
- System.out.println("[" + code + "] 响应: " + response.body());
|
|
|
+ log.debug("[{}] 响应: {}", code, response.body());
|
|
|
|
|
|
if (response.statusCode() == 200) {
|
|
|
JsonNode root = objectMapper.readTree(response.body());
|
|
|
@@ -189,7 +191,7 @@ public class StockDataController {
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- System.err.println("[" + code + "] 异常: " + e.getMessage());
|
|
|
+ log.error("[{}] 异常: {}", code, e.getMessage());
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
@@ -255,7 +257,7 @@ public class StockDataController {
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- System.err.println("[趋势数据] 获取失败: " + e.getMessage());
|
|
|
+ log.error("[趋势数据] 获取失败: {}", e.getMessage());
|
|
|
}
|
|
|
|
|
|
// 如果没有获取到趋势数据,返回空列表
|
|
|
@@ -283,7 +285,7 @@ public class StockDataController {
|
|
|
try {
|
|
|
return new BigDecimal(value);
|
|
|
} catch (NumberFormatException e) {
|
|
|
- System.err.println("无法解析数字字段 [" + fieldName + "]: " + value);
|
|
|
+ log.warn("无法解析数字字段 [{}]: {}", fieldName, value);
|
|
|
return null;
|
|
|
}
|
|
|
}
|