權限系統基本分析

權限系統的存在就是爲了用戶登錄系統存在的,而登錄的作用就是判斷用戶的權限,登錄的過程,是用戶輸入用戶名,密碼來得到用戶的權限,角色,部門及其系統中的欄目(或稱菜單)的過程,這個裏面有很多的實現,先分析欄目和部門綁定的過程。

 

-- 查詢登陸帳號對應的權限
select * from Fucdefine as fucdefine where fucdefine.id in
 (select rolefucperm.fucdefineid from Rolefucperm as rolefucperm where rolefucperm.roleid in
  (select userrole.roleid from Userrole as userrole where userrole.cmsuserid in
   (select account.cmsuserid from Account as account where account.id=account.loginname=? and account.loginpassword=?)
  )
 )
order by fucdefine.id asc

 

-- 查詢登陸帳號對應的用戶對應的部門編號
select cmsuser.departmentid from Cmsuser as cmsuser where cmsuser.id in
 (select account.cmsuserid from Account as account where account.id=account.loginname=? and account.loginpassword=?)

 

-- 查詢登陸帳號對應的用戶對應的部門編號對應的欄目
select deptcolumn.columninfoid from Deptcolumn as deptcolumn where deptcolumn.departmentid in
 (select cmsuser.departmentid from Cmsuser as cmsuser where cmsuser.id in
  (select account.cmsuserid from Account as account where account.loginname=? and account.loginpassword=?)
 )
    

 

通過相關sql,可以看到權限系統涉及到很多的表,賬戶表,用戶表,角色表,權限表,部門表,欄目表

多對多關係有:角色表和權限表、部門表和欄目表兩種,所以增加兩張表:角色權限表和部門欄目表

 

得到權限的過程

 1)賬戶表account與用戶表cmsuser存在關係,通過賬戶名、密碼找到帳戶表記錄中的cmsuserid
 2)用戶表與角色表userrole存在關係,通過cmsuserid找到角色id
 3)角色表與角色權限表rolefucperm存在關係,通過roleid找到權限id
 4)角色權限表與權限表fucdefine存在關係,通過權限id找到權限

 

得到部門的過程

 1)賬戶表account與用戶表cmsuser存在關係,通過賬戶名、密碼找到帳戶表記錄中的cmsuserid
 2)根據cmsuserid查詢用戶表,得到對應部門id

 

得到欄目的過程

1)賬戶表account與用戶表cmsuser存在關係,通過賬戶名、密碼找到帳戶表記錄中的cmsuserid
2)根據cmsuserid查詢用戶表,得到對應部門id

3)根據部門id查詢部門欄目表,得到欄目id

 

先簡單介紹到這裏,mark下

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章