【BOS基础系统_权限】用户组织权限相关查询SQL
----------------- 用户权限查询相关sql汇总-------------------
背景:EAS产品权限体系内部有一些逻辑处理,前台无法清楚详细的展示每个用户在每个组织下的'实际'权限信息。因此篇文章是根据用户权限体系内部逻辑整理的各种常用查询sql来帮助大家学习并了解用户组织权限的实际关系。
注意:由于社区文章查看会修改之前的格式,复制以下sql需要自行调整格式,或者使用附件里面的sql.
首先这里放上客户经常想要的sql:
--用户,权限(包含角色分配的权限),组织关系查询。(查看所有用户在哪些组织下有哪些功能权限)
--注意:权限类型 10:操作权;20:禁止权
SELECT u.fnumber as 用户名,bu.fnumber as 组织编码 ,bu.fname_l2 as 组织名称,pm.falias_l2 as 权限项名称, pm.flongnumber as 权限项长编码, pm.ftype as 权限类型 FROM
( SELECT fuserid,forgid,fpermitemid,fpermtype from (
SELECT fowner AS fuserid, forgid, fpermitemid, fpermtype
FROM t_pm_userorgperm
UNION ALL
SELECT fuserid, forgid, fpermitemid, b.fpermtype
FROM t_pm_userroleorg a
JOIN t_pm_roleperm b ON a.froleid = b.froleid
) )s
INNER JOIN T_pm_user u on s.fuserid = u.FID
INNER JOIN T_pm_permitem pm on s.fpermitemid = pm.FID
INNER JOIN T_org_baseunit bu on s.forgid = bu.FID
其他常用sql
--1、用户组织权限表 的关系(操作权限)
select u.FNUMBER as "用户名",bu.FNUMBER as "组织编码" , p.FNUMBER as "权限项编码",p.FALIAS_L2 as "权限项别名" from t_pm_userorgperm uop
inner join t_pm_user u ON uop.FOWNER = u.FID
inner join t_pm_permitem p ON uop.FPERMITEMID = p.FID
inner join t_org_baseunit bu ON UOP.FORGID = BU.FID
where uop.FPERMTYPE = 10 and u.FIsDelete = 0
-- 2、用户组织角色表 的关系
SELECT u.FNUMBER as 用户名,r.FNUMBER as 角色编码,bu.FNUMBER as 组织单元编码 FROM T_PM_USERROLEORG uro
INNER JOIN T_PM_USER u ON URO.FUSERID = U.FID
INNER JOIN T_PM_ROLE r ON URO.FROLEID = R.FID
INNER JOIN T_ORG_BASEUNIT bu ON URO.FORGID = BU.FID
where u.FIsDelete = 0
--3、查询这个用户 在哪些组织下 拥有哪些操作权限 (替换用户id)
SELECT fowner AS fuserid, forgid, fpermitemid, fpermtype
FROM t_pm_userorgperm
WHERE fowner IN ('用户id')
UNION ALL
SELECT fuserid, forgid, fpermitemid, b.fpermtype
FROM t_pm_userroleorg a
JOIN t_pm_roleperm b ON a.froleid = b.froleid
WHERE fuserid IN ('用户id')
--4、查看哪些用户在哪些组织下拥有该操作权限(4.1,4.2查出来的都有效)
--4.1、查看哪些用户在哪些组织下拥有该操作权限(用户组织权限表,替换权限项编码,如何查询权限项编码参考节点6)
SELECT
FOWNER,
FORGID
FROM
T_PM_USERORGPERM
WHERE
FPERMITEMID IN (
SELECT
FID
FROM
T_pm_permitem
WHERE
FNUMBER IN (
'权限项编码'
)
)
AND FPermType = 10
--4.2查看哪些用户在哪些组织下拥有该操作权限(用户组织角色表,替换权限项编码,如何查询权限项编码参考节点6)
SELECT
FUserID,
FORGID
FROM
t_pm_userroleorg
WHERE
FRoleID IN (
SELECT
FRoleID
FROM
T_PM_RolePerm
WHERE
FPermItemID IN (
SELECT
FID
FROM
T_pm_permitem
WHERE
FNUMBER IN (
'权限项编码'
)
)
AND FPermType = 10
)
--5、查看某权限是否在某组织下被禁用(5.1,5.2查出来的都有效)
--5.1、查看某权限是否在某组织下被禁用(用户权限组织表,替换权限项编码,如何查询权限项编码参考节点6)
SELECT
FOWNER,
fpermitemId,
forgId
FROM
T_PM_USERORGPERM
WHERE
FPERMITEMID IN (
SELECT
FID
FROM
T_pm_permitem
WHERE
FNUMBER IN (
'权限项编码'
)
)
AND FPermType = 20
--5.2、查看某权限是否在某组织下被禁用(用户角色组织表,替换权限项编码,如何查询权限项编码参考节点6)
SELECT
FUserID,
FROLEID,
forgId
FROM
t_pm_userroleorg
WHERE
FRoleID IN (
SELECT
FRoleID
FROM
T_PM_RolePerm
WHERE
FPermItemID IN (
SELECT
FID
FROM
T_pm_permitem
WHERE
FNUMBER IN (
'权限项编码'
)
)
AND FPermType = 20
)
--6、根据某权限项别名(可能会重复),来查询对应的fid,编码(fnumber),长编码(flongnumber),主业务组织类型(FORGRELATION)
--注意:长编码就是该权限项分配时的树结构,根据该树结构可以定位到具体哪个是你要找的权限项
例如:
SELECT fid,fnumber,flongnumber,FORGRELATION FROM T_pm_permitem where FALIAS_L2 = '报表查看' and fisleaf = 1
【BOS基础系统_权限】用户组织权限相关查询SQL
本文2024-09-22 20:09:36发表“eas cloud知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-eas-111835.html