IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[pub_save_webservice]') AND type = 'P')
DROP PROCEDURE [dbo].[pub_save_webservice]
GO
 
CREATE procedure [dbo].[pub_save_webservice] 
@svcid int,
@svc_name nvarchar(50),
@svc_url nvarchar(1000),
@svc_method nvarchar(2000),
@svc_paramtype nvarchar(1000),
@svc_resulttype nvarchar(1000),
@svc_requesttype varchar(256),
@svc_language varchar(30),
@svc_cycle varchar(50),
@svc_extsql nvarchar(max),
@svc_bizid int,
@svc_biztype nvarchar(50),
@svc_displayflds nvarchar(500),
@svc_resultfld varchar(100)
as
begin
set nocount on
declare @needgensql int = 1 
if (exists (
select 1 from ebs_kernel..pub_webservice 
where svc_id=@svcid and 
    ((svc_displayflds<>@svc_displayflds and @svc_displayflds<>'_none_') or 
 (svc_resultfld<>@svc_resultfld and @svc_resultfld<>'_none_')  or
 (svc_extsql<>@svc_extsql and @svc_extsql<>'_none_')
) 
)) 
begin
set @needgensql = 0 
end 
declare @samenum int, @cmpid int 

select @samenum = count(*) from  ebs_kernel..pub_webservice where svc_name = @svc_name

if @samenum > 0
begin
select '保存失败！有相同的名称: '+@svc_name  as result
end else
begin
set @svc_displayflds = ltrim(rtrim(@svc_displayflds)) --去除首尾空格  
update ebs_kernel..pub_webservice set 
svc_name = case when @svc_name='_none_' then svc_name else @svc_name end,
svc_url = case when @svc_url='_none_' then svc_url else @svc_url end,
svc_method = case when @svc_method='_none_' then svc_method else @svc_method end,
svc_paramtype = case when @svc_paramtype='_none_' then svc_paramtype else @svc_paramtype end,
svc_resulttype = case when @svc_resulttype='_none_' then svc_resulttype else @svc_resulttype end,
svc_requesttype = case when @svc_requesttype='_none_' then svc_requesttype else @svc_requesttype end,
svc_language = case when @svc_language='_none_' then svc_language else @svc_language end,
svc_extsql = case when @svc_extsql='_none_' then svc_extsql else @svc_extsql end,
svc_cycle = case when @svc_cycle='_none_' then svc_cycle else @svc_cycle end,
svc_bizid = case when @svc_bizid=-999999999 then svc_bizid else @svc_bizid end ,
svc_biztype = case when @svc_biztype='_none_' then svc_biztype else @svc_biztype end,
svc_resultfld = case when @svc_resultfld='_none_' then svc_resultfld else @svc_resultfld end,
svc_displayflds = case when @svc_displayflds='_none_' then svc_displayflds else @svc_displayflds end
where svc_id=@svcid

declare @xmltype varchar(20)='' 
select @xmltype = svc_resulttype from ebs_kernel..pub_webservice where svc_id = @svcid
set @xmltype = ISNULL(@xmltype,'') 
if (@xmltype='') set @xmltype='xml' 
if (@xmltype = 'xml' and @needgensql=0) 
begin
exec pub_gen_webservice_proc @cmpid,@svcid,'_none_'
end
end

set nocount off
end