Commit 24a56bb45f9bd11145042aa3781aa7d51b877e3d

Authored by puhui999
1 parent f56d3948

移除ProductSku相关的status属性,修改Property

yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java
1 package cn.iocoder.yudao.module.product.controller.admin.property; 1 package cn.iocoder.yudao.module.product.controller.admin.property;
2 2
  3 +import cn.hutool.core.collection.CollectionUtil;
  4 +import cn.hutool.crypto.symmetric.AES;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; 7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
@@ -18,6 +20,9 @@ import org.springframework.web.bind.annotation.*; @@ -18,6 +20,9 @@ import org.springframework.web.bind.annotation.*;
18 import javax.annotation.Resource; 20 import javax.annotation.Resource;
19 import javax.validation.Valid; 21 import javax.validation.Valid;
20 22
  23 +import java.util.Arrays;
  24 +import java.util.List;
  25 +
21 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 26 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
22 27
23 @Tag(name = "管理后台 - 商品属性值") 28 @Tag(name = "管理后台 - 商品属性值")
@@ -32,14 +37,14 @@ public class ProductPropertyValueController { @@ -32,14 +37,14 @@ public class ProductPropertyValueController {
32 @PostMapping("/create") 37 @PostMapping("/create")
33 @Operation(summary = "创建属性值") 38 @Operation(summary = "创建属性值")
34 @PreAuthorize("@ss.hasPermission('product:property:create')") 39 @PreAuthorize("@ss.hasPermission('product:property:create')")
35 - public CommonResult<Long> createProperty(@Valid @RequestBody ProductPropertyValueCreateReqVO createReqVO) { 40 + public CommonResult<Long> createPropertyValue(@Valid @RequestBody ProductPropertyValueCreateReqVO createReqVO) {
36 return success(productPropertyValueService.createPropertyValue(createReqVO)); 41 return success(productPropertyValueService.createPropertyValue(createReqVO));
37 } 42 }
38 43
39 @PutMapping("/update") 44 @PutMapping("/update")
40 @Operation(summary = "更新属性值") 45 @Operation(summary = "更新属性值")
41 @PreAuthorize("@ss.hasPermission('product:property:update')") 46 @PreAuthorize("@ss.hasPermission('product:property:update')")
42 - public CommonResult<Boolean> updateProperty(@Valid @RequestBody ProductPropertyValueUpdateReqVO updateReqVO) { 47 + public CommonResult<Boolean> updatePropertyValue(@Valid @RequestBody ProductPropertyValueUpdateReqVO updateReqVO) {
43 productPropertyValueService.updatePropertyValue(updateReqVO); 48 productPropertyValueService.updatePropertyValue(updateReqVO);
44 return success(true); 49 return success(true);
45 } 50 }
@@ -48,7 +53,7 @@ public class ProductPropertyValueController { @@ -48,7 +53,7 @@ public class ProductPropertyValueController {
48 @Operation(summary = "删除属性值") 53 @Operation(summary = "删除属性值")
49 @Parameter(name = "id", description = "编号", required = true, example = "1024") 54 @Parameter(name = "id", description = "编号", required = true, example = "1024")
50 @PreAuthorize("@ss.hasPermission('product:property:delete')") 55 @PreAuthorize("@ss.hasPermission('product:property:delete')")
51 - public CommonResult<Boolean> deleteProperty(@RequestParam("id") Long id) { 56 + public CommonResult<Boolean> deletePropertyValue(@RequestParam("id") Long id) {
52 productPropertyValueService.deletePropertyValue(id); 57 productPropertyValueService.deletePropertyValue(id);
53 return success(true); 58 return success(true);
54 } 59 }
@@ -57,7 +62,7 @@ public class ProductPropertyValueController { @@ -57,7 +62,7 @@ public class ProductPropertyValueController {
57 @Operation(summary = "获得属性值") 62 @Operation(summary = "获得属性值")
58 @Parameter(name = "id", description = "编号", required = true, example = "1024") 63 @Parameter(name = "id", description = "编号", required = true, example = "1024")
59 @PreAuthorize("@ss.hasPermission('product:property:query')") 64 @PreAuthorize("@ss.hasPermission('product:property:query')")
60 - public CommonResult<ProductPropertyValueRespVO> getProperty(@RequestParam("id") Long id) { 65 + public CommonResult<ProductPropertyValueRespVO> getPropertyValue(@RequestParam("id") Long id) {
61 return success(ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueService.getPropertyValue(id))); 66 return success(ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueService.getPropertyValue(id)));
62 } 67 }
63 68
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java
@@ -38,11 +38,6 @@ public class ProductSkuBaseVO { @@ -38,11 +38,6 @@ public class ProductSkuBaseVO {
38 @NotNull(message = "图片地址不能为空") 38 @NotNull(message = "图片地址不能为空")
39 private String picUrl; 39 private String picUrl;
40 40
41 - @Schema(description = "SKU 状态", required = true, example = "1")  
42 - @NotNull(message = "SKU 状态不能为空")  
43 - @InEnum(CommonStatusEnum.class)  
44 - private Integer status;  
45 -  
46 @Schema(description = "库存", required = true, example = "1") 41 @Schema(description = "库存", required = true, example = "1")
47 @NotNull(message = "库存不能为空") 42 @NotNull(message = "库存不能为空")
48 private Integer stock; 43 private Integer stock;
@@ -55,21 +50,4 @@ public class ProductSkuBaseVO { @@ -55,21 +50,4 @@ public class ProductSkuBaseVO {
55 50
56 @Schema(description = "商品体积", example = "1024") // 单位:m^3 平米 51 @Schema(description = "商品体积", example = "1024") // 单位:m^3 平米
57 private Double volume; 52 private Double volume;
58 -  
59 - @Schema(description = "商品属性")  
60 - @Data  
61 - @AllArgsConstructor  
62 - @NoArgsConstructor  
63 - public static class Property {  
64 -  
65 - @Schema(description = "属性编号", required = true, example = "1")  
66 - @NotNull(message = "属性编号不能为空")  
67 - private Long propertyId;  
68 -  
69 - @Schema(description = "属性值编号", required = true, example = "1024")  
70 - @NotNull(message = "属性值编号不能为空")  
71 - private Long valueId;  
72 -  
73 - }  
74 -  
75 } 53 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuCreateOrUpdateReqVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.sku.vo; 1 package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
2 2
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 -import lombok.Data;  
5 -import lombok.EqualsAndHashCode;  
6 -import lombok.ToString; 4 +import lombok.*;
7 5
  6 +import javax.validation.constraints.NotNull;
8 import java.util.List; 7 import java.util.List;
9 8
10 @Schema(description = "管理后台 - 商品 SKU 创建/更新 Request VO") 9 @Schema(description = "管理后台 - 商品 SKU 创建/更新 Request VO")
@@ -12,6 +11,21 @@ import java.util.List; @@ -12,6 +11,21 @@ import java.util.List;
12 @EqualsAndHashCode(callSuper = true) 11 @EqualsAndHashCode(callSuper = true)
13 @ToString(callSuper = true) 12 @ToString(callSuper = true)
14 public class ProductSkuCreateOrUpdateReqVO extends ProductSkuBaseVO { 13 public class ProductSkuCreateOrUpdateReqVO extends ProductSkuBaseVO {
  14 + @Schema(description = "商品属性")
  15 + @Data
  16 + @AllArgsConstructor
  17 + @NoArgsConstructor
  18 + public static class Property {
  19 +
  20 + @Schema(description = "属性编号", required = true, example = "1")
  21 + @NotNull(message = "属性编号不能为空")
  22 + private Long propertyId;
  23 +
  24 + @Schema(description = "属性值编号", required = true, example = "1024")
  25 + @NotNull(message = "属性值编号不能为空")
  26 + private Long valueId;
  27 +
  28 + }
15 29
16 /** 30 /**
17 * 属性数组 31 * 属性数组
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuRespVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.sku.vo; 1 package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
2 2
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 -import lombok.Data;  
5 -import lombok.EqualsAndHashCode;  
6 -import lombok.ToString; 4 +import lombok.*;
7 5
  6 +import javax.validation.constraints.NotNull;
8 import java.time.LocalDateTime; 7 import java.time.LocalDateTime;
9 import java.util.List; 8 import java.util.List;
10 9
@@ -20,9 +19,26 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { @@ -20,9 +19,26 @@ public class ProductSkuRespVO extends ProductSkuBaseVO {
20 @Schema(description = "创建时间") 19 @Schema(description = "创建时间")
21 private LocalDateTime createTime; 20 private LocalDateTime createTime;
22 21
  22 + @Schema(description = "商品属性")
  23 + @Data
  24 + @AllArgsConstructor
  25 + @NoArgsConstructor
  26 + public static class Property {
  27 +
  28 + @Schema(description = "属性编号", required = true, example = "1")
  29 + @NotNull(message = "属性编号不能为空")
  30 + private Long propertyId;
  31 +
  32 + @Schema(description = "属性值编号", required = true, example = "1024")
  33 + @NotNull(message = "属性值编号不能为空")
  34 + private Long valueId;
  35 +
  36 + @Schema(description = "属性值", example = "1024")
  37 + private String value;
  38 + }
23 /** 39 /**
24 * 属性数组 40 * 属性数组
25 */ 41 */
26 - private List<Property> properties; 42 + private List<ProductSkuCreateOrUpdateReqVO.Property> properties;
27 43
28 } 44 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
@@ -87,7 +87,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { @@ -87,7 +87,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
87 // 1、校验属性项存在 87 // 1、校验属性项存在
88 Set<Long> propertyIds = skus.stream().filter(p -> p.getProperties() != null) 88 Set<Long> propertyIds = skus.stream().filter(p -> p.getProperties() != null)
89 .flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性 89 .flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性
90 - .map(ProductSkuBaseVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId,最后形成集合 90 + .map(ProductSkuCreateOrUpdateReqVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId,最后形成集合
91 .collect(Collectors.toSet()); 91 .collect(Collectors.toSet());
92 List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyIds); 92 List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyIds);
93 if (propertyList.size() != propertyIds.size()) { 93 if (propertyList.size() != propertyIds.size()) {
@@ -114,7 +114,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { @@ -114,7 +114,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
114 // 4. 最后校验,每个 Sku 之间不是重复的 114 // 4. 最后校验,每个 Sku 之间不是重复的
115 Set<Set<Long>> skuAttrValues = new HashSet<>(); // 每个元素,都是一个 Sku 的 attrValueId 集合。这样,通过最外层的 Set ,判断是否有重复的. 115 Set<Set<Long>> skuAttrValues = new HashSet<>(); // 每个元素,都是一个 Sku 的 attrValueId 集合。这样,通过最外层的 Set ,判断是否有重复的.
116 for (ProductSkuCreateOrUpdateReqVO sku : skus) { 116 for (ProductSkuCreateOrUpdateReqVO sku : skus) {
117 - if (!skuAttrValues.add(convertSet(sku.getProperties(), ProductSkuBaseVO.Property::getValueId))) { // 添加失败,说明重复 117 + if (!skuAttrValues.add(convertSet(sku.getProperties(), ProductSkuCreateOrUpdateReqVO.Property::getValueId))) { // 添加失败,说明重复
118 throw exception(ErrorCodeConstants.SPU_SKU_NOT_DUPLICATE); 118 throw exception(ErrorCodeConstants.SPU_SKU_NOT_DUPLICATE);
119 } 119 }
120 } 120 }
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceTest.java
@@ -68,11 +68,9 @@ public class ProductSkuServiceTest extends BaseDbUnitTest { @@ -68,11 +68,9 @@ public class ProductSkuServiceTest extends BaseDbUnitTest {
68 List<ProductSkuCreateOrUpdateReqVO> skus = Arrays.asList( 68 List<ProductSkuCreateOrUpdateReqVO> skus = Arrays.asList(
69 randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试更新 69 randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试更新
70 o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 20L))); 70 o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 20L)));
71 - o.setStatus(CommonStatusEnum.ENABLE.getStatus());  
72 }), 71 }),
73 randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试新增 72 randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试新增
74 o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 40L))); 73 o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 40L)));
75 - o.setStatus(CommonStatusEnum.ENABLE.getStatus());  
76 }) 74 })
77 ); 75 );
78 76