| | |
| | | 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; |
| | |
| | | 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; |
| | | import com.nq.service.*; |
| | | import com.nq.utils.http.HttpClientRequest; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.http.HttpRequest; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | | import com.nq.utils.redis.RedisShardedPoolUtils; |
| | | import com.nq.utils.stock.pinyin.GetPyByChinese; |
| | |
| | | import com.nq.vo.stock.k.MinDataVO; |
| | | import com.nq.vo.stock.k.echarts.EchartsDataVO; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import javax.annotation.Resource; |
| | | 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; |
| | |
| | | @Autowired |
| | | SiteNewsMapper siteNewsMapper; |
| | | |
| | | @Autowired |
| | | StockConfigMapper stockConfigMapper; |
| | | |
| | | public ServerResponse getMarket() { |
| | | String market_url = PropertiesUtil.getProperty("sina.market.url"); |
| | |
| | | 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")) { //指数 |
| | |
| | | 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 { |
| | |
| | | * 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", "暂无数据"); |
| | |
| | | EchartsDataVO echartsDataVO = StockApi.assembleEchartsDataVO(minDataVO); |
| | | return ServerResponse.createBySuccess(echartsDataVO); |
| | | } |
| | | @lombok.Data |
| | | @Data |
| | | class kData { |
| | | long t; |
| | | String c; |
| | |
| | | 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"); |
| | | } |
| | |
| | | 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); |
| | |
| | | //新闻列表 |
| | | 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<String> usStockCodeList = Arrays.asList(usCodeList.split(",")); |
| | | List<String> hkStockCodeList = Arrays.asList(hkCodeList.split(",")); |
| | | List<String> inStockCodeList = Arrays.asList(inCodeList.split(",")); |
| | | List<String> twStockCodeList = Arrays.asList(twCodeList.split(",")); |
| | | List<StockConfig> stockConfigList = stockConfigMapper.selectList |
| | | (new LambdaQueryWrapper<StockConfig>() |
| | | .like(StockConfig::getCKey, EConfigKey.INDICES.getCode())); |
| | | |
| | | List<DataStockBean> usDataStockBeans = Lists.newArrayList(); |
| | | List<DataStockBean> hkDataStockBeans = Lists.newArrayList(); |
| | |
| | | Gson gson = new Gson(); |
| | | |
| | | // 统一处理各地区股票数据 |
| | | processStockData(usStockCodeList, EStockType.US.getCode(), usDataStockBeans, gson); |
| | | processStockData(hkStockCodeList, EStockType.HK.getCode(), hkDataStockBeans, gson); |
| | | processStockData(inStockCodeList, EStockType.IN.getCode(), inDataStockBeans, gson); |
| | | processStockData(twStockCodeList, 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<>(); |
| | |
| | | } |
| | | |
| | | // 提取的通用处理方法 |
| | | private void processStockData(List<String> stockCodeList, String stockType, |
| | | List<DataStockBean> targetList, Gson gson) { |
| | | 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); |
| | | EStockType eStockType = EStockType.getEStockTypeByCode(stockType); |
| | | String result = HttpRequest.doGrabGet(eStockType.stockUrl + "indices?key=" + eStockType.getStockKey() + "&country_id=" + eStockType.getContryId()); |
| | | // 把JSON数据解析为List<DataStockBean> |
| | | Type listType = new TypeToken<List<DataStockBean>>(){}.getType(); |
| | | List<DataStockBean> list = new Gson().fromJson(result, listType); |
| | | |
| | | for (String stockCode : stockCodeList) { // 增强for循环简化代码 |
| | | // 获取基础股票数据 |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stockType, stockCode); |
| | | //DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stockType, stockCode); |
| | | DataStockBean cacheBaseStock = list.stream() |
| | | .filter(x -> stockCode.equals(x.getId())) |
| | | .findFirst().orElse(null); |
| | | if (cacheBaseStock == null) { // 增加空指针防护(可选,根据实际业务) |
| | | continue; |
| | | } |
| | |
| | | @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())) { |
| | |
| | | } 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++) { |
| | |
| | | stockType = stock.getStockType(); |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | |
| | | //实时获取数据 |
| | | String s = RedisKeyUtil.doPost(pid, stockType); |
| | | Map<String, Object> stringObjectMap = RedisKeyUtil.jsonToMap(s); |
| | | resultMap.put("id", pid); |