| | |
| | | continue; // 股票不存在,跳过 |
| | | } |
| | | |
| | | // 先获取真实涨跌幅数据 |
| | | // 先获取真实数据,用于获取前收盘价和当前价格 |
| | | StockRealTimeBean realTimeStock = RedisKeyUtil.getCacheRealTimeStock(stock); |
| | | if (realTimeStock == null) { |
| | | if (realTimeStock == null || realTimeStock.getPc() == null) { |
| | | continue; // 无法获取真实数据,跳过 |
| | | } |
| | | |
| | | // 获取真实价格(从Redis获取,不经过StockSetting计算) |
| | | String s = RedisKeyUtil.doPost(stock.getStockCode(), stock.getStockType()); |
| | | if (s == null) { |
| | | continue; // 无法获取真实价格,跳过 |
| | | } |
| | | // 获取前收盘价和当前价格(last) |
| | | BigDecimal prevClose = new BigDecimal(realTimeStock.getPc()); |
| | | BigDecimal last = new BigDecimal(realTimeStock.getLast()); |
| | | |
| | | Map<String, Object> stringObjectMap = RedisKeyUtil.jsonToMap(s); |
| | | BigDecimal realPrice = new BigDecimal(stringObjectMap.get("Last").toString()); |
| | | |
| | | // 计算盘前价格 |
| | | // 计算盘前价格(根据StockSetting配置) |
| | | BigDecimal premarketPrice; |
| | | if ("0".equals(setting.getType())) { |
| | | // type=0: 直接指定价格 |
| | | premarketPrice = new BigDecimal(setting.getPrice()); |
| | | } else { |
| | | // type=1: 百分比调价格,基于真实价格计算 |
| | | premarketPrice = realPrice.multiply(new BigDecimal(setting.getPrice())); |
| | | // type=1: 百分比调价格,基于last计算 |
| | | premarketPrice = last.multiply(new BigDecimal(setting.getPrice())); |
| | | } |
| | | |
| | | // 获取前收盘价 |
| | | BigDecimal prevClose = new BigDecimal(realTimeStock.getPc()); |
| | | |
| | | // 基于盘前价格计算涨跌幅 = (盘前价格 - 前收盘价) / 前收盘价 |
| | | // 根据盘前价格计算涨跌幅 = (盘前价格 - 前收盘价) / 前收盘价 |
| | | BigDecimal hcrate = BigDecimal.ZERO; |
| | | if (prevClose.compareTo(BigDecimal.ZERO) > 0) { |
| | | hcrate = premarketPrice.subtract(prevClose) |
| | |
| | | |
| | | PremarketStockVO vo = new PremarketStockVO(); |
| | | vo.setCode(setting.getStockCode()); |
| | | vo.setPrice(premarketPrice); |
| | | vo.setPrice(premarketPrice); // price返回盘前价格 |
| | | vo.setHcrate(hcrate); |
| | | vo.setHcrateP(hcrateP); |
| | | resultList.add(vo); |