From d90db67d7ac0f5ce0e0ead9e7d1db8e3be30f524 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Thu, 28 Aug 2025 11:43:20 +0800
Subject: [PATCH] 配置新增指数 控制显示
---
src/main/java/com/nq/service/impl/StockServiceImpl.java | 63 +++++++++++++++++++++----------
1 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/StockServiceImpl.java b/src/main/java/com/nq/service/impl/StockServiceImpl.java
index e5ad771..8aa097d 100644
--- a/src/main/java/com/nq/service/impl/StockServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/StockServiceImpl.java
@@ -1,6 +1,8 @@
package com.nq.service.impl;
import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
@@ -11,6 +13,7 @@
import com.google.gson.reflect.TypeToken;
import com.nq.common.ServerResponse;
import com.nq.dao.*;
+import com.nq.enums.EConfigKey;
import com.nq.enums.EStockType;
import com.nq.pojo.*;
import com.nq.pojo.reponse.RPageInfo;
@@ -34,6 +37,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,6 +77,8 @@
@Autowired
SiteNewsMapper siteNewsMapper;
+ @Autowired
+ StockConfigMapper stockConfigMapper;
public ServerResponse getMarket() {
String market_url = PropertiesUtil.getProperty("sina.market.url");
@@ -239,7 +245,7 @@
Integer depositAmt = 0;
String introduction = null;
String result = null;
- com.alibaba.fastjson2.JSONObject json = null;
+ JSONObject json = null;
//期货
String url = null;
if (code.contains("sh") || code.contains("sz")) { //指数
@@ -269,7 +275,7 @@
if (result.contains("msg")) {
introduction = "暂无数据";
} else {
- json = com.alibaba.fastjson2.JSONObject.parseObject(result);
+ json = JSONObject.parseObject(result);
if (json.getJSONObject("data").getJSONArray("gszl").size() > 0) {
introduction = json.getJSONObject("data").getJSONArray("gszl").getJSONObject(0).getString("COMPPROFILE");
} else {
@@ -282,12 +288,12 @@
* 105.UCL&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=时间戳
*/
long now = System.currentTimeMillis();
- com.alibaba.fastjson2.JSONObject buyjson = null;
+ JSONObject buyjson = null;
String buyresult = null;
try {
String buyurl = PropertiesUtil.getProperty("us.stock.buy.url") + stockVO.getType() + "." + stock.getStockCode() + "&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=" + now;
buyresult = HttpClientRequest.doGet(buyurl);
- buyjson = com.alibaba.fastjson2.JSONObject.parseObject(buyresult);
+ buyjson = JSONObject.parseObject(buyresult);
} catch (Exception e) {
log.error("获取分时交易数据失败", e);
buyjson.put("data", "暂无数据");
@@ -405,7 +411,7 @@
EchartsDataVO echartsDataVO = StockApi.assembleEchartsDataVO(minDataVO);
return ServerResponse.createBySuccess(echartsDataVO);
}
- @lombok.Data
+ @Data
class kData {
long t;
String c;
@@ -662,8 +668,8 @@
log.info("涨停板接口:{}", url);
String res = HttpClientRequest.doGet(url);
- com.alibaba.fastjson2.JSONObject json = com.alibaba.fastjson2.JSONObject.parseObject(res);
- com.alibaba.fastjson2.JSONArray pool = null;
+ JSONObject json = JSONObject.parseObject(res);
+ JSONArray pool = null;
if (json.getJSONObject("data") != null) {
pool = json.getJSONObject("data").getJSONArray("pool");
}
@@ -679,13 +685,13 @@
url = url.replace("20221202", day1) + time;
// log.info("涨停板接口:{}",url);
String res = HttpClientRequest.doGet(url);
- com.alibaba.fastjson2.JSONObject json = com.alibaba.fastjson2.JSONObject.parseObject(res);
- com.alibaba.fastjson2.JSONArray pool = null;
+ JSONObject json = JSONObject.parseObject(res);
+ JSONArray pool = null;
if (json.getJSONObject("data") != null) {
pool = json.getJSONObject("data").getJSONArray("pool");
if (pool != null) {
for (int i = 0; i < pool.size(); i++) {
- com.alibaba.fastjson2.JSONObject jsonObject = pool.getJSONObject(i);
+ JSONObject jsonObject = pool.getJSONObject(i);
String c = jsonObject.getString("c");
if (c.equals(code)) {
pool.removeAll(pool);
@@ -704,10 +710,14 @@
//新闻列表
List<SiteNews> newsList = this.siteNewsMapper.getTopNewsList(pageSize);
- String usCodeList = PropertiesUtil.getProperty("us_home_indices_code");
+ /*String usCodeList = PropertiesUtil.getProperty("us_home_indices_code");
String hkCodeList = PropertiesUtil.getProperty("hk_home_indices_code");
String inCodeList = PropertiesUtil.getProperty("in_home_indices_code");
- String twCodeList = PropertiesUtil.getProperty("tw_home_indices_code");
+ String twCodeList = PropertiesUtil.getProperty("tw_home_indices_code");*/
+
+ List<StockConfig> stockConfigList = stockConfigMapper.selectList
+ (new LambdaQueryWrapper<StockConfig>()
+ .like(StockConfig::getCKey, EConfigKey.INDICES.getCode()));
List<DataStockBean> usDataStockBeans = Lists.newArrayList();
List<DataStockBean> hkDataStockBeans = Lists.newArrayList();
@@ -717,10 +727,10 @@
Gson gson = new Gson();
// 统一处理各地区股票数据
- processStockData(usCodeList, EStockType.US.getCode(), usDataStockBeans, gson);
- processStockData(hkCodeList, EStockType.HK.getCode(), hkDataStockBeans, gson);
- processStockData(inCodeList, EStockType.IN.getCode(), inDataStockBeans, gson);
- processStockData(twCodeList, EStockType.TW.getCode(), twDataStockBeans, gson);
+ processStockData(stockConfigList, EStockType.US.getCode(), usDataStockBeans, gson);
+ processStockData(stockConfigList, EStockType.HK.getCode(), hkDataStockBeans, gson);
+ processStockData(stockConfigList, EStockType.IN.getCode(), inDataStockBeans, gson);
+ processStockData(stockConfigList, EStockType.TW.getCode(), twDataStockBeans, gson);
// 组装返回结果
Map<String, Object> resultMap = new HashMap<>();
@@ -737,8 +747,15 @@
}
// 提取的通用处理方法
- private void processStockData(String stockCodes, String stockType,
+ private void processStockData(List<StockConfig> stockConfigList, String stockType,
List<DataStockBean> targetList, Gson gson) throws Exception {
+ String key = EConfigKey.getEConfigKeyByStockType(stockType).getCode();
+ StockConfig stockConfig = stockConfigList.stream()
+ .filter(x -> x.getCKey().equals(key)).findFirst().orElse(null);
+ if (stockConfig == null) {
+ return;
+ }
+ String stockCodes = stockConfig.getCValue();
String[] stockCodeList = stockCodes.split(",");
//实时获取数据
//String result = RedisKeyUtil.doPost(stockCodes, stockType);
@@ -779,7 +796,7 @@
@Override
public ServerResponse getIndicesList(String stockType) {
try {
- String codeList;
+ /*String codeList;
if(stockType.equals(EStockType.US.getCode())) {
codeList = PropertiesUtil.getProperty("us_home_indices_code");
} else if(stockType.equals(EStockType.HK.getCode())) {
@@ -789,9 +806,15 @@
} else if(stockType.equals(EStockType.TW.getCode())) {
codeList = PropertiesUtil.getProperty("tw_home_indices_code");
} else
- codeList = PropertiesUtil.getProperty("us_home_indices_code");
+ codeList = PropertiesUtil.getProperty("us_home_indices_code");*/
- List<String> stockCodeList = Arrays.asList(codeList.split(","));
+ String key = EConfigKey.getEConfigKeyByStockType(stockType).getCode();
+ StockConfig stockConfig = stockConfigMapper.selectOne(new LambdaQueryWrapper<StockConfig>()
+ .eq(StockConfig::getCKey, key));
+ if (stockConfig == null) {
+ return ServerResponse.createByErrorMsg("stockConfig [" + key + "] is null");
+ }
+ List<String> stockCodeList = Arrays.asList(stockConfig.getCValue().split(","));
Map<Integer, Object> resultMap = new HashMap<>();
for (int i = 0; i < stockCodeList.size(); i++) {
--
Gitblit v1.9.3