123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using Attribute;
- using Base;
- using Dto;
- using Model;
- using Model.Base;
- using Repository;
- using Service;
- namespace Services
- {
- /// <summary>
- /// 文章目录Service业务层处理
- /// </summary>
- [AppService(ServiceType = typeof(ISysPermissionService), ServiceLifetime = LifeTime.Transient)]
- public class SysPermissionService : BaseService<SysPermission>, ISysPermissionService
- {
- private readonly ISysRoleService SysRoleService;
- private readonly ISysMenuService SysMenuService;
- public SysPermissionService(
- ISysRoleService sysRoleService,
- ISysMenuService sysMenuService)
- {
- SysRoleService = sysRoleService;
- SysMenuService = sysMenuService;
- }
- /// <summary>
- /// 查询列表
- /// </summary>
- /// <param name="parm"></param>
- /// <returns></returns>
- public List<string> List()
- {
- List<string> list = new();
- list.Add("apigroup:add");
- list.Add("apigroup:edit");
- list.Add("apigroup:delete");
- list.Add("apigroup:export");
- list.Add("apigroup:sort");
- return list;
- }
- /// <summary>
- /// 获取角色数据权限
- /// </summary>
- /// <param name="user">用户信息</param>
- /// <returns>角色权限信息</returns>
- public List<string> GetRolePermission(SysUser user)
- {
- List<string> roles = new();
- // 管理员拥有所有权限
- if (user.IsAdmin())
- {
- roles.Add("admin");
- }
- else
- {
- roles.AddRange(SysRoleService.SelectUserRoleKeys(user.userId));
- }
- return roles;
- }
- /// <summary>
- /// 获取菜单数据权限
- /// </summary>
- /// <param name="user">用户信息</param>
- /// <returns>菜单权限信息</returns>
- public List<string> GetMenuPermission(SysUser user)
- {
- List<string> perms = new();
- // 管理员拥有所有权限
- if (user.IsAdmin() || GetRolePermission(user).Exists(f => f.Equals(GlobalConstant.AdminRole)))
- {
- perms.Add(GlobalConstant.AdminPerm);
- }
- else
- {
- perms.AddRange(SysMenuService.SelectMenuPermsByUserId(user.userId));
- }
- return perms;
- }
- }
- }
|