文档:增加功能列表

后端 + 前端:完善展示分类功能
This commit is contained in:
YunaiV
2019-05-05 20:19:38 +08:00
parent 83a3689088
commit dcc58fbba4
9 changed files with 480 additions and 276 deletions

View File

@@ -14,6 +14,7 @@ public enum ProductErrorCodeEnum {
PRODUCT_CATEGORY_STATUS_EQUALS(1002001003, "商品分类已经是该状态"),
PRODUCT_CATEGORY_DELETE_ONLY_DISABLE(1002001004, "只有关闭的商品分类才可以删除"),
PRODUCT_CATEGORY_MUST_ENABLE(1002001005, "只有开启的商品分类,才可以使用"),
PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2(1002001005, "父分类必须是一级分类"),
// ========== PRODUCT SPU + SKU 模块 ==========
PRODUCT_SKU_ATTR_CANT_NOT_DUPLICATE(1003002000, "一个 Sku 下,不能有重复的规格"),
@@ -46,4 +47,4 @@ public enum ProductErrorCodeEnum {
return message;
}
}
}

View File

@@ -47,11 +47,8 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
@Override
public CommonResult<ProductCategoryBO> addProductCategory(Integer adminId, ProductCategoryAddDTO productCategoryAddDTO) {
// 校验父分类是否存在
if (!ProductCategoryConstants.PID_ROOT.equals(productCategoryAddDTO.getPid())
&& productCategoryMapper.selectById(productCategoryAddDTO.getPid()) == null) {
return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode());
}
// 校验父分类
validParent(productCategoryAddDTO.getPid());
// 保存到数据库
ProductCategoryDO productCategory = ProductCategoryConvert.INSTANCE.convert(productCategoryAddDTO)
.setStatus(ProductCategoryConstants.STATUS_ENABLE);
@@ -65,10 +62,8 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
@Override
public CommonResult<Boolean> updateProductCategory(Integer adminId, ProductCategoryUpdateDTO productCategoryUpdateDTO) {
// 校验分类是否存在
if (productCategoryMapper.selectById(productCategoryUpdateDTO.getId()) == null) {
return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode());
}
// 校验分类
validParent(productCategoryUpdateDTO.getPid());
// 校验不能设置自己为父分类
if (productCategoryUpdateDTO.getId().equals(productCategoryUpdateDTO.getPid())) {
return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_SELF.getCode());
@@ -153,4 +148,18 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|| ProductCategoryConstants.STATUS_DISABLE.equals(status);
}
private void validParent(Integer pid) {
if (!ProductCategoryConstants.PID_ROOT.equals(pid)) {
ProductCategoryDO parentCategory = productCategoryMapper.selectById(pid);
// 校验父分类是否存在
if (parentCategory == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode());
}
// 父分类必须是一级分类
if (!ProductCategoryConstants.PID_ROOT.equals(parentCategory.getPid())) {
throw ServiceExceptionUtil.exception((ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2.getCode()));
}
}
}
}