完成角色的授权的功能

pull/2/head
YunaiV 2021-01-09 19:22:07 +08:00
parent 2651f9bce3
commit be2ba5be28
7 changed files with 25 additions and 406 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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()));
}
}

View File

@ -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">

View File

@ -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;

View File

@ -59,4 +59,6 @@ public class SysPermissionController {
// return success(true);
// }
// system:permission:assign-role-data-scope TODO
}