springboot+mongodb 实现按日期分组分页查询功能
程序员文章站
2024-02-18 23:49:22
具体代码如下所示:
walletdetailsresp walletdetailsresp = new walletdetailsresp();
list<...
具体代码如下所示:
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 实现按日期分组分页查询功能,希望对大家有所帮助