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

-- 生成时间:2018-11-22 18:21:54 by ebs-core  
CREATE  procedure order_266_3498_wrklink_after(
     @cmpid int, 
     @useruid int,
     @bizid int, 
     @ordid bigint, 
     @wrkid int, 
     @jbid bigint, 
     @wsid int, 
     @wsstatus nvarchar(50) 
  ) 
as  
begin  
set nocount on  
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
declare @autoapplycode varchar(50) 
  set @autoapplycode =  ''
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 * ,'' sourcefield into #new from mps_job with(nolock) where jb_id=@jbid 
exec drop_temp_table '#detail2' 
select *,null recid into #detail2 from order_266_2 with(nolock) where ord2_ordid=@ordid  
update #detail2 set recid=ord2_id 

 ---- 以下是开发人员写的 before link job 事件 --------------
 /*更新门店工单*/
update f set f.ord_dqzt = '门店返总部途中',f.ord_fzbsj = n.jb_enddate from order_260 f,#detail2 d,#new n where f.ord_id = d.ord2_mdordid

 ---- 以上是开发人员写的 before libk job 事件 --------------
 
  
 
update old set 
ord2_bz=case when new.ord2_bz is null or new.ord2_bz = '_none_'  then old.ord2_bz else new.ord2_bz end,ord2_caption=case when new.ord2_caption is null or new.ord2_caption = '_none_'  then old.ord2_caption else new.ord2_caption end,ord2_code=case when new.ord2_code is null or new.ord2_code = '_none_'  then old.ord2_code else new.ord2_code end,ord2_fatherord2id=case when new.ord2_fatherord2id is null or new.ord2_fatherord2id = -999999999  then old.ord2_fatherord2id else new.ord2_fatherord2id end,ord2_fbizid=case when new.ord2_fbizid is null or new.ord2_fbizid = -999999999  then old.ord2_fbizid else new.ord2_fbizid end,ord2_ford2id=case when new.ord2_ford2id is null or new.ord2_ford2id = -999999999  then old.ord2_ford2id else new.ord2_ford2id end,ord2_ford2tag=case when new.ord2_ford2tag is null or new.ord2_ford2tag = -999999999  then old.ord2_ford2tag else new.ord2_ford2tag end,ord2_fordid=case when new.ord2_fordid is null or new.ord2_fordid = -999999999  then old.ord2_fordid else new.ord2_fordid end,ord2_ftype=case when new.ord2_ftype is null or new.ord2_ftype = '_none_'  then old.ord2_ftype else new.ord2_ftype end,ord2_group=case when new.ord2_group is null or new.ord2_group = '_none_'  then old.ord2_group else new.ord2_group end,ord2_key=case when new.ord2_key is null or new.ord2_key = '_none_'  then old.ord2_key else new.ord2_key end,ord2_order=case when new.ord2_order is null or new.ord2_order = -999999999  then old.ord2_order else new.ord2_order end,ord2_rbizid=case when new.ord2_rbizid is null or new.ord2_rbizid = -999999999  then old.ord2_rbizid else new.ord2_rbizid end,ord2_rord2id=case when new.ord2_rord2id is null or new.ord2_rord2id = -999999999  then old.ord2_rord2id else new.ord2_rord2id end,ord2_rord2tag=case when new.ord2_rord2tag is null or new.ord2_rord2tag = -999999999  then old.ord2_rord2tag else new.ord2_rord2tag end,ord2_rordid=case when new.ord2_rordid is null or new.ord2_rordid = -999999999  then old.ord2_rordid else new.ord2_rordid end,ord2_rtype=case when new.ord2_rtype is null or new.ord2_rtype = '_none_'  then old.ord2_rtype else new.ord2_rtype end,ord2_status=case when new.ord2_status is null or new.ord2_status = '_none_'  then old.ord2_status else new.ord2_status end,ord2_tags=case when new.ord2_tags is null or new.ord2_tags = '_none_'  then old.ord2_tags else new.ord2_tags end,ord2_bxbl=case when new.ord2_bxbl is null or new.ord2_bxbl = '_none_'  then old.ord2_bxbl else new.ord2_bxbl end,ord2_jjmd=case when new.ord2_jjmd is null or new.ord2_jjmd = '_none_'  then old.ord2_jjmd else new.ord2_jjmd end,ord2_jjr=case when new.ord2_jjr is null or new.ord2_jjr = '_none_'  then old.ord2_jjr else new.ord2_jjr end,ord2_jjrq=case when new.ord2_jjrq is null or new.ord2_jjrq <= @nonedate then old.ord2_jjrq else new.ord2_jjrq end,ord2_pp=case when new.ord2_pp is null or new.ord2_pp = '_none_'  then old.ord2_pp else new.ord2_pp end,ord2_sjfj=case when new.ord2_sjfj is null or new.ord2_sjfj = '_none_'  then old.ord2_sjfj else new.ord2_sjfj end,ord2_sxlx=case when new.ord2_sxlx is null or new.ord2_sxlx = '_none_'  then old.ord2_sxlx else new.ord2_sxlx end,ord2_xh=case when new.ord2_xh is null or new.ord2_xh = '_none_'  then old.ord2_xh else new.ord2_xh end,ord2_ys=case when new.ord2_ys is null or new.ord2_ys = '_none_'  then old.ord2_ys else new.ord2_ys end,ord2_zbqr=case when new.ord2_zbqr is null or new.ord2_zbqr = '_none_'  then old.ord2_zbqr else new.ord2_zbqr end,ord2_zdimei=case when new.ord2_zdimei is null or new.ord2_zdimei = '_none_'  then old.ord2_zdimei else new.ord2_zdimei end,ord2_mdordid=case when new.ord2_mdordid is null or new.ord2_mdordid = -999999999  then old.ord2_mdordid else new.ord2_mdordid end
from order_266_2 old with(rowlock) , #detail2 new  
where old.ord2_id=new.ord2_id and (new.recid is not null)   

 
--- 清除临时表 
exec drop_temp_table '#new' 
exec drop_temp_table '#detail2'

set nocount off 
end