接口想要提高查询速度,需要减少查询数据库的次数,需要把循环里面的查询提出来一次性查询完毕,然后通过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);
}}}