mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
完成角色的授权的功能
This commit is contained in:
parent
2651f9bce3
commit
be2ba5be28
@ -8,14 +8,14 @@ import com.ruoyi.system.domain.vo.RouterVo;
|
||||
|
||||
/**
|
||||
* 菜单 业务层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ISysMenuService
|
||||
{
|
||||
/**
|
||||
* 根据用户查询系统菜单列表
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@ -23,7 +23,7 @@ public interface ISysMenuService
|
||||
|
||||
/**
|
||||
* 根据用户查询系统菜单列表
|
||||
*
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
@ -32,105 +32,18 @@ public interface ISysMenuService
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
public Set<String> selectMenuPermsByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询菜单树信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
public List<SysMenu> selectMenuTreeByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询菜单树信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 选中菜单列表
|
||||
*/
|
||||
public List<Integer> selectMenuListByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 构建前端路由所需要的菜单
|
||||
*
|
||||
* @param menus 菜单列表
|
||||
* @return 路由列表
|
||||
*/
|
||||
public List<RouterVo> buildMenus(List<SysMenu> menus);
|
||||
|
||||
/**
|
||||
* 构建前端所需要树结构
|
||||
*
|
||||
* @param menus 菜单列表
|
||||
* @return 树结构列表
|
||||
*/
|
||||
public List<SysMenu> buildMenuTree(List<SysMenu> menus);
|
||||
|
||||
/**
|
||||
* 构建前端所需要下拉树结构
|
||||
*
|
||||
* @param menus 菜单列表
|
||||
* @return 下拉树结构列表
|
||||
*/
|
||||
public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus);
|
||||
|
||||
/**
|
||||
* 根据菜单ID查询信息
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 菜单信息
|
||||
*/
|
||||
public SysMenu selectMenuById(Long menuId);
|
||||
|
||||
/**
|
||||
* 是否存在菜单子节点
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果 true 存在 false 不存在
|
||||
*/
|
||||
public boolean hasChildByMenuId(Long menuId);
|
||||
|
||||
/**
|
||||
* 查询菜单是否存在角色
|
||||
*
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果 true 存在 false 不存在
|
||||
*/
|
||||
public boolean checkMenuExistRole(Long menuId);
|
||||
|
||||
/**
|
||||
* 新增保存菜单信息
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertMenu(SysMenu menu);
|
||||
|
||||
/**
|
||||
* 修改保存菜单信息
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateMenu(SysMenu menu);
|
||||
|
||||
/**
|
||||
* 删除菜单管理信息
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteMenuById(Long menuId);
|
||||
|
||||
/**
|
||||
* 校验菜单名称是否唯一
|
||||
*
|
||||
* @param menu 菜单信息
|
||||
* @return 结果
|
||||
*/
|
||||
public String checkMenuNameUnique(SysMenu menu);
|
||||
}
|
||||
|
@ -2,130 +2,30 @@ package com.ruoyi.system.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
|
||||
/**
|
||||
* 角色业务层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ISysRoleService
|
||||
{
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 角色数据集合信息
|
||||
*/
|
||||
public List<SysRole> selectRoleList(SysRole role);
|
||||
public interface ISysRoleService {
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
public Set<String> selectRolePermissionByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 查询所有角色
|
||||
*
|
||||
* @return 角色列表
|
||||
*/
|
||||
public List<SysRole> selectRoleAll();
|
||||
|
||||
/**
|
||||
* 根据用户ID获取角色选择框列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 选中角色ID列表
|
||||
*/
|
||||
public List<Integer> selectRoleListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 角色对象信息
|
||||
*/
|
||||
public SysRole selectRoleById(Long roleId);
|
||||
|
||||
/**
|
||||
* 校验角色名称是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
public String checkRoleNameUnique(SysRole role);
|
||||
|
||||
/**
|
||||
* 校验角色权限是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
public String checkRoleKeyUnique(SysRole role);
|
||||
|
||||
/**
|
||||
* 校验角色是否允许操作
|
||||
*
|
||||
* @param role 角色信息
|
||||
*/
|
||||
public void checkRoleAllowed(SysRole role);
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int countUserRoleByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 新增保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRole(SysRole role);
|
||||
|
||||
/**
|
||||
* 修改保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRole(SysRole role);
|
||||
|
||||
/**
|
||||
* 修改角色状态
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRoleStatus(SysRole role);
|
||||
|
||||
/**
|
||||
* 修改数据权限信息
|
||||
*
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int authDataScope(SysRole role);
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRoleById(Long roleId);
|
||||
|
||||
/**
|
||||
* 批量删除角色信息
|
||||
*
|
||||
* @param roleIds 需要删除的角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRoleByIds(Long[] roleIds);
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import com.ruoyi.system.service.ISysMenuService;
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl implements ISysMenuService {
|
||||
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
|
||||
|
||||
/**
|
||||
* 根据用户查询系统菜单列表
|
||||
@ -99,29 +98,4 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||
return getChildPerms(menus, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询菜单树信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 选中菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<Integer> selectMenuListByRoleId(Long roleId) {
|
||||
SysRole role = roleMapper.selectRoleById(roleId);
|
||||
return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询菜单使用数量
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkMenuExistRole(Long menuId) {
|
||||
int result = roleMenuMapper.checkMenuExistRole(menuId);
|
||||
return result > 0 ? true : false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -28,19 +29,7 @@ import com.ruoyi.system.service.ISysRoleService;
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleServiceImpl implements ISysRoleService
|
||||
{
|
||||
@Autowired
|
||||
private SysRoleMapper roleMapper;
|
||||
|
||||
@Autowired
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
|
||||
@Autowired
|
||||
private SysRoleDeptMapper roleDeptMapper;
|
||||
public class SysRoleServiceImpl implements ISysRoleService {
|
||||
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
@ -50,85 +39,10 @@ public class SysRoleServiceImpl implements ISysRoleService
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public List<SysRole> selectRoleList(SysRole role)
|
||||
{
|
||||
public List<SysRole> selectRoleList(SysRole role) {
|
||||
return roleMapper.selectRoleList(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
@Override
|
||||
public Set<String> selectRolePermissionByUserId(Long userId)
|
||||
{
|
||||
List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (SysRole perm : perms)
|
||||
{
|
||||
if (StringUtils.isNotNull(perm))
|
||||
{
|
||||
permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
|
||||
}
|
||||
}
|
||||
return permsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有角色
|
||||
*
|
||||
* @return 角色列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> selectRoleAll()
|
||||
{
|
||||
return SpringUtils.getAopProxy(this).selectRoleList(new SysRole());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID获取角色选择框列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 选中角色ID列表
|
||||
*/
|
||||
@Override
|
||||
public List<Integer> selectRoleListByUserId(Long userId)
|
||||
{
|
||||
return roleMapper.selectRoleListByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 角色对象信息
|
||||
*/
|
||||
@Override
|
||||
public SysRole selectRoleById(Long roleId)
|
||||
{
|
||||
return roleMapper.selectRoleById(roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验角色名称是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String checkRoleNameUnique(SysRole role)
|
||||
{
|
||||
Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
|
||||
SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
|
||||
if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue())
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据权限信息
|
||||
*
|
||||
@ -137,8 +51,7 @@ public class SysRoleServiceImpl implements ISysRoleService
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int authDataScope(SysRole role)
|
||||
{
|
||||
public int authDataScope(SysRole role) {
|
||||
// 修改角色信息
|
||||
roleMapper.updateRole(role);
|
||||
// 删除角色与部门关联
|
||||
@ -147,71 +60,6 @@ public class SysRoleServiceImpl implements ISysRoleService
|
||||
return insertRoleDept(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色菜单信息
|
||||
*
|
||||
* @param role 角色对象
|
||||
*/
|
||||
public int insertRoleMenu(SysRole role)
|
||||
{
|
||||
int rows = 1;
|
||||
// 新增用户与角色管理
|
||||
List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
|
||||
for (Long menuId : role.getMenuIds())
|
||||
{
|
||||
SysRoleMenu rm = new SysRoleMenu();
|
||||
rm.setRoleId(role.getRoleId());
|
||||
rm.setMenuId(menuId);
|
||||
list.add(rm);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
{
|
||||
rows = roleMenuMapper.batchRoleMenu(list);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色部门信息(数据权限)
|
||||
*
|
||||
* @param role 角色对象
|
||||
*/
|
||||
public int insertRoleDept(SysRole role)
|
||||
{
|
||||
int rows = 1;
|
||||
// 新增角色与部门(数据权限)管理
|
||||
List<SysRoleDept> list = new ArrayList<SysRoleDept>();
|
||||
for (Long deptId : role.getDeptIds())
|
||||
{
|
||||
SysRoleDept rd = new SysRoleDept();
|
||||
rd.setRoleId(role.getRoleId());
|
||||
rd.setDeptId(deptId);
|
||||
list.add(rd);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
{
|
||||
rows = roleDeptMapper.batchRoleDept(list);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteRoleById(Long roleId)
|
||||
{
|
||||
// 删除角色与菜单关联
|
||||
roleMenuMapper.deleteRoleMenuByRoleId(roleId);
|
||||
// 删除角色与部门关联
|
||||
roleDeptMapper.deleteRoleDeptByRoleId(roleId);
|
||||
return roleMapper.deleteRoleById(roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除角色信息
|
||||
*
|
||||
@ -220,14 +68,11 @@ public class SysRoleServiceImpl implements ISysRoleService
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteRoleByIds(Long[] roleIds)
|
||||
{
|
||||
for (Long roleId : roleIds)
|
||||
{
|
||||
public int deleteRoleByIds(Long[] roleIds) {
|
||||
for (Long roleId : roleIds) {
|
||||
checkRoleAllowed(new SysRole(roleId));
|
||||
SysRole role = selectRoleById(roleId);
|
||||
if (countUserRoleByRoleId(roleId) > 0)
|
||||
{
|
||||
if (countUserRoleByRoleId(roleId) > 0) {
|
||||
throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName()));
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@
|
||||
row-key="id"
|
||||
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||
>
|
||||
<el-table-column prop="name" label="菜单名称" :show-overflow-tooltip="true" width="160"></el-table-column>
|
||||
<el-table-column prop="name" label="菜单名称" :show-overflow-tooltip="true" width="200"></el-table-column>
|
||||
<el-table-column prop="icon" label="图标" align="center" width="100">
|
||||
<template slot-scope="scope">
|
||||
<svg-icon :icon-class="scope.row.icon" />
|
||||
@ -156,7 +156,7 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item v-if="form.type != '1'" label="权限标识">
|
||||
<el-input v-model="form.perms" placeholder="请权限标识" maxlength="50" />
|
||||
<el-input v-model="form.permission" placeholder="请权限标识" maxlength="50" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
|
@ -112,14 +112,14 @@
|
||||
type="text"
|
||||
icon="el-icon-circle-check"
|
||||
@click="handleMenu(scope.row)"
|
||||
v-hasPermi="['system:role:edit']"
|
||||
v-hasPermi="['system:permission:assign-role-menu']"
|
||||
>菜单权限</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-circle-check"
|
||||
@click="handleDataScope(scope.row)"
|
||||
v-hasPermi="['system:role:edit']"
|
||||
v-hasPermi="['system:permission:assign-role-data-scope']"
|
||||
>数据权限</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
@ -214,7 +214,6 @@
|
||||
<el-input v-model="form.code" :disabled="true" />
|
||||
</el-form-item>
|
||||
<el-form-item label="菜单权限">
|
||||
<el-checkbox v-model="!form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动(选中父节点,自动选择子节点)</el-checkbox>
|
||||
<el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
|
||||
<el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
|
||||
<el-tree
|
||||
@ -356,15 +355,6 @@ export default {
|
||||
this.deptOptions = response.data;
|
||||
});
|
||||
},
|
||||
// 所有菜单节点数据
|
||||
getMenuAllCheckedKeys() {
|
||||
// 目前被选中的菜单节点
|
||||
let checkedKeys = this.$refs.menu.getCheckedKeys();
|
||||
// 半选中的菜单节点
|
||||
let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
|
||||
checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
|
||||
return checkedKeys;
|
||||
},
|
||||
// 所有部门节点数据
|
||||
getDeptAllCheckedKeys() {
|
||||
// 目前被选中的部门节点
|
||||
@ -434,7 +424,6 @@ export default {
|
||||
sort: 0,
|
||||
deptIds: [],
|
||||
menuIds: [],
|
||||
menuCheckStrictly: false, // 非严格,菜单弹窗的父子级联动
|
||||
deptCheckStrictly: false,
|
||||
remark: undefined
|
||||
};
|
||||
@ -515,12 +504,8 @@ export default {
|
||||
});
|
||||
// 获得角色拥有的菜单集合
|
||||
listRoleMenus(id).then(response => {
|
||||
// 设置为严格,避免设置父节点自动选中子节点,解决半选中问题
|
||||
// this.form.menuCheckStrictly = true
|
||||
// 设置选中
|
||||
this.$refs.menu.setCheckedKeys(response.data, false);
|
||||
// 设置为非严格,继续使用半选中
|
||||
// this.form.menuCheckStrictly = false
|
||||
this.$refs.menu.setCheckedKeys(response.data, true, false);
|
||||
})
|
||||
},
|
||||
/** 分配数据权限操作 */
|
||||
@ -575,7 +560,7 @@ export default {
|
||||
if (this.form.id !== undefined) {
|
||||
assignRoleMenu({
|
||||
roleId: this.form.id,
|
||||
menuIds: this.getMenuAllCheckedKeys()
|
||||
menuIds: this.$refs.menu.getCheckedKeys(true)
|
||||
}).then(response => {
|
||||
this.msgSuccess("修改成功");
|
||||
this.openMenu = false;
|
||||
|
@ -59,4 +59,6 @@ public class SysPermissionController {
|
||||
// return success(true);
|
||||
// }
|
||||
|
||||
// system:permission:assign-role-data-scope TODO
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user