!279 fix: 优化足迹搜索

Merge pull request !279 from OceansDeep/pg
This commit is contained in:
OceansDeep 2023-04-17 07:38:52 +00:00 committed by Gitee
commit 05c3c8a80c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -18,8 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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.Collectors;
import java.util.stream.IntStream;
/** /**
* 会员浏览历史业务层实现 * 会员浏览历史业务层实现
@ -80,11 +84,19 @@ public class FootprintServiceImpl extends ServiceImpl<FootprintMapper, FootPrint
if (footPrintPages.getRecords() != null && !footPrintPages.getRecords().isEmpty()) { if (footPrintPages.getRecords() != null && !footPrintPages.getRecords().isEmpty()) {
List<String> skuIds = footPrintPages.getRecords().stream().map(FootPrint::getSkuId).collect(Collectors.toList()); List<String> skuIds = footPrintPages.getRecords().stream().map(FootPrint::getSkuId).collect(Collectors.toList());
List<GoodsSku> goodsSkuByIdFromCache = goodsSkuService.getGoodsSkuByIdFromCache(skuIds); List<GoodsSku> goodsSkuByIdFromCache = goodsSkuService.getGoodsSkuByIdFromCache(skuIds);
List<EsGoodsIndex> 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<FootPrint> 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.setPages(footPrintPages.getPages());
esGoodsIndexIPage.setRecords(goodsSkuByIdFromCache.stream().map(i -> { esGoodsIndexIPage.setRecords(collect);
Optional<FootPrint> 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.setTotal(footPrintPages.getTotal()); esGoodsIndexIPage.setTotal(footPrintPages.getTotal());
esGoodsIndexIPage.setSize(footPrintPages.getSize()); esGoodsIndexIPage.setSize(footPrintPages.getSize());
esGoodsIndexIPage.setCurrent(footPrintPages.getCurrent()); esGoodsIndexIPage.setCurrent(footPrintPages.getCurrent());