From 41796774dc3794f04d4f327286bd442c158bd377 Mon Sep 17 00:00:00 2001 From: misworga831 Date: Mon, 17 Apr 2023 15:37:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E8=B6=B3=E8=BF=B9?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/FootprintServiceImpl.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java b/framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java index b97f97f4..b9239f6e 100644 --- a/framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/member/serviceimpl/FootprintServiceImpl.java @@ -18,8 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * 会员浏览历史业务层实现 @@ -80,11 +84,19 @@ public class FootprintServiceImpl extends ServiceImpl skuIds = footPrintPages.getRecords().stream().map(FootPrint::getSkuId).collect(Collectors.toList()); List goodsSkuByIdFromCache = goodsSkuService.getGoodsSkuByIdFromCache(skuIds); + List collect = IntStream.range(0, goodsSkuByIdFromCache.size()) + .mapToObj(i -> { + if (goodsSkuByIdFromCache.get(i) == null) { + EsGoodsIndex esGoodsIndex = new EsGoodsIndex(); + esGoodsIndex.setReleaseTime(footPrintPages.getRecords().get(i).getCreateTime().getTime()); + return esGoodsIndex; + } + Optional first = footPrintPages.getRecords().stream().filter(j -> j.getSkuId().equals(goodsSkuByIdFromCache.get(i).getId())).findFirst(); + return first.map(footPrint -> new EsGoodsIndex(goodsSkuByIdFromCache.get(i), footPrint.getCreateTime())).orElseGet(() -> new EsGoodsIndex(goodsSkuByIdFromCache.get(i))); + }) + .collect(Collectors.toList()); esGoodsIndexIPage.setPages(footPrintPages.getPages()); - esGoodsIndexIPage.setRecords(goodsSkuByIdFromCache.stream().map(i -> { - Optional first = footPrintPages.getRecords().stream().filter(j -> j.getSkuId().equals(i.getId())).findFirst(); - return first.map(footPrint -> new EsGoodsIndex(i, footPrint.getCreateTime())).orElseGet(() -> new EsGoodsIndex(i)); - }).sorted(Comparator.comparingLong(EsGoodsIndex::getReleaseTime).reversed()).collect(Collectors.toList())); + esGoodsIndexIPage.setRecords(collect); esGoodsIndexIPage.setTotal(footPrintPages.getTotal()); esGoodsIndexIPage.setSize(footPrintPages.getSize()); esGoodsIndexIPage.setCurrent(footPrintPages.getCurrent());