From e163ae8b70cca549fea70ec850f39b79eac6d85f Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 3 May 2023 02:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=95=86=E5=93=81=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=92=8C=E7=BC=96=E8=BE=91=E6=95=B0=E6=8D=AE=E5=9B=9E?= =?UTF-8?q?=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/spu/ProductSpuStatusEnum.java | 2 +- .../property/ProductPropertyController.java | 5 +-- .../vo/property/ProductPropertyListReqVO.java | 7 ++++- .../admin/sku/vo/ProductSkuRespVO.java | 10 +++--- .../admin/spu/ProductSpuController.java | 14 +-------- .../admin/spu/vo/ProductSpuDetailRespVO.java | 25 +++++---------- .../convert/sku/ProductSkuConvert.java | 2 +- .../convert/spu/ProductSpuConvert.java | 7 +++-- .../property/ProductPropertyServiceImpl.java | 5 +++ .../service/sku/ProductSkuService.java | 2 +- .../service/spu/ProductSpuService.java | 7 +++++ .../service/spu/ProductSpuServiceImpl.java | 31 +++++++++++++++++++ 12 files changed, 72 insertions(+), 45 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductSpuStatusEnum.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductSpuStatusEnum.java index 2223cf23d..4ba6124e0 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductSpuStatusEnum.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductSpuStatusEnum.java @@ -17,7 +17,7 @@ public enum ProductSpuStatusEnum implements IntArrayValuable { RECYCLE(-1, "回收站"), DISABLE(0, "下架"), - ENABLE(1, "上架"),; + ENABLE(1, "上架"); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductSpuStatusEnum::getStatus).toArray(); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java index bd063e0ec..0c203b551 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java @@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueServ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import oracle.jdbc.proxy.annotation.Post; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -81,10 +82,10 @@ public class ProductPropertyController { return success(ProductPropertyConvert.INSTANCE.convertPage(productPropertyService.getPropertyPage(pageVO))); } - @GetMapping("/get-value-list") + @PostMapping("/get-value-list") @Operation(summary = "获得属性项列表") @PreAuthorize("@ss.hasPermission('product:property:query')") - public CommonResult> getPropertyAndValueList(@Valid ProductPropertyListReqVO listReqVO) { + public CommonResult> getPropertyAndValueList(@Valid @RequestBody ProductPropertyListReqVO listReqVO) { // 查询属性项 List keys = productPropertyService.getPropertyList(listReqVO); if (CollUtil.isEmpty(keys)) { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java index 242caff84..44935147c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java @@ -4,12 +4,17 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.ToString; +import javax.validation.constraints.NotEmpty; +import java.util.List; + @Schema(description = "管理后台 - 属性项 List Request VO") @Data @ToString(callSuper = true) public class ProductPropertyListReqVO { - @Schema(description = "名称", example = "颜色") + @Schema(description = "属性名称", example = "颜色") private String name; + @Schema(description = "属性ids", example = "1,2") + private List propertyIds; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuRespVO.java index a229fa826..11bf4a734 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuRespVO.java @@ -7,6 +7,9 @@ import javax.validation.constraints.NotNull; import java.time.LocalDateTime; import java.util.List; +/** + * @author HUIHUI + */ @Schema(description = "管理后台 - 商品 SKU Response VO") @Data @EqualsAndHashCode(callSuper = true) @@ -16,9 +19,6 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { @Schema(description = "主键", required = true, example = "1024") private Long id; - @Schema(description = "创建时间") - private LocalDateTime createTime; - @Schema(description = "商品属性") @Data @AllArgsConstructor @@ -34,11 +34,11 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { private Long valueId; @Schema(description = "属性值", example = "1024") - private String value; + private String valueName; } /** * 属性数组 */ - private List properties; + private List properties; } 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 f2ce90c1d..2e2871faa 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 @@ -68,19 +68,7 @@ public class ProductSpuController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('product:spu:query')") public CommonResult getSpuDetail(@RequestParam("id") Long id) { - // 获得商品 SPU - ProductSpuDO spu = productSpuService.getSpu(id); - if (spu == null) { - throw exception(SPU_NOT_EXISTS); - } - - // 查询商品 SKU - List skus = productSkuService.getSkuListBySpuIdAndStatus(spu.getId(), null); - // 查询商品属性 - List propertyValues = productPropertyValueService - .getPropertyValueDetailList(ProductSkuConvert.INSTANCE.convertPropertyValueIds(skus)); - // 拼接 - return success(ProductSpuConvert.INSTANCE.convert03(spu, skus, propertyValues)); + return success(productSpuService.getSpuDetail(id)); } @GetMapping("/get-simple-list") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java index 58f9565c8..4672911ff 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java @@ -2,37 +2,26 @@ package cn.iocoder.yudao.module.product.controller.admin.spu.vo; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import javax.validation.constraints.NotNull; import java.util.List; @Schema(description = "管理后台 - 商品 SPU 详细 Response VO") // 包括关联的 SKU 等信息 @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class ProductSpuDetailRespVO extends ProductSpuRespVO { +public class ProductSpuDetailRespVO extends ProductSpuBaseVO { + @Schema(description = "商品编号", example = "1") + private Long id; // ========== SKU 相关字段 ========= - /** - * SKU 数组 - */ - private List skus; - - @Schema(description = "管理后台 - 商品 SKU 详细 Response VO") - @Data - @EqualsAndHashCode(callSuper = true) - @ToString(callSuper = true) - public static class Sku extends ProductSkuBaseVO { - - /** - * 属性数组 - */ - private List properties; - - } + @Schema(description = "SKU 数组", example = "1") + private List skus; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java index 8336242b4..dd69646af 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java @@ -43,7 +43,7 @@ public interface ProductSkuConvert { ProductSkuRespDTO convert02(ProductSkuDO bean); - List convertList03(List list); + List convertList03(List list); List convertList04(List list); 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 4ceddab4d..9fd142b28 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 @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO; @@ -88,7 +89,7 @@ public interface ProductSpuConvert { if (CollUtil.isEmpty(properties)) { continue; } - ProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i); + ProductSkuRespVO sku = spuVO.getSkus().get(i); sku.setProperties(new ArrayList<>(properties.size())); // 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中 properties.forEach(property -> { @@ -96,13 +97,13 @@ public interface ProductSpuConvert { if (propertyValue == null) { return; } - sku.getProperties().add(convert04(propertyValue)); + //sku.getProperties().add(convert04(propertyValue)); TODO 需要重写 }); } return spuVO; } ProductSpuDetailRespVO convert03(ProductSpuDO spu); - List convertList04(List skus); + List convertList04(List skus); ProductPropertyValueDetailRespVO convert04(ProductPropertyValueDetailRespBO propertyValue); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java index 328c343d6..96b41de8d 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.service.property; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO; @@ -92,6 +93,10 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { @Override public List getPropertyList(ProductPropertyListReqVO listReqVO) { + // 增加使用属性id查询 + if (CollUtil.isNotEmpty(listReqVO.getPropertyIds())){ + return productPropertyMapper.selectBatchIds(listReqVO.getPropertyIds()); + } return productPropertyMapper.selectList(listReqVO); } 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 923603487..8eb5f73fb 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 @@ -87,7 +87,7 @@ public interface ProductSkuService { /** * 基于 SPU 编号和状态,获得商品 SKU 集合 - * + * TODO SKU中已经不存在status属性 * @param spuId SPU 编号 * @param status 状态 * @return 商品 SKU 集合 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java index 0ae7359eb..f088a7e79 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java @@ -98,4 +98,11 @@ public interface ProductSpuService { */ void updateSpuStock(Map stockIncrCounts); + /** + * 得到spu详细 + * + * @param id id + * @return {@link ProductSpuDetailRespVO} + */ + ProductSpuDetailRespVO getSpuDetail(Long id); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index 45bc23389..4355f05ab 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -4,10 +4,13 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuDetailRespVO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; +import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; @@ -15,6 +18,8 @@ import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; +import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; +import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -23,6 +28,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.*; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; @@ -48,6 +54,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { private ProductBrandService brandService; @Resource private ProductCategoryService categoryService; + @Resource + private ProductPropertyValueService productPropertyValueService; @Override @Transactional(rollbackFor = Exception.class) @@ -191,4 +199,27 @@ public class ProductSpuServiceImpl implements ProductSpuService { stockIncrCounts.forEach((id, incCount) -> productSpuMapper.updateStock(id, incCount)); } + @Override + public ProductSpuDetailRespVO getSpuDetail(Long id) { + // 获得商品 SPU + ProductSpuDO spu = getSpu(id); + if (spu == null) { + throw exception(SPU_NOT_EXISTS); + } + ProductSpuDetailRespVO productSpuDetailRespVO = ProductSpuConvert.INSTANCE.convert03(spu); + // 查询商品 SKU + List skus = productSkuService.getSkuListBySpuId(spu.getId()); + if (CollUtil.isNotEmpty(skus)){ + List skuRespVoS = ProductSkuConvert.INSTANCE.convertList(skus); + // 获取所有的属性值id + Set valueIds = skus.stream().flatMap(p -> p.getProperties().stream()).map(ProductSkuDO.Property::getValueId).collect(Collectors.toSet()); + List valueDetailList = productPropertyValueService.getPropertyValueDetailList(valueIds); + Map stringMap = valueDetailList.stream().collect(Collectors.toMap(ProductPropertyValueDetailRespBO::getValueId, ProductPropertyValueDetailRespBO::getValueName)); + // 设置属性值名称 + skuRespVoS.stream().flatMap(p -> p.getProperties().stream()).forEach(item ->item.setValueName(stringMap.get(item.getValueId()))); + productSpuDetailRespVO.setSkus(skuRespVoS); + } + return productSpuDetailRespVO; + } + }