IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[order_191_1156_wrklink_after]') AND type = 'P')
DROP PROCEDURE [dbo].[order_191_1156_wrklink_after]
GO

-- 生成时间:2017-11-23 17:46:23 by ebs-core  
CREATE  procedure order_191_1156_wrklink_after(
     @cmpid int, 
     @useruid int,
     @bizid int, 
     @ordid bigint, 
     @wrkid int, 
     @jbid bigint, 
     @wsid int, 
     @wsstatus nvarchar(50) 
  ) 
as  
begin  
set nocount on  
declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1')
declare @ord2group2 nvarchar(50) 
set @ord2group2 = '' 
declare @sys_recid bigint 
set @sys_recid = 0 
  
 --- 以下是预处理事件中的临时表
 exec drop_temp_table '#new' select * into #new from mps_job where jb_id=@jbid exec drop_temp_table '#old' select * into #old from mps_job where jb_id=@jbid exec drop_temp_table '#master' select * into #master from order_191 where ord_id=@ordid exec drop_temp_table '#detail2' select *,null recid into #detail2 from order_191_2 where ord2_ordid=@ordid   alter table #detail2 add default '' for ord2_fbizid   alter table #detail2 add default '' for ord2_ford2tag   alter table #detail2 add default '' for ord2_jhbz   alter table #detail2 add default '' for ord2_order   alter table #detail2 add default '' for ord2_rbizid   alter table #detail2 add default '' for ord2_rord2tag   alter table #detail2 add default '' for ord2_tag   alter table #detail2 add default '' for ord2_zbrs   alter table #detail2 add default '' for ord2_date   alter table #detail2 add default '' for ord2_updated   alter table #detail2 add default '' for ord2_fatherord2id   alter table #detail2 add default '' for ord2_ford2id   alter table #detail2 add default '' for ord2_fordid   alter table #detail2 add default '' for ord2_ordid   alter table #detail2 add default '' for ord2_rord2id   alter table #detail2 add default '' for ord2_rordid   alter table #detail2 add default '' for ord2_code   alter table #detail2 add default '' for ord2_ftype   alter table #detail2 add default '' for ord2_key   alter table #detail2 add default '' for ord2_rtype   alter table #detail2 add default '' for ord2_tags   alter table #detail2 add default '' for ord2_bmmc   alter table #detail2 add default '' for ord2_bz   alter table #detail2 add default '' for ord2_caption   alter table #detail2 add default '' for ord2_group   alter table #detail2 add default '' for ord2_gw   alter table #detail2 add default '' for ord2_status update #detail2 set recid=ord2_id 
 ---- 以下是开发人员写的 before link job 事件 --------------
 insert into ebs2java.dbo.mps_testlog(txt,objid)
select top 1 'new第一步>>第二步执行后SQL',tjb.jb_id from #new tjb

insert into ebs2java.dbo.mps_testlog(txt,objid)
select top 1 'old第一步>>第二步执行后SQL',tjb.jb_id from #old tjb

insert into ebs2java.dbo.mps_testlog(txt,objid)
select top 1 'master第一步>>第二步执行后SQL',tjb.ord_id from #master tjb

insert into ebs2java.dbo.mps_testlog(txt,objid)
select top 1 'detail2第一步>>第二步执行后SQL',tjb.ord2_id from #detail2 tjb
 ---- 以上是开发人员写的 before libk job 事件 --------------
 
  
  set @ord2group2=''  select top 1 @ord2group2=ord2_group from #detail2 where ord2_group>''  set @ord2group2 = isnull(@ord2group2 , '')  insert into order_191_2(ord2_date,ord2_updated,ord2_tag,ord2_group,ord2_ordid,ord2_fbizid,ord2_ford2tag,ord2_jhbz,ord2_order,ord2_rbizid,ord2_rord2tag,ord2_zbrs,ord2_fatherord2id,ord2_ford2id,ord2_fordid,ord2_rord2id,ord2_rordid,ord2_code,ord2_ftype,ord2_key,ord2_rtype,ord2_tags,ord2_bmmc,ord2_bz,ord2_caption,ord2_gw,ord2_status)  select case when new.ord2_date>getdate()-40000 then new.ord2_date else getdate() end ,getdate(),2,    case when new.ord2_group>'' then new.ord2_group else @ord2group2 end , @ordid,new.ord2_fbizid,new.ord2_ford2tag,new.ord2_jhbz,new.ord2_order,new.ord2_rbizid,new.ord2_rord2tag,new.ord2_zbrs,new.ord2_fatherord2id,new.ord2_ford2id,new.ord2_fordid,new.ord2_rord2id,new.ord2_rordid,new.ord2_code,new.ord2_ftype,new.ord2_key,new.ord2_rtype,new.ord2_tags,new.ord2_bmmc,new.ord2_bz,new.ord2_caption,new.ord2_gw,new.ord2_status from #detail2 new where recid is null 
 
--- 清除临时表 
exec drop_temp_table '#new' exec drop_temp_table '#old' exec drop_temp_table '#master' exec drop_temp_table '#detail2'
set nocount off 
end