use of com.ibeiliao.deployment.admin.vo.account.Menu in project Corgi by kevinYin.
the class MenuServiceImpl method listToBeDeletedMenu.
/**
* 获取待删除的菜单
*
* @param appId
* @param root
* @return
*/
private List<Menu> listToBeDeletedMenu(int appId, MenuItem root) {
List<Menu> menus = new ArrayList<>();
List<MenuPO> menuPOs = menuDao.listByAppId(appId);
Map<String, Boolean> menuMap = mapMenus(appId, root);
for (MenuPO menuPO : menuPOs) {
String key = menuPO.getAppId() + "_" + menuPO.getMenuName();
if (!menuMap.containsKey(key)) {
Menu menu = VOUtil.from(menuPO, Menu.class);
menus.add(menu);
}
}
return menus;
}
use of com.ibeiliao.deployment.admin.vo.account.Menu in project Corgi by kevinYin.
the class MenuServiceImpl method clearRedundantMenu.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void clearRedundantMenu(int appId, MenuItem root) {
List<Menu> menus = listToBeDeletedMenu(appId, root);
List<UrlResource> resources = listToBeDeletedResource(appId, root);
for (Menu menu : menus) {
logger.info("删除多余菜单." + "[menu=" + JsonUtil.toJSONString(menu) + "]");
deleteMenu(menu);
}
for (UrlResource resource : resources) {
int resId = resource.getResId();
logger.info("删除多余菜单资源关系." + "[resId=" + resId + "]");
menuResourcesRelationDao.deleteByResource(resId);
logger.info("删除多余资源." + "[resId=" + resId + "]");
urlResourceDao.deleteById(resId);
}
}
use of com.ibeiliao.deployment.admin.vo.account.Menu in project Corgi by kevinYin.
the class MenuServiceImpl method deleteMenu.
/**
* 删除菜单
* @param menu
*/
private void deleteMenu(Menu menu) {
int menuId = menu.getMenuId();
ParameterUtil.assertGreaterThanZero(menuId, "菜单不能为空.");
ParameterUtil.assertGreaterThanZero(menu.getAppId(), "所属应用不能为空.");
// ParameterUtil.assertNonnegativeInt(menu.getParentMenuId(), "所属菜单不能为空.");
// 判断逻辑: 保证所传menuId对应的数据的正确性; 旨在解决传输非法构造数据以及错把资源当菜单的情况
MenuPO menuInDB = menuDao.getById(menu.getMenuId());
ParameterUtil.assertEqual(menu.getAppId(), menuInDB.getAppId(), "该应用系统下不存在此菜单(确认下是否属于资源).");
ParameterUtil.assertEqual(menu.getParentMenuId(), menuInDB.getParentMenuId(), "该父菜单下不存在此菜单(确认下是否属于资源).");
// delete role_menu
logger.info("删除角色菜单关系." + "[menuId=" + menuId + "]");
roleService.deleteMenu(menuId);
// delete menu
logger.info("删除菜单." + "[menuId=" + menuId + "]");
menuDao.deleteById(menuId);
// 获取菜单下面的子菜单(一级)
List<Integer> subMenuIds = menuDao.listMenuIdByParent(menuId);
// 如果子菜单不为空, 则递归删除子菜单; 如果子菜单为空, 则删除菜单资源关系以及对应的资源
if (subMenuIds != null && !subMenuIds.isEmpty()) {
for (Integer subMenuId : subMenuIds) {
MenuPO subMenuPO = menuDao.getById(subMenuId);
Menu subMenu = VOUtil.from(subMenuPO, Menu.class);
deleteMenu(subMenu);
}
} else {
List<Integer> resIds = menuResourcesRelationDao.listResource(Arrays.asList(menuId));
for (Integer resId : resIds) {
// delete menu_resource
logger.info("删除菜单资源关系." + "[resId=" + resId + "]");
menuResourcesRelationDao.deleteByResource(resId);
// delete resource
logger.info("删除资源." + "[resId=" + resId + "]");
urlResourceDao.deleteById(resId);
}
}
}
Aggregations