mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
移除ProductSku相关的status属性,修改Property
This commit is contained in:
parent
f56d394830
commit
24a56bb45f
@ -1,5 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.product.controller.admin.property;
|
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.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
|
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.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 商品属性值")
|
@Tag(name = "管理后台 - 商品属性值")
|
||||||
@ -32,14 +37,14 @@ public class ProductPropertyValueController {
|
|||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建属性值")
|
@Operation(summary = "创建属性值")
|
||||||
@PreAuthorize("@ss.hasPermission('product:property:create')")
|
@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));
|
return success(productPropertyValueService.createPropertyValue(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "更新属性值")
|
@Operation(summary = "更新属性值")
|
||||||
@PreAuthorize("@ss.hasPermission('product:property:update')")
|
@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);
|
productPropertyValueService.updatePropertyValue(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
@ -48,7 +53,7 @@ public class ProductPropertyValueController {
|
|||||||
@Operation(summary = "删除属性值")
|
@Operation(summary = "删除属性值")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
@PreAuthorize("@ss.hasPermission('product:property:delete')")
|
@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);
|
productPropertyValueService.deletePropertyValue(id);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
@ -57,7 +62,7 @@ public class ProductPropertyValueController {
|
|||||||
@Operation(summary = "获得属性值")
|
@Operation(summary = "获得属性值")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
@PreAuthorize("@ss.hasPermission('product:property:query')")
|
@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)));
|
return success(ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueService.getPropertyValue(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +38,6 @@ public class ProductSkuBaseVO {
|
|||||||
@NotNull(message = "图片地址不能为空")
|
@NotNull(message = "图片地址不能为空")
|
||||||
private String picUrl;
|
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")
|
@Schema(description = "库存", required = true, example = "1")
|
||||||
@NotNull(message = "库存不能为空")
|
@NotNull(message = "库存不能为空")
|
||||||
private Integer stock;
|
private Integer stock;
|
||||||
@ -55,21 +50,4 @@ public class ProductSkuBaseVO {
|
|||||||
|
|
||||||
@Schema(description = "商品体积", example = "1024") // 单位:m^3 平米
|
@Schema(description = "商品体积", example = "1024") // 单位:m^3 平米
|
||||||
private Double volume;
|
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
|
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.*;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 商品 SKU 创建/更新 Request VO")
|
@Schema(description = "管理后台 - 商品 SKU 创建/更新 Request VO")
|
||||||
@ -12,6 +11,21 @@ import java.util.List;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class ProductSkuCreateOrUpdateReqVO extends ProductSkuBaseVO {
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 属性数组
|
* 属性数组
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
|
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.*;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -20,9 +19,26 @@ public class ProductSkuRespVO extends ProductSkuBaseVO {
|
|||||||
@Schema(description = "创建时间")
|
@Schema(description = "创建时间")
|
||||||
private LocalDateTime createTime;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
|
|||||||
// 1、校验属性项存在
|
// 1、校验属性项存在
|
||||||
Set<Long> propertyIds = skus.stream().filter(p -> p.getProperties() != null)
|
Set<Long> propertyIds = skus.stream().filter(p -> p.getProperties() != null)
|
||||||
.flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性
|
.flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性
|
||||||
.map(ProductSkuBaseVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId,最后形成集合
|
.map(ProductSkuCreateOrUpdateReqVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId,最后形成集合
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyIds);
|
List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyIds);
|
||||||
if (propertyList.size() != propertyIds.size()) {
|
if (propertyList.size() != propertyIds.size()) {
|
||||||
@ -114,7 +114,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
|
|||||||
// 4. 最后校验,每个 Sku 之间不是重复的
|
// 4. 最后校验,每个 Sku 之间不是重复的
|
||||||
Set<Set<Long>> skuAttrValues = new HashSet<>(); // 每个元素,都是一个 Sku 的 attrValueId 集合。这样,通过最外层的 Set ,判断是否有重复的.
|
Set<Set<Long>> skuAttrValues = new HashSet<>(); // 每个元素,都是一个 Sku 的 attrValueId 集合。这样,通过最外层的 Set ,判断是否有重复的.
|
||||||
for (ProductSkuCreateOrUpdateReqVO sku : skus) {
|
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);
|
throw exception(ErrorCodeConstants.SPU_SKU_NOT_DUPLICATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,11 +68,9 @@ public class ProductSkuServiceTest extends BaseDbUnitTest {
|
|||||||
List<ProductSkuCreateOrUpdateReqVO> skus = Arrays.asList(
|
List<ProductSkuCreateOrUpdateReqVO> skus = Arrays.asList(
|
||||||
randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试更新
|
randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试更新
|
||||||
o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 20L)));
|
o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 20L)));
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
}),
|
}),
|
||||||
randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试新增
|
randomPojo(ProductSkuCreateOrUpdateReqVO.class, o -> { // 测试新增
|
||||||
o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 40L)));
|
o.setProperties(singletonList(new ProductSkuCreateOrUpdateReqVO.Property(10L, 40L)));
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user