| | |
| | | import com.nq.pojo.*; |
| | | import com.nq.pojo.reponse.RPageInfo; |
| | | import com.nq.service.*; |
| | | import com.nq.utils.ConverterUtil; |
| | | import com.nq.utils.http.HttpClientRequest; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | |
| | | 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); |
| | | Stock stock = new Stock(); |
| | | stock.setStockType(stockListVO.getStock_type()); |
| | | stock.setStockCode(stockListVO.getCode()); |
| | | StockRealTimeBean cacheRealTimeStock = RedisKeyUtil.getCacheRealTimeStock(stock); |
| | | stockListVO.setNowPrice(cacheRealTimeStock.getLast()); |
| | | stockListVO.setHcrateP(cacheRealTimeStock.getPcp()); |
| | | } |
| | | |
| | | // Wait for all futures to complete |
| | | CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); |
| | | |
| | | RPageInfo pageInfo = new RPageInfo(); |
| | | pageInfo.setList(stockListVOS); |