1. 预警配置
| 编辑人 | 修改时间 | 修改内容 | 文档状态 |
|---|---|---|---|
| 张小猛 | 20190810 | chore | 可用 |
1.1. 说明
EBS的预警实际就是对预先定义的事件进行定时捕获、事件处理,其中捕获主要手段是数据库定时任务对数据进行查询得到事件,事件处理主要包括消息提醒、预警消息对象、业务创建或接口调用(目前平台并没有定义和实现),预警分三个级别,且暂时只能用SQL定影.
注意:如果是业务级的预警当修改了预警,必须重新生成程序,否则会出现异常
1.2. 一、数据级预警
用于实现与业务和流程等都无关的预警 ,只和数据有关。


1.2.1. 代码模板
select 消息预警对象的cuid,
'{template}'
from 你的表名
- 实例(合同到期预警)
--需求:不同分公司人事(岗位id=351)收到各自的员工档案的合同超期预警,要求即使多个数据也只对接收人发送一条消息
--事件数据,根据自己需要自行定义
declare @eventdata table(mycuid bigint,mybcid bigint,msgtxt varchar(max))
--事件消息接收人及对应的消息
declare @users table(cuid bigint,msgtxt varchar(max))
insert into @eventdata(mycuid,mybcid,msgtxt)
select distinct cu_id,cu_bcid,'姓名:'+isnull(ord_name,'')+',工号:'+isnull(ord_jbcode,'')
from mps_employee with(nolock),
order_288 with(nolock)
where cu_otid = 351
and cu_use =0
and ord_gsid = cu_bcid
and DATEDIFF(day, getdate(),ord_htdqrq) >=0
and DATEDIFF(day, getdate(),ord_htdqrq) <=30
and DATEDIFF(day,ord_htdqrq,'1900-01-01') != 0 /*注意系统默认日志1900-01-01*/
and DATEPART(HH, GETDATE()) BETWEEN 9 AND 22
and ord_zt='在职'
insert into @users(cuid,msgtxt)
select mycuid,replace(stuff((select ';'+msgtxt from @eventdata i where i.mycuid =o.mycuid for xml path('')) ,1,1,''),';',char(13))
from @eventdata o group by mycuid
select cuid,
'{template}'
from @users,mps_login with(nolock)
where cu_id = cuid
消息模板
'有员工合同即将到期,请注意处理!'
+char(13)+msgtxt
+'{title}劳动合同到期提醒'
+'{url}/order/orders.htm?crmid=288&crmmc=~t~5854e55d6l84868'
1.3. 二、业务级预警
业务数据主要用于业务预警内容中包含业务数据的情况。
主要控制在第4、5部处,此处有坑,高能预警(哭笑) 注意:
坑1:建议不使用#user临时表,字段太少
坑2:建议@identkeyold如实例代码一样,更新为当前时间再加一个值,否则每次运行只有第一条业务数据会被预警
实例代码如下
/*start控制提醒时间频次*/
declare @IntervalMinutes int = 2
/*兼容平台以前逻辑*/
if (isnull(@identkey, '') = 'noidentkey' or isdate(isnull(@identkey, '')) = 0)
begin
set @identkey = convert(nvarchar(100), getdate(), 120)
end
if (isnull(@identkey, '') != '' and datediff(minute, isnull(@identkey, ''), getdate()) >=@IntervalMinutes
and DATEPART(HH, GETDATE()) BETWEEN 9 AND 22)
begin
set @identkey = convert(nvarchar(100), getdate(), 120)
end
/*业务结束时取消预警,如果不需要取消删除即可*/
if exists(select * from #master where ord_finished = 2 )
begin
set @identkey='remove'
end
/*end控制提醒时间频次代码结束*/
insert into #user(cuid)
select cu_id from mps_login
where cu_callname in ('张三', '李四', '王五', '赵小六', '孙七')
/*此处不能再写mps_login,巨坑*/
select cuid, '{template}'from #master,#user,#detail2
where DATEDIFF(day, ord2_jssj, getdate()) >= 0
AND datediff(day,ord2_jssj,'1900-01-01') != 0/*注意系统默认日志1900-01-01*/
and DATEPART(HH, GETDATE()) BETWEEN 9 AND 22
and ord2_zt!= '已完成'
and cu_id = cuid
and ord2_id = (select min(ord2_id) from #detail2 where ord2_zt!='已完成')
1.4. 三、流程级预警
1.设置流程处理时限:

2.设置预警
即①首先添加预警②设置预警条件,③再设置预警消息模板。
预警条件实例:
注意
用到了 jb_elapsedtime 时,一定要在 “基本参数-流程限时” 设置限时完成时间,否则预警无效。
/**步骤上的预警:
**jb_elapsedtime:本步骤实际耗时,单位为分钟.非工作时段不在计时范围,但需要保证mps_holiday中有数据,
**FirstTipMinutes 分钟后提醒一次,然后每隔 IntervalMinutes 分钟提醒一次,并且只计算上班时间。
**以 FirstTipMinutes = 120,IntervalMinutes = 240为例。
*/
/*必须设置*/
insert into #user(cuid)
select jb_cuid from #job
declare
@FirstTipMinutes int = 120,
@IntervalMinutes int = 240,
@elapsedMinutes int = 0,
@nInterval int = 0 ,
@notifiedTimes int = 0
if ISNUMERIC(@identkey)=0
begin
set @identkey = -1
end
set @notifiedTimes = convert(int,@identkey)
select @elapsedMinutes = jb_elapsedtime from #job
set @nInterval = floor((@elapsedMinutes-@FirstTipMinutes)/@IntervalMinutes)
if (@elapsedMinutes<@FirstTipMinutes)
set @notifiedTimes = -1
else if (@elapsedMinutes>=@FirstTipMinutes and @nInterval>@notifiedTimes and @nInterval<@notifiedTimes+2)
set @notifiedTimes = @notifiedTimes + 1
else if (@elapsedMinutes>=@FirstTipMinutes and -1=@notifiedTimes)
set @notifiedTimes = @nInterval
else if (@nInterval>@notifiedTimes+2)
begin
set @notifiedTimes = @nInterval
end
if (@elapsedMinutes>0 and @identkey<>convert(varchar(10),@notifiedTimes) and DATEPART(HH, GETDATE()) BETWEEN 9 AND 22
)
set @identkey = convert(varchar(10),@notifiedTimes)
else
set @identkey='abort'
/*业务结束时取消预警,如果不需要取消删除即可*/
if exists(select * from #master where ord_finished = 2 )
begin
set @identkey='remove'
end
/*end控制提醒时间频次代码结束*/
select jb_cuid ,'{template}' from #master,#job,#user
where DATEPART(HH, GETDATE()) BETWEEN 9 AND 22

需要注意的是消息模板中字段所在表需要包含在最后的select 后,否则会报错。如果设置成功,数据库EBS2java库中会创建两个存储过程,即:①order_{bizid}_{wrkid}_alarm_task,②order_{bizid}_alarm_{wrkid}_{alarmid},且mps_job_task表中,还会添加一条类似如下记录的任务数据。