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

-- 生成时间:2018-11-30 11:09:36 by ebs-core  
CREATE  procedure order_260_3554_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 '#master' 
select * into #master from order_260 with(nolock) where ord_id=@ordid 
 ---- 以下是开发人员写的 before link job 事件 --------------
 update #master set ord_ddsj = getdate()
update #master set ord_wxkssj = getdate()
 ---- 以上是开发人员写的 before libk job 事件 --------------
 
  
 

 declare @authority_old varchar(32)=''
declare @authority_new varchar(32)='' 
select top 1 @authority_old=substring(sys.fn_sqlvarbasetostr(HashBytes('MD5', convert(varchar(100),ord_createcuid) )),3,32) from order_260 with(nolock) where ord_id=@ordid 
set @authority_old = isnull(@authority_old,'') 
select top 1 @authority_new=substring(sys.fn_sqlvarbasetostr(HashBytes('MD5', convert(varchar(100),ord_createcuid) )),3,32) from #master 
set @authority_new = isnull(@authority_new,'') 
update old set 
ord_branch=case when new.ord_branch is null or new.ord_branch = '_none_'  then old.ord_branch else new.ord_branch end,ord_cbid=case when new.ord_cbid is null or new.ord_cbid = -999999999  then old.ord_cbid else new.ord_cbid end,ord_createbizids=case when new.ord_createbizids is null or new.ord_createbizids = '_none_'  then old.ord_createbizids else new.ord_createbizids end,ord_createcuid=case when new.ord_createcuid is null or new.ord_createcuid = -999999999  then old.ord_createcuid else new.ord_createcuid end,ord_createdepart=case when new.ord_createdepart is null or new.ord_createdepart = '_none_'  then old.ord_createdepart else new.ord_createdepart end,ord_createdpid=case when new.ord_createdpid is null or new.ord_createdpid = -999999999  then old.ord_createdpid else new.ord_createdpid end,ord_creator=case when new.ord_creator is null or new.ord_creator = '_none_'  then old.ord_creator else new.ord_creator end,ord_cuid=case when new.ord_cuid is null or new.ord_cuid = -999999999  then old.ord_cuid else new.ord_cuid end,ord_depart=case when new.ord_depart is null or new.ord_depart = '_none_'  then old.ord_depart else new.ord_depart end,ord_dpid=case when new.ord_dpid is null or new.ord_dpid = -999999999  then old.ord_dpid else new.ord_dpid end,ord_empname=case when new.ord_empname is null or new.ord_empname = '_none_'  then old.ord_empname else new.ord_empname end,ord_enddate=case when new.ord_enddate is null or new.ord_enddate <= @nonedate then old.ord_enddate else new.ord_enddate end,ord_fbizid=case when new.ord_fbizid is null or new.ord_fbizid = -999999999  then old.ord_fbizid else new.ord_fbizid end,ord_fjbid=case when new.ord_fjbid is null or new.ord_fjbid = -999999999  then old.ord_fjbid else new.ord_fjbid end,ord_ford2id=case when new.ord_ford2id is null or new.ord_ford2id = -999999999  then old.ord_ford2id else new.ord_ford2id end,ord_ford2tag=case when new.ord_ford2tag is null or new.ord_ford2tag = -999999999  then old.ord_ford2tag else new.ord_ford2tag end,ord_fordid=case when new.ord_fordid is null or new.ord_fordid = -999999999  then old.ord_fordid else new.ord_fordid end,ord_ftype=case when new.ord_ftype is null or new.ord_ftype = '_none_'  then old.ord_ftype else new.ord_ftype end,ord_key=case when new.ord_key is null or new.ord_key = '_none_'  then old.ord_key else new.ord_key end,ord_no=case when new.ord_no is null or new.ord_no = '_none_'  then old.ord_no else new.ord_no end,ord_noi=case when new.ord_noi is null or new.ord_noi = -999999999  then old.ord_noi else new.ord_noi end,ord_rbizid=case when new.ord_rbizid is null or new.ord_rbizid = -999999999  then old.ord_rbizid else new.ord_rbizid end,ord_rord2id=case when new.ord_rord2id is null or new.ord_rord2id = -999999999  then old.ord_rord2id else new.ord_rord2id end,ord_rord2tag=case when new.ord_rord2tag is null or new.ord_rord2tag = -999999999  then old.ord_rord2tag else new.ord_rord2tag end,ord_rordid=case when new.ord_rordid is null or new.ord_rordid = -999999999  then old.ord_rordid else new.ord_rordid end,ord_rtype=case when new.ord_rtype is null or new.ord_rtype = '_none_'  then old.ord_rtype else new.ord_rtype end,ord_security=case when new.ord_security is null or new.ord_security = -999999999  then old.ord_security else new.ord_security end,ord_sobjid=case when new.ord_sobjid is null or new.ord_sobjid = -999999999  then old.ord_sobjid else new.ord_sobjid end,ord_status=case when new.ord_status is null or new.ord_status = '_none_'  then old.ord_status else new.ord_status end,ord_style=case when new.ord_style is null or new.ord_style = -999999999  then old.ord_style else new.ord_style end,ord_sxly=case when new.ord_sxly is null or new.ord_sxly = '_none_'  then old.ord_sxly else new.ord_sxly end,ord_template=case when new.ord_template is null or new.ord_template = '_none_'  then old.ord_template else new.ord_template end,ord_templateid=case when new.ord_templateid is null or new.ord_templateid = -999999999  then old.ord_templateid else new.ord_templateid end,ord_title=case when new.ord_title is null or new.ord_title = '_none_'  then old.ord_title else new.ord_title end,ord_type=case when new.ord_type is null or new.ord_type = '_none_'  then old.ord_type else new.ord_type end,ord_xm=case when new.ord_xm is null or new.ord_xm = '_none_'  then old.ord_xm else new.ord_xm end,ord_wxlx=case when new.ord_wxlx is null or new.ord_wxlx = '_none_'  then old.ord_wxlx else new.ord_wxlx end,ord_bjbz=case when new.ord_bjbz is null or new.ord_bjbz = '_none_'  then old.ord_bjbz else new.ord_bjbz end,ord_fwbid=case when new.ord_fwbid is null or new.ord_fwbid = -999999999  then old.ord_fwbid else new.ord_fwbid end,ord_fwbmc=case when new.ord_fwbmc is null or new.ord_fwbmc = '_none_'  then old.ord_fwbmc else new.ord_fwbmc end,ord_fwlx=case when new.ord_fwlx is null or new.ord_fwlx = '_none_'  then old.ord_fwlx else new.ord_fwlx end,ord_gjrq=case when new.ord_gjrq is null or new.ord_gjrq <= @nonedate then old.ord_gjrq else new.ord_gjrq end,ord_imei=case when new.ord_imei is null or new.ord_imei = '_none_'  then old.ord_imei else new.ord_imei end,ord_jjmd=case when new.ord_jjmd is null or new.ord_jjmd = '_none_'  then old.ord_jjmd else new.ord_jjmd end,ord_jjrq=case when new.ord_jjrq is null or new.ord_jjrq <= @nonedate then old.ord_jjrq else new.ord_jjrq end,ord_mdbh=case when new.ord_mdbh is null or new.ord_mdbh = '_none_'  then old.ord_mdbh else new.ord_mdbh end,ord_mddpid=case when new.ord_mddpid is null or new.ord_mddpid = -999999999  then old.ord_mddpid else new.ord_mddpid end,ord_sfzh=case when new.ord_sfzh is null or new.ord_sfzh = '_none_'  then old.ord_sfzh else new.ord_sfzh end,ord_sjh=case when new.ord_sjh is null or new.ord_sjh = '_none_'  then old.ord_sjh else new.ord_sjh end,ord_sjmc=case when new.ord_sjmc is null or new.ord_sjmc = '_none_'  then old.ord_sjmc else new.ord_sjmc end,ord_sn=case when new.ord_sn is null or new.ord_sn = '_none_'  then old.ord_sn else new.ord_sn end,ord_ys=case when new.ord_ys is null or new.ord_ys = '_none_'  then old.ord_ys else new.ord_ys end,ord_zdlx=case when new.ord_zdlx is null or new.ord_zdlx = '_none_'  then old.ord_zdlx else new.ord_zdlx end,ord_zdpp=case when new.ord_zdpp is null or new.ord_zdpp = '_none_'  then old.ord_zdpp else new.ord_zdpp end,ord_zdxh=case when new.ord_zdxh is null or new.ord_zdxh = '_none_'  then old.ord_zdxh else new.ord_zdxh end,ord_fwfyy=case when new.ord_fwfyy is null or new.ord_fwfyy = -999999999  then old.ord_fwfyy else new.ord_fwfyy end,ord_gzfl1j=case when new.ord_gzfl1j is null or new.ord_gzfl1j = '_none_'  then old.ord_gzfl1j else new.ord_gzfl1j end,ord_gzfl2j=case when new.ord_gzfl2j is null or new.ord_gzfl2j = '_none_'  then old.ord_gzfl2j else new.ord_gzfl2j end,ord_gzms=case when new.ord_gzms is null or new.ord_gzms = '_none_'  then old.ord_gzms else new.ord_gzms end,ord_hxfs=case when new.ord_hxfs is null or new.ord_hxfs = '_none_'  then old.ord_hxfs else new.ord_hxfs end,ord_rjclff=case when new.ord_rjclff is null or new.ord_rjclff = '_none_'  then old.ord_rjclff else new.ord_rjclff end,ord_sjwcsj=case when new.ord_sjwcsj is null or new.ord_sjwcsj <= @nonedate then old.ord_sjwcsj else new.ord_sjwcsj end,ord_tcck=case when new.ord_tcck is null or new.ord_tcck = '_none_'  then old.ord_tcck else new.ord_tcck end,ord_trck=case when new.ord_trck is null or new.ord_trck = '_none_'  then old.ord_trck else new.ord_trck end,ord_wgzk=case when new.ord_wgzk is null or new.ord_wgzk = '_none_'  then old.ord_wgzk else new.ord_wgzk end,ord_wlfyy=case when new.ord_wlfyy is null or new.ord_wlfyy = -999999999  then old.ord_wlfyy else new.ord_wlfyy end,ord_wxbz=case when new.ord_wxbz is null or new.ord_wxbz = '_none_'  then old.ord_wxbz else new.ord_wxbz end,ord_wxgcs=case when new.ord_wxgcs is null or new.ord_wxgcs = '_none_'  then old.ord_wxgcs else new.ord_wxgcs end,ord_wxgcs2=case when new.ord_wxgcs2 is null or new.ord_wxgcs2 = '_none_'  then old.ord_wxgcs2 else new.ord_wxgcs2 end,ord_wxkssj=case when new.ord_wxkssj is null or new.ord_wxkssj <= @nonedate then old.ord_wxkssj else new.ord_wxkssj end,ord_wxmd=case when new.ord_wxmd is null or new.ord_wxmd = '_none_'  then old.ord_wxmd else new.ord_wxmd end,ord_xjimei=case when new.ord_xjimei is null or new.ord_xjimei = '_none_'  then old.ord_xjimei else new.ord_xjimei end,ord_xjsn=case when new.ord_xjsn is null or new.ord_xjsn = '_none_'  then old.ord_xjsn else new.ord_xjsn end,ord_yjclff=case when new.ord_yjclff is null or new.ord_yjclff = '_none_'  then old.ord_yjclff else new.ord_yjclff end,ord_zbts=case when new.ord_zbts is null or new.ord_zbts = '_none_'  then old.ord_zbts else new.ord_zbts end,ord_cfsj=case when new.ord_cfsj is null or new.ord_cfsj <= @nonedate then old.ord_cfsj else new.ord_cfsj end,ord_ddsj=case when new.ord_ddsj is null or new.ord_ddsj <= @nonedate then old.ord_ddsj else new.ord_ddsj end,ord_wxwcsj=case when new.ord_wxwcsj is null or new.ord_wxwcsj <= @nonedate then old.ord_wxwcsj else new.ord_wxwcsj end,ord_dqzt=case when new.ord_dqzt is null or new.ord_dqzt = '_none_'  then old.ord_dqzt else new.ord_dqzt end,ord_fcbz=case when new.ord_fcbz is null or new.ord_fcbz = '_none_'  then old.ord_fcbz else new.ord_fcbz end,ord_fzbsj=case when new.ord_fzbsj is null or new.ord_fzbsj <= @nonedate then old.ord_fzbsj else new.ord_fzbsj end,ord_khqjsj=case when new.ord_khqjsj is null or new.ord_khqjsj <= @nonedate then old.ord_khqjsj else new.ord_khqjsj end,ord_mdsjsj=case when new.ord_mdsjsj is null or new.ord_mdsjsj <= @nonedate then old.ord_mdsjsj else new.ord_mdsjsj end,ord_zbfcsj=case when new.ord_zbfcsj is null or new.ord_zbfcsj <= @nonedate then old.ord_zbfcsj else new.ord_zbfcsj end,ord_zbfdsj=case when new.ord_zbfdsj is null or new.ord_zbfdsj <= @nonedate then old.ord_zbfdsj else new.ord_zbfdsj end,ord_zbsjsj=case when new.ord_zbsjsj is null or new.ord_zbsjsj <= @nonedate then old.ord_zbsjsj else new.ord_zbsjsj end,ord_zbsjsjfc=case when new.ord_zbsjsjfc is null or new.ord_zbsjsjfc <= @nonedate then old.ord_zbsjsjfc else new.ord_zbsjsjfc end,ord_dqbmsyrcuid=case when new.ord_dqbmsyrcuid is null or new.ord_dqbmsyrcuid = -999999999  then old.ord_dqbmsyrcuid else new.ord_dqbmsyrcuid end,ord_zdmddgcsid=case when new.ord_zdmddgcsid is null or new.ord_zdmddgcsid = -999999999  then old.ord_zdmddgcsid else new.ord_zdmddgcsid end,ord_dqmdgcsid=case when new.ord_dqmdgcsid is null or new.ord_dqmdgcsid = -999999999  then old.ord_dqmdgcsid else new.ord_dqmdgcsid end,ord_czfwbid=case when new.ord_czfwbid is null or new.ord_czfwbid = -999999999  then old.ord_czfwbid else new.ord_czfwbid end,ord_sxfj=case when new.ord_sxfj is null or new.ord_sxfj = '_none_'  then old.ord_sxfj else new.ord_sxfj end,ord_ssgzmsid=case when new.ord_ssgzmsid is null or new.ord_ssgzmsid = -999999999  then old.ord_ssgzmsid else new.ord_ssgzmsid end,ord_xzppxhid=case when new.ord_xzppxhid is null or new.ord_xzppxhid = -999999999  then old.ord_xzppxhid else new.ord_xzppxhid end,ord_xzsjid=case when new.ord_xzsjid is null or new.ord_xzsjid = -999999999  then old.ord_xzsjid else new.ord_xzsjid end,ord_rjclid=case when new.ord_rjclid is null or new.ord_rjclid = -999999999  then old.ord_rjclid else new.ord_rjclid end,ord_yjclid=case when new.ord_yjclid is null or new.ord_yjclid = -999999999  then old.ord_yjclid else new.ord_yjclid end,ord_cjjj=case when new.ord_cjjj is null or new.ord_cjjj = '_none_'  then old.ord_cjjj else new.ord_cjjj end,ord_xzxhid=case when new.ord_xzxhid is null or new.ord_xzxhid = -999999999  then old.ord_xzxhid else new.ord_xzxhid end,ord_xzsjppid=case when new.ord_xzsjppid is null or new.ord_xzsjppid = -999999999  then old.ord_xzsjppid else new.ord_xzsjppid end,ord_xzppid=case when new.ord_xzppid is null or new.ord_xzppid = -999999999  then old.ord_xzppid else new.ord_xzppid end,ord_cjclff=case when new.ord_cjclff is null or new.ord_cjclff = '_none_'  then old.ord_cjclff else new.ord_cjclff end,ord_cxshbh=case when new.ord_cxshbh is null or new.ord_cxshbh = '_none_'  then old.ord_cxshbh else new.ord_cxshbh end,ord_return2head=case when new.ord_return2head is null or new.ord_return2head = -999999999  then old.ord_return2head else new.ord_return2head end,ord_tzqjsj=case when new.ord_tzqjsj is null or new.ord_tzqjsj <= @nonedate then old.ord_tzqjsj else new.ord_tzqjsj end,ord_fcsc=case when new.ord_fcsc is null or new.ord_fcsc = -999999999  then old.ord_fcsc else new.ord_fcsc end,ord_fwsc=case when new.ord_fwsc is null or new.ord_fwsc = -999999999  then old.ord_fwsc else new.ord_fwsc end,ord_qjjsr=case when new.ord_qjjsr is null or new.ord_qjjsr = '_none_'  then old.ord_qjjsr else new.ord_qjjsr end,ord_wxje=case when new.ord_wxje is null or new.ord_wxje = '_none_'  then old.ord_wxje else new.ord_wxje end,ord_wxzq=case when new.ord_wxzq is null or new.ord_wxzq = -999999999  then old.ord_wxzq else new.ord_wxzq end,ord_authority_factor=case when new.ord_authority_factor is null or new.ord_authority_factor = -999999999  then old.ord_authority_factor else new.ord_authority_factor end

from order_260 old with(rowlock), #master new  where old.ord_id=new.ord_id 

if (@authority_new<>@authority_old) 
begin
if (not exists (select 1 from order_260_authority_factor with(nolock) where ordaf_value=@authority_new)) 
begin
insert into order_260_authority_factor(ordaf_done,ordaf_ordid,ordaf_value) values(0,@ordid,@authority_new)
end 
end

 
--- 清除临时表 
exec drop_temp_table '#master' 

set nocount off 
end