SysPermissionService.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Attribute;
  2. using Base;
  3. using Dto;
  4. using Model;
  5. using Model.Base;
  6. using Repository;
  7. using Service;
  8. namespace Services
  9. {
  10. /// <summary>
  11. /// 文章目录Service业务层处理
  12. /// </summary>
  13. [AppService(ServiceType = typeof(ISysPermissionService), ServiceLifetime = LifeTime.Transient)]
  14. public class SysPermissionService : BaseService<SysPermission>, ISysPermissionService
  15. {
  16. private readonly ISysRoleService SysRoleService;
  17. private readonly ISysMenuService SysMenuService;
  18. public SysPermissionService(
  19. ISysRoleService sysRoleService,
  20. ISysMenuService sysMenuService)
  21. {
  22. SysRoleService = sysRoleService;
  23. SysMenuService = sysMenuService;
  24. }
  25. /// <summary>
  26. /// 查询列表
  27. /// </summary>
  28. /// <param name="parm"></param>
  29. /// <returns></returns>
  30. public List<string> List()
  31. {
  32. List<string> list = new();
  33. list.Add("apigroup:add");
  34. list.Add("apigroup:edit");
  35. list.Add("apigroup:delete");
  36. list.Add("apigroup:export");
  37. list.Add("apigroup:sort");
  38. return list;
  39. }
  40. /// <summary>
  41. /// 获取角色数据权限
  42. /// </summary>
  43. /// <param name="user">用户信息</param>
  44. /// <returns>角色权限信息</returns>
  45. public List<string> GetRolePermission(SysUser user)
  46. {
  47. List<string> roles = new();
  48. // 管理员拥有所有权限
  49. if (user.IsAdmin())
  50. {
  51. roles.Add("admin");
  52. }
  53. else
  54. {
  55. roles.AddRange(SysRoleService.SelectUserRoleKeys(user.userId));
  56. }
  57. return roles;
  58. }
  59. /// <summary>
  60. /// 获取菜单数据权限
  61. /// </summary>
  62. /// <param name="user">用户信息</param>
  63. /// <returns>菜单权限信息</returns>
  64. public List<string> GetMenuPermission(SysUser user)
  65. {
  66. List<string> perms = new();
  67. // 管理员拥有所有权限
  68. if (user.IsAdmin() || GetRolePermission(user).Exists(f => f.Equals(GlobalConstant.AdminRole)))
  69. {
  70. perms.Add(GlobalConstant.AdminPerm);
  71. }
  72. else
  73. {
  74. perms.AddRange(SysMenuService.SelectMenuPermsByUserId(user.userId));
  75. }
  76. return perms;
  77. }
  78. }
  79. }