🚀 删除菜单
This commit is contained in:
parent
8f20d4c82f
commit
970a13bc5b
|
@ -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 = "有下级菜单";
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class SysMenuController {
|
|||
@ApiOperation(value = "删除菜单")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result<SysMenu> remove(@PathVariable Long id) {
|
||||
sysMenuService.removeById(id);
|
||||
sysMenuService.removeMenuById(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,4 +21,11 @@ public interface SysMenuService extends IService<SysMenu> {
|
|||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> findNodes();
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
void removeMenuById(Long id);
|
||||
}
|
||||
|
|
|
@ -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<SysMenuMapper, SysMenu> impl
|
|||
public List<SysMenu> findNodes() {
|
||||
return MenuHelper.buildTree(list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
@Override
|
||||
public void removeMenuById(Long id) {
|
||||
// 判断当前菜单是否有下级菜单
|
||||
LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysMenu::getParentId, id);
|
||||
|
||||
// 查询菜单列表
|
||||
List<SysMenu> sysMenuList = list(wrapper);
|
||||
|
||||
// 为空时可以删除
|
||||
if (sysMenuList == null) removeById(id);
|
||||
|
||||
// 如果不为空抛出异常
|
||||
throw new BunnyException(MessageConstant.DELETE_MENU_ERROR_HAS_MENUS);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue