| | |
| | | long total = mongoTemplate.count(query, VideoOnlineResult.class); |
| | | query.with(Sort.by(Sort.Order.asc(TIME_FIELD))).skip(params.getSkipNum()).limit(Math.toIntExact(params.getPageSize())); |
| | | List<VideoOnlineResult> resultList = mongoTemplate.find(query, VideoOnlineResult.class); |
| | | long count = mongoTemplate.count(new Query(), VideoOnlineResult.class); |
| | | |
| | | // 统计 |
| | | Criteria criteriaCount = new Criteria(); |
| | | // 普通查询 |
| | | if (Objects.nonNull(params.getStartTime()) && Objects.nonNull(params.getEndTime())) { |
| | | criteriaCount.andOperator( |
| | | Criteria.where(TIME_FIELD).gte(params.getStartTime()).lte(params.getEndTime()) |
| | | ); |
| | | } |
| | | Query countQuery = new Query(); |
| | | countQuery.addCriteria(criteriaCount); |
| | | long count = mongoTemplate.count(countQuery, VideoOnlineResult.class); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("total", count); |
| | | map.put("count", Arrays.asList(count)); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |