错误码分组
This commit is contained in:
@@ -51,6 +51,11 @@ public enum ProductErrorCodeEnum implements ServiceExceptionUtil.Enumerable {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroup() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package cn.iocoder.mall.product.biz.enums.category;
|
||||
|
||||
public interface ProductCategoryConstants {
|
||||
|
||||
/**
|
||||
* 状态 - 开启
|
||||
*/
|
||||
Integer STATUS_ENABLE = 1;
|
||||
/**
|
||||
* 状态 - 关闭
|
||||
*/
|
||||
Integer STATUS_DISABLE = 2;
|
||||
|
||||
/**
|
||||
* 父分类编号 - 根节点
|
||||
*/
|
||||
Integer PID_ROOT = 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.product.biz.enums.category;
|
||||
|
||||
import cn.iocoder.common.framework.core.IntArrayValuable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/12
|
||||
* @Description: 商品分类节点枚举
|
||||
*/
|
||||
public enum ProductCategoryNodeEnum{
|
||||
|
||||
/**
|
||||
* 根节点
|
||||
*/
|
||||
ROOT(0);
|
||||
|
||||
private final Integer id;
|
||||
|
||||
ProductCategoryNodeEnum(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package cn.iocoder.mall.product.biz.bo.product;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品分类 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Deprecated // TODO jiangweifan 后面确认无使用后删除
|
||||
public class ProductCategoryBO implements Serializable {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*
|
||||
* 如果不存在父级,则 pid = 0 。
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 1-开启
|
||||
* 2-关闭
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -40,15 +40,9 @@ public interface ProductSpuConvert {
|
||||
})
|
||||
ProductSpuBO convert(ProductSpuDO spu);
|
||||
|
||||
@Named("translatePicUrlsFromString")
|
||||
default List<String> translatePicUrlsFromString(String picUrls) {
|
||||
return StringUtil.split(picUrls, ",");
|
||||
}
|
||||
|
||||
@Mappings({})
|
||||
List<ProductSpuBO> convert(List<ProductSpuDO> spus);
|
||||
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "picUrls", target = "picUrls", ignore = true)
|
||||
})
|
||||
@@ -131,4 +125,9 @@ public interface ProductSpuConvert {
|
||||
return spuDetailList;
|
||||
}
|
||||
|
||||
@Named("translatePicUrlsFromString")
|
||||
default List<String> translatePicUrlsFromString(String picUrls) {
|
||||
return StringUtil.split(picUrls, ",");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.iocoder.mall.product.biz.dao.category;
|
||||
|
||||
import cn.iocoder.mall.product.biz.dataobject.category.ProductCategoryDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
@@ -11,5 +12,14 @@ import org.springframework.stereotype.Repository;
|
||||
*/
|
||||
@Repository
|
||||
public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> {
|
||||
|
||||
/**
|
||||
* 查询商品分类的下一级子分类数量
|
||||
* @param productCategoryId
|
||||
* @return
|
||||
*/
|
||||
default Integer selectChildCategoryCount(Integer productCategoryId) {
|
||||
return this.selectCount(
|
||||
Wrappers.<ProductCategoryDO>lambdaQuery().eq(ProductCategoryDO::getPid, productCategoryId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
// TODO FROM 芋艿 to sunderui && q2118cs:貌似重复了,只要保留一个哈
|
||||
public class ProductSpuAddDTO {
|
||||
|
||||
// ========== 基本信息 =========
|
||||
|
||||
@@ -11,9 +11,8 @@ import cn.iocoder.mall.product.biz.dto.category.ProductCategoryDeleteDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateStatusDTO;
|
||||
import cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryConstants;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryNodeEnum;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryStatusEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -68,7 +67,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_SELF);
|
||||
}
|
||||
// 校验父分类是否存在
|
||||
if (!ProductCategoryConstants.PID_ROOT.equals(productCategoryUpdateDTO.getPid())
|
||||
if (!ProductCategoryNodeEnum.ROOT.getId().equals(productCategoryUpdateDTO.getPid())
|
||||
&& productCategoryMapper.selectById(productCategoryUpdateDTO.getPid()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
|
||||
}
|
||||
@@ -114,9 +113,8 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_DISABLE);
|
||||
}
|
||||
// 只有不存在子分类才可以删除
|
||||
Integer childCount = productCategoryMapper.selectCount(
|
||||
Wrappers.<ProductCategoryDO>lambdaQuery().eq(ProductCategoryDO::getPid, productCategoryId)
|
||||
);
|
||||
// TODO FROM 芋艿 to jiangweifan:Wrappers 只用在 Mapper 层 [DONE]
|
||||
Integer childCount = productCategoryMapper.selectChildCategoryCount(productCategoryId);
|
||||
if (childCount > 0) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD);
|
||||
}
|
||||
@@ -128,14 +126,14 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
}
|
||||
|
||||
private void validParent(Integer pid) {
|
||||
if (!ProductCategoryConstants.PID_ROOT.equals(pid)) {
|
||||
if (!ProductCategoryNodeEnum.ROOT.getId().equals(pid)) {
|
||||
ProductCategoryDO parentCategory = productCategoryMapper.selectById(pid);
|
||||
// 校验父分类是否存在
|
||||
if (parentCategory == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
|
||||
}
|
||||
// 父分类必须是一级分类
|
||||
if (!ProductCategoryConstants.PID_ROOT.equals(parentCategory.getPid())) {
|
||||
if (!ProductCategoryNodeEnum.ROOT.getId().equals(parentCategory.getPid())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2);
|
||||
}
|
||||
}
|
||||
@@ -149,7 +147,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode());
|
||||
}
|
||||
// 只有禁用的商品分类才可以删除
|
||||
if (ProductCategoryConstants.STATUS_DISABLE.equals(productCategory.getStatus())) {
|
||||
if (ProductCategoryStatusEnum.DISABLED.getStatus().equals(productCategory.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_MUST_ENABLE.getCode());
|
||||
}
|
||||
// 返回结果
|
||||
|
||||
@@ -15,7 +15,7 @@ import cn.iocoder.mall.product.biz.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.mall.product.biz.dto.sku.ProductSkuAddOrUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.sku.ProductSpuAddDTO;
|
||||
import cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryConstants;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryNodeEnum;
|
||||
import cn.iocoder.mall.product.biz.enums.spu.ProductSpuConstants;
|
||||
import cn.iocoder.mall.product.biz.service.attr.ProductAttrService;
|
||||
import cn.iocoder.mall.product.biz.service.category.ProductCategoryService;
|
||||
@@ -76,7 +76,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||
public ProductSpuDetailBO addProductSpu0(Integer adminId, ProductSpuAddDTO productSpuAddDTO) {
|
||||
// 校验商品分类分类存在
|
||||
ProductCategoryDO category = productCategoryService.validProductCategory(productSpuAddDTO.getCid());
|
||||
if (ProductCategoryConstants.PID_ROOT.equals(category.getPid())) {
|
||||
if (ProductCategoryNodeEnum.ROOT.getId().equals(category.getPid())) {
|
||||
// 商品只能添加到二级分类下
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_SPU_CATEGORY_MUST_BE_LEVEL2.getCode());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import cn.iocoder.mall.product.biz.dto.category.ProductCategoryAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryDeleteDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateStatusDTO;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryConstants;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryNodeEnum;
|
||||
import cn.iocoder.mall.product.biz.service.category.ProductCategoryService;
|
||||
import cn.iocoder.mall.product.rest.convert.category.AdminsProductCategoryConvert;
|
||||
import cn.iocoder.mall.product.rest.request.category.AdminsProductCategoryAddRequest;
|
||||
@@ -49,7 +49,7 @@ public class AdminsProductCategoryController {
|
||||
Map<Integer, AdminsProductCategoryTreeNodeResponse> treeNodeMap = productCategories.stream().collect(Collectors.toMap(ProductCategoryBO::getId, AdminsProductCategoryConvert.INSTANCE::convertToTreeNodeResponse));
|
||||
// 处理父子关系
|
||||
treeNodeMap.values().stream()
|
||||
.filter(node -> !node.getPid().equals(ProductCategoryConstants.PID_ROOT))
|
||||
.filter(node -> !node.getPid().equals(ProductCategoryNodeEnum.ROOT.getId()))
|
||||
.forEach((childNode) -> {
|
||||
// 获得父节点
|
||||
AdminsProductCategoryTreeNodeResponse parentNode = treeNodeMap.get(childNode.getPid());
|
||||
@@ -61,7 +61,7 @@ public class AdminsProductCategoryController {
|
||||
});
|
||||
// 获得到所有的根节点
|
||||
List<AdminsProductCategoryTreeNodeResponse> rootNodes = treeNodeMap.values().stream()
|
||||
.filter(node -> node.getPid().equals(ProductCategoryConstants.PID_ROOT))
|
||||
.filter(node -> node.getPid().equals(ProductCategoryNodeEnum.ROOT.getId()))
|
||||
.sorted(Comparator.comparing(AdminsProductCategoryTreeNodeResponse::getSort))
|
||||
.collect(Collectors.toList());
|
||||
return success(rootNodes);
|
||||
|
||||
Reference in New Issue
Block a user