feature(uniapp商品): 新增商品数据

This commit is contained in:
luowenfeng
2022-08-22 21:20:49 +08:00
parent 617573a59b
commit 8de29d302c
5 changed files with 28 additions and 18 deletions

View File

@ -19,8 +19,7 @@ public class ProductSkuBaseVO {
// TODO @franky类似这种字段有额外说明的。可以写成 @ApiModelProperty(value = "规格值数组", required = true, notes = "json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]")
@ApiModelProperty(value = "规格值数组-json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true)
@NotNull(message = "规格值数组-json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空")
@ApiModelProperty(value = "规格值数组-json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]")
private List<Property> properties;
@ApiModelProperty(value = "销售价格,单位:分", required = true)

View File

@ -91,7 +91,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
@Override
public void validateSkus(List<ProductSkuCreateReqVO> list) {
List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList());
List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> Optional.of(p.getProperties()).orElse(new ArrayList<>()).stream()).collect(Collectors.toList());
// 校验规格属性以及规格值是否存在
List<Long> propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList());
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds);

View File

@ -57,7 +57,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
categoryService.validateProductCategory(createReqVO.getCategoryId());
// 校验SKU
List<ProductSkuCreateReqVO> skuCreateReqList = createReqVO.getSkus();
productSkuService.validateSkus(skuCreateReqList);
if(createReqVO.getSpecType() == 1) {
productSkuService.validateSkus(skuCreateReqList);
}
// 插入SPU
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
ProductSpuMapper.insert(spu);
@ -81,7 +83,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
categoryService.validateProductCategory(updateReqVO.getCategoryId());
// 校验SKU
List<ProductSkuCreateReqVO> skuCreateReqList = updateReqVO.getSkus();
productSkuService.validateSkus(skuCreateReqList);
if(updateReqVO.getSpecType() == 1) {
productSkuService.validateSkus(skuCreateReqList);
}
// 更新
ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
ProductSpuMapper.updateById(updateObj);