芋道源码yudao-cloud 二开日记(添加接口权限和页面固定路由)
// 添加接口权限
@Override
public void addPermission(Long menuId, Long permissionId) {
Menu menu = getById(menuId);
if (menu == null) {
throw new ServiceException("菜单不存在");
}
Long existPermissionId = relationMapper.getPermissionIdByMenuId(menuId);
if (existPermissionId != null && !existPermissionId.equals(permissionId)) {
throw new ServiceException("菜单已有权限,不能重复设置");
}
if (permissionId != null) {
Relation relation = new Relation();
relation.setMenuId(menuId);
relation.setPermissionId(permissionId);
relationMapper.insert(relation);
}
}
// 添加固定路由
@Override
public void addFixedRoute(Long menuId, String routePath, String componentPath) {
Menu menu = getById(menuId);
if (menu == null) {
throw new ServiceException("菜单不存在");
}
Long existRouteId = fixedRouteMapper.getRouteIdByMenuId(menuId);
if (existRouteId != null) {
throw new ServiceException("菜单已有固定路由,不能重复设置");
}
FixedRoute route = new FixedRoute();
route.setMenuId(menuId);
route.setRoutePath(routePath);
route.setComponentPath(componentPath);
fixedRouteMapper.insert(route);
}
这段代码示例展示了如何在MenuService
接口中添加addPermission
和addFixedRoute
方法,用于给菜单添加接口权限和固定路由。在添加之前,它会检查是否已经存在权限或路由,并在不存在的情况下才进行添加。如果存在则抛出异常,防止重复设置。
评论已关闭