master:商城档口首页返回数据调优;
parent
5383930cc5
commit
16e073741e
|
|
@ -20,7 +20,7 @@ public class StoreHomeTemplateFiveResVO {
|
|||
@ApiModelProperty(value = "顶部右侧商品")
|
||||
List<StoreHomeTemplateItemResVO> topRightList;
|
||||
@ApiModelProperty(value = "右侧店铺公告")
|
||||
String notice;
|
||||
SHTFNoticeVO notice;
|
||||
@ApiModelProperty(value = "店家推荐")
|
||||
List<StoreHomeTemplateItemResVO> recommendList;
|
||||
@ApiModelProperty(value = "销量排行")
|
||||
|
|
@ -38,4 +38,13 @@ public class StoreHomeTemplateFiveResVO {
|
|||
private Integer orderNum;
|
||||
}
|
||||
|
||||
@Data
|
||||
@ApiModel
|
||||
public static class SHTFNoticeVO {
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String noticeTitle;
|
||||
@ApiModelProperty(value = "内容")
|
||||
private String noticeContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,19 @@ public class StoreHomeTemplateFiveResDTO {
|
|||
@ApiModelProperty(value = "顶部右侧商品")
|
||||
List<StoreHomeTemplateItemResDTO> topRightList;
|
||||
@ApiModelProperty(value = "右侧店铺公告")
|
||||
String notice;
|
||||
SHTFNoticeDTO notice;
|
||||
@ApiModelProperty(value = "店家推荐")
|
||||
List<StoreHomeTemplateItemResDTO> recommendList;
|
||||
@ApiModelProperty(value = "销量排行")
|
||||
List<StoreHomeTemplateItemResDTO> saleRankList;
|
||||
|
||||
@Data
|
||||
@ApiModel
|
||||
public static class SHTFNoticeDTO {
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String noticeTitle;
|
||||
@ApiModelProperty(value = "内容")
|
||||
private String noticeContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -727,26 +727,97 @@ public class StoreHomepageServiceImpl implements IStoreHomepageService {
|
|||
Notice storeNotice = storeNoticeList.stream()
|
||||
.filter(x -> Objects.equals(x.getPerpetuity(), 2) || (x.getEffectStart().before(now) && x.getEffectEnd().after(now)))
|
||||
.findFirst().orElse(null);
|
||||
// templateFive.setNotice(BeanUtil.toBean(storeNotice, StoreHomeTemplateTwoResDTO.SHTTNoticeDTO.class));
|
||||
templateFive.setNotice(BeanUtil.toBean(storeNotice, StoreHomeTemplateFiveResDTO.SHTFNoticeDTO.class));
|
||||
}
|
||||
|
||||
|
||||
// 其他区域
|
||||
List<StoreHomepage> otherList = this.storeHomeMapper.selectList(new LambdaQueryWrapper<StoreHomepage>()
|
||||
.eq(StoreHomepage::getStoreId, storeId).eq(StoreHomepage::getDelFlag, Constants.UNDELETED)
|
||||
.in(StoreHomepage::getFileType, Arrays.asList(HomepageType.POPULAR_SALES.getValue(),
|
||||
HomepageType.SLIDING_PICTURE_SMALL.getValue(), HomepageType.SEASON_NEW_PRODUCTS.getValue(),
|
||||
HomepageType.STORE_RECOMMENDED.getValue(), HomepageType.SALES_RANKING.getValue())));
|
||||
if (CollectionUtils.isEmpty(otherList)) {
|
||||
// 商品ID列表
|
||||
List<Long> prodIdList = CollectionUtils.isEmpty(otherList) ? new ArrayList<>() : otherList.stream().map(StoreHomepage::getBizId).collect(Collectors.toList());
|
||||
// 筛选商品最新的50条数据
|
||||
List<StoreProduct> latest50ProdList = this.storeProdMapper.selectList(new LambdaQueryWrapper<StoreProduct>()
|
||||
.eq(StoreProduct::getStoreId, storeId).eq(StoreProduct::getDelFlag, Constants.UNDELETED)
|
||||
.orderByDesc(StoreProduct::getCreateTime).last("LIMIT 50"));
|
||||
CollectionUtils.addAll(prodIdList, latest50ProdList.stream().map(StoreProduct::getId).collect(Collectors.toList()));
|
||||
if (CollectionUtils.isEmpty(latest50ProdList)) {
|
||||
return templateFive;
|
||||
}
|
||||
final List<Long> storeProdIdList = otherList.stream().map(StoreHomepage::getBizId).collect(Collectors.toList());
|
||||
List<StoreProdPriceAndMainPicAndTagDTO> attrList = storeProdMapper.selectPriceAndMainPicAndTagList(storeProdIdList);
|
||||
Map<Long, StoreProdPriceAndMainPicAndTagDTO> attrMap = attrList.stream().collect(Collectors.toMap(StoreProdPriceAndMainPicAndTagDTO::getStoreProdId, x -> x));
|
||||
return templateFive
|
||||
.setTopRightList(this.getTemplateTypeList(otherList, attrMap, HomepageType.SLIDING_PICTURE_SMALL.getValue(), 2))
|
||||
.setRecommendList(this.getTemplateTypeList(otherList, attrMap, HomepageType.STORE_RECOMMENDED.getValue(), 10))
|
||||
.setSaleRankList(this.getTemplateTypeList(otherList, attrMap, HomepageType.SALES_RANKING.getValue(), 10));
|
||||
// 商品价格、主图、标签等
|
||||
List<StoreProdPriceAndMainPicAndTagDTO> attrList = this.storeProdMapper.selectPriceAndMainPicAndTagList(prodIdList);
|
||||
Map<Long, StoreProdPriceAndMainPicAndTagDTO> attrMap = attrList.stream()
|
||||
.collect(Collectors.toMap(StoreProdPriceAndMainPicAndTagDTO::getStoreProdId, Function.identity()));
|
||||
// 顶部右侧商品2条
|
||||
List<StoreHomepage> topRightList = otherList.stream().filter(x -> Objects.equals(x.getFileType(), HomepageType.SLIDING_PICTURE_SMALL.getValue())).collect(Collectors.toList());
|
||||
List<StoreHomeTemplateItemResDTO> topRightRecommendList;
|
||||
if (CollectionUtils.isEmpty(topRightList)) {
|
||||
// 从latest50ProdList中随机选取最多2条数据
|
||||
List<StoreProduct> randomProductList = getRandomElements(latest50ProdList, 2);
|
||||
topRightRecommendList = randomProductList.stream().map(x -> {
|
||||
StoreProdPriceAndMainPicAndTagDTO dto = attrMap.get(x.getId());
|
||||
return BeanUtil.toBean(dto, StoreHomeTemplateItemResDTO.class)
|
||||
.setDisplayType(AdDisplayType.PRODUCT.getValue()).setProdPrice(ObjectUtils.isNotEmpty(dto) ? dto.getMinPrice() : null)
|
||||
.setTags(ObjectUtils.isNotEmpty(dto) && StringUtils.isNotBlank(dto.getTagStr()) ? StrUtil.split(dto.getTagStr(), ",") : null);
|
||||
}).collect(Collectors.toList());
|
||||
} else {
|
||||
topRightRecommendList = topRightList.stream().map(x -> {
|
||||
StoreProdPriceAndMainPicAndTagDTO dto = attrMap.get(x.getId());
|
||||
return BeanUtil.toBean(dto, StoreHomeTemplateItemResDTO.class)
|
||||
.setDisplayType(AdDisplayType.PRODUCT.getValue()).setProdPrice(ObjectUtils.isNotEmpty(dto) ? dto.getMinPrice() : null)
|
||||
.setTags(ObjectUtils.isNotEmpty(dto) && StringUtils.isNotBlank(dto.getTagStr()) ? StrUtil.split(dto.getTagStr(), ",") : null);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
// 顶部右侧推荐商品
|
||||
templateFive.setTopRightList(topRightRecommendList);
|
||||
|
||||
// 店家推荐 10条
|
||||
List<StoreHomepage> storeRecommendList = otherList.stream().filter(x -> Objects.equals(x.getFileType(), HomepageType.STORE_RECOMMENDED.getValue())).collect(Collectors.toList());
|
||||
List<StoreHomeTemplateItemResDTO> recommendList;
|
||||
if (CollectionUtils.isEmpty(storeRecommendList)) {
|
||||
// 从latest50ProdList中随机选取最多5条数据
|
||||
List<StoreProduct> randomProductList = getRandomElements(latest50ProdList, 10);
|
||||
recommendList = randomProductList.stream().map(x -> {
|
||||
StoreProdPriceAndMainPicAndTagDTO dto = attrMap.get(x.getId());
|
||||
return BeanUtil.toBean(dto, StoreHomeTemplateItemResDTO.class)
|
||||
.setDisplayType(AdDisplayType.PRODUCT.getValue()).setProdPrice(ObjectUtils.isNotEmpty(dto) ? dto.getMinPrice() : null)
|
||||
.setTags(ObjectUtils.isNotEmpty(dto) && StringUtils.isNotBlank(dto.getTagStr()) ? StrUtil.split(dto.getTagStr(), ",") : null);
|
||||
}).collect(Collectors.toList());
|
||||
} else {
|
||||
recommendList = storeRecommendList.stream().map(x -> {
|
||||
StoreProdPriceAndMainPicAndTagDTO dto = attrMap.get(x.getId());
|
||||
return BeanUtil.toBean(dto, StoreHomeTemplateItemResDTO.class)
|
||||
.setDisplayType(AdDisplayType.PRODUCT.getValue()).setProdPrice(ObjectUtils.isNotEmpty(dto) ? dto.getMinPrice() : null)
|
||||
.setTags(ObjectUtils.isNotEmpty(dto) && StringUtils.isNotBlank(dto.getTagStr()) ? StrUtil.split(dto.getTagStr(), ",") : null);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
// 档口推荐列表
|
||||
templateFive.setRecommendList(recommendList);
|
||||
|
||||
List<StoreHomeTemplateItemResDTO> saleRankRecommendList;
|
||||
// 销量排行 10条
|
||||
List<StoreHomepage> salesRankingList = otherList.stream().filter(x -> Objects.equals(x.getFileType(), HomepageType.SALES_RANKING.getValue())).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(salesRankingList)) {
|
||||
// 从latest50ProdList中随机选取最多10条数据
|
||||
List<StoreProduct> randomProductList = getRandomElements(latest50ProdList, 10);
|
||||
saleRankRecommendList = randomProductList.stream().map(x -> {
|
||||
StoreProdPriceAndMainPicAndTagDTO dto = attrMap.get(x.getId());
|
||||
return BeanUtil.toBean(dto, StoreHomeTemplateItemResDTO.class)
|
||||
.setDisplayType(AdDisplayType.PRODUCT.getValue()).setProdPrice(ObjectUtils.isNotEmpty(dto) ? dto.getMinPrice() : null)
|
||||
.setTags(ObjectUtils.isNotEmpty(dto) && StringUtils.isNotBlank(dto.getTagStr()) ? StrUtil.split(dto.getTagStr(), ",") : null);
|
||||
}).collect(Collectors.toList());
|
||||
} else {
|
||||
saleRankRecommendList = salesRankingList.stream().map(x -> {
|
||||
StoreProdPriceAndMainPicAndTagDTO dto = attrMap.get(x.getId());
|
||||
return BeanUtil.toBean(dto, StoreHomeTemplateItemResDTO.class)
|
||||
.setDisplayType(AdDisplayType.PRODUCT.getValue()).setProdPrice(ObjectUtils.isNotEmpty(dto) ? dto.getMinPrice() : null)
|
||||
.setTags(ObjectUtils.isNotEmpty(dto) && StringUtils.isNotBlank(dto.getTagStr()) ? StrUtil.split(dto.getTagStr(), ",") : null);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
// 销量排行列表
|
||||
templateFive.setSaleRankList(saleRankRecommendList);
|
||||
return templateFive;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue