springboot+mongodb 實現(xiàn)按日期分組分頁查詢功能
更新時間:2018年07月13日 10:52:56 作者:0劍小破
這篇文章主要介紹了springboot+mongodb 實現(xiàn)按日期分組分頁查詢功能,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
具體代碼如下所示:
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);
總結(jié)
以上所述是小編給大家介紹的springboot+mongodb 實現(xiàn)按日期分組分頁查詢功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
劍指Offer之Java算法習(xí)題精講鏈表與二叉樹專項訓(xùn)練
跟著思路走,之后從簡單題入手,反復(fù)去看,做過之后可能會忘記,之后再做一次,記不住就反復(fù)做,反復(fù)尋求思路和規(guī)律,慢慢積累就會發(fā)現(xiàn)質(zhì)的變化2022-03-03Java調(diào)用SSE流式接口并流式返回給前端實現(xiàn)打字輸出效果
在Web開發(fā)中,有時我們需要將文件以流的形式返回給前端,下面這篇文章主要給大家介紹了關(guān)于Java調(diào)用SSE流式接口并流式返回給前端實現(xiàn)打字輸出效果的相關(guān)資料,需要的朋友可以參考下2024-08-08Mybatis之collection標(biāo)簽中javaType和ofType屬性的區(qū)別說明
這篇文章主要介紹了Mybatis之collection標(biāo)簽中javaType和ofType屬性的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12