This commit is contained in:
@@ -68,9 +68,16 @@ public class ProductServiceImpl implements ProductService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除分类
|
* 删除分类
|
||||||
|
* 检查是否有商品使用该分类,存在则不允许删除
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteCategory(String id) {
|
public void deleteCategory(String id) {
|
||||||
|
// 检查是否有商品使用该分类
|
||||||
|
Long count = productMapper.selectCount(new LambdaQueryWrapper<Product>()
|
||||||
|
.eq(Product::getCategoryId, id));
|
||||||
|
if (count > 0) {
|
||||||
|
throw new RuntimeException("该分类下有商品,无法删除");
|
||||||
|
}
|
||||||
categoryMapper.deleteById(id);
|
categoryMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user