1 Star 0 Fork 737

codingstudio/CCFlow

forked from 济南驰骋公司/CCFlow 
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
CCIM_MSSQL.sql 31.77 KB
Copy Edit Raw Blame History
驰骋BPM authored 2020-04-20 10:04 +08:00 . 升级集团版本的二级管理员.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
CREATE TABLE [UserRecentContact](
[UserID] [varchar](50) NOT NULL,
[ContactID] [varchar](50) NULL,
[ContactType] [int] NULL,
[ContactTime] [varchar](50) NULL,
[OrderID] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [SMS](
[msgID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[smsMsgContent] [text] NOT NULL,
[sendID] [nchar](20) NOT NULL,
[datetime] [datetime] NOT NULL,
CONSTRAINT [PK_SMS] PRIMARY KEY CLUSTERED
(
[msgID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [sendCount](
[MsgID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[smsMsgContent] [text] NOT NULL,
[saveDate] [datetime] NOT NULL,
CONSTRAINT [PK_sendCount] PRIMARY KEY CLUSTERED
(
[MsgID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [RecordMsgUser](
[ID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[MsgId] [numeric](18, 0) NOT NULL,
[ReceiveID] [nchar](20) NOT NULL,
[isSendSuccess] [bit] NOT NULL,
[isSave] [bit] NOT NULL,
CONSTRAINT [PK_GroupRecordMsg] 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 function [Get_StrArrayStrOfIndex]
(
@str varchar(8000), --要分割的字符串
@split varchar(10), --分隔符号
@index int --取第几个元素
)
returns varchar(1024)
as
begin
declare @location int
declare @start int
declare @next int
declare @seed int
set @str=ltrim(rtrim(@str))
set @start=1
set @next=1
set @seed=len(@split)
set @location=charindex(@split,@str)
while @location<>0 and @index>@next
begin
set @start=@location+@seed
set @location=charindex(@split,@str,@start)
set @next=@next+1
end
if @location =0 select @location =len(@str)+1
--这儿存在两种情况:1、字符串不存在分隔符号 2、字符串中存在分隔符号,
--跳出while循环后,@location为0,那默认为字符串后边有一个分隔符号。
return substring(@str,@start,@location-@start)
end
GO
CREATE function [dbo].[Get_StrArrayLength]
(
@str varchar(8000), --要分割的字符串
@split varchar(10) --分隔符号
)
returns int
as
begin
declare @location int
declare @start int
declare @length int
set @str=ltrim(rtrim(@str))
set @location=charindex(@split,@str)
set @length=1
while @location<>0
begin
set @start=@location+1
set @location=charindex(@split,@str,@start)
set @length=@length+1
end
return @length
end
GO
CREATE TABLE [CustomGroup](
[GroupID] [int] IDENTITY(1,1) NOT NULL,
[GroupName] [varchar](50) NULL,
[Notice] [nvarchar](200) NULL,
[users] [ntext] NULL,
[UserID] [varchar](50) NULL,
[CreateDateTime] [datetime] NULL,
CONSTRAINT [PK_CustomGroup] PRIMARY KEY CLUSTERED
(
[GroupID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE FUNCTION [GetParentDeptID](@DeptID varchar(1000))
RETURNS int
AS
BEGIN
DECLARE @ParentDeptID int
--传入的是字符型部门编号(能转换为整数),编码规则为aabbccdd
IF LEN(@DeptID)=2
SET @ParentDeptID=0 --最上一级
ELSE
BEGIN
SET @ParentDeptID=CAST(LEFT(@DeptID,LEN(@DeptID)-2) as int)
END
RETURN @ParentDeptID
END
GO
CREATE TABLE [RecordMsg](
[MsgID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[sendID] [nchar](200) NULL,
[msgDateTime] [datetime] NULL,
[msgContent] [text] NULL,
[ImageInfo] [ntext] NULL,
[fontName] [nchar](30) NULL,
[fontSize] [float] NULL,
[fontBold] [bit] NULL,
[fontItalic] [bit] NULL,
[fontStrikeout] [bit] NULL,
[fontUnderline] [bit] NULL,
[fontColor] [int] NULL,
[InfoClass] [int] NULL,
[SMSInfo] [tinyint] NULL,
[GroupID] [int] NULL,
[SendUserID] [nchar](200) NULL,
CONSTRAINT [PK_RecordMsg] PRIMARY KEY CLUSTERED
(
[MsgID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE FUNCTION [MD5]
(
-- 源字符串
@src nvarchar(max),
-- 加密类型(16/32)
@type int = 32
)
RETURNS nvarchar(max)
WITH EXECUTE AS CALLER
AS
BEGIN
-- 存放md5加密串(ox)
DECLARE @smd5 varchar(34)
-- 加密字符串
SELECT @smd5 =sys.fn_VarBinToHexStr(hashbytes('MD5', @src));
IF @type=16
SELECT @smd5 = SUBSTRING(@smd5,11,16) --16位
ELSE
SELECT @smd5 = SUBSTRING(@smd5,3,32) --32位
-- 返回加密串
RETURN @smd5
END
GO
CREATE TABLE [IMUser](
[UserID] [varchar](50) NOT NULL,
[orderID] [int] NULL,
[headPicIdx] [int] NULL,
[onlineState] [tinyint] NULL,
[lastIP] [char](30) NULL,
[lastPort] [int] NULL,
[lastNetClass] [tinyint] NULL,
[lastDate] [datetime] NULL,
[onlineDateLength] [int] NULL,
[CreateGroupMax] [tinyint] NULL,
[isSendSMS] [tinyint] NULL,
[isEditUserData] [tinyint] NULL,
[isAdmin] [bit] NULL,
[Remark] [nvarchar](200) NULL,
[isAbandan] [bit] NULL,
[DepsVersion] [char](32) NULL,
[UsersVersion] [char](32) NULL,
[DepsCount] [int] NULL,
[UsersCount] [int] NULL,
[headPicFile] [nvarchar](256) NULL,
[SID] [varchar](20) NULL,
[Sex] [varchar](50) NULL,
[Tel] [varchar](50) NULL,
[Mobile] [varchar](50) NULL,
[Fax] [varchar](50) NULL,
[EMail] [varchar](50) NULL,
[Address] [varchar](200) NULL,
[PostCode] [varchar](50) NULL
) ON [PRIMARY]
GO
CREATE TABLE [IMDept](
[DeptID] [int] NOT NULL,
[orderID] [int] NULL,
[Phone] [varchar](50) NULL,
[Fax] [varchar](50) NULL,
[isAbandan] [bit] NULL
) ON [PRIMARY]
GO
CREATE PROCEDURE [GroupMsgRecordInsertUsers]
-- Add the parameters for the stored procedure here
@MsgId int,
@ReceiveID varchar(8000) --消息多个接收者用分号隔开
--@isSave bit
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.---1
SET NOCOUNT ON;
declare @next int
set @next=1
while @next<dbo.Get_StrArrayLength(@ReceiveID,';')
begin
insert into RecordMsgUser (MsgId,ReceiveID) values(@MsgId ,dbo.Get_StrArrayStrOfIndex(@ReceiveID,';',@next) )
set @next=@next+1
end
END
GO
CREATE PROC [GetOrgInfo]
@userID varchar(50)
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP 1 * FROM IMUser
END
GO
CREATE PROCEDURE [GetAllUsersSigns]
AS
BEGIN
SET NOCOUNT ON;
SELECT UserID,Remark from IMUser where UserID<>'admin'
END
GO
CREATE PROCEDURE [CustomGroupGetInfoFromGroupID]
-- Add the parameters for the stored procedure here
@GroupID int
AS
BEGIN
SET NOCOUNT ON;
SELECT * from customGroup where GroupID=@GroupID
END
GO
CREATE PROCEDURE [CustomGroupGetIDs]
-- Add the parameters for the stored procedure here
--@userID varchar(20)
@userID nvarchar(20)
AS
BEGIN
SET NOCOUNT ON;
SELECT GroupID,GroupName from customGroup where userID=@userID or users like '%' + @userID + ';%'
END
GO
CREATE PROCEDURE [CustomGroupCreateOrUpdate]
-- Add the parameters for the stored procedure here
@GroupID int,
@GroupName nvarchar(20),
@Notice nchar(100),
@Users text,
@userID nvarchar(20)
AS
BEGIN
declare @createMax int --标识用户用户组创建充许的最大值数
declare @createCount int --标识用户已经创建用户组的数目
declare @returnGroupID int--标识创建成功的用户组号,不成功为0;
set @createMax=1 --假设当前用户创建的最大值数
set @createCount=0 --假设当前用户已经创建的用户组数
set @returnGroupID=0--假设创建没有成功
SET NOCOUNT ON;
if @GroupID=0 --表示用户是创建新用户组
begin
--获取用户已经创建用户组的数目
select @createCount=count(*) from CustomGroup where UserID=@userID
--获取用户用户组创建充许的最大值
--select @createMax=CreateGroupMax from SystemUsers where UserID=@userID
--select @createMax=CreateGroupMax from Users where UserID=@userID
select @createMax=CreateGroupMax from IMUser where UserID=@userID
if @createCount<@createMax --如果还未达到最大值,则创建用户组,并返回创建组号
begin
insert into CustomGroup(GroupName,Notice,users,UserID) values( @GroupName,@Notice,@Users,@userID)--将创建用户组的信息存入表中
set @returnGroupID=@@IDENTITY --返回已创建或更新的用户组号码
end
end
if @GroupID<>0 --表示用户是更新其创建用户组的信息
begin
select @createCount=count(*) from CustomGroup where GroupID=@GroupID and UserID=@userID --判断要更新的用户组是否当前用户创建的
if @createCount=0 --如果不是当前用户创建的用户组,则无权更新信息
begin
set @returnGroupID=0
end
if @createCount=1 --如果是当前用户创建的用户组,则更新信息
begin
update CustomGroup set GroupName=@GroupName,Notice=@Notice,Users=@Users where GroupID=@GroupID
set @returnGroupID=@GroupID --设置返回用户组的ID
end
end
return @returnGroupID --返回已创建或更新的用户组号码
SET NOCOUNT OFF
END
GO
CREATE VIEW [V_Emp]
AS
SELECT [No] as UserID,[Name] as UserName,Pass,CAST(FK_Dept as int) as DeptID FROM Port_Emp
GO
CREATE VIEW [V_Dept]
AS
--SELECT CAST([No] as int) as DeptID,[Name] as DeptName,dbo.GetParentDeptID(No) as ParentDeptID
--FROM Port_Dept
SELECT CAST([No] as int) as DeptID,[Name] as DeptName,CAST(ParentNo as int) as ParentDeptID FROM Port_Dept
GO
CREATE PROCEDURE [UserUpdateSign]
@userID nvarchar(20),--用户ID
@Sign varchar(200) --签名
AS
BEGIN
SET NOCOUNT ON;
update IMUser set Remark=@Sign where userID=@userID
END
GO
CREATE PROCEDURE [UserUpdateOnlineState]
-- Add the parameters for the stored procedure here
--@userID varchar(20),--用户ID
@userID nvarchar(20),--用户ID
@State tinyint-- 0<用户状态值<255
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF @State=0--如果用户离线,则计算并保存其在线的时间
begin
--update systemUsers set onlineState=@State,onlineDateLength=(select isnull(onlineDateLength,0)+datediff(ss,lastDate,getdate()) from systemUsers where UserID=@userID) where UserID=@userID
update IMUser set onlineState=@State,onlineDateLength=(select isnull(onlineDateLength,0)+datediff(ss,lastDate,getdate()) from IMUser where UserID=@userID) where UserID=@userID
end
else
begin--否则只更新用户在线状态
--update systemUsers set onlineState=@State where UserID=@userID
update IMUser set onlineState=@State where UserID=@userID
end
END
GO
CREATE PROCEDURE [UserUpdateOnlineInfo]
-- Add the parameters for the stored procedure here
--@userID varchar(20),--用户ID
@userID nvarchar(20),--用户ID
--@IP varchar(15) ,--用户IP
@IP nvarchar(15) ,--用户IP
@Port int,--端口
@SID varchar(20), --SID
@NetClass tinyint--网络类型
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
--update systemUsers set lastIp=@IP,lastPort=@Port,lastNetClass=@NetClass,lastDate=GetDate(),
--onlineState=1 where userID=@userID
update IMUser set lastIp=@IP,lastPort=@Port,lastNetClass=@NetClass,lastDate=GetDate(),[SID]=@SID,onlineState=1 where userID=@userID
END
GO
CREATE PROCEDURE [RecordMsgInsert]
-- Add the parameters for the stored procedure here
--@userID varchar(20),
@userID nvarchar(20),
@ReceiveID varchar(20),
@msgContent ntext,
@ImageInfo ntext,
@fontName nchar(30),
@fontSize float,
@fontBold bit,
@fontItalic bit,
@fontStrikeout bit,
@fontUnderline bit,
@fontColor int,
@InfoClass int,
@SMSInfo tinyint,
@GroupID int
AS
BEGIN
SET NOCOUNT ON;
insert into RecordMsg (sendID,
msgContent,
ImageInfo,
fontName,
fontSize,
fontBold,
fontItalic,
fontStrikeout,
fontUnderline,
fontColor,
InfoClass,
SMSInfo,
GroupID
)
values(@userID,
@msgContent,
@ImageInfo,
@fontName,
@fontSize,
@fontBold,
@fontItalic,
@fontStrikeout,
@fontUnderline ,
@fontColor,
@InfoClass,
@SMSInfo,
@GroupID
)
if (@ReceiveID<>'')--如果接收者ID不为空,说明不是群发消息,则将用户记录添加到RecordMsgUser表
begin
insert into RecordMsgUser (MsgId,ReceiveID ) values(@@IDENTITY ,@ReceiveID )
end
SET NOCOUNT OFF
return @@IDENTITY
END
GO
CREATE PROCEDURE [RecordMsgGetFromId]
-- Add the parameters for the stored procedure here
@ID numeric (18,0)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT * from RecordMsg where MsgId= @ID
END
GO
CREATE PROCEDURE [RecordMsgGet]
-- Add the parameters for the stored procedure here
@userID nvarchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT * from RecordMsg,RecordMsgUser where RecordMsgUser.isSendSuccess=0 and RecordMsgUser.ReceiveID=@userID and RecordMsg.MsgId=RecordMsgUser.MsgId
END
GO
CREATE PROCEDURE [RecordMsgDelFromID]
-- Add the parameters for the stored procedure here
@ID numeric (18,0),
@userID nvarchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- update RecordMsgUser set isSendSuccess=1 where ReceiveID=@userID and MsgId=@ID
-- 先删除RecordMsgUser表中的用户信息
delete from RecordMsgUser where ReceiveID=@userID and MsgId=@ID
-- 获取当前消息的记录条数是否为0
DECLARE @Total INT
select @Total=count(*) from RecordMsgUser where MsgId=@ID
if (@Total=0)
begin
delete from RecordMsg where MsgId=@ID --删除当前离线消息
end
END
GO
CREATE PROCEDURE [UpdateRecentContact]
-- Add the parameters for the stored procedure here
--@userID varchar(20),--用户ID
@userID nvarchar(20),--用户ID
@receiveID nvarchar(20)-- 最近联系人ID
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @existUserID int;
DECLARE @cTime varchar(50);
SET @cTime= CONVERT(varchar(4),year(getdate()))+'-'+CONVERT(varchar(4),month(getdate()))+'-'+CONVERT(varchar(2),day(getdate()))+' '+CONVERT(varchar(2),datepart(hh,getdate
()))+':'+CONVERT(varchar(2),datepart(mi,getdate()))+':'+CONVERT(varchar(2),datepart(ss,getdate()))+'.'+CONVERT(varchar(10),datepart(ms,getdate()))
SELECT @existUserID=COUNT(*) FROM UserRecentContact WHERE UserID=@userID AND ContactID=@receiveID
IF @existUserID=0--列表中没有该用户,则添加记录
begin
INSERT INTO UserRecentContact(UserID,ContactID,ContactType,ContactTime,OrderID) VALUES(@userID,@receiveID,0,@cTime,0)
end
else --列表中已存在,则更新时间
begin
update UserRecentContact set ContactTime=@cTime where UserID=@userID AND ContactID=@receiveID
end
END
GO
CREATE PROCEDURE [SYSTEMRecordMsgGet]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT * from RecordMsg,RecordMsgUser where RecordMsgUser.isSendSuccess=0 and RecordMsg.SendID='SYSTEM' and RecordMsg.MsgId=RecordMsgUser.MsgId
END
GO
CREATE TABLE [smsUser](
[ID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[msgID] [numeric](18, 0) NOT NULL,
[receiveID] [nchar](20) NOT NULL,
[sendFailedCount] [tinyint] NULL,
[isSendSuccess] [bit] NULL,
[lastDate] [datetime] NULL,
CONSTRAINT [PK_smsUser] 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
--只获取前20个
CREATE PROCEDURE [UserGetRecentContactList]
@userId varchar(20)
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP 20 UserID,ContactID,ContactType,ContactTime,OrderID from UserRecentContact where UserID=@userId ORDER BY CONVERT(datetime,ContactTime) DESC
END
GO
CREATE PROCEDURE [UserGetUsersSignsByUserID]
@userID nvarchar(20)
AS
BEGIN
SET NOCOUNT ON;
SELECT Remark from IMUser where userID=@userID
END
GO
CREATE PROCEDURE [UserGetUserDataFromUserID]
-- Add the parameters for the stored procedure here
--@userID varchar(20)
@userID nvarchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
--2011.6.7修改
--SELECT * from systemUsers where userID=@userID
--由于只取版本号等和部门用户名无关的信息,所以就这么也行
SELECT a.*,b.orderID,b.Remark,b.SID from V_Emp a,IMUser b where a.UserID=b.UserID AND a.userID=@userID
END
GO
CREATE PROCEDURE [userIsPassword]
--@userID varchar(20),
@userID nvarchar(20),
--@password varchar(32)
@password nvarchar(32)
AS
BEGIN
SET NOCOUNT ON;
declare @count int
-- Insert statements for procedure here
--SELECT @count=count(*) from systemUsers where userID=@userID and password=@password
SELECT @count=count(*) from V_Emp where userID=@userID and pass=@password
return @count
END
GO
CREATE PROCEDURE [userIsExist]
-- Add the parameters for the stored procedure here
--@userID varchar(20)
@userID nvarchar(20)
AS
BEGIN
SET NOCOUNT ON;
declare @userCount tinyint
set @userCount=0
--SELECT @userCount=count(userID) from systemUsers where UserID=@userID
SELECT @userCount=count(userID) from V_Emp where UserID=@userID
return @userCount
END
GO
CREATE PROCEDURE [userGetrData]
-- Add the parameters for the stored procedure here
--@userId varchar(20)
@userId nvarchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
--SELECT * from SystemUsers where userID=@userId
SELECT a.UserID,a.UserName,a.UserName as [Name],
b.Tel as ophone,b.Mobile,b.Fax,b.EMail,b.Tel as PHS
FROM V_Emp a,IMUser b WHERE a.UserID=b.UserID AND a.UserID=@userId
END
GO
CREATE PROCEDURE [UserGetPageUsersBaseInfo]
--@UserID varchar(20),
@UserID nvarchar(20),
@PageSize int,
@PageIndex int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
CREATE TABLE #PageIndex --创建临时表
(
IndexId int IDENTITY (1, 1) NOT NULL,
--UserID varchar(20)--用于保存用户ID集合
UserID nvarchar(20)--用于保存用户ID集合
)
--INSERT INTO #PageIndex(UserID) select userID from systemUsers
--where DepId<>1 order by orderID,userID asc
INSERT INTO #PageIndex(UserID) select a.userID from V_Emp a,IMUser b
where a.UserID=b.UserID order by b.orderID,a.userID asc
--select userID,userName,DepId,orderID from systemUsers
--WHERE userID in(select userID from #PageIndex where IndexId BETWEEN @PageSize*(@PageIndex-1)+1 AND @PageSize*(@PageIndex))
select a.userID,a.userName,a.DeptID as DepId,b.orderID
from V_Emp a,IMUser b WHERE a.UserID=b.UserID AND a.userID in(select userID from #PageIndex
where IndexId BETWEEN @PageSize*(@PageIndex-1)+1 AND @PageSize*(@PageIndex))
END
GO
CREATE PROCEDURE [userGetBaseData]
-- Add the parameters for the stored procedure here
--@userId varchar(20)
@userId nvarchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
--SELECT * from SystemUsers where userID=@userId
SELECT a.UserID,a.UserName,b.PostCode as post,
b.Tel as phone,b.Mobile as GSM,b.Fax as phs
FROM V_Emp a,IMUser b WHERE a.UserID=b.UserID AND a.UserID=@userId
END
GO
CREATE PROCEDURE [UserChangePassword]
--@userID varchar(20),
@userID nvarchar(20),
@PasswordOld varchar(32),--密码为32位MD5值
@PasswordNew varchar(32) --密码为32位MD5值
AS
BEGIN
declare @userCount int--记录用户旧密码是否正确
SET NOCOUNT ON;
--select @userCount=count(*) from systemUsers where UserID=@userID and password=@PasswordOld
select @userCount=count(*) from V_Emp where UserID=@userID and Pass=@PasswordOld
if @userCount=0
return 0--返回0表示修改密码不成功,原因旧密码不正确
--update systemUsers set Password=@PasswordNew where UserID=@userID
update V_Emp set Pass=@PasswordNew where UserID=@userID
return 1 --返回1表示修改密码成功
END
GO
CREATE PROC [UpdateSystemData]
AS
BEGIN
DECLARE @OldUsersVersion varchar(50)
DECLARE @OldDepsVersion varchar(50)
DECLARE @OldUsersCount int
DECLARE @OldDepsCount int
DECLARE @NewUsersVersion varchar(50)
DECLARE @NewDepsVersion varchar(50)
DECLARE @NewUsersCount int
DECLARE @NewDepsCount int
--部门
DELETE FROM IMDept WHERE DeptID NOT IN (SELECT DeptID FROM V_Dept)
INSERT INTO IMDept(DeptID,orderID,isAbandan) SELECT DeptID,1,'False' FROM V_Dept
WHERE DeptID NOT IN (SELECT DeptID FROM IMDept)
--用户
DELETE FROM IMUser WHERE UserID NOT IN (SELECT UserID FROM V_Emp)
INSERT INTO IMUser(UserID,orderID,headPicIdx,CreateGroupMax,isSendSMS,isEditUserData,isAdmin,isAbandan,
DepsVersion,UsersVersion) SELECT UserID,1,0,10,0,0,'False','False',0,0 FROM V_Emp
WHERE UserID NOT IN (SELECT UserID FROM IMUser)
--判断首次
SELECT @OldUsersCount=COUNT(*) FROM IMUser WHERE UsersVersion<>0
IF @OldUsersCount=0
BEGIN
UPDATE IMUser SET UsersVersion=1
END
SELECT @OldDepsCount=COUNT(*) FROM IMUser WHERE DepsVersion<>0
IF @OldDepsCount=0
BEGIN
UPDATE IMUser SET DepsVersion=1
END
SELECT TOP 1 @OldUsersVersion=UsersVersion,@OldDepsVersion=DepsVersion,@OldUsersCount=UsersCount,
@OldDepsCount=DepsCount FROM IMUser WHERE DepsVersion<>0
SELECT @NewUsersCount=count(*) FROM IMUser
SELECT @NewDepsCount=count(*) FROM IMDept
SET @NewUsersVersion=CAST(CAST(@OldUsersVersion as int)+1 as varchar)
SET @NewDepsVersion=CAST(CAST(@OldDepsVersion as int)+1 as varchar)
update IMUser set UsersCount=@NewUsersCount,UsersVersion=@NewUsersVersion,DepsCount=@NewDepsCount,DepsVersion=@NewDepsVersion
END
GO
CREATE PROCEDURE [smsSendSuccess]
-- Add the parameters for the stored procedure here
@ID numeric(18,0)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
update smsUser set isSendSuccess=1,lastDate=getdate() where id=@ID
SET NOCOUNT off;
END
GO
CREATE PROCEDURE [smsSendFailed]
-- Add the parameters for the stored procedure here
@ID numeric(18,0)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
update smsUser set sendFailedCount=sendFailedCount+1,lastDate=getdate() where ID=@ID
SET NOCOUNT off;
END
GO
CREATE PROCEDURE [smsInsert]
-- Add the parameters for the stored procedure here
@ReceiveID varchar(8000) ,
@sendID varchar(20) ,
@msgContent varchar(1000)
AS
BEGIN
declare @MsgId numeric(18,0)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
insert SMS(sendID,smsMsgContent) values(@sendID,@msgContent)
set @MsgId= @@IDENTITY
declare @next int
set @next=1
while @next<dbo.Get_StrArrayLength(@ReceiveID,';')
begin
insert into smsUser (MsgId,ReceiveID) values(@MsgId ,dbo.Get_StrArrayStrOfIndex(@ReceiveID,';',@next))
set @next=@next+1
end
SET NOCOUNT OFF
END
GO
CREATE PROCEDURE [smsGetSendSuccessfulCount]
AS
BEGIN
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT count(*) from smsUser where isSendSuccess=1
END
GO
CREATE PROCEDURE [smsDelNoSendFailed]
AS
BEGIN
SET NOCOUNT ON;
delete from smsUser where smsUser.isSendSuccess=0
END
GO
CREATE PROCEDURE [DepGetDepsPageBaseInfo]
-- Add the parameters for the stored procedure here
--@UserID varchar(20),
@UserID nvarchar(20),
@PageSize int,
@PageIndex int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
CREATE TABLE #PageIndex --创建临时表
(
IndexId int IDENTITY (1, 1) NOT NULL,
DepID int --用于保存部门ID集合
)
--INSERT INTO #PageIndex(DepID) select DepID from Department
--where DepId<>1 order by OrderID,DepID asc
INSERT INTO #PageIndex(DepID) select a.DeptID from V_Dept a,IMDept b WHERE a.DeptID=b.DeptID order by b.OrderID,a.DeptID asc
--select DepID,DepName,SuperiorId,OrderID from Department
--WHERE DepID in(select DepID from #PageIndex where IndexId BETWEEN @PageSize*(@PageIndex-1)+1 AND @PageSize*(@PageIndex))
select a.DeptID as DepID,a.DeptName as DepName,a.ParentDeptID as SuperiorId,b.OrderID from V_Dept a,IMDept b WHERE a.DeptID=b.DeptID AND a.DeptID in(select DepID from
#PageIndex where IndexId BETWEEN @PageSize*(@PageIndex-1)+1 AND @PageSize*(@PageIndex))
END
GO
CREATE PROCEDURE [DepGetData]
-- Add the parameters for the stored procedure here
--@DepId varchar(20),
@DepId int,
@flag bit
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
if @flag = 0
begin
--SELECT * from Department where DepId=@DepId
SELECT a.*,b.orderID from V_Dept a,IMDept b where a.DeptID=b.DeptID AND a.DeptID=@DepId
end
else
begin
--SELECT * from Department where SuperiorId=@DepId
SELECT a.*,b.orderID from V_Dept a,IMDept b where a.DeptID=b.DeptID AND ParentDeptID=@DepId
end
END
GO
/****** Object: Default [DF_SMS_sendfailedCount] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [SMS] ADD CONSTRAINT [DF_SMS_sendfailedCount] DEFAULT (getdate()) FOR [datetime]
GO
/****** Object: Default [DF_sendCount_saveDate] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [sendCount] ADD CONSTRAINT [DF_sendCount_saveDate] DEFAULT (getdate()) FOR [saveDate]
GO
/****** Object: Default [DF_RecordMsgUser_isSendSuccess] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [RecordMsgUser] ADD CONSTRAINT [DF_RecordMsgUser_isSendSuccess] DEFAULT ((0)) FOR [isSendSuccess]
GO
/****** Object: Default [DF_RecordMsgUser_isSave] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [RecordMsgUser] ADD CONSTRAINT [DF_RecordMsgUser_isSave] DEFAULT ((0)) FOR [isSave]
GO
/****** Object: Default [DF_CustomGroup_CreateDateTime] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [CustomGroup] ADD CONSTRAINT [DF_CustomGroup_CreateDateTime] DEFAULT (getdate()) FOR [CreateDateTime]
GO
/****** Object: Default [DF_RecordMsg_msgDateTime] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [RecordMsg] ADD CONSTRAINT [DF_RecordMsg_msgDateTime] DEFAULT (getdate()) FOR [msgDateTime]
GO
/****** Object: Default [DF_RecordMsg_fontBold] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [RecordMsg] ADD CONSTRAINT [DF_RecordMsg_fontBold] DEFAULT ((0)) FOR [fontBold]
GO
/****** Object: Default [DF_RecordMsg_fontItalic] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [RecordMsg] ADD CONSTRAINT [DF_RecordMsg_fontItalic] DEFAULT ((0)) FOR [fontItalic]
GO
/****** Object: Default [DF_RecordMsg_fontStrikeout] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [RecordMsg] ADD CONSTRAINT [DF_RecordMsg_fontStrikeout] DEFAULT ((0)) FOR [fontStrikeout]
GO
/****** Object: Default [DF_RecordMsg_fontUnderline] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [RecordMsg] ADD CONSTRAINT [DF_RecordMsg_fontUnderline] DEFAULT ((0)) FOR [fontUnderline]
GO
/****** Object: Default [DF_RecordMsg_isSendSMS] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [RecordMsg] ADD CONSTRAINT [DF_RecordMsg_isSendSMS] DEFAULT ((0)) FOR [SMSInfo]
GO
/****** Object: Default [DF_RecordMsg_GroupID] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [RecordMsg] ADD CONSTRAINT [DF_RecordMsg_GroupID] DEFAULT ((-1)) FOR [GroupID]
GO
/****** Object: Default [DF_IMUser_orderID] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMUser] ADD CONSTRAINT [DF_IMUser_orderID] DEFAULT ((1)) FOR [orderID]
GO
/****** Object: Default [DF_IMUser_headPicIdx] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMUser] ADD CONSTRAINT [DF_IMUser_headPicIdx] DEFAULT ((0)) FOR [headPicIdx]
GO
/****** Object: Default [DF_IMUser_CreateGroupMax] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMUser] ADD CONSTRAINT [DF_IMUser_CreateGroupMax] DEFAULT ((10)) FOR [CreateGroupMax]
GO
/****** Object: Default [DF_IMUser_isSendSMS] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMUser] ADD CONSTRAINT [DF_IMUser_isSendSMS] DEFAULT ((0)) FOR [isSendSMS]
GO
/****** Object: Default [DF_IMUser_isEditUserData] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMUser] ADD CONSTRAINT [DF_IMUser_isEditUserData] DEFAULT ((0)) FOR [isEditUserData]
GO
/****** Object: Default [DF_IMUser_isAdmin] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMUser] ADD CONSTRAINT [DF_IMUser_isAdmin] DEFAULT ((0)) FOR [isAdmin]
GO
/****** Object: Default [DF_IMUser_isAbandan] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMUser] ADD CONSTRAINT [DF_IMUser_isAbandan] DEFAULT ((0)) FOR [isAbandan]
GO
/****** Object: Default [DF_IMUser_DepsVersion] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMUser] ADD CONSTRAINT [DF_IMUser_DepsVersion] DEFAULT ((0)) FOR [DepsVersion]
GO
/****** Object: Default [DF_IMUser_UsersVersion] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMUser] ADD CONSTRAINT [DF_IMUser_UsersVersion] DEFAULT ((0)) FOR [UsersVersion]
GO
/****** Object: Default [DF_IMDept_orderID] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMDept] ADD CONSTRAINT [DF_IMDept_orderID] DEFAULT ((1)) FOR [orderID]
GO
/****** Object: Default [DF_IMDept_isAbandan] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [IMDept] ADD CONSTRAINT [DF_IMDept_isAbandan] DEFAULT ((0)) FOR [isAbandan]
GO
/****** Object: Default [DF_smsUser_sendFailedCount] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [smsUser] ADD CONSTRAINT [DF_smsUser_sendFailedCount] DEFAULT ((0)) FOR [sendFailedCount]
GO
/****** Object: Default [DF_smsUser_isSendSuccess] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [smsUser] ADD CONSTRAINT [DF_smsUser_isSendSuccess] DEFAULT ((0)) FOR [isSendSuccess]
GO
/****** Object: ForeignKey [FK_smsUser_SMS] Script Date: 06/24/2013 14:00:01 ******/
ALTER TABLE [smsUser] WITH CHECK ADD CONSTRAINT [FK_smsUser_SMS] FOREIGN KEY([msgID])
REFERENCES [SMS] ([msgID])
GO
ALTER TABLE [smsUser] CHECK CONSTRAINT [FK_smsUser_SMS]
GO
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/codingstudio/ccflow.git
git@gitee.com:codingstudio/ccflow.git
codingstudio
ccflow
CCFlow
develop

Search