Commit e163ae8b70cca549fea70ec850f39b79eac6d85f
1 parent
70816371
完成商品保存和编辑数据回显
Showing
12 changed files
with
72 additions
and
45 deletions
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 { | @@ -17,7 +17,7 @@ public enum ProductSpuStatusEnum implements IntArrayValuable { | ||
| 17 | 17 | ||
| 18 | RECYCLE(-1, "回收站"), | 18 | RECYCLE(-1, "回收站"), |
| 19 | DISABLE(0, "下架"), | 19 | DISABLE(0, "下架"), |
| 20 | - ENABLE(1, "上架"),; | 20 | + ENABLE(1, "上架"); |
| 21 | 21 | ||
| 22 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductSpuStatusEnum::getStatus).toArray(); | 22 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductSpuStatusEnum::getStatus).toArray(); |
| 23 | 23 |
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 | @@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueServ | ||
| 12 | import io.swagger.v3.oas.annotations.Operation; | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | import io.swagger.v3.oas.annotations.Parameter; | 13 | import io.swagger.v3.oas.annotations.Parameter; |
| 14 | import io.swagger.v3.oas.annotations.tags.Tag; | 14 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 15 | +import oracle.jdbc.proxy.annotation.Post; | ||
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | 16 | import org.springframework.security.access.prepost.PreAuthorize; |
| 16 | import org.springframework.validation.annotation.Validated; | 17 | import org.springframework.validation.annotation.Validated; |
| 17 | import org.springframework.web.bind.annotation.*; | 18 | import org.springframework.web.bind.annotation.*; |
| @@ -81,10 +82,10 @@ public class ProductPropertyController { | @@ -81,10 +82,10 @@ public class ProductPropertyController { | ||
| 81 | return success(ProductPropertyConvert.INSTANCE.convertPage(productPropertyService.getPropertyPage(pageVO))); | 82 | return success(ProductPropertyConvert.INSTANCE.convertPage(productPropertyService.getPropertyPage(pageVO))); |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | - @GetMapping("/get-value-list") | 85 | + @PostMapping("/get-value-list") |
| 85 | @Operation(summary = "获得属性项列表") | 86 | @Operation(summary = "获得属性项列表") |
| 86 | @PreAuthorize("@ss.hasPermission('product:property:query')") | 87 | @PreAuthorize("@ss.hasPermission('product:property:query')") |
| 87 | - public CommonResult<List<ProductPropertyAndValueRespVO>> getPropertyAndValueList(@Valid ProductPropertyListReqVO listReqVO) { | 88 | + public CommonResult<List<ProductPropertyAndValueRespVO>> getPropertyAndValueList(@Valid @RequestBody ProductPropertyListReqVO listReqVO) { |
| 88 | // 查询属性项 | 89 | // 查询属性项 |
| 89 | List<ProductPropertyDO> keys = productPropertyService.getPropertyList(listReqVO); | 90 | List<ProductPropertyDO> keys = productPropertyService.getPropertyList(listReqVO); |
| 90 | if (CollUtil.isEmpty(keys)) { | 91 | if (CollUtil.isEmpty(keys)) { |
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; | @@ -4,12 +4,17 @@ import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | import lombok.Data; | 4 | import lombok.Data; |
| 5 | import lombok.ToString; | 5 | import lombok.ToString; |
| 6 | 6 | ||
| 7 | +import javax.validation.constraints.NotEmpty; | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 7 | @Schema(description = "管理后台 - 属性项 List Request VO") | 10 | @Schema(description = "管理后台 - 属性项 List Request VO") |
| 8 | @Data | 11 | @Data |
| 9 | @ToString(callSuper = true) | 12 | @ToString(callSuper = true) |
| 10 | public class ProductPropertyListReqVO { | 13 | public class ProductPropertyListReqVO { |
| 11 | 14 | ||
| 12 | - @Schema(description = "名称", example = "颜色") | 15 | + @Schema(description = "属性名称", example = "颜色") |
| 13 | private String name; | 16 | private String name; |
| 14 | 17 | ||
| 18 | + @Schema(description = "属性ids", example = "1,2") | ||
| 19 | + private List<Long> propertyIds; | ||
| 15 | } | 20 | } |
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; | @@ -7,6 +7,9 @@ import javax.validation.constraints.NotNull; | ||
| 7 | import java.time.LocalDateTime; | 7 | import java.time.LocalDateTime; |
| 8 | import java.util.List; | 8 | import java.util.List; |
| 9 | 9 | ||
| 10 | +/** | ||
| 11 | + * @author HUIHUI | ||
| 12 | + */ | ||
| 10 | @Schema(description = "管理后台 - 商品 SKU Response VO") | 13 | @Schema(description = "管理后台 - 商品 SKU Response VO") |
| 11 | @Data | 14 | @Data |
| 12 | @EqualsAndHashCode(callSuper = true) | 15 | @EqualsAndHashCode(callSuper = true) |
| @@ -16,9 +19,6 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { | @@ -16,9 +19,6 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { | ||
| 16 | @Schema(description = "主键", required = true, example = "1024") | 19 | @Schema(description = "主键", required = true, example = "1024") |
| 17 | private Long id; | 20 | private Long id; |
| 18 | 21 | ||
| 19 | - @Schema(description = "创建时间") | ||
| 20 | - private LocalDateTime createTime; | ||
| 21 | - | ||
| 22 | @Schema(description = "商品属性") | 22 | @Schema(description = "商品属性") |
| 23 | @Data | 23 | @Data |
| 24 | @AllArgsConstructor | 24 | @AllArgsConstructor |
| @@ -34,11 +34,11 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { | @@ -34,11 +34,11 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { | ||
| 34 | private Long valueId; | 34 | private Long valueId; |
| 35 | 35 | ||
| 36 | @Schema(description = "属性值", example = "1024") | 36 | @Schema(description = "属性值", example = "1024") |
| 37 | - private String value; | 37 | + private String valueName; |
| 38 | } | 38 | } |
| 39 | /** | 39 | /** |
| 40 | * 属性数组 | 40 | * 属性数组 |
| 41 | */ | 41 | */ |
| 42 | - private List<ProductSkuCreateOrUpdateReqVO.Property> properties; | 42 | + private List<Property> properties; |
| 43 | 43 | ||
| 44 | } | 44 | } |
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 { | @@ -68,19 +68,7 @@ public class ProductSpuController { | ||
| 68 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 68 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 69 | @PreAuthorize("@ss.hasPermission('product:spu:query')") | 69 | @PreAuthorize("@ss.hasPermission('product:spu:query')") |
| 70 | public CommonResult<ProductSpuDetailRespVO> getSpuDetail(@RequestParam("id") Long id) { | 70 | public CommonResult<ProductSpuDetailRespVO> getSpuDetail(@RequestParam("id") Long id) { |
| 71 | - // 获得商品 SPU | ||
| 72 | - ProductSpuDO spu = productSpuService.getSpu(id); | ||
| 73 | - if (spu == null) { | ||
| 74 | - throw exception(SPU_NOT_EXISTS); | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - // 查询商品 SKU | ||
| 78 | - List<ProductSkuDO> skus = productSkuService.getSkuListBySpuIdAndStatus(spu.getId(), null); | ||
| 79 | - // 查询商品属性 | ||
| 80 | - List<ProductPropertyValueDetailRespBO> propertyValues = productPropertyValueService | ||
| 81 | - .getPropertyValueDetailList(ProductSkuConvert.INSTANCE.convertPropertyValueIds(skus)); | ||
| 82 | - // 拼接 | ||
| 83 | - return success(ProductSpuConvert.INSTANCE.convert03(spu, skus, propertyValues)); | 71 | + return success(productSpuService.getSpuDetail(id)); |
| 84 | } | 72 | } |
| 85 | 73 | ||
| 86 | @GetMapping("/get-simple-list") | 74 | @GetMapping("/get-simple-list") |
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; | @@ -2,37 +2,26 @@ package cn.iocoder.yudao.module.product.controller.admin.spu.vo; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO; | 3 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO; |
| 4 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; | 4 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; |
| 5 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; | ||
| 5 | import io.swagger.v3.oas.annotations.media.Schema; | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | import lombok.Data; | 7 | import lombok.Data; |
| 7 | import lombok.EqualsAndHashCode; | 8 | import lombok.EqualsAndHashCode; |
| 8 | import lombok.ToString; | 9 | import lombok.ToString; |
| 9 | 10 | ||
| 11 | +import javax.validation.constraints.NotNull; | ||
| 10 | import java.util.List; | 12 | import java.util.List; |
| 11 | 13 | ||
| 12 | @Schema(description = "管理后台 - 商品 SPU 详细 Response VO") // 包括关联的 SKU 等信息 | 14 | @Schema(description = "管理后台 - 商品 SPU 详细 Response VO") // 包括关联的 SKU 等信息 |
| 13 | @Data | 15 | @Data |
| 14 | @EqualsAndHashCode(callSuper = true) | 16 | @EqualsAndHashCode(callSuper = true) |
| 15 | @ToString(callSuper = true) | 17 | @ToString(callSuper = true) |
| 16 | -public class ProductSpuDetailRespVO extends ProductSpuRespVO { | 18 | +public class ProductSpuDetailRespVO extends ProductSpuBaseVO { |
| 17 | 19 | ||
| 20 | + @Schema(description = "商品编号", example = "1") | ||
| 21 | + private Long id; | ||
| 18 | // ========== SKU 相关字段 ========= | 22 | // ========== SKU 相关字段 ========= |
| 19 | 23 | ||
| 20 | - /** | ||
| 21 | - * SKU 数组 | ||
| 22 | - */ | ||
| 23 | - private List<Sku> skus; | ||
| 24 | - | ||
| 25 | - @Schema(description = "管理后台 - 商品 SKU 详细 Response VO") | ||
| 26 | - @Data | ||
| 27 | - @EqualsAndHashCode(callSuper = true) | ||
| 28 | - @ToString(callSuper = true) | ||
| 29 | - public static class Sku extends ProductSkuBaseVO { | ||
| 30 | - | ||
| 31 | - /** | ||
| 32 | - * 属性数组 | ||
| 33 | - */ | ||
| 34 | - private List<ProductPropertyValueDetailRespVO> properties; | ||
| 35 | - | ||
| 36 | - } | 24 | + @Schema(description = "SKU 数组", example = "1") |
| 25 | + private List<ProductSkuRespVO> skus; | ||
| 37 | 26 | ||
| 38 | } | 27 | } |
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 { | @@ -43,7 +43,7 @@ public interface ProductSkuConvert { | ||
| 43 | 43 | ||
| 44 | ProductSkuRespDTO convert02(ProductSkuDO bean); | 44 | ProductSkuRespDTO convert02(ProductSkuDO bean); |
| 45 | 45 | ||
| 46 | - List<ProductSpuDetailRespVO.Sku> convertList03(List<ProductSkuDO> list); | 46 | + List<ProductSkuRespVO> convertList03(List<ProductSkuDO> list); |
| 47 | 47 | ||
| 48 | List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list); | 48 | List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list); |
| 49 | 49 |
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; | @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | 5 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 6 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO; | 6 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO; |
| 7 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; | ||
| 7 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; | 8 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; |
| 8 | import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; | 9 | import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; |
| 9 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO; | 10 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO; |
| @@ -88,7 +89,7 @@ public interface ProductSpuConvert { | @@ -88,7 +89,7 @@ public interface ProductSpuConvert { | ||
| 88 | if (CollUtil.isEmpty(properties)) { | 89 | if (CollUtil.isEmpty(properties)) { |
| 89 | continue; | 90 | continue; |
| 90 | } | 91 | } |
| 91 | - ProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i); | 92 | + ProductSkuRespVO sku = spuVO.getSkus().get(i); |
| 92 | sku.setProperties(new ArrayList<>(properties.size())); | 93 | sku.setProperties(new ArrayList<>(properties.size())); |
| 93 | // 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中 | 94 | // 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中 |
| 94 | properties.forEach(property -> { | 95 | properties.forEach(property -> { |
| @@ -96,13 +97,13 @@ public interface ProductSpuConvert { | @@ -96,13 +97,13 @@ public interface ProductSpuConvert { | ||
| 96 | if (propertyValue == null) { | 97 | if (propertyValue == null) { |
| 97 | return; | 98 | return; |
| 98 | } | 99 | } |
| 99 | - sku.getProperties().add(convert04(propertyValue)); | 100 | + //sku.getProperties().add(convert04(propertyValue)); TODO 需要重写 |
| 100 | }); | 101 | }); |
| 101 | } | 102 | } |
| 102 | return spuVO; | 103 | return spuVO; |
| 103 | } | 104 | } |
| 104 | ProductSpuDetailRespVO convert03(ProductSpuDO spu); | 105 | ProductSpuDetailRespVO convert03(ProductSpuDO spu); |
| 105 | - List<ProductSpuDetailRespVO.Sku> convertList04(List<ProductSkuDO> skus); | 106 | + List<ProductSkuRespVO> convertList04(List<ProductSkuDO> skus); |
| 106 | ProductPropertyValueDetailRespVO convert04(ProductPropertyValueDetailRespBO propertyValue); | 107 | ProductPropertyValueDetailRespVO convert04(ProductPropertyValueDetailRespBO propertyValue); |
| 107 | 108 | ||
| 108 | } | 109 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.property; | 1 | package cn.iocoder.yudao.module.product.service.property; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.hutool.core.util.ObjUtil; | 4 | import cn.hutool.core.util.ObjUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO; | 6 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO; |
| @@ -92,6 +93,10 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -92,6 +93,10 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 92 | 93 | ||
| 93 | @Override | 94 | @Override |
| 94 | public List<ProductPropertyDO> getPropertyList(ProductPropertyListReqVO listReqVO) { | 95 | public List<ProductPropertyDO> getPropertyList(ProductPropertyListReqVO listReqVO) { |
| 96 | + // 增加使用属性id查询 | ||
| 97 | + if (CollUtil.isNotEmpty(listReqVO.getPropertyIds())){ | ||
| 98 | + return productPropertyMapper.selectBatchIds(listReqVO.getPropertyIds()); | ||
| 99 | + } | ||
| 95 | return productPropertyMapper.selectList(listReqVO); | 100 | return productPropertyMapper.selectList(listReqVO); |
| 96 | } | 101 | } |
| 97 | 102 |
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 { | @@ -87,7 +87,7 @@ public interface ProductSkuService { | ||
| 87 | 87 | ||
| 88 | /** | 88 | /** |
| 89 | * 基于 SPU 编号和状态,获得商品 SKU 集合 | 89 | * 基于 SPU 编号和状态,获得商品 SKU 集合 |
| 90 | - * | 90 | + * TODO SKU中已经不存在status属性 |
| 91 | * @param spuId SPU 编号 | 91 | * @param spuId SPU 编号 |
| 92 | * @param status 状态 | 92 | * @param status 状态 |
| 93 | * @return 商品 SKU 集合 | 93 | * @return 商品 SKU 集合 |
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 { | @@ -98,4 +98,11 @@ public interface ProductSpuService { | ||
| 98 | */ | 98 | */ |
| 99 | void updateSpuStock(Map<Long, Integer> stockIncrCounts); | 99 | void updateSpuStock(Map<Long, Integer> stockIncrCounts); |
| 100 | 100 | ||
| 101 | + /** | ||
| 102 | + * 得到spu详细 | ||
| 103 | + * | ||
| 104 | + * @param id id | ||
| 105 | + * @return {@link ProductSpuDetailRespVO} | ||
| 106 | + */ | ||
| 107 | + ProductSpuDetailRespVO getSpuDetail(Long id); | ||
| 101 | } | 108 | } |
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; | @@ -4,10 +4,13 @@ import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 6 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; | 6 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; |
| 7 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; | ||
| 7 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO; | 8 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO; |
| 9 | +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuDetailRespVO; | ||
| 8 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; | 10 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; |
| 9 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO; | 11 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO; |
| 10 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; | 12 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; |
| 13 | +import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | ||
| 11 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; | 14 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; |
| 12 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | 15 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 13 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | 16 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| @@ -15,6 +18,8 @@ import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; | @@ -15,6 +18,8 @@ import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; | ||
| 15 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; | 18 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 16 | import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; | 19 | import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; |
| 17 | import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; | 20 | import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; |
| 21 | +import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; | ||
| 22 | +import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; | ||
| 18 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; | 23 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 19 | import org.springframework.context.annotation.Lazy; | 24 | import org.springframework.context.annotation.Lazy; |
| 20 | import org.springframework.stereotype.Service; | 25 | import org.springframework.stereotype.Service; |
| @@ -23,6 +28,7 @@ import org.springframework.validation.annotation.Validated; | @@ -23,6 +28,7 @@ import org.springframework.validation.annotation.Validated; | ||
| 23 | 28 | ||
| 24 | import javax.annotation.Resource; | 29 | import javax.annotation.Resource; |
| 25 | import java.util.*; | 30 | import java.util.*; |
| 31 | +import java.util.stream.Collectors; | ||
| 26 | 32 | ||
| 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 28 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | 34 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| @@ -48,6 +54,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -48,6 +54,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 48 | private ProductBrandService brandService; | 54 | private ProductBrandService brandService; |
| 49 | @Resource | 55 | @Resource |
| 50 | private ProductCategoryService categoryService; | 56 | private ProductCategoryService categoryService; |
| 57 | + @Resource | ||
| 58 | + private ProductPropertyValueService productPropertyValueService; | ||
| 51 | 59 | ||
| 52 | @Override | 60 | @Override |
| 53 | @Transactional(rollbackFor = Exception.class) | 61 | @Transactional(rollbackFor = Exception.class) |
| @@ -191,4 +199,27 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -191,4 +199,27 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 191 | stockIncrCounts.forEach((id, incCount) -> productSpuMapper.updateStock(id, incCount)); | 199 | stockIncrCounts.forEach((id, incCount) -> productSpuMapper.updateStock(id, incCount)); |
| 192 | } | 200 | } |
| 193 | 201 | ||
| 202 | + @Override | ||
| 203 | + public ProductSpuDetailRespVO getSpuDetail(Long id) { | ||
| 204 | + // 获得商品 SPU | ||
| 205 | + ProductSpuDO spu = getSpu(id); | ||
| 206 | + if (spu == null) { | ||
| 207 | + throw exception(SPU_NOT_EXISTS); | ||
| 208 | + } | ||
| 209 | + ProductSpuDetailRespVO productSpuDetailRespVO = ProductSpuConvert.INSTANCE.convert03(spu); | ||
| 210 | + // 查询商品 SKU | ||
| 211 | + List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId()); | ||
| 212 | + if (CollUtil.isNotEmpty(skus)){ | ||
| 213 | + List<ProductSkuRespVO> skuRespVoS = ProductSkuConvert.INSTANCE.convertList(skus); | ||
| 214 | + // 获取所有的属性值id | ||
| 215 | + Set<Long> valueIds = skus.stream().flatMap(p -> p.getProperties().stream()).map(ProductSkuDO.Property::getValueId).collect(Collectors.toSet()); | ||
| 216 | + List<ProductPropertyValueDetailRespBO> valueDetailList = productPropertyValueService.getPropertyValueDetailList(valueIds); | ||
| 217 | + Map<Long, String> stringMap = valueDetailList.stream().collect(Collectors.toMap(ProductPropertyValueDetailRespBO::getValueId, ProductPropertyValueDetailRespBO::getValueName)); | ||
| 218 | + // 设置属性值名称 | ||
| 219 | + skuRespVoS.stream().flatMap(p -> p.getProperties().stream()).forEach(item ->item.setValueName(stringMap.get(item.getValueId()))); | ||
| 220 | + productSpuDetailRespVO.setSkus(skuRespVoS); | ||
| 221 | + } | ||
| 222 | + return productSpuDetailRespVO; | ||
| 223 | + } | ||
| 224 | + | ||
| 194 | } | 225 | } |