From 24a56bb45f9bd11145042aa3781aa7d51b877e3d Mon Sep 17 00:00:00 2001
From: puhui999 <puhui999@163.com>
Date: Sun, 30 Apr 2023 17:34:56 +0800
Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4ProductSku=E7=9B=B8=E5=85=B3?=
 =?UTF-8?q?=E7=9A=84status=E5=B1=9E=E6=80=A7=EF=BC=8C=E4=BF=AE=E6=94=B9Pro?=
 =?UTF-8?q?perty?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../ProductPropertyValueController.java       | 13 ++++++----
 .../admin/sku/vo/ProductSkuBaseVO.java        | 22 -----------------
 .../sku/vo/ProductSkuCreateOrUpdateReqVO.java | 20 +++++++++++++---
 .../admin/sku/vo/ProductSkuRespVO.java        | 24 +++++++++++++++----
 .../service/sku/ProductSkuServiceImpl.java    |  4 ++--
 .../service/sku/ProductSkuServiceTest.java    |  2 --
 6 files changed, 48 insertions(+), 37 deletions(-)

diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java
index 92ce6bee0..fbac32712 100644
--- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java
+++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java
@@ -1,5 +1,7 @@
 package cn.iocoder.yudao.module.product.controller.admin.property;
 
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.crypto.symmetric.AES;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
@@ -18,6 +20,9 @@ import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.validation.Valid;
 
+import java.util.Arrays;
+import java.util.List;
+
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
 @Tag(name = "管理后台 - 商品属性值")
@@ -32,14 +37,14 @@ public class ProductPropertyValueController {
     @PostMapping("/create")
     @Operation(summary = "创建属性值")
     @PreAuthorize("@ss.hasPermission('product:property:create')")
-    public CommonResult<Long> createProperty(@Valid @RequestBody ProductPropertyValueCreateReqVO createReqVO) {
+    public CommonResult<Long> createPropertyValue(@Valid @RequestBody ProductPropertyValueCreateReqVO createReqVO) {
         return success(productPropertyValueService.createPropertyValue(createReqVO));
     }
 
     @PutMapping("/update")
     @Operation(summary = "更新属性值")
     @PreAuthorize("@ss.hasPermission('product:property:update')")
-    public CommonResult<Boolean> updateProperty(@Valid @RequestBody ProductPropertyValueUpdateReqVO updateReqVO) {
+    public CommonResult<Boolean> updatePropertyValue(@Valid @RequestBody ProductPropertyValueUpdateReqVO updateReqVO) {
         productPropertyValueService.updatePropertyValue(updateReqVO);
         return success(true);
     }
@@ -48,7 +53,7 @@ public class ProductPropertyValueController {
     @Operation(summary = "删除属性值")
     @Parameter(name = "id", description = "编号", required = true, example = "1024")
     @PreAuthorize("@ss.hasPermission('product:property:delete')")
-    public CommonResult<Boolean> deleteProperty(@RequestParam("id") Long id) {
+    public CommonResult<Boolean> deletePropertyValue(@RequestParam("id") Long id) {
         productPropertyValueService.deletePropertyValue(id);
         return success(true);
     }
@@ -57,7 +62,7 @@ public class ProductPropertyValueController {
     @Operation(summary = "获得属性值")
     @Parameter(name = "id", description = "编号", required = true, example = "1024")
     @PreAuthorize("@ss.hasPermission('product:property:query')")
-    public CommonResult<ProductPropertyValueRespVO> getProperty(@RequestParam("id") Long id) {
+    public CommonResult<ProductPropertyValueRespVO> getPropertyValue(@RequestParam("id") Long id) {
         return success(ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueService.getPropertyValue(id)));
     }
 
diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java
index f28220046..e9c9bb48c 100755
--- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java
+++ b/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 {
     @NotNull(message = "图片地址不能为空")
     private String picUrl;
 
-    @Schema(description = "SKU 状态", required = true, example = "1")
-    @NotNull(message = "SKU 状态不能为空")
-    @InEnum(CommonStatusEnum.class)
-    private Integer status;
-
     @Schema(description = "库存", required = true, example = "1")
     @NotNull(message = "库存不能为空")
     private Integer stock;
@@ -55,21 +50,4 @@ public class ProductSkuBaseVO {
 
     @Schema(description = "商品体积", example = "1024") // 单位:m^3 平米
     private Double volume;
-
-    @Schema(description = "商品属性")
-    @Data
-    @AllArgsConstructor
-    @NoArgsConstructor
-    public static class Property {
-
-        @Schema(description = "属性编号", required = true, example = "1")
-        @NotNull(message = "属性编号不能为空")
-        private Long propertyId;
-
-        @Schema(description = "属性值编号", required = true, example = "1024")
-        @NotNull(message = "属性值编号不能为空")
-        private Long valueId;
-
-    }
-
 }
diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuCreateOrUpdateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuCreateOrUpdateReqVO.java
index 496475f99..54de91cf1 100755
--- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuCreateOrUpdateReqVO.java
+++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuCreateOrUpdateReqVO.java
@@ -1,10 +1,9 @@
 package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
 
 import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
+import lombok.*;
 
+import javax.validation.constraints.NotNull;
 import java.util.List;
 
 @Schema(description = "管理后台 - 商品 SKU 创建/更新 Request VO")
@@ -12,6 +11,21 @@ import java.util.List;
 @EqualsAndHashCode(callSuper = true)
 @ToString(callSuper = true)
 public class ProductSkuCreateOrUpdateReqVO extends ProductSkuBaseVO {
+    @Schema(description = "商品属性")
+    @Data
+    @AllArgsConstructor
+    @NoArgsConstructor
+    public static class Property {
+
+        @Schema(description = "属性编号", required = true, example = "1")
+        @NotNull(message = "属性编号不能为空")
+        private Long propertyId;
+
+        @Schema(description = "属性值编号", required = true, example = "1024")
+        @NotNull(message = "属性值编号不能为空")
+        private Long valueId;
+
+    }
 
     /**
      * 属性数组
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 95e394ada..a229fa826 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
@@ -1,10 +1,9 @@
 package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
 
 import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
+import lombok.*;
 
+import javax.validation.constraints.NotNull;
 import java.time.LocalDateTime;
 import java.util.List;
 
@@ -20,9 +19,26 @@ public class ProductSkuRespVO extends ProductSkuBaseVO {
     @Schema(description = "创建时间")
     private LocalDateTime createTime;
 
+    @Schema(description = "商品属性")
+    @Data
+    @AllArgsConstructor
+    @NoArgsConstructor
+    public static class Property {
+
+        @Schema(description = "属性编号", required = true, example = "1")
+        @NotNull(message = "属性编号不能为空")
+        private Long propertyId;
+
+        @Schema(description = "属性值编号", required = true, example = "1024")
+        @NotNull(message = "属性值编号不能为空")
+        private Long valueId;
+
+        @Schema(description = "属性值", example = "1024")
+        private String value;
+    }
     /**
      * 属性数组
      */
-    private List<Property> properties;
+    private List<ProductSkuCreateOrUpdateReqVO.Property> properties;
 
 }
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 04430764b..a314318fc 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
@@ -87,7 +87,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
         // 1、校验属性项存在
         Set<Long> propertyIds = skus.stream().filter(p -> p.getProperties() != null)
                 .flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性
-                .map(ProductSkuBaseVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId,最后形成集合
+                .map(ProductSkuCreateOrUpdateReqVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId,最后形成集合
                 .collect(Collectors.toSet());
         List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyIds);
         if (propertyList.size() != propertyIds.size()) {
@@ -114,7 +114,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
         // 4. 最后校验,每个 Sku 之间不是重复的
         Set<Set<Long>> skuAttrValues = new HashSet<>(); // 每个元素,都是一个 Sku 的 attrValueId 集合。这样,通过最外层的 Set ,判断是否有重复的.
         for (ProductSkuCreateOrUpdateReqVO sku : skus) {
-            if (!skuAttrValues.add(convertSet(sku.getProperties(), ProductSkuBaseVO.Property::getValueId))) { // 添加失败,说明重复
+            if (!skuAttrValues.add(convertSet(sku.getProperties(), ProductSkuCreateOrUpdateReqVO.Property::getValueId))) { // 添加失败,说明重复
                 throw exception(ErrorCodeConstants.SPU_SKU_NOT_DUPLICATE);
             }
         }
diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceTest.java
index ec088cfdd..a6651c8b2 100644
--- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceTest.java
+++ b/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 {
         List<ProductSkuCreateOrUpdateReqVO> skus = Arrays.asList(
                 randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试更新
                     o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 20L)));
-                    o.setStatus(CommonStatusEnum.ENABLE.getStatus());
                 }),
                 randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试新增
                     o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 40L)));
-                    o.setStatus(CommonStatusEnum.ENABLE.getStatus());
                 })
         );