Commit c5630518418d01e214371e28885971d913bda597
1 parent
409ec555
feat:mall product 新增通过 spuIds 获取相关 spu 详情列表的接口
Showing
4 changed files
with
25 additions
and
2 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
| ... | ... | @@ -21,6 +21,7 @@ import javax.annotation.Resource; |
| 21 | 21 | import javax.servlet.http.HttpServletResponse; |
| 22 | 22 | import javax.validation.Valid; |
| 23 | 23 | import java.io.IOException; |
| 24 | +import java.util.Collection; | |
| 24 | 25 | import java.util.List; |
| 25 | 26 | import java.util.Map; |
| 26 | 27 | |
| ... | ... | @@ -100,6 +101,15 @@ public class ProductSpuController { |
| 100 | 101 | return success(ProductSpuConvert.INSTANCE.convertList02(list)); |
| 101 | 102 | } |
| 102 | 103 | |
| 104 | + @GetMapping("/list") | |
| 105 | + @Operation(summary = "获得商品 SPU 详情列表") | |
| 106 | + @Parameter(name = "spuIds", description = "spu 编号列表", required = true, example = "[1,2,3]") | |
| 107 | + @PreAuthorize("@ss.hasPermission('product:spu:query')") | |
| 108 | + public CommonResult<List<ProductSpuDetailRespVO>> getSpuList(@RequestParam("spuIds") Collection<Long> spuIds) { | |
| 109 | + return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespListVO( | |
| 110 | + productSpuService.getSpuList(spuIds), productSkuService.getSkuListBySpuId(spuIds))); | |
| 111 | + } | |
| 112 | + | |
| 103 | 113 | @GetMapping("/page") |
| 104 | 114 | @Operation(summary = "获得商品 SPU 分页") |
| 105 | 115 | @PreAuthorize("@ss.hasPermission('product:spu:query')") | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.product.convert.spu; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 4 | 5 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; |
| 5 | 6 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 6 | 7 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; |
| ... | ... | @@ -18,6 +19,7 @@ import org.mapstruct.factory.Mappers; |
| 18 | 19 | |
| 19 | 20 | import java.util.ArrayList; |
| 20 | 21 | import java.util.List; |
| 22 | +import java.util.Map; | |
| 21 | 23 | |
| 22 | 24 | import static cn.hutool.core.util.ObjectUtil.defaultIfNull; |
| 23 | 25 | |
| ... | ... | @@ -107,4 +109,15 @@ public interface ProductSpuConvert { |
| 107 | 109 | return detailRespVO; |
| 108 | 110 | } |
| 109 | 111 | |
| 112 | + default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) { | |
| 113 | + ArrayList<ProductSpuDetailRespVO> vos = new ArrayList<>(); | |
| 114 | + Map<Long, List<ProductSkuDO>> skuMultiMap = CollectionUtils.convertMultiMap(skus, ProductSkuDO::getSpuId); | |
| 115 | + spus.forEach(spu -> { | |
| 116 | + ProductSpuDetailRespVO detailRespVO = convert03(spu); | |
| 117 | + detailRespVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skuMultiMap.get(spu.getId()))); | |
| 118 | + vos.add(detailRespVO); | |
| 119 | + }); | |
| 120 | + return vos; | |
| 121 | + } | |
| 122 | + | |
| 110 | 123 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java
| ... | ... | @@ -90,7 +90,7 @@ public interface ProductSkuService { |
| 90 | 90 | * @param spuIds spu 编码集合 |
| 91 | 91 | * @return 商品 sku 集合 |
| 92 | 92 | */ |
| 93 | - List<ProductSkuDO> getSkuListBySpuId(List<Long> spuIds); | |
| 93 | + List<ProductSkuDO> getSkuListBySpuId(Collection<Long> spuIds); | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * 通过 spuId 删除 sku 信息 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
| ... | ... | @@ -148,7 +148,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | @Override |
| 151 | - public List<ProductSkuDO> getSkuListBySpuId(List<Long> spuIds) { | |
| 151 | + public List<ProductSkuDO> getSkuListBySpuId(Collection<Long> spuIds) { | |
| 152 | 152 | return productSkuMapper.selectListBySpuId(spuIds); |
| 153 | 153 | } |
| 154 | 154 | ... | ... |