IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_auto_import]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_auto_import]
GO
CREATE procedure [dbo].[mps_save_auto_import]
(
@cmpid int ,
@autotype varchar(20),
@auto_interval int,
@auto_unit varchar(10),
@auto_starttime datetime ,
@auto_webservice varchar(50),
@auto_sql nvarchar(max) 
) as
begin
declare @autoid int 
select top 1 @autoid = auto_id from  mps_auto_import with(nolock) 
where auto_cmpid=@cmpid and auto_type=@autotype 
set @autoid=ISNULL(@autoid,0) 
if (@autoid<=0) 
begin
insert into mps_auto_import(auto_cmpid,auto_type) values(@cmpid , @autotype) 
select top 1 @autoid = auto_id from  mps_auto_import with(nolock) 
where auto_cmpid=@cmpid and auto_type=@autotype 
end 
update mps_auto_import set 
auto_interval = case when @auto_interval=-999999999 then auto_interval else @auto_interval end ,
auto_unit = case when @auto_unit='_none_' then auto_unit else @auto_unit end ,
auto_starttime = case when @auto_starttime<GETDATE()-10000 then auto_starttime else @auto_starttime end ,
auto_webservice = case when @auto_webservice='_none_' then auto_webservice else @auto_webservice end ,
auto_sql = case when @auto_sql='_none_' then auto_sql else @auto_sql end  
where auto_id=@autoid 

if (@autotype='branch') 
begin
exec mps_gen_branchimport @cmpid 
exec mps_gen_branchimport_web @cmpid 
end 
if (@autotype='depart') 
begin
exec mps_gen_departimport @cmpid 
exec mps_gen_departimport_web @cmpid 
end 
if (@autotype='shop') 
begin
exec mps_gen_shopimport @cmpid 
exec mps_gen_shopimport_web @cmpid 
end 
if (@autotype='employee') 
begin
exec mps_gen_employeeimport @cmpid 
exec mps_gen_employeeimport_web @cmpid 
end 
end