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

-- 生成时间:2018-11-23 17:09:55 by ebs-core  
CREATE  procedure order_258_3802_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_258 with(nolock) where ord_id=@ordid 
 ---- 以下是开发人员写的 before link job 事件 --------------
 --判断是否第一次咨询
declare @temp1 int = 0, @temp2 int
select @temp1 = (select ord_fordid from #master where ord_id = @ordid)
--第一次咨询
if (@temp1 = 0)
    begin
        insert into order_261
            (ord_khid,ord_khxm,ord_khdh,ord_jzxm,ord_jzdh,ord_khdz,ord_zxmd,ord_cppp,ord_cpxh,ord_gmrq,ord_creator,ord_date,ord_no,ord_fordid,ord_fbizid)
        select
            ord_khid,ord_khxm,ord_khdh,ord_jzxm,ord_jzdh,ord_khdz,ord_zxmd,ord_cppp,ord_cpxh,ord_gmrq,ord_creator,ord_date,ord_no,@ordid,258
        from #master where ord_id = @ordid
            
        select @temp2 = ord_id from order_261 where ord_fordid = @ordid and ord_fbizid = 258
            
        insert into order_261_2
            (ord2_zxpt,ord2_clr,ord2_clsj,ord2_imh,ord2_sqsh,ord2_yysj,ord2_ccxlh,ord2_xh1,ord2_ywlx,ord2_zj,ord2_clxq,ord2_fordid,ord2_tag,ord2_ordid)
        select
            ord_zxpt,ord_creator,ord_date,ord_imh,ord_sqsh,ord_yjddsj,ord_ccxlh,ord_xh1,ord_wtbt,ord_zxgl,ord_clxq,@ordid,2,@temp2
        from #master where ord_id = @ordid
    end

--不是第一次咨询
if (@temp1 > 0)
    begin
        select @temp2 = ord_id from order_261 where ord_fordid = @ordid and ord_fbizid = 258
        
        insert into order_261_2
            (ord2_zxpt,ord2_clr,ord2_clsj,ord2_imh,ord2_sqsh,ord2_yysj,ord2_ccxlh,ord2_xh1,ord2_ywlx,ord2_zj,ord2_clxq,ord2_fordid,ord2_tag,ord2_ordid)
        select
            ord_zxpt,ord_creator,ord_date,ord_imh,ord_sqsh,ord_yjddsj,ord_ccxlh,ord_xh1,ord_wtbt,ord_zxgl,ord_clxq,@ordid,2,@temp2
        from #master where ord_id = @ordid
    end
   
--短信发送
declare @iphone varchar(50), @xxmb varchar(50)
select @iphone = (select ord_dxmbhm from #master where ord_id = @ordid)
if(@iphone = 11)
    begin
        select @xxmb = (select ord_xxmb from #master where ord_id = @ordid)
        if(@xxmb = '400上门告知')
            begin
                insert  ebs_kernel.dbo.pub_message(
                msg_mpid,
                msg_cmpid,
                msg_text,
                msg_type,
                msg_target,
                msg_cuid,
                msg_sendtimes,
                msg_senddate
                )
                select mp_id,1,'{ord_jjgcs}'+r.ord_jjgcs+'{ord_gcssj}'+r.ord_gcssj,'DAYU',r.ord_dxmbhm,0,0,getdate()
                from ebs_kernel.dbo.pub_messagetemplate m, #master r
                where m.mp_dayuincode > '' and m.mp_name = @xxmb
            end
        if(@xxmb = '400服务告知')
            begin
                insert  ebs_kernel.dbo.pub_message(
                msg_mpid,
                msg_cmpid,
                msg_text,
                msg_type,
                msg_target,
                msg_cuid,
                msg_sendtimes,
                msg_senddate
                )
                select mp_id,1,'','DAYU',r.ord_dxmbhm,0,0,getdate()
                from ebs_kernel.dbo.pub_messagetemplate m, #master r
                where m.mp_dayuincode > '' and m.mp_name = @xxmb
            end
        if(@xxmb = '400门店类')
            begin
                insert  ebs_kernel.dbo.pub_message(
                msg_mpid,
                msg_cmpid,
                msg_text,
                msg_type,
                msg_target,
                msg_cuid,
                msg_sendtimes,
                msg_senddate
                )
                select mp_id,1,'{ord_mddz}'+r.ord_mddz+'{ord_mddh}'+r.ord_mddh,'DAYU',r.ord_dxmbhm,0,0,getdate()
                from ebs_kernel.dbo.pub_messagetemplate m, #master r
                where m.mp_dayuincode > '' and m.mp_name = @xxmb
            end
        if(@xxmb = '400技术类')
            begin
                insert  ebs_kernel.dbo.pub_message(
                msg_mpid,
                msg_cmpid,
                msg_text,
                msg_type,
                msg_target,
                msg_cuid,
                msg_sendtimes,
                msg_senddate
                )
                select mp_id,1,'{ord_wtbt}'+r.ord_wtbt+'{ord_bzlj}'+r.ord_bzlj,'DAYU',r.ord_dxmbhm,0,0,getdate()
                from ebs_kernel.dbo.pub_messagetemplate m, #master r
                where m.mp_dayuincode > '' and m.mp_name = @xxmb
            end
    end

 ---- 以上是开发人员写的 before libk job 事件 --------------
 
  
 
 
--- 清除临时表 
exec drop_temp_table '#master' 

set nocount off 
end