From 970a13bc5b24cdbd8b583fcdce638af8f0fbba52 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Tue, 23 Apr 2024 20:07:55 +0800 Subject: [PATCH] =?UTF-8?q?:rocket:=20=E5=88=A0=E9=99=A4=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/atguigu/constant/MessageConstant.java | 4 +--- .../auth/controller/SysMenuController.java | 2 +- .../atguigu/auth/service/SysMenuService.java | 7 ++++++ .../auth/service/impl/SysMenuServiceImpl.java | 24 +++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/common/service-util/src/main/java/com/atguigu/constant/MessageConstant.java b/common/service-util/src/main/java/com/atguigu/constant/MessageConstant.java index 67b1720..b949152 100644 --- a/common/service-util/src/main/java/com/atguigu/constant/MessageConstant.java +++ b/common/service-util/src/main/java/com/atguigu/constant/MessageConstant.java @@ -32,7 +32,5 @@ public class MessageConstant { public static final String LOGIN_DTO_IS_EMPTY = "登录参数不能为空"; public static final String TOKEN_IS_EMPTY = "token为空"; public static final String DATA_IS_EMPTY = "数据为空"; - public static final String STOCK_LESS = "库存不足"; - public static final String SKU_NUM_CANNOT_BE_LESS = "商品数量不能再少了"; - public static final String CART_IS_EMPTY = "购物车为空"; + public static final String DELETE_MENU_ERROR_HAS_MENUS = "有下级菜单"; } diff --git a/service-oa/src/main/java/com/atguigu/auth/controller/SysMenuController.java b/service-oa/src/main/java/com/atguigu/auth/controller/SysMenuController.java index cab54fd..4c231df 100644 --- a/service-oa/src/main/java/com/atguigu/auth/controller/SysMenuController.java +++ b/service-oa/src/main/java/com/atguigu/auth/controller/SysMenuController.java @@ -50,7 +50,7 @@ public class SysMenuController { @ApiOperation(value = "删除菜单") @DeleteMapping("remove/{id}") public Result remove(@PathVariable Long id) { - sysMenuService.removeById(id); + sysMenuService.removeMenuById(id); return Result.success(); } } diff --git a/service-oa/src/main/java/com/atguigu/auth/service/SysMenuService.java b/service-oa/src/main/java/com/atguigu/auth/service/SysMenuService.java index b7ded3b..f3deb3d 100644 --- a/service-oa/src/main/java/com/atguigu/auth/service/SysMenuService.java +++ b/service-oa/src/main/java/com/atguigu/auth/service/SysMenuService.java @@ -21,4 +21,11 @@ public interface SysMenuService extends IService { * @return 菜单列表 */ List findNodes(); + + /** + * 删除菜单 + * + * @param id 菜单id + */ + void removeMenuById(Long id); } diff --git a/service-oa/src/main/java/com/atguigu/auth/service/impl/SysMenuServiceImpl.java b/service-oa/src/main/java/com/atguigu/auth/service/impl/SysMenuServiceImpl.java index 3eeacce..c394f3f 100644 --- a/service-oa/src/main/java/com/atguigu/auth/service/impl/SysMenuServiceImpl.java +++ b/service-oa/src/main/java/com/atguigu/auth/service/impl/SysMenuServiceImpl.java @@ -3,7 +3,10 @@ package com.atguigu.auth.service.impl; import com.atguigu.auth.mapper.SysMenuMapper; import com.atguigu.auth.service.SysMenuService; import com.atguigu.common.utlis.MenuHelper; +import com.atguigu.constant.MessageConstant; +import com.atguigu.exception.BunnyException; import com.atguigu.model.system.SysMenu; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; @@ -29,4 +32,25 @@ public class SysMenuServiceImpl extends ServiceImpl impl public List findNodes() { return MenuHelper.buildTree(list()); } + + /** + * 删除菜单 + * + * @param id 菜单id + */ + @Override + public void removeMenuById(Long id) { + // 判断当前菜单是否有下级菜单 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SysMenu::getParentId, id); + + // 查询菜单列表 + List sysMenuList = list(wrapper); + + // 为空时可以删除 + if (sysMenuList == null) removeById(id); + + // 如果不为空抛出异常 + throw new BunnyException(MessageConstant.DELETE_MENU_ERROR_HAS_MENUS); + } }