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

时间:2021-09-28 15:47:43

具体代码如下所示:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 实现按日期分组分页查询功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:https://blog.csdn.net/kljxp/article/details/81027719