系列目錄html
這節咱們說下權限系統的特色,本系統採用的是MVC4+EF5+IOC 接口編程的架構,其中的權限樹用的是DWTree,功能上作到靈活,受權操控細緻,權限能夠細到按鈕級別
,爲了部署簡單,致使設計和編碼上也是比較複雜
該系統主要功能以下: 數據庫
從數據庫結構來看,一共設計了七個表(table),表名及功能分別以下:
1.模塊管理(SysModule)
系統菜單的管理,支持無限級別樹,表咱們在以前的文章已經建好了
2.用戶表(SysUser)
系統會員,登陸系統的惟一憑證
3.角色組(SysRole)
對角色組基本信息進行管理。用戶能夠自定義成各類各樣的角色組,而後對用戶受權
4.模塊操做碼(SysModuleOperate)
操做碼錶的父表是模塊表,一下模塊下面有多個操做碼,好比增長,刪除,審覈,修改等.
5.受權表(SysRoleSysUser)
用戶和角色組的對應表,一個角色擁有多個用戶,一個用戶能夠擁有多個角色
6.角色權限表(SysRight)
將角色與系統中的權限點關聯起來,也就是完成受權的動做。
7.被付權限操做碼錶(SysRightOperate)
保存有權限的角色的操做碼,當有一個操做碼被賦予權限時,將激活對應的菜單編程
咱們經過一張物理模型圖看出表與表以前的關係架構
如今經過物理模型轉化爲SQL語句編碼
CREATE TABLE [dbo].[SysModule]( [Id] [varchar](50) NOT NULL, [Name] [varchar](200) NOT NULL, [EnglishName] [varchar](200) NULL, [ParentId] [varchar](50) NULL, [Url] [varchar](200) NULL, [Iconic] [varchar](200) NULL, [Sort] [int] NULL, [Remark] [varchar](4000) NULL, [State] [bit] NULL, [CreatePerson] [varchar](200) NULL, [CreateTime] [datetime] NULL, [IsLast] [bit] NOT NULL, [Version] [timestamp] NULL, CONSTRAINT [PK_SysModule] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TABLE [dbo].[SysModuleOperate]( [Id] [varchar](200) NOT NULL, [Name] [varchar](200) NOT NULL, [KeyCode] [varchar](200) NOT NULL, [ModuleId] [varchar](50) NOT NULL, [IsValid] [bit] NOT NULL, [Sort] [int] NOT NULL, CONSTRAINT [PK_SysModuleOperate] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TABLE [dbo].[SysRole]( [Id] [varchar](50) NOT NULL, [Name] [varchar](200) NOT NULL, [Description] [varchar](4000) NOT NULL, [CreateTime] [datetime] NOT NULL, [CreatePerson] [varchar](200) NOT NULL, CONSTRAINT [PK_SysRole] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TABLE [dbo].[SysUser]( [Id] [varchar](50) NOT NULL, [UserName] [varchar](200) NOT NULL, [Password] [varchar](200) NOT NULL, [TrueName] [varchar](200) NULL, [Card] [varchar](50) NULL, [MobileNumber] [varchar](200) NULL, [PhoneNumber] [varchar](200) NULL, [QQ] [varchar](50) NULL, [EmailAddress] [varchar](200) NULL, [OtherContact] [varchar](200) NULL, [Province] [varchar](200) NULL, [City] [varchar](200) NULL, [Village] [varchar](200) NULL, [Address] [varchar](200) NULL, [State] [bit] NULL, [CreateTime] [datetime] NULL, [CreatePerson] [varchar](200) NULL, [Sex] [varchar](10) NULL, [Birthday] [datetime] NULL, [JoinDate] [datetime] NULL, [Marital] [varchar](10) NULL, [Political] [varchar](50) NULL, [Nationality] [varchar](20) NULL, [Native] [varchar](20) NULL, [School] [varchar](50) NULL, [Professional] [varchar](100) NULL, [Degree] [varchar](20) NULL, [DepId] [varchar](50) NOT NULL, [PosId] [varchar](50) NOT NULL, [Expertise] [varchar](3000) NULL, [JobState] [varchar](20) NULL, [Photo] [varchar](200) NULL, [Attach] [varchar](200) NULL, CONSTRAINT [PK_SysUser] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'身份證' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'MobileNumber' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'婚姻' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'Marital' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'黨派' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'Political' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'民族' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'Nationality' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'籍貫' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'Native' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'畢業學校' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'School' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'就讀專業' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'Professional' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'學歷' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'Degree' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'部門' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'DepId' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'職位' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'PosId' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'我的簡介' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'Expertise' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'在職情況' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'JobState' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'照片' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'Photo' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'附件' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'Attach' GO CREATE TABLE [dbo].[SysRoleSysUser]( [SysUserId] [varchar](50) NOT NULL, [SysRoleId] [varchar](50) NOT NULL, CONSTRAINT [PK_SysRoleSysUser] PRIMARY KEY CLUSTERED ( [SysUserId] ASC, [SysRoleId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TABLE [dbo].[SysRight]( [Id] [varchar](200) NOT NULL, [ModuleId] [varchar](50) NOT NULL, [RoleId] [varchar](50) NOT NULL, [Rightflag] [bit] NOT NULL, CONSTRAINT [PK_SysRight] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TABLE [dbo].[SysRightOperate]( [Id] [varchar](200) NOT NULL, [RightId] [varchar](200) NOT NULL, [KeyCode] [varchar](200) NOT NULL, [IsValid] [bit] NOT NULL, CONSTRAINT [PK_SysRightOperate] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[SysModule] WITH NOCHECK ADD CONSTRAINT [FK_SysModule_SysModule] FOREIGN KEY([ParentId]) REFERENCES [dbo].[SysModule] ([Id]) GO ALTER TABLE [dbo].[SysModule] NOCHECK CONSTRAINT [FK_SysModule_SysModule] GO ALTER TABLE [dbo].[SysModuleOperate] WITH CHECK ADD CONSTRAINT [FK_SysModuleOperate_SysModule] FOREIGN KEY([ModuleId]) REFERENCES [dbo].[SysModule] ([Id]) ON DELETE CASCADE GO ALTER TABLE [dbo].[SysModuleOperate] CHECK CONSTRAINT [FK_SysModuleOperate_SysModule] GO ALTER TABLE [dbo].[SysRoleSysUser] WITH CHECK ADD CONSTRAINT [FK_SysRoleSysUser_SysRole] FOREIGN KEY([SysRoleId]) REFERENCES [dbo].[SysRole] ([Id]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[SysRoleSysUser] CHECK CONSTRAINT [FK_SysRoleSysUser_SysRole] GO ALTER TABLE [dbo].[SysRoleSysUser] WITH CHECK ADD CONSTRAINT [FK_SysRoleSysUser_SysUser] FOREIGN KEY([SysUserId]) REFERENCES [dbo].[SysUser] ([Id]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[SysRoleSysUser] CHECK CONSTRAINT [FK_SysRoleSysUser_SysUser] GO ALTER TABLE [dbo].[SysRight] WITH CHECK ADD CONSTRAINT [FK_SysRight_SysModule] FOREIGN KEY([ModuleId]) REFERENCES [dbo].[SysModule] ([Id]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[SysRight] CHECK CONSTRAINT [FK_SysRight_SysModule] GO ALTER TABLE [dbo].[SysRight] WITH CHECK ADD CONSTRAINT [FK_SysRight_SysRole] FOREIGN KEY([RoleId]) REFERENCES [dbo].[SysRole] ([Id]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[SysRight] CHECK CONSTRAINT [FK_SysRight_SysRole] GO ALTER TABLE [dbo].[SysRightOperate] WITH CHECK ADD CONSTRAINT [FK_SysRightOperate_SysRight] FOREIGN KEY([RightId]) REFERENCES [dbo].[SysRight] ([Id]) ON DELETE CASCADE GO ALTER TABLE [dbo].[SysRightOperate] CHECK CONSTRAINT [FK_SysRightOperate_SysRight] GO
複製SQL語句放到查詢窗口執行一下而後用視圖看看他們之間的對應關係spa
今天就到這裏了設計