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

}

}

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-22 20:40:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-22 20:40:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-22 20:40:03       82 阅读
  4. Python语言-面向对象

    2024-04-22 20:40:03       91 阅读

热门阅读

  1. 分治法构建Gray码问题

    2024-04-22 20:40:03       34 阅读
  2. 深入理解与运用Vue 2中的插槽(Slots)

    2024-04-22 20:40:03       35 阅读
  3. 测试testing1

    2024-04-22 20:40:03       29 阅读
  4. Mysql多表联查使用聚合函数常见问题

    2024-04-22 20:40:03       30 阅读
  5. 第七周笔记

    2024-04-22 20:40:03       30 阅读
  6. MySQL运维故障排查与高效解决方案

    2024-04-22 20:40:03       36 阅读
  7. 机器学习笔记 - torch.hub 和 torchvision.models 的区别

    2024-04-22 20:40:03       32 阅读
  8. MySQL运维故障解决方案:实战案例与深度解析

    2024-04-22 20:40:03       32 阅读
  9. JWT原理

    JWT原理

    2024-04-22 20:40:03      37 阅读
  10. Docker - 网络

    2024-04-22 20:40:03       32 阅读
  11. MySQL无法远程连接方案解决(示例)

    2024-04-22 20:40:03       38 阅读
  12. 卸载jenkins和docker

    2024-04-22 20:40:03       35 阅读
  13. 算法=问题的解决方法

    2024-04-22 20:40:03       38 阅读
  14. Unity中Socket,Tcp,Udp网络连接协议总结

    2024-04-22 20:40:03       29 阅读
  15. 浅谈薪酬绩效设计及运行的忌讳

    2024-04-22 20:40:03       38 阅读
  16. ubuntu用户与用户组管理

    2024-04-22 20:40:03       37 阅读