| | |
| | | package com.nq.service.impl; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | |
| | | import com.google.common.collect.Lists; |
| | | import com.google.common.collect.Maps; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.config.StockPoll; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.pojo.*; |
| | |
| | | import com.nq.utils.stock.pinyin.GetPyByChinese; |
| | | import com.nq.utils.stock.qq.QqStockApi; |
| | | import com.nq.utils.stock.sina.StockApi; |
| | | import com.nq.utils.translate.GoogleTranslateUtil; |
| | | import com.nq.vo.stock.*; |
| | | import com.nq.vo.stock.k.MinDataVO; |
| | | import com.nq.vo.stock.k.echarts.EchartsDataVO; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.math.BigDecimal; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import lombok.Data; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | @Autowired |
| | | StockMapper stockMapper; |
| | | |
| | | @Resource |
| | | RealTimeMapper realTimeMapper; |
| | | |
| | | @Autowired |
| | | IStockMarketsDayService iStockMarketsDayService; |
| | | |
| | | @Autowired |
| | | StockPoll stockPoll; |
| | | |
| | | @Resource |
| | | StockFuturesMapper stockFuturesMapper; |
| | |
| | | IUserService iUserService; |
| | | |
| | | @Autowired |
| | | IStockOptionService iStockOptionService; |
| | | @Autowired |
| | | ISiteSettingService iSiteSettingService; |
| | | |
| | | |
| | | @Autowired |
| | | InStockMapper inStockMapper; |
| | | |
| | | @Resource |
| | | StockDzMapper stockDzMapper; |
| | | |
| | | |
| | | @Autowired |
| | | IPriceServices iPriceServices; |
| | | |
| | | @Autowired |
| | | SiteNewsMapper siteNewsMapper; |
| | | |
| | | |
| | | public ServerResponse getMarket() { |
| | |
| | | List<Stock> stockList = new ArrayList<>(); |
| | | if (stockType.equals("99")) { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | stockList.addAll(stockMapper.findZtStockListByKeyWords(keyWords, stockPlate, "IN", Integer.valueOf(0))); |
| | | stockList.addAll(stockMapper.findZtStockListByKeyWords(keyWords, stockPlate, "MEX", Integer.valueOf(0))); |
| | | } else if (stockType.equals("100")) { |
| | | User user = iUserService.getCurrentRefreshUser(request); |
| | | if (user == null) { |
| | |
| | | |
| | | @Override |
| | | public ServerResponse getStockByType(int pageNum, int pageSize, String orderBy, String keyWords, String stockType, HttpServletRequest request) { |
| | | List<Stock> stockList = new ArrayList<>(); |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | stockList.addAll(stockMapper.findStockByType(orderBy,stockType,keyWords)); |
| | | List<Stock> stockList = stockMapper.findStockByType(orderBy, stockType, keyWords); |
| | | // 获取分页信息 |
| | | PageInfo<Stock> pageInfo = new PageInfo<>(stockList); |
| | | |
| | | List<StockListVO> stockListVOS = Lists.newArrayList(); |
| | | if (stockList.size() > 0){ |
| | | if (stockList.size() > 0) { |
| | | stockListVOS.addAll(Objects.requireNonNull(StockApi.getStockReailTimes(stockList))); |
| | | } |
| | | |
| | | // Create a list to hold Futures |
| | | List<CompletableFuture<Void>> futures = new ArrayList<>(); |
| | | |
| | | // Use CompletableFuture to perform asynchronous processing for each stockListVO |
| | | // for (StockListVO stockListVO : stockListVOS) { |
| | | // CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { |
| | | // stockListVO.setNowPrice(iPriceServices.getNowPrice(stockListVO.getCode(), stockType).toString()); |
| | | // Map<String, Object> newStock = iPriceServices.getNewStock(stockListVO.getCode()); |
| | | // stockListVO.setHcrateP(newStock.get("pcp").toString()); |
| | | // }); |
| | | // futures.add(future); |
| | | // } |
| | | // |
| | | // // Wait for all futures to complete |
| | | // CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); |
| | | |
| | | RPageInfo pageInfo = new RPageInfo(); |
| | | pageInfo.setList(stockListVOS); |
| | | pageInfo.setStockType(stockType); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | RPageInfo resultPageInfo = new RPageInfo(); |
| | | resultPageInfo.setList(stockListVOS); |
| | | resultPageInfo.setStockType(stockType); |
| | | // 设置分页信息 |
| | | resultPageInfo.setTotal(pageInfo.getTotal()); |
| | | resultPageInfo.setPageNum(pageInfo.getPageNum()); |
| | | resultPageInfo.setPageSize(pageInfo.getPageSize()); |
| | | resultPageInfo.setPages(pageInfo.getPages()); |
| | | resultPageInfo.setHasNextPage(pageInfo.isHasNextPage()); |
| | | return ServerResponse.createBySuccess(resultPageInfo); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (StringUtils.isBlank(code)) |
| | | return ServerResponse.createByErrorMsg(""); |
| | | Stock stock = stockMapper.findStockByCode(code); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stock); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stock.getStockType(), stock.getStockCode()); |
| | | Integer depositAmt = 0; |
| | | String introduction = null; |
| | | StockVO stockVO = StockApi.assembleInStockVO(stock); |
| | |
| | | stockVO.setSpell(stock.getStockSpell()); |
| | | stockVO.setGid(stock.getStockGid().toUpperCase()); |
| | | Map<String, Object> newStock = iPriceServices.getNewStock(stock.getStockCode()); |
| | | stockVO.setHcrate(newStock.get("pcp").toString().replaceAll("%", "")); |
| | | stockVO.setToday_max(newStock.get("high").toString()); |
| | | stockVO.setToday_min(newStock.get("low").toString()); |
| | | stockVO.setHcrate(newStock.get("ChgPct").toString().replaceAll("%", "")); |
| | | stockVO.setToday_max(newStock.get("High").toString()); |
| | | stockVO.setToday_min(newStock.get("Low").toString()); |
| | | if(null != cacheBaseStock){ |
| | | stockVO.setOpen_px(cacheBaseStock.getOpen()); |
| | | stockVO.setPreclose_px(cacheBaseStock.getPrevClose()); |
| | |
| | | if (StringUtils.isBlank(code)) |
| | | return null; |
| | | Stock stock = stockMapper.findStockByCode(code); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stock); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stock.getStockType(), stock.getStockCode()); |
| | | Integer depositAmt = 0; |
| | | String introduction = null; |
| | | StockVO stockVO = StockApi.assembleInStockVO(stock); |
| | |
| | | @Override |
| | | public Object getKData(String pid, String interval, String stockType) { |
| | | EStockType eStockType = EStockType.getEStockTypeByCode(stockType); |
| | | if(eStockType == EStockType.IN){ |
| | | Object object = HttpUtil.get(eStockType.stockUrl + "api/all/getKData.do?pid=" + pid + "&interval=" + interval + "&stockType=in"); |
| | | Gson gson = new Gson(); |
| | | List<kData> dataList = gson.fromJson(object.toString(), new TypeToken<List<kData>>(){}.getType()); |
| | | Object object = HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey); |
| | | Gson gson = new Gson(); |
| | | List<kData> dataList = gson.fromJson(object.toString(), new TypeToken<List<kData>>(){}.getType()); |
| | | |
| | | Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, pid).eq(Stock::getStockType, "IN")); |
| | | BigDecimal nowPrice = iPriceServices.getNowPrice(stock.getStockCode()); |
| | | Map singleStock = getSingleStock(stock.getStockCode()); |
| | | StockVO stockVO = (StockVO)singleStock.get("stock"); |
| | | // 修改 List 中的最后一条数据 |
| | | kData lastData = dataList.get(dataList.size() - 1); |
| | | lastData.setC(nowPrice.toString()); |
| | | lastData.setO(stockVO.getOpen_px()); |
| | | lastData.setH(stockVO.getToday_max()); |
| | | lastData.setL(stockVO.getToday_min()); |
| | | return gson.toJson(dataList); |
| | | |
| | | } |
| | | return HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey); |
| | | Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, pid).eq(Stock::getStockType, stockType)); |
| | | BigDecimal nowPrice = iPriceServices.getNowPrice(stock.getStockCode()); |
| | | Map singleStock = getSingleStock(stock.getStockCode()); |
| | | StockVO stockVO = (StockVO)singleStock.get("stock"); |
| | | // 修改 List 中的最后一条数据 |
| | | kData lastData = dataList.get(dataList.size() - 1); |
| | | lastData.setC(nowPrice.toString()); |
| | | lastData.setO(stockVO.getOpen_px()); |
| | | lastData.setH(stockVO.getToday_max()); |
| | | lastData.setL(stockVO.getToday_min()); |
| | | return gson.toJson(dataList); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | return ServerResponse.createBySuccess(pool); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse getIndicesIndexListAndNews(Integer pageSize) { |
| | | try { |
| | | //新闻列表 |
| | | List<SiteNews> newsList = this.siteNewsMapper.getTopNewsList(pageSize); |
| | | |
| | | String usCodeList = PropertiesUtil.getProperty("us_home_indices_code"); |
| | | String mxCodeList = PropertiesUtil.getProperty("mx_home_indices_code"); |
| | | List<String> usStockCodeList = Arrays.asList(usCodeList.split(",")); |
| | | List<String> mxStockCodeList = Arrays.asList(mxCodeList.split(",")); |
| | | List<DataStockBean> usDataStockBeans = Lists.newArrayList(); |
| | | List<DataStockBean> mxDataStockBeans = Lists.newArrayList(); |
| | | for (int i = 0; i < usStockCodeList.size(); i++) { |
| | | String stockCode = usStockCodeList.get(i); |
| | | String stockType = EStockType.US.getCode(); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stockType, stockCode); |
| | | // 获取K线数据 |
| | | Object kData = RedisKeyUtil.getCaCheStockKData(stockType, stockCode); |
| | | if (kData == null) { |
| | | //重新获取并缓存redis |
| | | kData = getKData(stockCode, "D", stockType); |
| | | RedisKeyUtil.setCaCheStockKData(stockType, stockCode, kData); |
| | | } |
| | | Gson gson = new Gson(); |
| | | List<kData> dataList = gson.fromJson(kData.toString(), new TypeToken<List<kData>>(){}.getType()); |
| | | cacheBaseStock.setKData(dataList); |
| | | cacheBaseStock.setStockType(stockType); |
| | | usDataStockBeans.add(cacheBaseStock); |
| | | } |
| | | for (int i = 0; i < mxStockCodeList.size(); i++) { |
| | | String stockCode = mxStockCodeList.get(i); |
| | | String stockType = EStockType.MX.getCode(); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stockType, stockCode); |
| | | // 获取K线数据 |
| | | Object kData = RedisKeyUtil.getCaCheStockKData(stockType, stockCode); |
| | | if (kData == null) { |
| | | //重新获取并缓存redis |
| | | kData = getKData(stockCode, "D", stockType); |
| | | RedisKeyUtil.setCaCheStockKData(stockType, stockCode, kData); |
| | | } |
| | | Gson gson = new Gson(); |
| | | List<kData> dataList = gson.fromJson(kData.toString(), new TypeToken<List<kData>>(){}.getType()); |
| | | cacheBaseStock.setKData(dataList); |
| | | cacheBaseStock.setStockType(stockType); |
| | | mxDataStockBeans.add(cacheBaseStock); |
| | | } |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | resultMap.put("newsList", newsList); //新闻列表 |
| | | resultMap.put("usDataStockBeans", usDataStockBeans);//美国指数 |
| | | resultMap.put("mxDataStockBeans", mxDataStockBeans);//墨西哥指数 |
| | | return ServerResponse.createBySuccess(resultMap); |
| | | } catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse getIndicesList(String stockType) { |
| | | try { |
| | | String codeList; |
| | | if(stockType.equals(EStockType.MX.getCode()) || stockType.equals("MX")) { |
| | | codeList = PropertiesUtil.getProperty("mx_home_indices_code"); |
| | | } else { |
| | | codeList = PropertiesUtil.getProperty("us_home_indices_code"); |
| | | } |
| | | List<String> stockCodeList = Arrays.asList(codeList.split(",")); |
| | | |
| | | Map<Integer, Object> resultMap = new HashMap<>(); |
| | | for (int i = 0; i < stockCodeList.size(); i++) { |
| | | String stockCode = stockCodeList.get(i); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stockType, stockCode); |
| | | Map<String, Object> stockInfo = new HashMap<>(); |
| | | stockInfo.put("pid", cacheBaseStock.getId()); |
| | | stockInfo.put("name", cacheBaseStock.getName()); |
| | | stockInfo.put("stockType", stockType); |
| | | resultMap.put(i+1, stockInfo); |
| | | } |
| | | return ServerResponse.createBySuccess(resultMap); |
| | | } catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse getIndicesAndKData(String pid, String stockType) { |
| | | try { |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", pid)); |
| | | if (stock == null) { |
| | | return ServerResponse.createByErrorMsg("无股票信息"); |
| | | } |
| | | stockType = stock.getStockType(); |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stockType, pid); |
| | | if (cacheBaseStock != null) { |
| | | resultMap.put("id", cacheBaseStock.getId()); |
| | | resultMap.put("stockType", stockType); |
| | | resultMap.put("name", cacheBaseStock.getName()); |
| | | resultMap.put("last", cacheBaseStock.getLast()); |
| | | resultMap.put("chg", cacheBaseStock.getChg()); |
| | | resultMap.put("chgPct", cacheBaseStock.getChgPct()); |
| | | resultMap.put("kData", cacheBaseStock.getChg()); |
| | | // 获取K线数据 |
| | | Object kData = RedisKeyUtil.getCaCheStockKData(stockType, pid); |
| | | if (kData == null) { |
| | | //重新获取并缓存redis |
| | | kData = getKData(pid, "D", stockType); |
| | | RedisKeyUtil.setCaCheStockKData(stockType, pid, kData); |
| | | } |
| | | Gson gson = new Gson(); |
| | | List<kData> dataList = gson.fromJson(kData.toString(), new TypeToken<List<kData>>(){}.getType()); |
| | | resultMap.put("kData", dataList); |
| | | return ServerResponse.createBySuccess(resultMap); |
| | | } |
| | | } catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | } |