public ProdDailyPrice queryProdDailyPrice(String code, int month) { Futures prod = productBuss.queryFuturesByCode(code); if (prod == null) { return null; } else { List<KLine> kLineList = null; List<ProdIndex> indexList = null; if (month < 0) { // 所有 kLineList = kLineRepos.findByCodeOrderByDtAsc(code); indexList = prodIndexRepos.findByCodeOrderByDtAsc(code); } else { // 指定月数 Calendar cal = Calendar.getInstance(); Date endDt = cal.getTime(); cal.add(Calendar.MONTH, -month); Date startDt = cal.getTime(); kLineList = kLineRepos.findByCodeAndDtBetweenOrderByDtAsc(code, startDt, endDt); indexList = prodIndexRepos.findByCodeAndDtBetweenOrderByDtAsc(code, startDt, endDt); } List<Price> mainPriceList = kLineList .stream() .map( kLine -> { return new Price(kLine.getDt(), kLine.getEndPrice()); }) .collect(Collectors.toList()); List<Price> indexPriceList = indexList .stream() .map( index -> { return new Price(index.getDt(), index.getPrice()); }) .collect(Collectors.toList()); return new ProdDailyPrice(prod.getCode(), prod.getName(), mainPriceList, indexPriceList); } }
@Cacheable(value = "KLineBuss.queryAscByCode") public List<KLine> queryAscByCode(String code) { return Collections.unmodifiableList(kLineRepos.findByCodeOrderByDtAsc(code)); }