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 | 17 | |
| 18 | 18 | RECYCLE(-1, "回收站"), |
| 19 | 19 | DISABLE(0, "下架"), |
| 20 | - ENABLE(1, "上架"),; | |
| 20 | + ENABLE(1, "上架"); | |
| 21 | 21 | |
| 22 | 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 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | 13 | import io.swagger.v3.oas.annotations.Parameter; |
| 14 | 14 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 15 | +import oracle.jdbc.proxy.annotation.Post; | |
| 15 | 16 | import org.springframework.security.access.prepost.PreAuthorize; |
| 16 | 17 | import org.springframework.validation.annotation.Validated; |
| 17 | 18 | import org.springframework.web.bind.annotation.*; |
| ... | ... | @@ -81,10 +82,10 @@ public class ProductPropertyController { |
| 81 | 82 | return success(ProductPropertyConvert.INSTANCE.convertPage(productPropertyService.getPropertyPage(pageVO))); |
| 82 | 83 | } |
| 83 | 84 | |
| 84 | - @GetMapping("/get-value-list") | |
| 85 | + @PostMapping("/get-value-list") | |
| 85 | 86 | @Operation(summary = "获得属性项列表") |
| 86 | 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 | 90 | List<ProductPropertyDO> keys = productPropertyService.getPropertyList(listReqVO); |
| 90 | 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 | 4 | import lombok.Data; |
| 5 | 5 | import lombok.ToString; |
| 6 | 6 | |
| 7 | +import javax.validation.constraints.NotEmpty; | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 7 | 10 | @Schema(description = "管理后台 - 属性项 List Request VO") |
| 8 | 11 | @Data |
| 9 | 12 | @ToString(callSuper = true) |
| 10 | 13 | public class ProductPropertyListReqVO { |
| 11 | 14 | |
| 12 | - @Schema(description = "名称", example = "颜色") | |
| 15 | + @Schema(description = "属性名称", example = "颜色") | |
| 13 | 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 | 7 | import java.time.LocalDateTime; |
| 8 | 8 | import java.util.List; |
| 9 | 9 | |
| 10 | +/** | |
| 11 | + * @author HUIHUI | |
| 12 | + */ | |
| 10 | 13 | @Schema(description = "管理后台 - 商品 SKU Response VO") |
| 11 | 14 | @Data |
| 12 | 15 | @EqualsAndHashCode(callSuper = true) |
| ... | ... | @@ -16,9 +19,6 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { |
| 16 | 19 | @Schema(description = "主键", required = true, example = "1024") |
| 17 | 20 | private Long id; |
| 18 | 21 | |
| 19 | - @Schema(description = "创建时间") | |
| 20 | - private LocalDateTime createTime; | |
| 21 | - | |
| 22 | 22 | @Schema(description = "商品属性") |
| 23 | 23 | @Data |
| 24 | 24 | @AllArgsConstructor |
| ... | ... | @@ -34,11 +34,11 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { |
| 34 | 34 | private Long valueId; |
| 35 | 35 | |
| 36 | 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 | 68 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 69 | 69 | @PreAuthorize("@ss.hasPermission('product:spu:query')") |
| 70 | 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 | 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 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO; |
| 4 | 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 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | 7 | import lombok.Data; |
| 7 | 8 | import lombok.EqualsAndHashCode; |
| 8 | 9 | import lombok.ToString; |
| 9 | 10 | |
| 11 | +import javax.validation.constraints.NotNull; | |
| 10 | 12 | import java.util.List; |
| 11 | 13 | |
| 12 | 14 | @Schema(description = "管理后台 - 商品 SPU 详细 Response VO") // 包括关联的 SKU 等信息 |
| 13 | 15 | @Data |
| 14 | 16 | @EqualsAndHashCode(callSuper = true) |
| 15 | 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 | 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 | 43 | |
| 44 | 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 | 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 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 6 | 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 | 8 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; |
| 8 | 9 | import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; |
| 9 | 10 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO; |
| ... | ... | @@ -88,7 +89,7 @@ public interface ProductSpuConvert { |
| 88 | 89 | if (CollUtil.isEmpty(properties)) { |
| 89 | 90 | continue; |
| 90 | 91 | } |
| 91 | - ProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i); | |
| 92 | + ProductSkuRespVO sku = spuVO.getSkus().get(i); | |
| 92 | 93 | sku.setProperties(new ArrayList<>(properties.size())); |
| 93 | 94 | // 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中 |
| 94 | 95 | properties.forEach(property -> { |
| ... | ... | @@ -96,13 +97,13 @@ public interface ProductSpuConvert { |
| 96 | 97 | if (propertyValue == null) { |
| 97 | 98 | return; |
| 98 | 99 | } |
| 99 | - sku.getProperties().add(convert04(propertyValue)); | |
| 100 | + //sku.getProperties().add(convert04(propertyValue)); TODO 需要重写 | |
| 100 | 101 | }); |
| 101 | 102 | } |
| 102 | 103 | return spuVO; |
| 103 | 104 | } |
| 104 | 105 | ProductSpuDetailRespVO convert03(ProductSpuDO spu); |
| 105 | - List<ProductSpuDetailRespVO.Sku> convertList04(List<ProductSkuDO> skus); | |
| 106 | + List<ProductSkuRespVO> convertList04(List<ProductSkuDO> skus); | |
| 106 | 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 | 1 | package cn.iocoder.yudao.module.product.service.property; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.hutool.core.util.ObjUtil; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO; |
| ... | ... | @@ -92,6 +93,10 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { |
| 92 | 93 | |
| 93 | 94 | @Override |
| 94 | 95 | public List<ProductPropertyDO> getPropertyList(ProductPropertyListReqVO listReqVO) { |
| 96 | + // 增加使用属性id查询 | |
| 97 | + if (CollUtil.isNotEmpty(listReqVO.getPropertyIds())){ | |
| 98 | + return productPropertyMapper.selectBatchIds(listReqVO.getPropertyIds()); | |
| 99 | + } | |
| 95 | 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
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 | 98 | */ |
| 99 | 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 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 6 | 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 | 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 | 10 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; |
| 9 | 11 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO; |
| 10 | 12 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; |
| 13 | +import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | |
| 11 | 14 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; |
| 12 | 15 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 13 | 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 | 18 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 16 | 19 | import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; |
| 17 | 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 | 23 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 19 | 24 | import org.springframework.context.annotation.Lazy; |
| 20 | 25 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -23,6 +28,7 @@ import org.springframework.validation.annotation.Validated; |
| 23 | 28 | |
| 24 | 29 | import javax.annotation.Resource; |
| 25 | 30 | import java.util.*; |
| 31 | +import java.util.stream.Collectors; | |
| 26 | 32 | |
| 27 | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 28 | 34 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| ... | ... | @@ -48,6 +54,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 48 | 54 | private ProductBrandService brandService; |
| 49 | 55 | @Resource |
| 50 | 56 | private ProductCategoryService categoryService; |
| 57 | + @Resource | |
| 58 | + private ProductPropertyValueService productPropertyValueService; | |
| 51 | 59 | |
| 52 | 60 | @Override |
| 53 | 61 | @Transactional(rollbackFor = Exception.class) |
| ... | ... | @@ -191,4 +199,27 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 191 | 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 | } | ... | ... |