在线商城
This commit is contained in:
1 parent
878ce352dc
commit
877a9bb2ac
1 file changed
+30
-4
+30
-4
@@ -34,15 +34,41 @@ public class AppShopSpuController {
|
||||
@Operation(summary = "APP商品分页", description = "移动端商品分页")
|
||||
public R<IPage<ShopSpuListAppVo>> page(
|
||||
@ParameterObject Page page,
|
||||
@RequestParam(required = false) Integer categoryId,
|
||||
@RequestParam(required = false) String keyword
|
||||
@RequestParam(required = false) Long categoryId,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) String merchantId
|
||||
) {
|
||||
LambdaQueryWrapper<ShopSpuEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(categoryId != null, ShopSpuEntity::getCategoryId, categoryId);
|
||||
wrapper.like(StrUtil.isNotBlank(keyword), ShopSpuEntity::getProductName, keyword);
|
||||
wrapper.like(cn.hutool.core.util.StrUtil.isNotBlank(keyword), ShopSpuEntity::getProductName, keyword);
|
||||
wrapper.eq(ShopSpuEntity::getStatus, 0); // 只查上架
|
||||
if (cn.hutool.core.util.StrUtil.isNotBlank(merchantId)) {
|
||||
wrapper.apply("FIND_IN_SET({0}, merchant_ids)", merchantId.trim());
|
||||
}
|
||||
IPage<ShopSpuEntity> spuPage = shopSpuService.page(page, wrapper);
|
||||
IPage<ShopSpuListAppVo> voPage = spuPage.convert(spu -> BeanUtils.toBean(spu, ShopSpuListAppVo.class));
|
||||
List<Long> spuIds = spuPage.getRecords().stream().map(ShopSpuEntity::getId).collect(java.util.stream.Collectors.toList());
|
||||
List<ShopSkuEntity> skuList = spuIds.isEmpty() ? List.of() : shopSkuService.list(
|
||||
Wrappers.<ShopSkuEntity>lambdaQuery().in(ShopSkuEntity::getSpuId, spuIds)
|
||||
);
|
||||
java.util.Map<Long, List<ShopSkuEntity>> skuMap = skuList.stream().collect(java.util.stream.Collectors.groupingBy(ShopSkuEntity::getSpuId));
|
||||
IPage<ShopSpuListAppVo> voPage = spuPage.convert(spu -> {
|
||||
ShopSpuListAppVo vo = com.bsd.pjcloud.common.core.util.BeanUtils.toBean(spu, ShopSpuListAppVo.class);
|
||||
List<ShopSkuEntity> skus = skuMap.getOrDefault(spu.getId(), List.of());
|
||||
vo.setMinPrice(skus.stream()
|
||||
.map(ShopSkuEntity::getRetailPrice)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.map(price -> new java.math.BigDecimal(price).divide(new java.math.BigDecimal(100)))
|
||||
.min(java.math.BigDecimal::compareTo)
|
||||
.orElse(java.math.BigDecimal.ZERO));
|
||||
vo.setTotalStock(
|
||||
skus.stream()
|
||||
.map(ShopSkuEntity::getStock)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.mapToDouble(Double::doubleValue)
|
||||
.sum()
|
||||
);
|
||||
return vo;
|
||||
});
|
||||
return R.ok(voPage);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user