mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	【代码优化】商城: 校验商品分类增加商品分类层级校验
This commit is contained in:
		@@ -87,6 +87,7 @@ public interface ProductCategoryService {
 | 
				
			|||||||
     * 校验商品分类是否有效。如下情况,视为无效:
 | 
					     * 校验商品分类是否有效。如下情况,视为无效:
 | 
				
			||||||
     * 1. 商品分类编号不存在
 | 
					     * 1. 商品分类编号不存在
 | 
				
			||||||
     * 2. 商品分类被禁用
 | 
					     * 2. 商品分类被禁用
 | 
				
			||||||
 | 
					     * 3. 商品分类层级校验,必须使用第二级的商品分类及以下
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param ids 商品分类编号数组
 | 
					     * @param ids 商品分类编号数组
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@ import java.util.Map;
 | 
				
			|||||||
import java.util.Objects;
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL;
 | 
				
			||||||
import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.PARENT_ID_NULL;
 | 
					import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.PARENT_ID_NULL;
 | 
				
			||||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
 | 
					import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -119,6 +120,10 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
 | 
				
			|||||||
            if (!CommonStatusEnum.ENABLE.getStatus().equals(category.getStatus())) {
 | 
					            if (!CommonStatusEnum.ENABLE.getStatus().equals(category.getStatus())) {
 | 
				
			||||||
                throw exception(CATEGORY_DISABLED, category.getName());
 | 
					                throw exception(CATEGORY_DISABLED, category.getName());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            // 校验层级
 | 
				
			||||||
 | 
					            if (getCategoryLevel(id) < CATEGORY_LEVEL) {
 | 
				
			||||||
 | 
					                throw exception(SPU_SAVE_FAIL_CATEGORY_LEVEL_ERROR);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user