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

CREATE  procedure [dbo].[mps_create_task_java_item_type](
@cmpid int  ,
@autotype varchar(20) 
) as
begin

declare @autoid int 
set @autoid = 0 
if (charindex('sys',@autotype)=1) 
begin
set @autoid = CONVERT(int,replace(@autotype,'sys',''))  
end 
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) = '' 
declare @sql nvarchar(4000) 
declare @nweb nvarchar(1000)

if (charindex('sys',@autotype)=1) 
begin
select top 1 @unit=auto_unit, @interval=auto_interval ,@web=auto_webservice , @time=auto_starttime 
from mps_auto_import with(nolock) where  auto_id=@autoid  
end else
begin
 select top 1 @unit=auto_unit, @interval=auto_interval ,@web=auto_webservice , @time=auto_starttime 
 from mps_auto_import with(nolock) where auto_cmpid=@cmpid and auto_type=@autotype  
end 
 
 
if (@unit>'' and @interval>0 and @time>'1910-01-01') 
begin
if (@web>'') 
begin
select top 1 @webparam=svc_url  from ebs_kernel..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) 
end 
end else 
begin
set @webparam='' 
end 
end 
set @nweb = @web 
print @nweb
if (not exists (select 1 from mps_task_java with(nolock) where tsk_cmpid=@cmpid and tsk_type='webservice' and tsk_objtype=@autotype and tsk_name=@nweb)) 
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,@nweb,
case when @unit='小时' then @interval * 60 
 when @unit='天' then @interval * 60 * 24 
 else @interval 
end , GETDATE(),@time,'webservice',@autotype,0,0,0,0) 
end 
end else 
begin
if (charindex('sys',@autotype)=1) 
begin
set @web = 'sys_import_'+CONVERT(varchar(10),@autoid)  
end else
begin
set @web = @autotype+'_import' 
end 

if (not exists (select 1 from mps_task_java with(nolock) where tsk_cmpid=@cmpid and tsk_type='sql' and tsk_type=@autotype  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',@autotype,0,0,0,0) 
end 
end 
end 
end