|
@@ -36,6 +36,7 @@ import java.util.stream.Collectors;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
|
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS;
|
|
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS;
|
|
|
|
+import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_SAVE_FAIL_CATEGORY_LEVEL_ERROR;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 商品 SPU Service 实现类
|
|
* 商品 SPU Service 实现类
|
|
@@ -66,7 +67,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
@Transactional
|
|
@Transactional
|
|
public Long createSpu(ProductSpuCreateReqVO createReqVO) {
|
|
public Long createSpu(ProductSpuCreateReqVO createReqVO) {
|
|
// 校验分类
|
|
// 校验分类
|
|
- categoryService.validateCategoryLevel(createReqVO.getCategoryId());
|
|
|
|
|
|
+ validateCategory(createReqVO.getCategoryId());
|
|
// 校验品牌
|
|
// 校验品牌
|
|
brandService.validateProductBrand(createReqVO.getBrandId());
|
|
brandService.validateProductBrand(createReqVO.getBrandId());
|
|
// 校验SKU
|
|
// 校验SKU
|
|
@@ -91,7 +92,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
// 校验 SPU 是否存在
|
|
// 校验 SPU 是否存在
|
|
validateSpuExists(updateReqVO.getId());
|
|
validateSpuExists(updateReqVO.getId());
|
|
// 校验分类
|
|
// 校验分类
|
|
- categoryService.validateCategoryLevel(updateReqVO.getCategoryId());
|
|
|
|
|
|
+ validateCategory(updateReqVO.getCategoryId());
|
|
// 校验品牌
|
|
// 校验品牌
|
|
brandService.validateProductBrand(updateReqVO.getBrandId());
|
|
brandService.validateProductBrand(updateReqVO.getBrandId());
|
|
// 校验SKU
|
|
// 校验SKU
|
|
@@ -109,6 +110,19 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|
productSkuService.updateSkus(updateObj.getId(), updateObj.getName(), updateReqVO.getSkus());
|
|
productSkuService.updateSkus(updateObj.getId(), updateObj.getName(), updateReqVO.getSkus());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 校验商品分类是否合法
|
|
|
|
+ *
|
|
|
|
+ * @param id 商品分类编号
|
|
|
|
+ */
|
|
|
|
+ private void validateCategory(Long id) {
|
|
|
|
+ categoryService.validateCategory(id);
|
|
|
|
+ // 校验层级
|
|
|
|
+ if (categoryService.getCategoryLevel(id) != 3) {
|
|
|
|
+ throw exception(SPU_SAVE_FAIL_CATEGORY_LEVEL_ERROR);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
public void deleteSpu(Long id) {
|
|
public void deleteSpu(Long id) {
|