JEESITE快速开发平台用户-角色-部门-区域-菜单-权限表关系
Posted 化妆舞会
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JEESITE快速开发平台用户-角色-部门-区域-菜单-权限表关系相关的知识,希望对你有一定的参考价值。
一、表关系
一共有8张表分别用来实现用户-角色-部门-区域-菜单-权限管理,详细如下:
二、SQL语句
- /*********************一共八张表************************/
- select * from sys_user; //用户表
- select * from sys_menu; //菜单表
- select * from sys_role; //角色表
- select * from sys_user_role; //用户角色表
- select * from sys_role_menu; //角色与菜单表
- select * from sys_area; //区域表
- select * from sys_office; //公司和部门表
- select * from sys_role_office; //角色与部门表
- /*********************用户关联角色************************/
- select * from sys_user where id=‘11‘
- select * from sys_user_role where user_id=‘11‘
- select * from sys_role where id=‘3‘
- select count(1),user_id from sys_user_role GROUP BY user_id
- select count(*) from sys_user_role where user_id=‘1‘
- select us.name,sr.name as rolename from (select * from sys_user where id=‘1‘) us
- left JOIN sys_user_role usrole on us.id=usrole.user_id
- LEFT JOIN sys_role sr on usrole.role_id = sr.id
- /****以用户表为主表(通过sys_user的ID关联sys_user_role中的user_id,然后再通过sys_user_role中的role_Id关联角色表)****/
- select su.name as username,sr.name as rolename from sys_user su
- LEFT JOIN sys_user_role sur on su.id = sur.user_id
- LEFT JOIN sys_role sr on sur.role_id = sr.id
- /****以角色表为主表(通过sys_role的id关联sys_user_role中的role_id,然后再通过sys_user_role中的user_id关联sys_ser表中的id)****/
- SELECT u.name as uname,a.name as rolename FROM sys_role a
- LEFT JOIN sys_user_role ur ON ur.role_id = a.id
- LEFT JOIN sys_user u ON u.id = ur.user_id
- select * from sys_user_role; //用户角色表
- select * from sys_role; //角色表
- /*********************角色关联菜单************************/
- /****以角色表为主表****/
- SELECT u.id as userid,u.name as username,a.id as roleid,a.name as rolename,sm.name menuname FROM sys_role a
- LEFT JOIN sys_user_role ur ON ur.role_id = a.id
- LEFT JOIN sys_user u ON u.id = ur.user_id
- LEFT JOIN sys_role_menu srm on srm.role_id = a.id
- LEFT JOIN sys_menu sm on srm.menu_id = sm.id
- select a.name as menuname FROM sys_menu a
- select a.name as menuname FROM sys_menu a
- LEFT JOIN sys_menu p ON p.id = a.parent_id
- /****以菜单表为主表****/
- select a.name as menuname,r.name as rolename,u.name as username FROM sys_menu a
- LEFT JOIN sys_menu p ON p.id = a.parent_id
- JOIN sys_role_menu rm ON rm.menu_id = a.id
- JOIN sys_role r ON r.id = rm.role_id AND r.useable=‘1‘
- JOIN sys_user_role ur ON ur.role_id = r.id
- JOIN sys_user u ON u.id = ur.user_id
- select * from sys_user_role; //用户角色表
- select * from sys_role; //角色表
- select * from sys_role_menu; //角色与菜单表
- /*********************用户关联公司和部门************************/
- /****通过company_id关联机构表中的公司****/
- select su.name as username,so.name as companyname from sys_user su
- LEFT JOIN sys_office so on su.company_id = so.id
- select of.* from sys_user us
- left JOIN sys_office of on us.company_id = of.id where us.id=‘11‘
- /****通过office_id关联机构表的部门****/
- select su.name as username,so.name as officename from sys_user su
- LEFT JOIN sys_office so on su.office_id = so.id
- select of.* from sys_user us
- left JOIN sys_office of on us.office_id = of.id where us.id=‘11‘
- select * from sys_user; //用户表
- select * from sys_office; //公司和部门表
- /*********************角色关联公司和部门************************/
- /******通过sys_role中的id然后关联sys_user_role表中的role_id,然后再通过sys_user_role中的user_id关联sys_user中的id
- 然后再通过sys_role_office中的role_id关联sys_role中的id,最后通过sys_role_office中的office_id关联sys_office中的id*****/
- SELECT u.name as uname,a.id as roleid,a.name as rolename,so.name as officename FROM sys_role a
- LEFT JOIN sys_user_role ur ON ur.role_id = a.id
- LEFT JOIN sys_user u ON u.id = ur.user_id
- LEFT JOIN sys_role_office sro on a.id = sro.role_id
- LEFT JOIN sys_office so on sro.office_id = so.id
- select * from sys_user; //用户表
- select * from sys_user_role; //用户角色表
- select * from sys_role; //角色表
- select * from sys_office; //公司和部门表
- select * from sys_role_office; //角色与部门表
- /*********************公司和部关联区域表************************/
- /******通过sys_office中的area_id然后关联sys_area表中的id*****/
- select of.name as officename,ar.name as areaname from sys_office of
- LEFT JOIN sys_area ar on of.area_id=ar.id
- select * from sys_area; //区域表
- select * from sys_office; //公司和部门表
以上是关于JEESITE快速开发平台用户-角色-部门-区域-菜单-权限表关系的主要内容,如果未能解决你的问题,请参考以下文章