List<Integer> types = new ArrayList<>();  
types.add("条件1");  
types.add("条件2");  
Criteria eatCriteria = Criteria.where("_change_type").in(types).and("_downstream_user_id").is(userId);  
Sort.Order orders = new Sort.Order(Sort.Direction.DESC, "changeDate");  
  
  
Aggregation eatAggregation = Aggregation.newAggregation(  
        //查询条件  
        Aggregation.match(eatCriteria),  
        //查询项  
        Aggregation.project("_change_money","_change_type")  
                   .andExpression("substr(_change_time,0,10)").as("changeDate"),  
        //分组条件和聚合项  
        Aggregation.group("changeDate","_change_type").sum("_change_money").as("changeMoney"),  
        //排序  
        Aggregation.sort(new Sort(orders)),  
        //分页  
        Aggregation.skip(pageIndex > 1 ? (pageIndex - 1) * pageSize : 0L),  
        Aggregation.limit(pageSize));  
  
  
AggregationResults<BasicDBObject> eatOutputType = mongoTemplate.aggregate(eatAggregation, "inner_cash_change", BasicDBObject.class);  
for (DBObject obj : eatOutputType) {  
    WalletDetailsResp.WalletDetail walletDetail = new WalletDetailsResp.WalletDetail();  
    walletDetail.setChangeType(Integer.parseInt(obj.get("_change_type").toString()));  
    walletDetail.setChangeMoney(new BigDecimal(obj.get("changeMoney").toString()).divide(QRType.YUAN_TO_FEN));  
    walletDetail.setChangeDate(obj.get("changeDate").toString());  
    list.add(walletDetail);  
}  
walletDetailsResp.setWalletDetails(list);  
pageInfoBean.setPageIndex(pageIndex);  
pageInfoBean.setPageSize(pageSize);  
//pageInfoBean.setRecordTotal();  //总页数需要单独count出来
walletDetailsResp.setPageInfo(pageInfoBean);

 

相关文章:

  • 2022-12-23
  • 2021-11-30
  • 2022-01-25
  • 2021-12-29
  • 2022-12-23
  • 2021-09-09
  • 2022-01-07
猜你喜欢
  • 2021-04-11
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2021-04-11
  • 2021-09-01
相关资源
相似解决方案