当前位置: 首页 > news >正文

springboot接口提高查询速度方法

接口想要提高查询速度,需要减少查询数据库的次数,需要把循环里面的查询提出来一次性查询完毕,然后通过java代码来获取响应的值。如下所示:

List<OrderInfoHtVO> orderInfoList = orderInfoService.getOrderInfoHtlist(query);if(CollectionUtils.isNotEmpty(orderInfoList)){List<Integer> orderIdList = orderInfoList.stream().map(OrderInfoHtVO::getOrderId)
.collect(Collectors.toList());List<String> orderNoList = orderInfoList.stream().map(OrderInfoHtVO::getOrderNumber)
.collect(Collectors.toList());List<InvoiceStatusVO> invoiceStatusVOList = applayInvoiceInfoService.
getInvoiceStatusByOrderList(orderIdList,orderNoList,orderInfoList);Map<Integer,List<InvoiceStatusVO>> invoiceStatusVOMap = invoiceStatusVOList.stream().
collect(Collectors.groupingBy(InvoiceStatusVO::getOrderId));List<ApplayInvoiceHongChongCountVO> applayInvoiceHongChongCountVOList = applayInvoiceInfoService
.searchApplayInvoiceHongChongCountListByOrderNoList(orderNoList);Map<String,List<ApplayInvoiceHongChongCountVO>> applayInvoiceHongChongCountVOMap = applayInvoiceHongChongCountVOList.stream()
.collect(Collectors.groupingBy(ApplayInvoiceHongChongCountVO::getOrderNo));List<PackageGoodsCountVO> packageGoodsCountVOList = orderInfoService
.searchPackageGoodsCountListByOrderIdList(orderIdList);Map<Integer,List<PackageGoodsCountVO>> packageGoodsCountVOMap = packageGoodsCountVOList.stream()
.collect(Collectors.groupingBy(PackageGoodsCountVO::getOrderId));for (OrderInfoHtVO orderInfoHtVO : orderInfoList) {if(CollectionUtils.isNotEmpty(invoiceStatusVOMap.get(orderInfoHtVO.getOrderId()))){orderInfoHtVO.setInvoiceStatus(invoiceStatusVOMap.get(orderInfoHtVO.getOrderId()).get(0).getInvoiceStatus());
}else{orderInfoHtVO.setInvoiceStatus(0);
}if(CollectionUtils.isNotEmpty(applayInvoiceHongChongCountVOMap.get(orderInfoHtVO.getOrderNumber()))){orderInfoHtVO.setIsHongChong(applayInvoiceHongChongCountVOMap.get(orderInfoHtVO.getOrderNumber()).get(0).getIsHongChong());
}else{orderInfoHtVO.setIsHongChong(0);
}if(CollectionUtils.isNotEmpty(packageGoodsCountVOMap.get(orderInfoHtVO.getOrderId()))){orderInfoHtVO.setIsPackage(packageGoodsCountVOMap.get(orderInfoHtVO.getOrderId()).get(0).getIsPackage());
}else{orderInfoHtVO.setIsPackage(0);
}}}
http://www.lryc.cn/news/339646.html

相关文章:

  • 如何在苹果手机上安装iOS应用的.ipa文件?
  • IDEA pom.xml显示灰色并被划线
  • 玄子Share-使用 Pycharm 执行 Shell 脚本
  • 如何让Nrf connect、EFR connect直接显示特征值数据及其单位
  • python笔记
  • Java编译期注解处理器AbstractProcessor使用
  • JetBrains相关的IDE有哪些?
  • Git-常规用法-含解决分支版本冲突解决方法
  • 基于springboot实现大型商场应急预案管理系统项目【项目源码+论文说明】
  • 系统学c#:1、基础准备(软件下载与安装)
  • 解决CSS中鼠标移入到某个元素其子元素被遮挡的问题
  • 【华为OD机试】虚拟理财游戏【C卷|100分】
  • ssh 使用
  • Springboot+Vue项目-基于Java+MySQL的母婴商城系统(附源码+演示视频+LW)
  • Android多线程:Handler runOnUiThread 异步消息处理机制
  • AndroidStudio 导出aar包,并使用
  • python与设计模式之工厂模式的那些事儿
  • 什么是区块链?
  • 2022年电赛F题23年电赛D题-信号调制度测量装置说明中提到带通采样定律。
  • Rust面试宝典第2题:逆序输出整数
  • Linux笔记之查看docker容器目录映射
  • ​​​​网络编程探索系列之——广播原理剖析
  • jar包解压和重新打包
  • Python基于Django的微博热搜、微博舆论可视化系统
  • Flink SQL:debezium-json 格式的表一定是数据库的 CDC 数据吗?
  • 基于STM32的RFID智能门锁系统
  • 测试用例的编写评审
  • 二叉树的前、中、后序遍历【c++】
  • Hadoop HDFS:海量数据的存储解决方案
  • Leetcode二十三题:合并K个升序链表【22/1000 python】