一、表的说明

1具权限项掩码表:包括字段 ID,权限类别,权限明细,权限码,下属权限码 等

权限码 用二进制数为标志 如1 2 4 8 16等

下属权限码 是该权限所包含的统一权限类别的其他的权限 用二进制数表示

权限明细与权限码保持一致 但是用字符串表示 如edit delect 等

权限类别是某一功能的表示 如client 等

 

2 角色表:包括字段,ID,角色名,角色的描述 等

 

3权限表:ID,权限类别,权限码总和

权限类别 跟权限表的权限类别关联

权限码总和 是指同一权限类别的权限总和(用二进制表示权限码的意义就是能够通过权限码的总和可以分出具体的那些权限)


4 用户表:包括三个或以上字段,ID,用户名,对该用户的描述,其它(如地址、电话等信息);

 

5用户部门表:包含 ID,部门编号,部门名称 等

 

6部门-角色-用户表 ID,部门ID,角色ID,用户ID

用来解决一个用户多部门多角色的问题 同一个职员在一个部门也可以拥有多个角色

如 用户1-部门1-角色1

用户1-部门2-角色1

用户1-部门3-角色2

等等

 

二、程序解决方法

1具权限项掩码表

 

 
  
  1. 代码  
  2.  
  3. GO  
  4. if exists (select 1  
  5.             from  sysobjects  
  6.            where  id = object_id('t_Object')  
  7.             and   type = 'U')  
  8.    drop table t_Object  
  9. GO  
  10. create table  t_Object(  
  11.     FObjectno            varchar(40)        not null,  
  12.     FObjectgroup         varchar(40)        not null,  
  13.     FObjectorder         int                not null,  
  14.     FSysID               varchar(40)        not null   default ('system'),  
  15.     F0bjectdetail        nvarchar(40)       not null   default (''),  
  16.     FAccessmask          bigint             not null   default ((0)),  
  17.     FAccessinclude       bigint             not null   default ((0)),  
  18.     FServicetype         nvarchar(20)       not null   default (''),  
  19.     FObjectid            bigint             not null,  
  20.  constraint [PK_t_Object] primary key clustered   
  21. (  
  22.     FSysID asc,  
  23.     Fobjectid asc  
  24. )with (ignore_dup_key = off) on [primary]  
  25. ) on [primary]  
  26. GO 

2 角色表

 

 
  
  1. 代码  
  2.  
  3. GO  
  4. if exists (select 1  
  5.             from  sysobjects  
  6.            where  id = object_id('t_Role')  
  7.             and   type = 'U')  
  8.    drop table t_Role  
  9. GO  
  10. create table t_Role(  
  11.    FRoleID              bigint               not null,  
  12.    FSysID               nvarchar(40)         not null,  
  13.    FRoleName             nvarchar(50)          not null,  
  14.    FRoleType               nvarchar(40)         not null,  
  15.    FRoleNO              nvarchar(40)            null,  
  16.    FDesc              nvarchar(40)            null  
  17.  constraint [PK_t_Role] primary key clustered   
  18. (  
  19.     FRoleID ASC,  
  20.     FSysID ASC  
  21. )with (ignore_dup_key = off) on [primary]  
  22. ) on [primary]  
  23. GO 

3权限表

 

 
  
  1. 代码  
  2.  
  3. GO  
  4. if exists (select 1  
  5.             from  sysobjects  
  6.            where  id = object_id('t_RoleRelation')  
  7.             and   type = 'U')  
  8.    drop table t_RoleRelation  
  9. GO  
  10. create table t_RoleRelation(  
  11.    FRoleID              bigint               not null,  
  12.    FSysID               nvarchar(40)         not null,  
  13.    FObjectNO            nvarchar(40)               not null,  
  14.    FAccessMask            bigint           null  
  15.  constraint [PK_t_RoleRelation] primary key clustered   
  16. (  
  17.     FRoleID ASC,  
  18.     FSysID ASC,  
  19.     FObjectNO ASC  
  20. )with (ignore_dup_key = off) on [primary]  
  21. ) on [primary]  
  22. GO 

4 用户表

 

 
  
  1. 代码  
  2.  
  3. GO  
  4. create table  t_Employee(  
  5.     FEmpID     bigint            not null,  
  6.     FEmpNO     nvarchar(50)      not null,  
  7.     FEmpName   nvarchar(50)      not null,  
  8.     FEmpType   smallint          not null,  
  9.     FSysID     varchar(40)       not null,  
  10.     FDeptID    bigint            null DEFAULT ((-1)),  
  11.     FSex       nchar(1)          null DEFAULT (''),  
  12.     FBirthday  datetime          null,  
  13.     FMobile    nvarchar(50)      null,  
  14.     FEmail     nvarchar(100)     null,  
  15.     FAllowSMS  bit               not null DEFAULT ('True'),  
  16.  
  17.  constraint [PK_t_Employee] primary key clustered   
  18. (  
  19.     FEmpID ASC,  
  20.     FSysID ASC  
  21. )with (ignore_dup_key = off) on [primary]  
  22. ) on [primary]  
  23. GO 

5用户部门表

 

 
  
  1. 代码  
  2.  
  3. GO  
  4. create table  t_Department (  
  5.      FDeptID      bigint             not null,  
  6.      FDeptNo      nvarchar(50)       not null,  
  7.      FDeptName    nvarchar(50)       not null,  
  8.      FDesc        nvarchar(255)      null,  
  9.      FSysID       varchar(40)        not null,  
  10.  constraint [PK_t_Department] primary key clustered   
  11. (  
  12.     FDeptID ASC,  
  13.     FSysID ASC  
  14. )with (ignore_dup_key = off) on [primary]  
  15. ) on [primary]  
  16. GO 

6部门-角色-用户表

 

 
  
  1. 代码  
  2.  
  3. GO  
  4. if exists (select 1  
  5.             from  sysobjects  
  6.            where  id = object_id('t_RoleAccess')  
  7.             and   type = 'U')  
  8.    drop table t_RoleAccess  
  9. GO  
  10. create table t_RoleAccess(  
  11.    FRoleAccessID       bigint               not null,  
  12.    FCoid               nvarchar(40)         not null,  
  13.    FRoleID             bigint               not null,  
  14.    FBuID               bigint               not null,  
  15.    FDeptID             bigint               not null,  
  16.    FEmpID              bigint               not null,  
  17.    FHidTag             smallint               null,  
  18.    FDelTag             smallint               null,  
  19.    FState              smallint               null  
  20.  constraint [PK_t_RoleAccess] primary key clustered   
  21. (  
  22.     FRoleAccessID ASC,  
  23.     FCoid ASC  
  24. )with (ignore_dup_key = off) on [primary]  
  25. ) on [primary]  
  26. GO