IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_sys_calc_bizpower]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_sys_calc_bizpower]
GO
CREATE procedure [dbo].[mps_sys_calc_bizpower](
@cmpid int ,
@bizid int 
) as
begin

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
-- 计算新建人有哪些
  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,
'biz',@bizid,0,0,@bizid,'biznew,bizshow,bizconfig,bizflowpower,bizaudit,bizview,bizabolish,bizdelete,bizdn' 
declare @users table(pptype varchar(30), ppgroup int , useruid int) 
insert into @users( pptype ,ppgroup,useruid) 
select distinct case when pptype='bizshow' then 'bizview' else pptype end   ,grp , cuid from #myuser 

drop table #myuser
exec drop_temp_table '#permittion' 

  
  -- 首先要判断一下，当前用户是否可以新建  
  
  delete mps_biztype_users with(rowlock) 
  where bp_bizid=@bizid and (not exists (select 1 from @users where pptype=bp_type and bp_cuid=useruid)) 
  
  delete @users from mps_biztype_users with(nolock) 
  where bp_bizid=@bizid and pptype=bp_type and bp_cuid=useruid 
  
  insert into mps_biztype_users(bp_type,bp_bizid,bp_cuid)
  select distinct pptype,@bizid,useruid
  from @users  
  
  
end