| | |
| | | @GetMapping("api/hobi!getRealtime.action") |
| | | public Result<List<Realtime>> getRealtime(@RequestParam String symbol) { |
| | | try { |
| | | if (symbol == null || symbol.isEmpty()){ |
| | | return Result.succeed(); |
| | | } |
| | | List<Realtime> data = this.dataService.realtime(symbol); |
| | | data.forEach(d->{ |
| | | Item bySymbol = itemService.findBySymbol(d.getSymbol()); |
| | |
| | | items.addAll(itemsTop); |
| | | } else if ("US-stocks".equals(type)) { |
| | | // 只查询指数top6 |
| | | items = itemService.cacheGetAll().stream().filter(item -> "global".equals(item.getCategory())).limit(3).collect(Collectors.toList()); |
| | | List<Item> itemsTop = itemService.cacheGetAll().stream().filter(item -> "technology,prominent".equals(item.getCategory())).sorted(Comparator.comparing(Item::getSorted).reversed()).limit(size) |
| | | items = itemService.cacheGetAll().stream().filter(item -> item.getType().equalsIgnoreCase(Item.US_STOCKS)) |
| | | .sorted(Comparator.comparing(Item::getSorted).reversed()) |
| | | .limit(3).collect(Collectors.toList()); |
| | | /*List<Item> itemsTop = itemService.cacheGetAll().stream().filter(item -> "technology,prominent".equals(item.getCategory())).sorted(Comparator.comparing(Item::getSorted).reversed()).limit(size) |
| | | .collect(Collectors.toList()); |
| | | items.addAll(itemsTop); |
| | | items.addAll(itemsTop);*/ |
| | | } |
| | | // 加密货币、外汇、 top4 |
| | | else { |
| | |
| | | @RequestParam(required = false) Integer pageNo, |
| | | @RequestParam(required = false) Integer pageSize) { |
| | | try { |
| | | pageSize = null == pageSize ? 1000 : pageSize; |
| | | pageSize = null == pageSize ? 50 : pageSize; |
| | | List<Item> itemsTotal; |
| | | List<Item> items = new ArrayList<>(); |
| | | //按字符串排序 |
| | | List<Item> itemList = itemService.cacheGetAll().stream().sorted(Comparator.comparing(Item::getSorted).reversed()).collect(Collectors.toList()); |
| | | if (type != null && type.equalsIgnoreCase(Item.US_STOCKS)) { |
| | | category = null; |
| | | } |
| | | //按数字排序 |
| | | // List<Item> itemList = itemService.cacheGetAll().stream().sorted(Comparator.comparing(Item::getSorted, (x,y)->{ |
| | | // int xInt = 0; |
| | |
| | | // })).collect(Collectors.toList()); |
| | | |
| | | if (null != type && null != category) { |
| | | String finalCategory = category; |
| | | // 知名类 需要模糊查询 |
| | | if ("prominent".equals(category)) { |
| | | itemsTotal = new ArrayList<>(itemList).stream().filter(item -> item.getType().equals(type) |
| | | && item.getCategory().contains(category)).collect(Collectors.toList()); |
| | | && item.getCategory().contains(finalCategory)).collect(Collectors.toList()); |
| | | } else { |
| | | itemsTotal = new ArrayList<>(itemList).stream().filter(item -> item.getType().equals(type) |
| | | && item.getCategory().equals(category)).collect(Collectors.toList()); |
| | | && item.getCategory().equals(finalCategory)).collect(Collectors.toList()); |
| | | } |
| | | if (pageNo * pageSize - pageSize < itemsTotal.size()) { |
| | | int pages = itemsTotal.size() % pageSize == 0 ? itemsTotal.size() / pageSize : itemsTotal.size() / pageSize + 1; |
| | |
| | | int pages = itemsTotal.size() % pageSize == 0 ? itemsTotal.size() / pageSize : itemsTotal.size() / pageSize + 1; |
| | | int start = pageNo <= 0 ? 0 : (pageNo > pages ? (pages - 1) * pageSize : (pageNo - 1) * pageSize); |
| | | items = itemsTotal.stream().skip(start).limit(pageSize).collect(Collectors.toList()); |
| | | items.forEach(x -> x.setCategory("prominent")); |
| | | } |
| | | } else { |
| | | itemsTotal = new ArrayList<>(itemList); |