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