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);

springboot+mongodb 按日期分组分页查询的更多相关文章

  1. SpringBoot-07:SpringBoot整合PageHelper做多条件分页查询

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客讲述如何在SpringBoot中整合PageHelper,如何实现带多个条件,以及PageInfo中的 ...

  2. 【MySQL】条件查询之排序聚合分组分页查询

    排序查询 语法:order by 子句 order by 排序字段1 排序方式1 , 排序字段2 排序方式2... 排序方式: ASC:升序,默认的. DESC:降序. 注意: 如果有多个排序条件,则 ...

  3. SpringBoot整合PageHelper做多条件分页查询

    https://yq.aliyun.com/articles/619586 本篇博客讲述如何在SpringBoot中整合PageHelper,如何实现带多个条件,以及PageInfo中的属性的中文解释 ...

  4. springboot+thymeleaf+pageHelper带条件分页查询

    html层 <div> <a class="num"><b th:text="'共 '+ ${result.resultMap['pages ...

  5. mongodb按照日期分组统计

    目录 1.使用时间格式化方法 2.进行时间补偿(默认当前时区是东八区,即8x3600x1000=28800000) mongodb的默认时间是格林尼治时间,如果是要按照日期进行分组需要注意!!!. 解 ...

  6. MongoDB动态条件之分页查询

    一.使用QueryByExampleExecutor 1. 继承MongoRepository public interface StudentRepository extends MongoRepo ...

  7. SpringBoot Jpa 分页查询最新配置方式

    这是已经被废弃的接口 Sort sort = new Sort(Sort.Direction.DESC,"bean类中字段"); //创建时间降序排序 Pageable pagea ...

  8. spring-boot 集合mybatis 的分页查询

    spring-boot 集合mybatis 的github分页查询 一.依赖包 <!-- mysql 数据库驱动. --> <dependency> <groupId&g ...

  9. springboot结合mybatis使用pageHelper插件进行分页查询

    1.pom相关依赖引入 <dependencies> <dependency> <groupId>org.springframework.boot</grou ...

随机推荐

  1. delphi资源文件制作及使用详解

    一.引子:现在的Windows应用程序几乎都使用图标.图片.光标.声音等,我们称它们为资源(Resource).最简单的使用资源的办法是把这些资源的源文件打入软件包,以方便程序需要的时候调用.资源是程 ...

  2. 使用Visual Studio Code创建第一个ASP.NET Core应用程序

    全文翻译自:Your First ASP.NET Core Application on a Mac Using Visual Studio Code 这篇文章将向你展示如何在Mac上写出你的第一个A ...

  3. ObjectForScripting 注册

                c#和javascript函数的相互调用(ObjectForScripting 的类必须对 COM 可见.请确认该对象是公共的,或考虑向您的类添加 ComVisible 属性. ...

  4. DNS之主服务器正向区域部署流程

    正向区域:将域名解析为IP 搭建步骤 1)定义区域 2)编写区域解析库文件 3)添加记录 环境介绍 [root@dns ~]# cat /etc/centos-releaseCentOS releas ...

  5. zabbix-3.2.6安装部署

    一.准备一台虚拟机并安装centos7.x版本系统 二.配置zabbix_server 1.http install: #安装各类软件支持库 yum install apr-devel apr-uti ...

  6. kubernetes实战篇之dashboard搭建

    系列目录 kubernetes dashboard是kubernetes官方提供的web管理界面,通过dashboard可以很方便地查看集群的各种资源.以及修改资源编排文件,对集群进行扩容操作,查看日 ...

  7. 关于vue项目中在js中引入图片问题

    <template> <div> <img v-for="(star,index) in stars" :src="star.src&quo ...

  8. Spring Batch 入门级示例教程

    Spring Batch 入门级示例教程 我将向您展示如何使用Spring Boot创建一个的Spring Batch的Hello World示例. (循序渐进) 因此,如果您是Spring Batc ...

  9. Zookeeper_ACL

    getAcl path 查看某个node的权限 设置权限1 world方式 setAcl <path> world:anyone:<acl>例如 setAcl /node1 w ...

  10. 设计模式之策略模式和状态模式(strategy pattern & state pattern)

    本文来讲解一下两个结构比较相似的行为设计模式:策略模式和状态模式.两者单独的理解和学习都是比较直观简单的,但是实际使用的时候却并不好实践,算是易学难用的设计模式吧.这也是把两者放在一起介绍的原因,经过 ...