U8权限管理规范

账套号 3位流水号

定义每个账套的用户组

权限编号 描述 账套001角色编号 账套007角色编号
001 普通员工 001001 007001
002 财务经理 001002 007002
003 财务 001003 007003
004 采购 001004 007004
--这个是将【001账套的002财务经理】赋予到【007账套的002财务经理】
--需要复制权限的角色【002财务经理】
DECLARE @role_type nvarchar(2)='002'
--目标账套
DECLARE @Acc_Id nvarchar(30)='007'
--从哪个账套复制
DECLARE @template_acc_id nvarchar(30)='001'
--复制到哪个角色【@template_User_Id】下
DECLARE @template_User_Id nvarchar(30)=@template_acc_id+@role_type

--需要复制权限的角色
DECLARE @cUser_Id nvarchar(30)=@Acc_Id+@role_type
DECLARE @Acc_Year int 
select @Acc_Year=iYear from UFSystem.DBO.UA_Account
where cAcc_Id=@Acc_Id


insert into [UFSystem].[dbo].[UA_HoldAuth]([cAcc_Id]
      ,[iYear]
      ,[cUser_Id]
      ,[cAuth_Id]
      ,[iIsUser]
      ,[csub_id]
      ,[cAuthType]
      ,[cRepellent]
      ,[cRepellentModule]
      ,[cNotRepellent])
SELECT [cAcc_Id]=@Acc_Id
      ,[iYear]=@Acc_Year
      ,[cUser_Id]=@cUser_Id
      ,v1.[cAuth_Id]
      ,v1.[iIsUser]
      ,v1.[csub_id]
      ,v1.[cAuthType]
      ,v1.[cRepellent]
      ,v1.[cRepellentModule]
      ,v1.[cNotRepellent]
  FROM [UFSystem].[dbo].[UA_HoldAuth] v1
  inner join [UFSystem].dbo.UA_Group v2g on 1=1
  left join [UFSystem].[dbo].[UA_HoldAuth] v2 on v2.cAcc_Id=@Acc_Id and v2.cUser_Id=v2g.cGroup_Id and v1.cAuth_Id=v2.cAuth_Id and V1.cAcc_Id=V2.cAcc_Id
  where v1.cUser_Id=@template_User_Id and v1.iIsUser=0
  AND v1.cAcc_Id=@template_acc_id
  and v2.cAcc_Id is null
  and v2g.cGroup_Id=@cUser_Id
 

开通权限时,用户提出的都是跟某某某的权限一样

-- 被复制权限的用户
DECLARE @old_UserID NVARCHAR(20)='aaaa';
-- 需要被授权的用户
DECLARE @new_UserID NVARCHAR(20)='xxxx';

insert into UA_Role(cGroup_Id,cUser_Id)
select v1.cGroup_Id,@new_UserID as cUser_Id from UA_Role v1
left join UA_Role v2 on v1.cGroup_Id=v2.cGroup_Id and v2.cUser_Id=@new_UserID
where v1.cUser_Id=@old_UserID
and v2.cGroup_Id is null

 

posted @ 2025-07-08 10:37  帆帆Evan  阅读(15)  评论(0)    收藏  举报