|
@@ -41,30 +41,38 @@ public class SysRoleMenuServiceImpl implements ISysRoleMenuService{
|
|
|
/**
|
|
|
* 功能描述: 批量保存roleMenu
|
|
|
*
|
|
|
- * @param dto dto
|
|
|
+ * @param dtos dtos
|
|
|
* @return int
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
|
|
|
public int saveList(List<RoleMenuDto> dtos) {
|
|
|
int effective = 0;
|
|
|
+ List<SysMenu> allMenus =menuService.selectMenuListAll(new SysMenu());
|
|
|
for (RoleMenuDto dto : dtos) {
|
|
|
Long menuId = requireNonNull(dto.getMenuId(), "menuId is empty");
|
|
|
Long roleId = requireNonNull(dto.getRoleId(), "roleId is empty");
|
|
|
+
|
|
|
SysMenu menu = requireNonNull(menuService.selectMenuById(menuId), "根据menuId = [" + menuId + "], 未找到菜单");
|
|
|
- List<String> head = dto.getHead();
|
|
|
- requireNonNull(head, "操作为空");
|
|
|
- List<SysMenu> allMenus = menuService.selectMenuListAll(new SysMenu());
|
|
|
+ // 当前menu的祖宗十八代都在里面
|
|
|
+ List<SysMenu> parentList = Lists.newArrayListWithCapacity(16);
|
|
|
+ // 此方法只找到menu的祖宗十八代,但是不包含自己
|
|
|
+ menuService.recGetParent(allMenus, Collections.singletonList(menu), parentList);
|
|
|
+ parentList.add(menu);
|
|
|
+
|
|
|
+ List<String> head = requireNonNull(dto.getHead(), "操作为空");
|
|
|
List<SysMenu> childList = menuService.getChildList(allMenus, menu);
|
|
|
if (isEmpty(childList)) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ // 把parentList放进去
|
|
|
+ childList.addAll(parentList);
|
|
|
// 根据子菜单和前台传过来的head来判断包含AMD...中的哪些
|
|
|
childList = buildBtnByHead(head, childList);
|
|
|
List<SysRoleMenu> roleMenuList = buildRoleMenu(roleId, map(childList, SysMenu::getId));
|
|
|
- // 先删除,再添加,防止联合索引报错
|
|
|
try {
|
|
|
+ // 先删除,再添加,防止联合索引报错
|
|
|
deleteByRoleIdList(Collections.singletonList(roleId));
|
|
|
effective += batchRoleMenu(roleMenuList);
|
|
|
} catch (Exception e) {
|
|
@@ -86,6 +94,11 @@ public class SysRoleMenuServiceImpl implements ISysRoleMenuService{
|
|
|
private List<SysMenu> buildBtnByHead(List<String> head, List<SysMenu> menuList) {
|
|
|
List<SysMenu> result = Lists.newArrayListWithCapacity(menuList.size());
|
|
|
for (SysMenu menu : menuList) {
|
|
|
+ if (!"F".equalsIgnoreCase(menu.getMenuType())) {
|
|
|
+ result.add(menu);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
String perms = menu.getPerms();
|
|
|
if (isEmpty(perms)) {
|
|
|
continue;
|