ASP.NET MVC5+EF6+EasyUI 後臺管理系統(41)-組織架構

weixin_34126215發表於2015-03-22

系列目錄

本節開始我們要實現工作流,此工作流可以和之前的所有章節脫離關係,也可以緊密合並。

我們當初設計的專案解決方案就是可伸縮可以拆離,可共享的專案解決方案。所以我們同時要新增App.Flow資料夾

工作流的開始之前,我們必須有一個組織架構,我們做成無限動態級別樹,因為之前的模組管理也是無限級別的

知識點:Easyui TreeGrid用法,根據組織架構讀取架構下所有使用者(with...as....)

穿越到模組管理的原始碼 有點雷同的Easyui TreeGrid的製作

CREATE TABLE [dbo].[SysStruct](
    [Id] [varchar](50) NOT NULL,            --主鍵ID
    [Name] [varchar](50) NOT NULL,          --架構名稱
    [ParentId] [varchar](50) NOT NULL,      --上級ID
    [Sort] [int] NOT NULL,                  --排序
    [Higher] [varchar](50) NULL,            --  備用
    [Enable] [bit] NOT NULL,                --是否啟用
    [Remark] [varchar](500) NULL,           --說明
    [CreateTime] [datetime] NOT NULL,       --建立時間
 CONSTRAINT [PK_SysStruct] 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

ALTER TABLE [dbo].[SysStruct]  WITH NOCHECK ADD  CONSTRAINT [FK_SysStruct_SysStruct] FOREIGN KEY([ParentId])
REFERENCES [dbo].[SysStruct] ([Id])
GO

ALTER TABLE [dbo].[SysStruct] NOCHECK CONSTRAINT [FK_SysStruct_SysStruct]
GO

ALTER TABLE [dbo].[SysStruct] ADD  CONSTRAINT [DF_SysStruct_Sort]  DEFAULT ((0)) FOR [Sort]
GO

ALTER TABLE [dbo].[SysStruct] ADD  CONSTRAINT [DF__SysStruct__Highe__3D2915A8]  DEFAULT ((0)) FOR [Higher]
GO

ALTER TABLE [dbo].[SysStruct] ADD  CONSTRAINT [DF_SysStruct_State]  DEFAULT ((1)) FOR [Enable]
GO

ALTER TABLE [dbo].[SysStruct] ADD  CONSTRAINT [DF_SysStruct_CreateTime]  DEFAULT (getdate()) FOR [CreateTime]
GO

最終效果圖

理論是無限級別的。這裡我只做了3級

接下來我們關聯SysUser和SysStruct的關係。並新增儲存過程,這個儲存過程很有用,sql沒有遞迴,用with...as....語句最適合不過了,貌似2005版本以上才支援

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) NOT 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] NOT 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] [bit] NOT NULL,
    [Photo] [varchar](200) NULL,
    [Attach] [varchar](200) NULL,
    [Lead] [varchar](4000) NULL,
    [LeadName] [varchar](4000) NULL,
    [IsSelLead] [bit] NOT NULL,
    [IsReportCalendar] [bit] NOT NULL,
    [IsSecretary] [bit] NOT 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'在職狀況1在職,2離職' , @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

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'Lead'
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'LeadName'
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'IsSelLead'
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'IsReportCalendar'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'開啟 小祕書訊息提示(預設每10分鐘提示一次)
開啟 小祕書訊息提示(每2分鐘提示一次)
開啟 小祕書訊息提示(每5分鐘提示一次)
開啟 小祕書訊息提示(每20分鐘提示一次)
開啟 小祕書訊息提示(每30分鐘提示一次)
開啟 小祕書訊息提示(每1小時提示一次)
開啟 小祕書訊息提示(每2小時提示一次)
禁用 小祕書訊息提示(不再提示)
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SysUser', @level2type=N'COLUMN',@level2name=N'IsSecretary'
GO
這是我的SysUser表

我們以後如果按組織架構流轉。比如按總公司流轉,那麼我們根據總公司的ID就能找到無限樹葉的所有使用者了。

我以前習慣叫部門,所以儲存過程的Dep就是現在的Strcut了

USE [AppDB]
GO
/****** Object:  StoredProcedure [dbo].[P_Sys_GetUserByDepId]    Script Date: 03/21/2015 22:08:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[P_Sys_GetUserByDepId]
@DepId varchar(50)
as
begin

--讀取角色所包含的使用者
with CTE_Depart(Id ,Name ,ParentID )as
(
    select    a.Id ,a.Name ,a.Id  ParentID
    from    SysStruct  a
    union    all
    select    a.Id,a.Name ,b.ParentID 
    from    SysStruct a
            join CTE_Depart b on a.ParentID = b.Id 
)

 select    b.*,0 as flag
from    CTE_Depart a
        left join SysUser b  on a.id = b.DepId 
where    a.ParentID=@DepId and b.Id is not null


end 

好了。沒啥...

相關文章