IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_webservice_schema]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_webservice_schema]
GO
CREATE procedure [dbo].[mps_save_webservice_schema] 
@svcid int,
@cmpid int,
@cycle varchar(50),
@nextexecute  datetime
as
begin


update ebs_kernel..pub_webservice set svc_nextexecute=@nextexecute  , svc_cycle=@cycle  where svc_id=@svcid 

declare @s1 varchar(50) 
set @s1 = @cycle 
declare @i int 
set @i = CHARINDEX('|',@s1) 
declare @s2 varchar(50) 
set @s2 = SUBSTRING(@s1,@i+1,50) 
set @s1 = SUBSTRING(@s1,1,@i-1) 
set @i = CONVERT(int,@s1) 

declare @tskid int 
select top 1 @tskid=tsk_id from mps_task_java with(nolock) 
where tsk_cmpid=@cmpid and tsk_name='service_'+CONVERT(varchar(10),@svcid)+'_auto' 
set @tskid = ISNULL(@tskid,0) 
if (@tskid<=0) 
begin
insert into mps_task_java(tsk_cmpid,tsk_name,tsk_interval,tsk_nextruntime,tsk_times,tsk_type) 
select @cmpid , 'service_'+CONVERT(varchar(10),@svcid)+'_auto',
case when @s2='分钟' then @i 
 when @s2='小时' then @i*60 
 when @s2='天' then @i*60*24 
 else  @i  
end ,@nextexecute,0,'webservice'
end else
begin
update mps_task_java set 
tsk_nextruntime = case when tsk_nextruntime<@nextexecute then @nextexecute else tsk_nextruntime end , 
tsk_interval=case when @s2='分钟' then @i 
   when @s2='小时' then @i*60 
  when @s2='天' then @i*60*24 
  else  @i  
 end
where tsk_id=@tskid 
end 
 
set nocount off
end