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

This commit is contained in:
puhui999 2023-04-30 17:34:56 +08:00
parent f56d394830
commit 24a56bb45f
6 changed files with 48 additions and 37 deletions

View File

@ -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)));
}

View File

@ -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;
}
}

View File

@ -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;
}
/**
* 属性数组

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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());
})
);