• 定时提醒模型


    --表结构
    
    CREATE TABLE [dbo].[ARP_TXSZ](
    	[TXSZ_ID] [int] IDENTITY(1,1) NOT NULL,
    	[TXSZ_LX] [varchar](50) NOT NULL,
    	[TXSZ_YC_SJ] [datetime] NULL,
    	[TXSZ_CF_PL] [varchar](50) NULL,
    	[TXSZ_MTPL_LX] [varchar](50) NULL,
    	[TXSZ_MTPL_YC_SJ] [varchar](8) NULL,
    	[TXSZ_MTPL_JG_SL] [int] NULL,
    	[TXSZ_MTPL_JG_DW] [varchar](50) NULL,
    	[TXSZ_MZPL_ZJ] [varchar](50) NULL,
    	[TXSZ_MYPL_JH] [varchar](100) NULL,
    	[TXSZ_NR] [varchar](500) NULL,
    	[TXSZ_KSRQ] [varchar](10) NULL,
    	[TXSZ_ZZRQ] [varchar](10) NULL,
    	[TXSZ_BZ] [varchar](50) NULL,
    	[TXSZ_DJRQ] [datetime] NULL,
    	[TXSZ_DJBH] [varchar](50) NULL,
    	[TXSZ_JSR] [varchar](50) NULL,
    	[TXSZ_DJZT] [varchar](10) NULL,
     CONSTRAINT [PK_ARP_TXSZ] PRIMARY KEY CLUSTERED 
    (
    	[TXSZ_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'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_LX'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'一次性提醒执行时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_YC_SJ'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'重复频率(每天、每周、每月)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_CF_PL'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'每天频率类型(执行一次、执行间隔)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_MTPL_LX'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'每天在几点几分执行一次' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_MTPL_YC_SJ'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'每天每多少执行一次(单位在TXSZ_MTPL_JG_)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_MTPL_JG_SL'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'间隔单位(时、分、秒)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_MTPL_JG_DW'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'每周周几(可以多选)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_MZPL_ZJ'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'每月几号(可以多选)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_MYPL_JH'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'提醒内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_NR'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'开始日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_KSRQ'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'终止日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_ZZRQ'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_BZ'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'单据日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_DJRQ'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'单据编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_DJBH'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'经手人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_JSR'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'生效状态' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZ', @level2type=N'COLUMN',@level2name=N'TXSZ_DJZT'
    GO
    
    
    CREATE TABLE [dbo].[ARP_TXSZMX](
    	[TXSZMX_ID] [int] IDENTITY(1,1) NOT NULL,
    	[TXSZMX_DJBH] [varchar](50) NULL,
    	[TXSZMX_LX] [varchar](50) NULL,
    	[TXSZMX_BH] [varchar](50) NULL,
    	[TXSZMX_MC] [varchar](50) NULL,
     CONSTRAINT [PK_ARP_TXSZRY] PRIMARY KEY CLUSTERED 
    (
    	[TXSZMX_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'ARP_TXSZMX', @level2type=N'COLUMN',@level2name=N'TXSZMX_DJBH'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'类型(用户或者角色)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZMX', @level2type=N'COLUMN',@level2name=N'TXSZMX_LX'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZMX', @level2type=N'COLUMN',@level2name=N'TXSZMX_BH'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TXSZMX', @level2type=N'COLUMN',@level2name=N'TXSZMX_MC'
    GO
    
    CREATE TABLE [dbo].[ARP_TX](
    	[TX_ID] [int] IDENTITY(1,1) NOT NULL,
    	[TX_DJBH] [varchar](50) NULL,
    	[TX_TXRY] [varchar](50) NULL,
    	[TX_TXSJ] [datetime] NULL,
    	[TX_TXNR] [varchar](500) NULL,
    	[TX_CLZT] [varchar](50) NULL,
     CONSTRAINT [PK_ARP_TX] PRIMARY KEY CLUSTERED 
    (
    	[TX_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'ARP_TX', @level2type=N'COLUMN',@level2name=N'TX_DJBH'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'提醒人员' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TX', @level2type=N'COLUMN',@level2name=N'TX_TXRY'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'产生时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TX', @level2type=N'COLUMN',@level2name=N'TX_TXSJ'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'提醒内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TX', @level2type=N'COLUMN',@level2name=N'TX_TXNR'
    GO
    
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'处理状态(0:未处理,1:已处理)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ARP_TX', @level2type=N'COLUMN',@level2name=N'TX_CLZT'
    GO

      

    create procedure [dbo].[sp_exec_tx](@djbh varchar(50)='')
    as
    /*
    @Copy Right:kuailewangzi1212
    创建日期:2013-11-19
    作者:kuailewangzi1212
    功能描述:根据提醒设置生成提醒内容
    算法说明:
    	1、删除新单据明细。
    	2、插入原单据明细
    	3、修改你单据的"年度、类型、起始日期、终止日期"
    参数说明:	
    测试代码:
    审核人:
    审核日期:
    
    --
    修改日期1:
    修改人:
    修改内容说明:
    测试代码:
    	--1、测试一次提醒select * from arp_txsz
    		delete from arp_tx
    		execute sp_exec_tx 
    		select * from arp_tx
    	
    	--2测试重复提醒
    	--2.1、测试重复提醒-天、一次性提醒
    		delete from arp_tx
    		execute sp_exec_tx 'TXSZ-20131119-003'
    		select * from arp_tx
    	--2.2、测试重复提醒-天、间隔提醒		
    		--delete from arp_tx
    		execute sp_exec_tx 'TXSZ-20131120-001'
    		select * from arp_tx
    	--2.3、每周		
    		--delete from arp_tx
    		execute sp_exec_tx 'TXSZ-20131120-002'
    		select * from arp_tx
    	--2.4、每月		
    		--delete from arp_tx
    		execute sp_exec_tx 'TXSZ-20131120-003'
    		select * from arp_tx
    	
    审核人:
    审核日期:
    */
    begin
    	--select * from arp_txsz select * from arp_txszmx select * from arp_tx
    	declare @dt10 varchar(10),--
    			@txsz_djbh varchar(50),--单据编号
    			@txsz_lx varchar(50),--提醒类型(一次提醒或者重复提醒)
    			@txsz_yc_sj varchar(50),--一次提醒时间
    			@txsz_cf_pl varchar(50),--重复提醒频率(每天、每周、每月)
    			@txsz_mtpl_lx varchar(50),--每天频率类型(提醒一次或者间隔提醒)
    			@txsz_mtpl_yc_sj varchar(50),--每天提醒一次,提醒时间
    			@txsz_mtpl_jg_sl int,--每天间隔数量
    			@txsz_mtpl_jg_dw varchar(50),--每天间隔单位
    			@txsz_mzpl_zj varchar(50),--每周周几
    			@txsz_mypl_jh varchar(50),--每月几号
    			@txsz_nr varchar(500)--提醒内容
    			
    	declare @sl int,--间隔数量
    			@sc int--是否是首次提醒 0表示首次提醒
    	select @sl=0,@sc=0
    	
    	declare @zj varchar(10),--当前是周几	
    			@jh varchar(10),--当前是几号
    			@jhCnt int,--几号个数
    			@ts int--当月的天数
    	
    	select @dt10=CONVERT(char(10),getdate(),120)
    	declare cur_m cursor for--select * from arp_txsz
    		select txsz_djbh,txsz_lx,txsz_yc_sj,txsz_cf_pl,txsz_mtpl_lx,txsz_mtpl_yc_sj,txsz_mtpl_jg_sl,txsz_mtpl_jg_dw,txsz_mzpl_zj,txsz_mypl_jh,txsz_nr
    		from arp_txsz 
    		where txsz_ksrq<=@dt10 and (txsz_zzrq>=@dt10 or isnull(txsz_zzrq,'')='') and txsz_djzt='已审核' and isnull(txsz_xtcf,'定时器')='定时器' and txsz_djbh like @djbh+'%'
    	open cur_m
    	fetch cur_m into @txsz_djbh,@txsz_lx,@txsz_yc_sj,@txsz_cf_pl,@txsz_mtpl_lx,@txsz_mtpl_yc_sj,@txsz_mtpl_jg_sl,@txsz_mtpl_jg_dw,@txsz_mzpl_zj,@txsz_mypl_jh,@txsz_nr
    	while @@FETCH_STATUS=0
    	begin
    		if @txsz_lx='一次提醒'
    		begin
    			if convert(datetime,@txsz_yc_sj)<=GETDATE()
    			begin
    				if exists(select txszmx_id from arp_txszmx where txszmx_djbh=@txsz_djbh)
    				begin--提醒指定人员或角色
    					--插入未提醒过的人员
    					insert into arp_tx(tx_djbh,tx_txry,tx_txsj,tx_txnr,tx_clzt)
    					select @txsz_djbh,username,GETDATE(),@txsz_nr,'未处理' 
    					from v_txry_list
    					where djbh=@txsz_djbh and username not in(select tx_txry from arp_tx where tx_djbh=@txsz_djbh)			
    				end
    				else
    				begin--提醒所有人
    					----插入未提醒过的人员
    					insert into arp_tx(tx_djbh,tx_txry,tx_txsj,tx_txnr,tx_clzt)
    					select @txsz_djbh,username,GETDATE(),@txsz_nr,'未处理' 
    					from v_txry_all
    					where username not in(select tx_txry from arp_tx where tx_djbh=@txsz_djbh)	
    				end
    			end
    		end
    		
    		if @txsz_lx='重复提醒'
    		begin--重复提醒
    			if @txsz_cf_pl='每周'
    			begin
    				--@txsz_mzpl_zj--每周周几
    				select @zj=convert(varchar(10),case datepart(WEEKDAY,GETDATE()) - 1 when 0 then 7 else datepart(WEEKDAY,GETDATE()) - 1 end)				
    				if(charindex(CONVERT(varchar(1),@zj),@txsz_mzpl_zj)>0)
    				begin
    					select @txsz_cf_pl='每天'--转到每天
    				end
    			end
    			if @txsz_cf_pl='每月'
    			begin
    				----@txsz_mypl_jh--每月几号							
    				select @jh=datepart(DAY,GETDATE())
    				select @jhCnt=LEN(REPLACE(@txsz_mypl_jh,',','aa')) - LEN(@txsz_mypl_jh)
    				select @txsz_mypl_jh=','+@txsz_mypl_jh+','--前后添加","符号	
    				if(charindex(','+CONVERT(varchar(10),@jh)+',',@txsz_mypl_jh)>0)
    				begin
    					select @txsz_cf_pl='每天'--转到每天
    				end	
    				--如果是28号29号30号是当月的最后一天,则判断31号是否符合条件
    				select @ts=datepart(DAY,dateadd(dd,-1,left(convert(varchar(10),dateadd(mm,1,GETDATE()),120),7)+'-01'))
    				if @jh=@ts and charindex(',31,',@txsz_mypl_jh)>0
    				begin
    					select @txsz_cf_pl='每天'--转到每天
    				end
    			end
    			if @txsz_cf_pl='每天'--重复频率是'每天'
    			begin
    				if @txsz_mtpl_lx='提醒一次'
    				begin					
    					if convert(datetime,@dt10+' '+@txsz_mtpl_yc_sj)<=GETDATE()
    					begin
    						if exists(select txszmx_id from arp_txszmx where txszmx_djbh=@txsz_djbh)
    						begin--提醒指定人员或角色
    							--插入未提醒过的人员
    							insert into arp_tx(tx_djbh,tx_txry,tx_txsj,tx_txnr,tx_clzt)
    							select @txsz_djbh,username,GETDATE(),@txsz_nr,'未处理' 
    							from v_txry_list
    							where djbh=@txsz_djbh and username not in(select tx_txry from arp_tx where tx_djbh=@txsz_djbh)			
    						end
    						else
    						begin--提醒所有人
    							----插入未提醒过的人员
    							insert into arp_tx(tx_djbh,tx_txry,tx_txsj,tx_txnr,tx_clzt)
    							select @txsz_djbh,username,GETDATE(),@txsz_nr,'未处理' 
    							from v_txry_all
    							where username not in(select tx_txry from arp_tx where tx_djbh=@txsz_djbh)	
    						end
    					end
    				end
    				if @txsz_mtpl_lx='间隔提醒'
    				begin					
    					select @sc= COUNT(*) from ARP_TX where TX_DJBH=@txsz_djbh					
    					if @txsz_mtpl_jg_dw='小时'
    					begin 						 
    						select @sl= DATEDIFF(hour,MAX(TX_TXSJ),GETDATE()) from ARP_TX where TX_DJBH=@txsz_djbh
    						select @sl=ISNULL(@sl,0)
    					end
    					if @txsz_mtpl_jg_dw='分钟'
    					begin 
    						select @sl= DATEDIFF(MINUTE,MAX(TX_TXSJ),GETDATE()) from ARP_TX where TX_DJBH=@txsz_djbh
    						select @sl=ISNULL(@sl,0)
    					end
    					if @txsz_mtpl_jg_dw='秒钟'
    					begin 
    						select @sl= DATEDIFF(SECOND,MAX(TX_TXSJ),GETDATE()) from ARP_TX where TX_DJBH=@txsz_djbh
    						select @sl=ISNULL(@sl,0)
    					end					
    					if @sl>=@txsz_mtpl_jg_sl or @sc=0--@sc=0表示是当天的首次提醒
    					begin
    						if exists(select txszmx_id from arp_txszmx where txszmx_djbh=@txsz_djbh)
    						begin--提醒指定人员或角色
    							--插入未提醒过的人员
    							insert into arp_tx(tx_djbh,tx_txry,tx_txsj,tx_txnr,tx_clzt)
    							select @txsz_djbh,username,GETDATE(),@txsz_nr,'未处理' 
    							from v_txry_list
    							where djbh=@txsz_djbh --and username not in(select tx_txry from arp_tx where tx_djbh=@txsz_djbh)			
    						end
    						else
    						begin--提醒所有人
    							----插入未提醒过的人员
    							insert into arp_tx(tx_djbh,tx_txry,tx_txsj,tx_txnr,tx_clzt)
    							select @txsz_djbh,username,GETDATE(),@txsz_nr,'未处理' 
    							from v_txry_all
    							--where username --not in(select tx_txry from arp_tx where tx_djbh=@txsz_djbh)	
    						end
    					end
    				end
    			end
    		end
    	fetch cur_m into @txsz_djbh,@txsz_lx,@txsz_yc_sj,@txsz_cf_pl,@txsz_mtpl_lx,@txsz_mtpl_yc_sj,@txsz_mtpl_jg_sl,@txsz_mtpl_jg_dw,@txsz_mzpl_zj,@txsz_mypl_jh,@txsz_nr
    	end
    	close cur_m
    	deallocate cur_m
    end
    

      

  • 相关阅读:
    Jmeter实际操作
    Windows+JMeter+InfluxDB+Grafana搭建可视化实时监控
    c# 新语法
    js 判断打印或取消 打印插件
    BACnet协议
    串口偶尔出现串口乱码原因
    面向流程葵花宝典
    lwip框架示意图
    linux 算法介绍
    什么是序列化与反序列化
  • 原文地址:https://www.cnblogs.com/kuailewangzi1212/p/3433062.html
Copyright © 2020-2023  润新知