用户、角色、权限、菜单--数据库设计

菜单表--menu
id--------------------主键
menu---------------菜单名称
permission_id--  菜单权限
url-------------------路径
sort-----------------排序
style----------------样式(可设置css图标)
parent_id----------父主键ID
create_time-------创建时间
is_deleted---------状态(0:未删除 1:删除)

用户表--user
id---------------------主键
user_id--------------用户ID(可设置唯一索引UNIQUE)
user_name---------用户名称
password-----------密码
create_time--------创建时间
is_deleted----------状态(0:未删除 1:删除)

权限表--permission
id------------------------主键
permission_id--------权限ID(自定义)可设置唯一索引UNIQUE
permission_name---权限名称
remark-----------------说明
create_time----------创建时间
is_deleted---- -------状态(0:未删除 1:删除)

角色表--role
id-------------------主键
role_id------------角色ID(自定义)可设置唯一索引UNIQUE
role_name-------角色名称
permission_id---权限类别(主要定义角色属于哪种层级)
create_time------创建时间
is_deleted--------状态(0:未删除 1:删除)

用户角色关联表--user_role
id-------------------主键
user_id------------用户ID
role_id-------------角色ID
create_time------创建时间
is_deleted--------状态(0:未删除 1:删除)

角色权限关联表--role_permission
id-------------------主键
role_id-------------角色ID
permission_id----权限ID
create_time-------创建时间
is_deleted---------状态(0:未删除 1:删除)

建表语句SQL,并且初始化了一些数据便于理解

sys_menu菜单表

-- ----------------------------
-- Table structure for sys_menu
-- ----------------------------
DROP TABLE IF EXISTS `sys_menu`;
CREATE TABLE `sys_menu`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
  `menu_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '菜单名称',
  `permission_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限ID',
  `url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求路径',
  `sort` tinyint NULL DEFAULT NULL COMMENT '排序',
  `style` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '样式(可设置css图标)',
  `parent_id` int NULL DEFAULT NULL COMMENT '父主键ID(有值的,属于该值菜单的下级菜单)',
  `create_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `update_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '修改人',
  `update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  `is_deleted` tinyint UNSIGNED NULL DEFAULT 0 COMMENT '是否删除(0:正常/1:删除)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '菜单表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of sys_menu
-- ----------------------------
INSERT INTO `sys_menu` VALUES (1, '系统管理', '10001', NULL, 1, NULL, NULL, '88888888', '2021-03-23 15:09:11', NULL, NULL, 0);
INSERT INTO `sys_menu` VALUES (2, '权限管理', '10002', '/sys/permission', 2, NULL, 1, '88888888', '2021-03-23 15:09:11', NULL, NULL, 0);
INSERT INTO `sys_menu` VALUES (3, '角色管理', '10003', '/sys/role', 3, NULL, 1, '88888888', '2021-03-23 15:09:11', NULL, NULL, 0);
INSERT INTO `sys_menu` VALUES (4, '用户管理', '10004', '/sys/user', 4, NULL, 1, '88888888', '2021-03-23 15:09:11', NULL, NULL, 0);

sys_permission权限表 

权限分类型:比如说页面菜单展示的权限、访问接口的权限,根据当前登录用户拥有的所有角色的菜单权限   展示所拥有的菜单列表

配置接口类型的权限:用于查询数据以及新增、修改、删除等等按钮请求后台接口路径权限

-- ----------------------------
-- Table structure for sys_permission
-- ----------------------------
DROP TABLE IF EXISTS `sys_permission`;
CREATE TABLE `sys_permission`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
  `permission_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限ID(自定义)可设置唯一索引UNIQUE',
  `permission_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限名称',
  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '描述说明',
  `create_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `update_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '修改人',
  `update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  `is_deleted` tinyint UNSIGNED NULL DEFAULT 0 COMMENT '是否删除(0:正常/1:删除)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '权限表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of sys_permission
-- ----------------------------
INSERT INTO `sys_permission` VALUES (1, '10001', '系统管理', '菜单权限(一级菜单)', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (2, '10002', '权限管理', '菜单权限(二级菜单)', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (3, '10003', '角色管理', '菜单权限(二级菜单)', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (4, '10004', '用户管理', '菜单权限(二级菜单)', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (5, '00001', '超级管理员', '当用户角色拥有该权限时,可分配sys_role表中权限ID为该值的角色给用户', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (6, '50001', '组长管理员', '组长角色拥有该权限时,可分配测试员的角色给用户', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (7, '60001', '查询权限列表', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (8, '60002', '新增权限', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (9, '60003', '修改权限', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (10, '60004', '删除权限', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (11, '60005', '查询角色列表', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (12, '60006', '新增角色', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (13, '60007', '修改角色', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (14, '60008', '删除角色', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (15, '60009', '查询用户列表', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (16, '60010', '新增用户', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (17, '60011', '修改用户', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);
INSERT INTO `sys_permission` VALUES (18, '60012', '删除用户', '接口权限', '88888888', '2021-03-23 15:11:42', NULL, NULL, 0);

sys_role角色表

根据初始化的一些数据可以看出,组长这个角色拥有50001的权限,而测试员的角色的权限ID属于50001,所有当拥有组长角色的用户登录时,前端页面展示该用户可以给其他新用户赋予测试员的角色,而超级管理员角色的用户拥有赋予其他用户     组长和测试员角色的权限

-- ----------------------------
-- Table structure for sys_role
-- ----------------------------
DROP TABLE IF EXISTS `sys_role`;
CREATE TABLE `sys_role`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
  `role_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '角色ID(自定义)可设置唯一索引UNIQUE',
  `role_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '角色名称',
  `permission_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限类别(主要定义角色属于哪种层级)',
  `create_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `update_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '修改人',
  `update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  `is_deleted` tinyint(1) NULL DEFAULT 0 COMMENT '是否删除(0:正常/1:删除)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '角色表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of sys_role
-- ----------------------------
INSERT INTO `sys_role` VALUES (1, '888888', '超级管理员', '', '88888888', '2021-03-23 15:18:10', NULL, NULL, 0);
INSERT INTO `sys_role` VALUES (2, '100001', '组长', '00001', '88888888', '2021-03-23 15:18:10', NULL, NULL, 0);
INSERT INTO `sys_role` VALUES (3, '100002', '测试员', '50001', '88888888', '2021-03-23 15:18:10', NULL, NULL, 0);

sys_role_permission角色权限关联表

超级管理员拥有所有的权限,所有角色首先要先拥有菜单权限,然后才有某个后台接口的请求权限,比如:组长需要拥有系统管理菜单下的用户管理菜单,并且有该页面上的新增、修改、删除等按钮权限

-- ----------------------------
-- Table structure for sys_role_permission
-- ----------------------------
DROP TABLE IF EXISTS `sys_role_permission`;
CREATE TABLE `sys_role_permission`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
  `role_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '角色ID',
  `permission_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限ID',
  `create_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `update_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '修改人',
  `update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  `is_deleted` tinyint(1) NULL DEFAULT 0 COMMENT '是否删除(0:正常/1:删除)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '角色权限关联表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of sys_role_permission
-- ----------------------------
INSERT INTO `sys_role_permission` VALUES (1, '888888', '10001', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (2, '888888', '10002', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (3, '888888', '10003', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (4, '888888', '10004', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (5, '888888', '00001', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (6, '888888', '50001', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (7, '888888', '60001', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (8, '888888', '60002', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (9, '888888', '60003', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (10, '888888', '60004', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (11, '888888', '60005', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (12, '888888', '60006', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (13, '888888', '60007', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (14, '888888', '60008', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (15, '888888', '60009', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (16, '888888', '60010', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (17, '888888', '60011', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (18, '888888', '60012', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (19, '100001', '10001', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (20, '100001', '10004', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (21, '100001', '60009', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (22, '100001', '60010', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (23, '100001', '60011', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);
INSERT INTO `sys_role_permission` VALUES (24, '100001', '60012', '88888888', '2021-03-23 15:29:09', NULL, NULL, 0);

sys_user用户表

-- ----------------------------
-- Table structure for sys_user
-- ----------------------------
DROP TABLE IF EXISTS `sys_user`;
CREATE TABLE `sys_user`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户ID(可设置唯一索引UNIQUE)',
  `user_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户名称',
  `password` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '密码',
  `create_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `update_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '修改人',
  `update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  `is_deleted` tinyint(1) NULL DEFAULT 0 COMMENT '是否删除(0:正常/1:删除)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of sys_user
-- ----------------------------
INSERT INTO `sys_user` VALUES (1, '88888888', '超级管理员', '88888888', '88888888', '2021-03-23 15:51:27', NULL, NULL, 0);
INSERT INTO `sys_user` VALUES (2, '80000001', '张三', '123456', '88888888', '2021-03-23 15:51:27', NULL, NULL, 0);
INSERT INTO `sys_user` VALUES (3, '80000002', '李四', '123456', '88888888', '2021-03-23 15:51:27', NULL, NULL, 0);
INSERT INTO `sys_user` VALUES (4, '80000003', '王五', '123456', '88888888', '2021-03-23 15:51:27', NULL, NULL, 0);

sys_user_role用户角色关联表

一个用户可以拥有多个角色,在权限判断时需要对重复的权限做去重处理

一个角色可以赋予多个用户使用

-- ----------------------------
-- Table structure for sys_user_role
-- ----------------------------
DROP TABLE IF EXISTS `sys_user_role`;
CREATE TABLE `sys_user_role`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户ID',
  `role_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '角色ID',
  `create_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `update_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '修改人',
  `update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  `is_deleted` tinyint(1) NULL DEFAULT 0 COMMENT '是否删除(0:正常/1:删除)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户角色关联表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of sys_user_role
-- ----------------------------
INSERT INTO `sys_user_role` VALUES (1, '88888888', '888888', '88888888', '2021-03-23 15:54:17', NULL, NULL, 0);
INSERT INTO `sys_user_role` VALUES (2, '88888888', '100001', '88888888', '2021-03-23 15:54:17', NULL, NULL, 0);
INSERT INTO `sys_user_role` VALUES (3, '88888888', '100002', '88888888', '2021-03-23 15:54:17', NULL, NULL, 0);
INSERT INTO `sys_user_role` VALUES (4, '80000001', '100001', '88888888', '2021-03-23 15:54:17', NULL, NULL, 0);
INSERT INTO `sys_user_role` VALUES (5, '80000001', '100002', '88888888', '2021-03-23 15:54:17', NULL, NULL, 0);
INSERT INTO `sys_user_role` VALUES (6, '80000002', '100002', '88888888', '2021-03-23 15:54:17', NULL, NULL, 0);
INSERT INTO `sys_user_role` VALUES (7, '80000003', '100002', '88888888', '2021-03-23 15:54:17', NULL, NULL, 0);

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值