From c5630518418d01e214371e28885971d913bda597 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 3 Jul 2023 14:44:27 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Amall=20product=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E9=80=9A=E8=BF=87=20spuIds=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=20spu=20=E8=AF=A6=E6=83=85=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/spu/ProductSpuController.java | 10 ++++++++++ .../product/convert/spu/ProductSpuConvert.java | 13 +++++++++++++ .../product/service/sku/ProductSkuService.java | 2 +- .../product/service/sku/ProductSkuServiceImpl.java | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java index 0df57ca4f..2fcffb275 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java +++ b/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; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -100,6 +101,15 @@ public class ProductSpuController { return success(ProductSpuConvert.INSTANCE.convertList02(list)); } + @GetMapping("/list") + @Operation(summary = "获得商品 SPU 详情列表") + @Parameter(name = "spuIds", description = "spu 编号列表", required = true, example = "[1,2,3]") + @PreAuthorize("@ss.hasPermission('product:spu:query')") + public CommonResult> getSpuList(@RequestParam("spuIds") Collection spuIds) { + return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespListVO( + productSpuService.getSpuList(spuIds), productSkuService.getSkuListBySpuId(spuIds))); + } + @GetMapping("/page") @Operation(summary = "获得商品 SPU 分页") @PreAuthorize("@ss.hasPermission('product:spu:query')") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java index aaad240a4..833ed0722 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.product.convert.spu; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; @@ -18,6 +19,7 @@ import org.mapstruct.factory.Mappers; import java.util.ArrayList; import java.util.List; +import java.util.Map; import static cn.hutool.core.util.ObjectUtil.defaultIfNull; @@ -107,4 +109,15 @@ public interface ProductSpuConvert { return detailRespVO; } + default List convertForSpuDetailRespListVO(List spus, List skus) { + ArrayList vos = new ArrayList<>(); + Map> skuMultiMap = CollectionUtils.convertMultiMap(skus, ProductSkuDO::getSpuId); + spus.forEach(spu -> { + ProductSpuDetailRespVO detailRespVO = convert03(spu); + detailRespVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skuMultiMap.get(spu.getId()))); + vos.add(detailRespVO); + }); + return vos; + } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java index 4c106d1bc..fbc9830bf 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java +++ b/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 { * @param spuIds spu 编码集合 * @return 商品 sku 集合 */ - List getSkuListBySpuId(List spuIds); + List getSkuListBySpuId(Collection spuIds); /** * 通过 spuId 删除 sku 信息 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index 3f77fbe8d..7c6c5030e 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/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 { } @Override - public List getSkuListBySpuId(List spuIds) { + public List getSkuListBySpuId(Collection spuIds) { return productSkuMapper.selectListBySpuId(spuIds); }