From 5750adeb03e87ed2984dc33bf83de904c9032bbb Mon Sep 17 00:00:00 2001 From: Agent Date: Tue, 31 Mar 2026 16:03:36 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=98=AF=E5=90=A6=E6=9C=89=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/building/service/impl/ProductServiceImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/example/building/service/impl/ProductServiceImpl.java b/src/main/java/com/example/building/service/impl/ProductServiceImpl.java index 8f1e998..7695616 100644 --- a/src/main/java/com/example/building/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/example/building/service/impl/ProductServiceImpl.java @@ -68,9 +68,16 @@ public class ProductServiceImpl implements ProductService { /** * 删除分类 + * 检查是否有商品使用该分类,存在则不允许删除 */ @Override public void deleteCategory(String id) { + // 检查是否有商品使用该分类 + Long count = productMapper.selectCount(new LambdaQueryWrapper() + .eq(Product::getCategoryId, id)); + if (count > 0) { + throw new RuntimeException("该分类下有商品,无法删除"); + } categoryMapper.deleteById(id); }