zoukankan      html  css  js  c++  java
  • 改进版本号的精确数据权限定义和实现

    因为project实现上的某些小问题。为了达到方便实现如图效果,对数据结构做了一点点的调整。


    新的数据结构例如以下图:

    第一个图片的数据源视图:

    IF EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'RoleDataPermit') AND OBJECTPROPERTY(id, N'ISVIEW') = 1)
    DROP VIEW RoleDataPermit
    GO
    
    
    /*****视图:查询全部角色的数据权限*****/
    
    CREATE VIEW RoleDataPermit
    AS
    
    with 
    List as (
    select distinct
           G.ID as DataId,
           null as ParentId,
           PM.RoleId,
           0 as Action,
           G.Name as 模块,
           null as 读写权限
    from SYS_ModuleGroup G
    join SYS_Module M on M.ModuleGroupId = G.ID
    join SYS_RolePerm_Module PM on PM.ModuleId = M.ID
    left join SYS_RolePerm_Data PD on PD.PermId = PM.ID
    where PM.Permission >= 0
      or PD.ID is not null
    
    union all
    select M.ID as DataId,
           case when M.ModuleGroupId is null then M.ParentId else M.ModuleGroupId end as ParentId,
           PM.RoleId,
           1 as Action,
           M.ApplicationName as 模块,
           null as 读写权限
    from SYS_Module M
    join SYS_RolePerm_Module PM on PM.ModuleId = M.ID
    where PM.Permission >= 0
    
    union all
    select PM.ID as DataId,
           PM.ModuleId as ParentId,
           PM.RoleId,
           2 as Action,
           '无归属数据' as 模块,
           case when PM.Permission = 0 then '仅仅读' else '读写' end as 读写权限
    from SYS_RolePerm_Module PM
    where PM.Permission >= 0
    
    union all
    select PD.ID as DataId,
           M.ModuleId as ParentId,
           M.RoleId,
           PD.Mode + 3 as Action,
           case PD.Mode when 0 then '仅本人' when 1 then '仅本部门' when 2 then '本部门全部' when 3 then '本机构全部' when 4 then '根机构全部' else '自己定义' end as 模块,
           case when PD.Permission = 0 and PD.Mode < 5 then '仅仅读' when PD.Permission = 1 and PD.Mode < 5 then '读写' else null end as 读写权限
    from SYS_RolePerm_Data PD
    join SYS_RolePerm_Module M on M.ID = PD.PermId
    
    union all
    select PC.ID as DataId,
           PC.PermDataId as ParentId,
           PM.RoleId,
           9 as Action,
           O.FullName as 模块,
           case when PC.Permission = 0 then '仅仅读' else '读写' end as 读写权限
    from SYS_RolePerm_Module PM
    join SYS_RolePerm_Data PD on PD.PermId = PM.ID
      and PD.Mode = 5
    join SYS_RolePerm_Custom PC on PC.PermDataId = PD.ID
      and PC.OrgId is not null
    join SYS_Organization O on O.ID = PC.OrgId
    
    union all
    select PC.ID as DataId,
           PC.PermDataId as ParentId,
           PM.RoleId,
           10 as Action,
           U.Name + '(' + U.LoginName + ')' as 模块,
           case when PC.Permission = 0 then '仅仅读' else '读写' end as 读写权限
    from SYS_RolePerm_Module PM
    join SYS_RolePerm_Data PD on PD.PermId = PM.ID
      and PD.Mode = 5
    join SYS_RolePerm_Custom PC on PC.PermDataId = PD.ID
      and PC.UserId is not null
    join SYS_User U on U.ID = PC.UserId
    )
    
    select newid() as ID, * from List
    
    GO


  • 相关阅读:
    84. Largest Rectangle in Histogram (Solution 2)
    84. Largest Rectangle in Histogram (Solution 1)
    73. Set Matrix Zeroes
    【JavaScript】Symbol 静态方法
    【JavaScript】Date
    【JavaScript】Math
    725. Split Linked List in Parts把链表分成长度不超过1的若干部分
    791. Custom Sort String字符串保持字母一样,位置可以变
    508. Most Frequent Subtree Sum 最频繁的子树和
    762. Prime Number of Set Bits in Binary Representation二进制中有质数个1的数量
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5244783.html
Copyright © 2011-2022 走看看