IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_create_task_java_item]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_create_task_java_item]
GO
create procedure [dbo].[mps_create_task_java_item](
@cmpid int,
@bizid int,
@wrkid int,
@ordid bigint,
@jbid bigint = default
) as
begin
declare @interval int 
declare @unit varchar(20)
declare @web varchar(1000)
declare @time datetime 
declare @webparam nvarchar(4000)
declare @i int 
declare @s varchar(200) 
declare @pm varchar(4000) = '' 
-- 如果 jbid=0 生成业务单的任务
if (@jbid=0) 
begin
select top 1 @unit=biz_auto2_unit, @interval=biz_auto2_interval ,@web=biz_auto2_webservice , @time=biz_auto2_starttime from mps_biztype with(nolock) where biz_id=@bizid 
if (@unit>'' and @interval>0 and @time>'1910-01-01') 
begin
if (@web>'') 
begin
select top 1 @webparam=svc_url  from pub_webservice with(nolock) where svc_cmpid=@cmpid and svc_name=@web 
set @webparam = ISNULL(@webparam,'') 
-- 分析出所有的参数 
while (@webparam>'') 
begin
set @i = CHARINDEX('{',@webparam) 
if (@i>0) 
begin
set @webparam = SUBSTRING(@webparam,@i+1,4000) 
set @i = CHARINDEX('}',@webparam) 
if (@i>0) 
begin
set @s = SUBSTRING(@webparam,1,@i-1) 
set @webparam = SUBSTRING(@webparam,@i+1,4000) 
if (CHARINDEX('ord_',@s)>0) 
begin
set @pm = @pm+'+''&'+@s+'=''+'+@s 
end 
end 
end else 
begin
set @webparam='' 
end 
end 
if (@pm>'') 
begin
print @pm 
end 
end else 
begin
set @web = 'order_'+convert(varchar(10),@bizid)+'_import_ord' 
if (not exists (select 1 from mps_task_java with(nolock) where tsk_cmpid=@cmpid and tsk_type='biz' and tsk_bizid=@bizid and tsk_ordid=@ordid and tsk_name=@web)) 
begin
insert into mps_task_java(tsk_cmpid,tsk_name,tsk_interval,tsk_runtime,tsk_nextruntime,tsk_type,tsk_objtype,tsk_ordid,tsk_bizid,tsk_wrkid,tsk_jbid) 
values(@cmpid,@web,
case when @unit='小时' then @interval * 60 
 when @unit='天' then @interval * 60 * 24 
 else @interval 
end , GETDATE(),@time,'sql','biz',@ordid,@bizid,0,0) 
end 
end 
end 
end else
begin
select top 1 @unit=wrk_auto2_unit,@interval=wrk_auto2_interval ,@web=wrk_auto2_webservice, @time=wrk_auto2_starttime from mps_flowwork with(nolock) where wrk_id=@wrkid 
end 
end