IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_sys_calc_docpower]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_sys_calc_docpower]
GO
CREATE procedure [dbo].[mps_sys_calc_docpower](
@cmpid int ,
@dcid int 
) as
begin
-- 计算新建人有哪些
  exec drop_temp_table '#permittion' 
  create table #permittion(ptype varchar(30), ctgid int , pid int , pobjid1 int , pobjid2 int) 
  
create table #myuser(pptype varchar(30),cuid int, grp int) 
exec mps_gen_powerusers @cmpid,0,0,0,0,0,0,0,0,
'doc',@dcid,0,0,@dcid,'docnew,docshow,docconfig,docview,docdelete,docarchive' 
declare @users table(pptype varchar(30), ppgroup int , useruid int) 
insert into @users( pptype ,ppgroup,useruid) 
select distinct   case when pptype='docshow' then 'docview' else pptype end     ,grp , cuid from #myuser 

drop table #myuser
exec drop_temp_table '#permittion' 

  
  -- 首先要判断一下，当前用户是否可以新建  
  
  delete mps_docctg_users 
  where dp_dcid=@dcid and (not exists (select 1 from @users where pptype=dp_type and dp_cuid=useruid)) 
  
  insert into mps_docctg_users(dp_type,dp_dcid,dp_cuid)
  select distinct pptype,@dcid,useruid
  from @users  
  where (not exists (select 1 from mps_docctg_users where dp_dcid=@dcid and pptype=dp_type and dp_cuid=useruid)) 
  
  
  
end