//
1.分组查询
Aggregation agg=Aggregation
.newAggregation(
Aggregation
.match(Criteria
.where(
"tenantId")
.is(TenantUtils
.getTenantId())
.and(
"ancestor._id")
.is(id)
.and(
"vmallOnShelf")
.is(true)),
Aggregation
.group(
"goodsId")
.push(Aggregation
.ROOT)
.as(
"goodsList")
.first(
"vmallPrice")
.as(
"vmallPrice"),
Aggregation
.sort(direction,
"vmallPrice"),
Aggregation
.skip(m),
Aggregation
.limit(n)
)
List<GoodsSKU> list = mongoTemplate
.aggregate(agg,
"goods", GoodsSKU
.class)
.getMappedResults()
return list
.stream()
.map(GoodsSKU::getFirstGoods)
.collect(Collectors
.toList())