完成角色的授权的功能
parent
ad1d1978d2
commit
2651f9bce3
|
@ -111,18 +111,6 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
||||||
return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly());
|
return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建前端所需要下拉树结构
|
|
||||||
*
|
|
||||||
* @param menus 菜单列表
|
|
||||||
* @return 下拉树结构列表
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) {
|
|
||||||
List<SysMenu> menuTrees = buildMenuTree(menus);
|
|
||||||
return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询菜单使用数量
|
* 查询菜单使用数量
|
||||||
*
|
*
|
||||||
|
|
|
@ -9,6 +9,14 @@ export function listMenu(query) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询菜单(精简)列表
|
||||||
|
export function listSimpleMenus() {
|
||||||
|
return request({
|
||||||
|
url: '/system/menu/list-all-simple',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 查询菜单详细
|
// 查询菜单详细
|
||||||
export function getMenu(id) {
|
export function getMenu(id) {
|
||||||
return request({
|
return request({
|
||||||
|
@ -17,22 +25,6 @@ export function getMenu(id) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询菜单下拉树结构
|
|
||||||
export function treeselect() {
|
|
||||||
return request({
|
|
||||||
url: '/system/menu/treeselect',
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据角色ID查询菜单下拉树结构
|
|
||||||
export function roleMenuTreeselect(roleId) {
|
|
||||||
return request({
|
|
||||||
url: '/system/menu/roleMenuTreeselect/' + roleId,
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新增菜单
|
// 新增菜单
|
||||||
export function addMenu(data) {
|
export function addMenu(data) {
|
||||||
return request({
|
return request({
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 查询角色拥有的菜单数组
|
||||||
|
export function listRoleMenus(roleId) {
|
||||||
|
return request({
|
||||||
|
url: '/system/permission/list-role-resources?roleId=' + roleId,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 赋予角色菜单
|
||||||
|
export function assignRoleMenu(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/permission/assign-role-menu',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
|
@ -148,5 +148,5 @@ export function handleTree(data, id, parentId, children, rootId) {
|
||||||
//返回第一层
|
//返回第一层
|
||||||
return father[parentId] === rootId;
|
return father[parentId] === rootId;
|
||||||
});
|
});
|
||||||
return treeData != '' ? treeData : data;
|
return treeData !== '' ? treeData : data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,9 +182,9 @@
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="数据权限" v-show="form.dataScope == 2">
|
<el-form-item label="数据权限" v-show="form.dataScope == 2">
|
||||||
|
<el-checkbox v-model="form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox>
|
||||||
<el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠</el-checkbox>
|
<el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠</el-checkbox>
|
||||||
<el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox>
|
<el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox>
|
||||||
<el-checkbox v-model="form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox>
|
|
||||||
<el-tree
|
<el-tree
|
||||||
class="tree-border"
|
class="tree-border"
|
||||||
:data="deptOptions"
|
:data="deptOptions"
|
||||||
|
@ -192,7 +192,7 @@
|
||||||
default-expand-all
|
default-expand-all
|
||||||
ref="dept"
|
ref="dept"
|
||||||
node-key="id"
|
node-key="id"
|
||||||
:check-strictly="!form.deptCheckStrictly"
|
:check-strictly="form.deptCheckStrictly"
|
||||||
empty-text="加载中,请稍后"
|
empty-text="加载中,请稍后"
|
||||||
:props="defaultProps"
|
:props="defaultProps"
|
||||||
></el-tree>
|
></el-tree>
|
||||||
|
@ -214,16 +214,16 @@
|
||||||
<el-input v-model="form.code" :disabled="true" />
|
<el-input v-model="form.code" :disabled="true" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="菜单权限">
|
<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="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
|
||||||
<el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
|
<el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
|
||||||
<el-checkbox v-model="form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox>
|
|
||||||
<el-tree
|
<el-tree
|
||||||
class="tree-border"
|
class="tree-border"
|
||||||
:data="menuOptions"
|
:data="menuOptions"
|
||||||
show-checkbox
|
show-checkbox
|
||||||
ref="menu"
|
ref="menu"
|
||||||
node-key="id"
|
node-key="id"
|
||||||
:check-strictly="!form.menuCheckStrictly"
|
:check-strictly="form.menuCheckStrictly"
|
||||||
empty-text="加载中,请稍后"
|
empty-text="加载中,请稍后"
|
||||||
:props="defaultProps"
|
:props="defaultProps"
|
||||||
></el-tree>
|
></el-tree>
|
||||||
|
@ -239,7 +239,8 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
|
import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
|
||||||
import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu";
|
import { listSimpleMenus } from "@/api/system/menu";
|
||||||
|
import { listRoleMenus, assignRoleMenu } from "@/api/system/permission";
|
||||||
import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept";
|
import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept";
|
||||||
import {SysCommonStatusEnum, SysMenuTypeEnum} from "@/utils/constants";
|
import {SysCommonStatusEnum, SysMenuTypeEnum} from "@/utils/constants";
|
||||||
import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict";
|
import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict";
|
||||||
|
@ -311,8 +312,8 @@ export default {
|
||||||
// 表单参数
|
// 表单参数
|
||||||
form: {},
|
form: {},
|
||||||
defaultProps: {
|
defaultProps: {
|
||||||
children: "children",
|
label: "name",
|
||||||
label: "label"
|
children: "children"
|
||||||
},
|
},
|
||||||
// 表单校验
|
// 表单校验
|
||||||
rules: {
|
rules: {
|
||||||
|
@ -349,12 +350,6 @@ export default {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
/** 查询菜单树结构 */
|
|
||||||
getMenuTreeselect() {
|
|
||||||
menuTreeselect().then(response => {
|
|
||||||
this.menuOptions = response.data;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
/** 查询部门树结构 */
|
/** 查询部门树结构 */
|
||||||
getDeptTreeselect() {
|
getDeptTreeselect() {
|
||||||
deptTreeselect().then(response => {
|
deptTreeselect().then(response => {
|
||||||
|
@ -379,13 +374,6 @@ export default {
|
||||||
checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
|
checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
|
||||||
return checkedKeys;
|
return checkedKeys;
|
||||||
},
|
},
|
||||||
/** 根据角色ID查询菜单树结构 */
|
|
||||||
getRoleMenuTreeselect(id) {
|
|
||||||
return roleMenuTreeselect(id).then(response => {
|
|
||||||
this.menuOptions = response.menus;
|
|
||||||
return response;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
/** 根据角色ID查询部门树结构 */
|
/** 根据角色ID查询部门树结构 */
|
||||||
getRoleDeptTreeselect(id) {
|
getRoleDeptTreeselect(id) {
|
||||||
return roleDeptTreeselect(id).then(response => {
|
return roleDeptTreeselect(id).then(response => {
|
||||||
|
@ -432,23 +420,22 @@ export default {
|
||||||
},
|
},
|
||||||
// 表单重置
|
// 表单重置
|
||||||
reset() {
|
reset() {
|
||||||
if (this.$refs.menu != undefined) {
|
if (this.$refs.menu !== undefined) {
|
||||||
this.$refs.menu.setCheckedKeys([]);
|
this.$refs.menu.setCheckedKeys([]);
|
||||||
}
|
}
|
||||||
this.menuExpand = false,
|
this.menuExpand = false;
|
||||||
this.menuNodeAll = false,
|
this.menuNodeAll = false;
|
||||||
this.deptExpand = true,
|
this.deptExpand = true;
|
||||||
this.deptNodeAll = false,
|
this.deptNodeAll = false;
|
||||||
this.form = {
|
this.form = {
|
||||||
id: undefined,
|
id: undefined,
|
||||||
name: undefined,
|
name: undefined,
|
||||||
code: undefined,
|
code: undefined,
|
||||||
sort: 0,
|
sort: 0,
|
||||||
status: "0",
|
|
||||||
ids: [],
|
|
||||||
deptIds: [],
|
deptIds: [],
|
||||||
menuCheckStrictly: true,
|
menuIds: [],
|
||||||
deptCheckStrictly: true,
|
menuCheckStrictly: false, // 非严格,菜单弹窗的父子级联动
|
||||||
|
deptCheckStrictly: false,
|
||||||
remark: undefined
|
remark: undefined
|
||||||
};
|
};
|
||||||
this.resetForm("form");
|
this.resetForm("form");
|
||||||
|
@ -466,12 +453,12 @@ export default {
|
||||||
},
|
},
|
||||||
// 树权限(展开/折叠)
|
// 树权限(展开/折叠)
|
||||||
handleCheckedTreeExpand(value, type) {
|
handleCheckedTreeExpand(value, type) {
|
||||||
if (type == 'menu') {
|
if (type === 'menu') {
|
||||||
let treeList = this.menuOptions;
|
let treeList = this.menuOptions;
|
||||||
for (let i = 0; i < treeList.length; i++) {
|
for (let i = 0; i < treeList.length; i++) {
|
||||||
this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
|
this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
|
||||||
}
|
}
|
||||||
} else if (type == 'dept') {
|
} else if (type === 'dept') {
|
||||||
let treeList = this.deptOptions;
|
let treeList = this.deptOptions;
|
||||||
for (let i = 0; i < treeList.length; i++) {
|
for (let i = 0; i < treeList.length; i++) {
|
||||||
this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
|
this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
|
||||||
|
@ -480,18 +467,18 @@ export default {
|
||||||
},
|
},
|
||||||
// 树权限(全选/全不选)
|
// 树权限(全选/全不选)
|
||||||
handleCheckedTreeNodeAll(value, type) {
|
handleCheckedTreeNodeAll(value, type) {
|
||||||
if (type == 'menu') {
|
if (type === 'menu') {
|
||||||
this.$refs.menu.setCheckedNodes(value ? this.menuOptions: []);
|
this.$refs.menu.setCheckedNodes(value ? this.menuOptions: []);
|
||||||
} else if (type == 'dept') {
|
} else if (type === 'dept') {
|
||||||
this.$refs.dept.setCheckedNodes(value ? this.deptOptions: []);
|
this.$refs.dept.setCheckedNodes(value ? this.deptOptions: []);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 树权限(父子联动)
|
// 树权限(父子联动)
|
||||||
handleCheckedTreeConnect(value, type) {
|
handleCheckedTreeConnect(value, type) {
|
||||||
if (type == 'menu') {
|
if (type === 'menu') {
|
||||||
this.form.menuCheckStrictly = value ? true: false;
|
this.form.menuCheckStrictly = value;
|
||||||
} else if (type == 'dept') {
|
} else if (type === 'dept') {
|
||||||
this.form.deptCheckStrictly = value ? true: false;
|
this.form.deptCheckStrictly = value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** 新增按钮操作 */
|
/** 新增按钮操作 */
|
||||||
|
@ -514,27 +501,27 @@ export default {
|
||||||
handleMenu(row) {
|
handleMenu(row) {
|
||||||
this.reset();
|
this.reset();
|
||||||
const id = row.id
|
const id = row.id
|
||||||
// TODO 优化
|
// 处理了 form 的角色 name 和 code 的展示
|
||||||
this.getMenuTreeselect();
|
this.form.id = id;
|
||||||
const roleMenu = this.getRoleMenuTreeselect(id);
|
this.form.name = row.name;
|
||||||
this.$nextTick(() => {
|
this.form.code = row.code;
|
||||||
roleMenu.then(res => {
|
// 打开弹窗
|
||||||
this.$refs.menu.setCheckedKeys(res.checkedKeys);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.openMenu = true;
|
this.openMenu = true;
|
||||||
|
// 获得菜单列表
|
||||||
// const roleDeptTreeselect = this.getRoleDeptTreeselect(row.id);
|
listSimpleMenus().then(response => {
|
||||||
// getRole(row.id).then(response => {
|
// 处理 menuOptions 参数
|
||||||
// this.form = response.data;
|
this.menuOptions = [];
|
||||||
// this.openDataScope = true;
|
this.menuOptions.push(...this.handleTree(response.data, "id"));
|
||||||
// this.$nextTick(() => {
|
});
|
||||||
// roleDeptTreeselect.then(res => {
|
// 获得角色拥有的菜单集合
|
||||||
// this.$refs.dept.setCheckedKeys(res.checkedKeys);
|
listRoleMenus(id).then(response => {
|
||||||
// });
|
// 设置为严格,避免设置父节点自动选中子节点,解决半选中问题
|
||||||
// });
|
// this.form.menuCheckStrictly = true
|
||||||
// this.title = "分配数据权限";
|
// 设置选中
|
||||||
// });
|
this.$refs.menu.setCheckedKeys(response.data, false);
|
||||||
|
// 设置为非严格,继续使用半选中
|
||||||
|
// this.form.menuCheckStrictly = false
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/** 分配数据权限操作 */
|
/** 分配数据权限操作 */
|
||||||
handleDataScope(row) {
|
handleDataScope(row) {
|
||||||
|
@ -556,16 +543,12 @@ export default {
|
||||||
this.$refs["form"].validate(valid => {
|
this.$refs["form"].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.id !== undefined) {
|
if (this.form.id !== undefined) {
|
||||||
// TODO 芋艿:需要迁移
|
|
||||||
// this.form.ids = this.getMenuAllCheckedKeys();
|
|
||||||
updateRole(this.form).then(response => {
|
updateRole(this.form).then(response => {
|
||||||
this.msgSuccess("修改成功");
|
this.msgSuccess("修改成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
this.getList();
|
this.getList();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// TODO 芋艿:需要迁移
|
|
||||||
// this.form.ids = this.getMenuAllCheckedKeys();
|
|
||||||
addRole(this.form).then(response => {
|
addRole(this.form).then(response => {
|
||||||
this.msgSuccess("新增成功");
|
this.msgSuccess("新增成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
|
@ -577,7 +560,7 @@ export default {
|
||||||
},
|
},
|
||||||
/** 提交按钮(数据权限) */
|
/** 提交按钮(数据权限) */
|
||||||
submitDataScope: function() {
|
submitDataScope: function() {
|
||||||
if (this.form.id != undefined) {
|
if (this.form.id !== undefined) {
|
||||||
this.form.deptIds = this.getDeptAllCheckedKeys();
|
this.form.deptIds = this.getDeptAllCheckedKeys();
|
||||||
dataScope(this.form).then(response => {
|
dataScope(this.form).then(response => {
|
||||||
this.msgSuccess("修改成功");
|
this.msgSuccess("修改成功");
|
||||||
|
@ -589,11 +572,13 @@ export default {
|
||||||
/** 提交按钮(菜单权限) */
|
/** 提交按钮(菜单权限) */
|
||||||
submitMenu: function() {
|
submitMenu: function() {
|
||||||
// TODO 需要改动下
|
// TODO 需要改动下
|
||||||
if (this.form.id != undefined) {
|
if (this.form.id !== undefined) {
|
||||||
this.form.deptIds = this.getDeptAllCheckedKeys();
|
assignRoleMenu({
|
||||||
dataScope(this.form).then(response => {
|
roleId: this.form.id,
|
||||||
|
menuIds: this.getMenuAllCheckedKeys()
|
||||||
|
}).then(response => {
|
||||||
this.msgSuccess("修改成功");
|
this.msgSuccess("修改成功");
|
||||||
this.openDataScope = false;
|
this.openMenu = false;
|
||||||
this.getList();
|
this.getList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package cn.iocoder.dashboard.modules.system.controller.permission;
|
package cn.iocoder.dashboard.modules.system.controller.permission;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuCreateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.*;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuListReqVO;
|
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuRespVO;
|
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuUpdateReqVO;
|
|
||||||
import cn.iocoder.dashboard.modules.system.convert.permission.SysMenuConvert;
|
import cn.iocoder.dashboard.modules.system.convert.permission.SysMenuConvert;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
||||||
import cn.iocoder.dashboard.modules.system.service.permission.SysMenuService;
|
import cn.iocoder.dashboard.modules.system.service.permission.SysMenuService;
|
||||||
|
@ -15,6 +13,7 @@ import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||||
|
@ -30,8 +29,22 @@ public class SysMenuController {
|
||||||
@ApiOperation("获取菜单列表")
|
@ApiOperation("获取菜单列表")
|
||||||
// @PreAuthorize("@ss.hasPermi('system:menu:list')")
|
// @PreAuthorize("@ss.hasPermi('system:menu:list')")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public CommonResult<List<SysMenuRespVO>> list(SysMenuListReqVO reqVO) {
|
public CommonResult<List<SysMenuRespVO>> listMenus(SysMenuListReqVO reqVO) {
|
||||||
return success(menuService.listMenus(reqVO));
|
List<SysMenuDO> list = menuService.listMenus(reqVO);
|
||||||
|
list.sort(Comparator.comparing(SysMenuDO::getSort));
|
||||||
|
return success(SysMenuConvert.INSTANCE.convertList(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取菜单精简信息列表", notes = "只包含被开启的菜单,主要用于前端的下拉选项")
|
||||||
|
@GetMapping("/list-all-simple")
|
||||||
|
public CommonResult<List<SysMenuSimpleRespVO>> listSimpleMenus() {
|
||||||
|
// 获得菜单列表,只要开启状态的
|
||||||
|
SysMenuListReqVO reqVO = new SysMenuListReqVO();
|
||||||
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
List<SysMenuDO> list = menuService.listMenus(reqVO);
|
||||||
|
// 排序后,返回个诶前端
|
||||||
|
list.sort(Comparator.comparing(SysMenuDO::getSort));
|
||||||
|
return success(SysMenuConvert.INSTANCE.convertList02(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获取菜单信息")
|
@ApiOperation("获取菜单信息")
|
||||||
|
@ -42,17 +55,6 @@ public class SysMenuController {
|
||||||
return success(SysMenuConvert.INSTANCE.convert(menu));
|
return success(SysMenuConvert.INSTANCE.convert(menu));
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 获取菜单下拉树列表
|
|
||||||
// */
|
|
||||||
// @GetMapping("/treeselect")
|
|
||||||
// public AjaxResult treeselect(SysMenu menu) {
|
|
||||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
||||||
// Long userId = loginUser.getUser().getUserId();
|
|
||||||
// List<SysMenu> menus = menuService.selectMenuList(menu, userId);
|
|
||||||
// return AjaxResult.success(menuService.buildMenuTreeSelect(menus));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
// /**
|
||||||
// * 加载对应角色菜单列表树
|
// * 加载对应角色菜单列表树
|
||||||
// */
|
// */
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package cn.iocoder.dashboard.modules.system.controller.permission;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.permission.SysPermissionAssignRoleMenuReqVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限 Controller,提供赋予用户、角色的权限的 API 接口
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Api(tags = "权限 API")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/permission")
|
||||||
|
public class SysPermissionController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysPermissionService permissionService;
|
||||||
|
|
||||||
|
@ApiOperation("获得角色拥有的菜单编号")
|
||||||
|
@GetMapping("/list-role-resources")
|
||||||
|
@ApiImplicitParam(name = "roleId", value = "角色编号", required = true)
|
||||||
|
// @RequiresPermissions("system:permission:assign-role-menu")
|
||||||
|
public CommonResult<Set<Long>> listRoleMenus(Long roleId) {
|
||||||
|
return success(permissionService.listRoleMenuIds(roleId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/assign-role-menu")
|
||||||
|
@ApiOperation("赋予角色菜单")
|
||||||
|
// @RequiresPermissions("system:permission:assign-role-resource")
|
||||||
|
public CommonResult<Boolean> assignRoleMenu(@Validated @RequestBody SysPermissionAssignRoleMenuReqVO reqVO) {
|
||||||
|
permissionService.assignRoleMenu(reqVO.getRoleId(), reqVO.getMenuIds());
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @GetMapping("/list-admin-roles")
|
||||||
|
// @ApiOperation("获得管理员拥有的角色编号列表")
|
||||||
|
//// @RequiresPermissions("system:permission:assign-admin-role")
|
||||||
|
// @ApiImplicitParam(name = "adminId", value = "管理员编号", required = true)
|
||||||
|
// public CommonResult<Set<Integer>> listAdminRoles(Integer adminId) {
|
||||||
|
// return success(permissionManager.listAdminRoles(adminId));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @PostMapping("/assign-admin-role")
|
||||||
|
// @ApiOperation("赋予用户角色")
|
||||||
|
//// @RequiresPermissions("system:permission:assign-admin-role")
|
||||||
|
// public CommonResult<Boolean> assignAdminRole(PermissionAssignAdminRoleDTO assignAdminRoleDTO) {
|
||||||
|
// permissionManager.assignAdminRole(assignAdminRoleDTO);
|
||||||
|
// return success(true);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package cn.iocoder.dashboard.modules.system.controller.permission.vo.menu;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@ApiModel("菜单精简信息 Response VO")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SysMenuSimpleRespVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单编号", required = true, example = "1024")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单名称", required = true, example = "芋道")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "父菜单 ID", required = true, example = "1024")
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package cn.iocoder.dashboard.modules.system.controller.permission.vo.permission;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ApiModel("赋予角色菜单 Request VO")
|
||||||
|
@Data
|
||||||
|
public class SysPermissionAssignRoleMenuReqVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色名", required = true, example = "1")
|
||||||
|
@NotNull(message = "角色编号不能为空")
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单编号列表", example = "1,3,5")
|
||||||
|
private Set<Long> menuIds = Collections.emptySet(); // 兜底
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package cn.iocoder.dashboard.modules.system.convert.permission;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuCreateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuCreateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuRespVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuRespVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuSimpleRespVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuUpdateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuUpdateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -22,4 +23,6 @@ public interface SysMenuConvert {
|
||||||
|
|
||||||
SysMenuRespVO convert(SysMenuDO bean);
|
SysMenuRespVO convert(SysMenuDO bean);
|
||||||
|
|
||||||
|
List<SysMenuSimpleRespVO> convertList02(List<SysMenuDO> list);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,35 @@
|
||||||
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission;
|
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleMenuDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleMenuDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenuDO> {
|
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenuDO> {
|
||||||
|
|
||||||
|
default List<SysRoleMenuDO> selectListByRoleId(Long roleId) {
|
||||||
|
return selectList(new QueryWrapper<SysRoleMenuDO>().eq("role_id", roleId));
|
||||||
|
}
|
||||||
|
|
||||||
|
default void insertList(Long roleId, Collection<Long> menuIds) {
|
||||||
|
List<SysRoleMenuDO> list = menuIds.stream().map(menuId -> {
|
||||||
|
SysRoleMenuDO entity = new SysRoleMenuDO();
|
||||||
|
entity.setRoleId(roleId);
|
||||||
|
entity.setMenuId(menuId);
|
||||||
|
return entity;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
// TODO 芋艿,mybatis plus 增加批量插入的功能
|
||||||
|
list.forEach(this::insert);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void deleteListByRoleIdAndMenuIds(Long roleId, Collection<Long> menuIds) {
|
||||||
|
delete(new QueryWrapper<SysRoleMenuDO>().eq("role_id", roleId)
|
||||||
|
.in("menu_id", menuIds));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package cn.iocoder.dashboard.modules.system.service.permission;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuCreateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuCreateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuListReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuListReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuRespVO;
|
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuUpdateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuUpdateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
|
||||||
|
|
||||||
|
@ -21,13 +20,20 @@ public interface SysMenuService {
|
||||||
*/
|
*/
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得所有菜单列表
|
||||||
|
*
|
||||||
|
* @return 菜单列表
|
||||||
|
*/
|
||||||
|
List<SysMenuDO> listMenus();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 筛选菜单列表
|
* 筛选菜单列表
|
||||||
*
|
*
|
||||||
* @param reqVO 筛选条件请求 VO
|
* @param reqVO 筛选条件请求 VO
|
||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
List<SysMenuRespVO> listMenus(SysMenuListReqVO reqVO);
|
List<SysMenuDO> listMenus(SysMenuListReqVO reqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得所有菜单,从缓存中
|
* 获得所有菜单,从缓存中
|
||||||
|
|
|
@ -43,6 +43,22 @@ public interface SysPermissionService {
|
||||||
*/
|
*/
|
||||||
Set<Long> listUserRoleIds(Long userId, @Nullable Collection<Integer> roleStatuses);
|
Set<Long> listUserRoleIds(Long userId, @Nullable Collection<Integer> roleStatuses);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得角色拥有的菜单编号集合
|
||||||
|
*
|
||||||
|
* @param roleId 角色编号
|
||||||
|
* @return 菜单编号集合
|
||||||
|
*/
|
||||||
|
Set<Long> listRoleMenuIds(Long roleId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 赋予赋予角色菜单
|
||||||
|
*
|
||||||
|
* @param roleId 角色编号
|
||||||
|
* @param menuIds 菜单编号集合
|
||||||
|
*/
|
||||||
|
void assignRoleMenu(Long roleId, Set<Long> menuIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理角色删除时,删除关联授权角色
|
* 处理角色删除时,删除关联授权角色
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,7 +3,6 @@ package cn.iocoder.dashboard.modules.system.service.permission.impl;
|
||||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuCreateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuCreateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuListReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuListReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuRespVO;
|
|
||||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuUpdateReqVO;
|
import cn.iocoder.dashboard.modules.system.controller.permission.vo.menu.SysMenuUpdateReqVO;
|
||||||
import cn.iocoder.dashboard.modules.system.convert.permission.SysMenuConvert;
|
import cn.iocoder.dashboard.modules.system.convert.permission.SysMenuConvert;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission.SysMenuMapper;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission.SysMenuMapper;
|
||||||
|
@ -78,10 +77,13 @@ public class SysMenuServiceImpl implements SysMenuService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysMenuRespVO> listMenus(SysMenuListReqVO reqVO) {
|
public List<SysMenuDO> listMenus() {
|
||||||
List<SysMenuDO> list = menuMapper.selectList(reqVO);
|
return menuMapper.selectList();
|
||||||
// TODO 排序
|
}
|
||||||
return SysMenuConvert.INSTANCE.convertList(list);
|
|
||||||
|
@Override
|
||||||
|
public List<SysMenuDO> listMenus(SysMenuListReqVO reqVO) {
|
||||||
|
return menuMapper.selectList(reqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package cn.iocoder.dashboard.modules.system.service.permission.impl;
|
package cn.iocoder.dashboard.modules.system.service.permission.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission.SysRoleMenuMapper;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission.SysRoleMenuMapper;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission.SysUserRoleMapper;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission.SysUserRoleMapper;
|
||||||
|
@ -16,6 +17,7 @@ import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -110,6 +112,36 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||||
return CollectionUtils.convertSet(userRoleList, SysUserRoleDO::getRoleId);
|
return CollectionUtils.convertSet(userRoleList, SysUserRoleDO::getRoleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Long> listRoleMenuIds(Long roleId) {
|
||||||
|
// 如果是管理员的情况下,获取全部菜单编号
|
||||||
|
SysRoleDO role = roleService.getRole(roleId);
|
||||||
|
if (roleService.hasAnyAdmin(Collections.singletonList(role))) {
|
||||||
|
return CollectionUtils.convertSet(menuService.listMenus(), SysMenuDO::getId);
|
||||||
|
}
|
||||||
|
// 如果是非管理员的情况下,获得拥有的菜单编号
|
||||||
|
return CollectionUtils.convertSet(roleMenuMapper.selectListByRoleId(roleId),
|
||||||
|
SysRoleMenuDO::getMenuId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void assignRoleMenu(Long roleId, Set<Long> menuIds) {
|
||||||
|
// 获得角色拥有菜单编号
|
||||||
|
Set<Long> dbMenuIds = CollectionUtils.convertSet(roleMenuMapper.selectListByRoleId(roleId),
|
||||||
|
SysRoleMenuDO::getMenuId);
|
||||||
|
// 计算新增和删除的菜单编号
|
||||||
|
Collection<Long> createMenuIds = CollUtil.subtract(menuIds, dbMenuIds);
|
||||||
|
Collection<Long> deleteMenuIds = CollUtil.subtract(dbMenuIds, menuIds);
|
||||||
|
// 执行新增和删除。对于已经授权的菜单,不用做任何处理
|
||||||
|
if (!CollectionUtil.isEmpty(createMenuIds)) {
|
||||||
|
roleMenuMapper.insertList(roleId, createMenuIds);
|
||||||
|
}
|
||||||
|
if (!CollectionUtil.isEmpty(deleteMenuIds)) {
|
||||||
|
roleMenuMapper.deleteListByRoleIdAndMenuIds(roleId, deleteMenuIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processRoleDeleted(Long roleId) {
|
public void processRoleDeleted(Long roleId) {
|
||||||
// TODO 实现我
|
// TODO 实现我
|
||||||
|
|
|
@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
@ -115,6 +116,7 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteRole(Long id) {
|
public void deleteRole(Long id) {
|
||||||
// 校验是否可以更新
|
// 校验是否可以更新
|
||||||
this.checkUpdateRole(id);
|
this.checkUpdateRole(id);
|
||||||
|
@ -129,7 +131,6 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||||
return roleMapper.selectById(id);
|
return roleMapper.selectById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<SysRoleDO> pageRole(SysRolePageReqVO reqVO) {
|
public PageResult<SysRoleDO> pageRole(SysRolePageReqVO reqVO) {
|
||||||
IPage<SysRoleDO> roleDOPage = roleMapper.selectPage(reqVO);
|
IPage<SysRoleDO> roleDOPage = roleMapper.selectPage(reqVO);
|
||||||
|
|
Loading…
Reference in New Issue