当前位置: 移动技术网 > IT编程>开发语言>Java > springboot+mongodb 实现按日期分组分页查询功能

springboot+mongodb 实现按日期分组分页查询功能

2019年07月19日  | 移动技术网IT编程  | 我要评论

具体代码如下所示:

walletdetailsresp walletdetailsresp = new walletdetailsresp();
list<walletdetailsresp.walletdetail> list = new arraylist<>();
walletdetailsresp.pageinfobean pageinfobean = new walletdetailsresp.pageinfobean();
list<integer> types = new arraylist<>();
types.add(innercashtype.finisher_add_cutmoney.getcode());
types.add(innercashtype.finisher_add_reward.getcode());
types.add(innercashtype.finisher_sub_withdraw.getcode());
types.add(innercashtype.finisher_add_withdraw.getcode());
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(eatoutputtype.getmappedresults().size());
walletdetailsresp.setpageinfo(pageinfobean);

总结

以上所述是小编给大家介绍的springboot+mongodb 实现按日期分组分页查询功能,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网