DataPermi.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Base;
  2. using Infrastructure;
  3. using Model;
  4. using SqlSugar.IOC;
  5. using Util;
  6. namespace SqlSugar
  7. {
  8. public enum DataPermiEnum
  9. {
  10. None = 0,
  11. /// <summary>
  12. /// 全部数据权限
  13. /// </summary>
  14. All = 1,
  15. /// <summary>
  16. /// 仅本人数据权限
  17. /// </summary>
  18. SELF = 5,
  19. /// <summary>
  20. /// 部门数据权限
  21. /// </summary>
  22. DEPT = 3,
  23. /// <summary>
  24. /// 自定数据权限
  25. /// </summary>
  26. CUSTOM = 2,
  27. /// <summary>
  28. /// 部门及以下数据权限
  29. /// </summary>
  30. DEPT_CHILD = 4
  31. }
  32. /// <summary>
  33. /// 数据权限
  34. /// </summary>
  35. public class DataPermi
  36. {
  37. /// <summary>
  38. /// 数据过滤
  39. /// </summary>
  40. /// <param name="configId">多库id</param>
  41. public static void FilterData(int configId)
  42. {
  43. //获取当前用户的信息
  44. var user = JwtUtil.GetLoginUser(App.HttpContext);
  45. if (user == null) return;
  46. //管理员不过滤
  47. // if (user.RoleIds.Any(f => f.Equals(GlobalConstant.AdminRole))) return;
  48. var db = DbScoped.SugarScope.GetConnectionScope(configId);
  49. // var expUser = Expressionable.Create<SysUser>();
  50. // var expRole = Expressionable.Create<SysRole>();
  51. // foreach (var role in user.Roles.OrderBy(f => f.DataScope))
  52. // {
  53. // var dataScope = (DataPermiEnum)role.DataScope;
  54. // if (DataPermiEnum.All.Equals(dataScope))//所有权限
  55. // {
  56. // break;
  57. // }
  58. // else if (DataPermiEnum.DEPT.Equals(dataScope))//本部门数据
  59. // {
  60. // expUser.Or(it => it.DeptId == user.DeptId);
  61. // }
  62. // else if (DataPermiEnum.SELF.Equals(dataScope))//仅本人数据
  63. // {
  64. // expUser.Or(it => it.UserId == user.UserId);
  65. // expRole.Or(it => user.RoleIds.Contains(it.RoleKey));
  66. // }
  67. // }
  68. // db.QueryFilter.AddTableFilter(expUser.ToExpression());
  69. // db.QueryFilter.AddTableFilter(expRole.ToExpression());
  70. }
  71. }
  72. }