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


  • 相关阅读:
    [珠玑之椟]字符串和序列:左移、哈希、最长重复子序列的后缀数组解法、最大连续子序列
    [珠玑之椟]二分思想与分治法、排序思想
    [珠玑之椟]浅谈代码正确性:循环不变式、断言、debug
    [珠玑之椟]随机数函数取样与概率
    逆序对:从插入排序到归并排序
    [珠玑之椟]估算的应用与Little定律
    [珠玑之椟]位向量/位图的定义和应用
    lua----------------使用VS2015搭建lua开发环境的一些侥幸成功经验,
    Lua--------------------unity3D与Slua融合使用
    lua------------------Unity3D研究院编辑器之打开unity不可识别的文件(十三)
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5244783.html
Copyright © 2011-2022 走看看