作者: whooyun发表于: 2023-02-11 18:43
RBAC-RBAC0模型
用户和角色是多对多的关系,即一个用户可以同时充当多个角色,一个角色可以有多个用户,角色与权限资源也是多对多关系。
CREATE TABLE `user_demo`.`company` ( `id` int(11) NOT NULL, `company_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '企业名称', `company_no` int(11) NOT NULL COMMENT '企业编号', `address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '地址', `status` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '状态,1启用,2禁用', `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `create_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `update_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `creator` int(11) NOT NULL, `modifier` int(11) NOT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; CREATE TABLE `user_demo`.`privilege` ( `id` int(11) NOT NULL, `privilege_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '资源名称', `privilege_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '资源路径', `view_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '视图路径', `parent_id` int(11) NOT NULL COMMENT '父级资源id', `level_cnt` int(11) NOT NULL COMMENT '级别', `sort_num` int(11) NOT NULL COMMENT '排序号', `icon` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图标', `status` tinyint(255) NOT NULL COMMENT '状态,1启用,2禁用', `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `creator` int(11) NOT NULL, `modifier` int(11) NOT NULL, `create_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `update_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; CREATE TABLE `user_demo`.`role` ( `id` int(11) NOT NULL, `role_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色名称', `company_id` int(11) NOT NULL, `status` tinyint(255) NOT NULL COMMENT '状态,1启用,2禁用', `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '备注', `create_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `update_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `creator` int(11) NOT NULL, `modifier` int(11) NOT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; CREATE TABLE `user_demo`.`role_privilege` ( `id` int(11) NOT NULL, `role_id` int(11) NOT NULL COMMENT '角色id', `privilege_id` int(11) NOT NULL COMMENT '权限id(资源id)', `create_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `update_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `creator` int(11) NOT NULL, `modifier` int(11) NOT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; CREATE TABLE `user_demo`.`staffer` ( `id` int(11) NOT NULL AUTO_INCREMENT, `staffer_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '员工姓名', `staffer_sex` tinyint(255) NOT NULL COMMENT '性别', `staffer_mobile` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '手机', `staffer_address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '地址', `birthday_dtm` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '生日', `status` tinyint(255) NOT NULL COMMENT '状态,1在职,2离职,3冻结', `account_id` int(11) NOT NULL COMMENT '账号id', `account_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '登录账号', `account_no` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '账号编码', `account_pwd` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '账号密码', `lock_dtm` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '锁定时间', `company_id` int(11) NOT NULL COMMENT '企业id', `department_id` int(11) NOT NULL COMMENT '部门id', `creator` int(255) NOT NULL, `modifier` int(255) NOT NULL, `create_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `update_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; CREATE TABLE `user_demo`.`staffer_role` ( `id` int(11) NOT NULL, `role_id` int(11) NOT NULL COMMENT '角色id', `staffer_id` int(11) NOT NULL COMMENT '员工id', `role_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色名称', `create_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `update_time` datetime(0) NOT NULL ON UPDATE CURRENT_TIMESTAMP(0), `creator` int(11) NOT NULL, `modifier` int(11) NOT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;