Search in sources :

Example 1 with RoleMenu

use of com.github.liuweijw.business.admin.domain.RoleMenu in project fw-cloud-framework by liuweijw.

the class PermissionServiceImpl method updateRoleMenuPermissions.

@Override
@CacheEvict(value = { AdminCacheKey.PERMISSION_INFO, AdminCacheKey.MENU_INFO, AdminCacheKey.MODULE_INFO, AdminCacheKey.ROLE_INFO }, allEntries = true)
@Transactional
public boolean updateRoleMenuPermissions(String roleCode, String... permissions) {
    Role role = roleService.findRoleByCode(roleCode.trim());
    if (null == role)
        return false;
    // 菜单集合
    Map<Integer, List<String>> roleMenuIdList = new HashMap<Integer, List<String>>();
    for (String permission : permissions) {
        if (!permission.contains("|"))
            continue;
        String[] menuPermissions = permission.split("\\|");
        Integer menuId = WebUtils.parseStrToInteger(menuPermissions[0], null);
        if (null == menuId || StringHelper.isBlank(menuPermissions[1]))
            continue;
        if (!roleMenuIdList.containsKey(menuId)) {
            roleMenuIdList.put(menuId, new ArrayList<String>());
        }
        roleMenuIdList.get(menuId).add(menuPermissions[1].trim());
    }
    // 删除RoleMenuRoleMenuPermission
    this.delRoleMenuPermission(role.getRoleId());
    if (roleMenuIdList.size() > 0) {
        roleMenuIdList.forEach((menuId, menuPermissions) -> {
            RoleMenu menuRole = new RoleMenu();
            menuRole.setMenuId(menuId);
            menuRole.setRoleId(role.getRoleId());
            menuRole = roleMenuRepository.saveAndFlush(menuRole);
            Integer menuRoleId = menuRole.getId();
            menuPermissions.forEach(p -> {
                String permission = p.trim();
                if (permission.contains("_")) {
                    RoleMenuPermission roleMenuPermission = new RoleMenuPermission();
                    roleMenuPermission.setRoleMenuId(menuRoleId);
                    roleMenuPermission.setPermission(permission);
                    roleMenuPermissionRepository.saveAndFlush(roleMenuPermission);
                }
            });
        });
    }
    return true;
}
Also used : Role(com.github.liuweijw.business.admin.domain.Role) QRoleMenuPermission(com.github.liuweijw.business.admin.domain.QRoleMenuPermission) RoleMenuPermission(com.github.liuweijw.business.admin.domain.RoleMenuPermission) HashMap(java.util.HashMap) QRoleMenu(com.github.liuweijw.business.admin.domain.QRoleMenu) RoleMenu(com.github.liuweijw.business.admin.domain.RoleMenu) ArrayList(java.util.ArrayList) List(java.util.List) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RoleMenu

use of com.github.liuweijw.business.admin.domain.RoleMenu in project fw-cloud-framework by liuweijw.

the class PermissionServiceImpl method delRoleMenuPermission.

private boolean delRoleMenuPermission(Integer roleId) {
    QRoleMenu qRoleMenu = QRoleMenu.roleMenu;
    List<RoleMenu> roleMeunList = this.queryFactory.selectFrom(qRoleMenu).where(qRoleMenu.roleId.eq(roleId.intValue())).fetch();
    Set<Integer> roleMenuIdList = new HashSet<Integer>();
    roleMeunList.forEach(r -> {
        roleMenuIdList.add(r.getId());
        roleMenuRepository.delete(r.getId());
    });
    Integer[] roleMenuIdArray = new Integer[roleMenuIdList.size()];
    return this.delRoleMenuPermissionByRoleMenuId(roleMenuIdList.toArray(roleMenuIdArray));
}
Also used : QRoleMenu(com.github.liuweijw.business.admin.domain.QRoleMenu) RoleMenu(com.github.liuweijw.business.admin.domain.RoleMenu) QRoleMenu(com.github.liuweijw.business.admin.domain.QRoleMenu) HashSet(java.util.HashSet)

Aggregations

QRoleMenu (com.github.liuweijw.business.admin.domain.QRoleMenu)2 RoleMenu (com.github.liuweijw.business.admin.domain.RoleMenu)2 QRoleMenuPermission (com.github.liuweijw.business.admin.domain.QRoleMenuPermission)1 Role (com.github.liuweijw.business.admin.domain.Role)1 RoleMenuPermission (com.github.liuweijw.business.admin.domain.RoleMenuPermission)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CacheEvict (org.springframework.cache.annotation.CacheEvict)1 Transactional (org.springframework.transaction.annotation.Transactional)1