using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Admin.Core.Common;
using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.IService.ISys;
using Admin.Core.Model;
using Admin.Core.Model.Sys;
using SqlSugar;
namespace Admin.Core.Service
{
///
/// 部门表Service
///
public partial class SysPermissionService : BaseServices, ISysPermissionService
{
IBaseRepository dal;
ISysRoleService roleService;
ISysMenuService menuService;
ISysUserRoleService userRoleService;
public SysPermissionService(IBaseRepository dal, ISysRoleService roleService, ISysMenuService menuService, ISysUserRoleService userRoleService)
{
this.dal = dal;
base.BaseDal = dal;
this.roleService = roleService;
this.menuService = menuService;
this.userRoleService = userRoleService;
}
///
/// 获取角色数据权限
///
///
///
public async Task> GetRolePermission(int userId)
{
List roles = new List();
// 管理员拥有所有权限
if (UserView.IsAdmin(userId))
{
roles.Add("admin");
}
else
{
var roleList = await QueryMuchAsync(
(a, b, c) => new object[] {
JoinType.Inner, a.UserID == b.UserID,
JoinType.Inner, b.RoleID == c.RoleID
},
(a, b, c) => new SysRole
{
RoleKey = c.RoleKey
},
(a, b, c) => c.Status == SysConst.ENABLE && a.UserID == userId
);
roles.AddRange(roleList.Select(x => x.RoleKey));
}
return roles;
}
///
/// 获取菜单数据权限
///
///
///
public async Task> GetMenuPermission(int userId)
{
List perms = new List();
// 管理员拥有所有权限
if (UserView.IsAdmin(userId))
{
perms.Add("*:*:*");
}
else
{
perms.AddRange(await menuService.SelectMenuPermsByUserId(userId));
}
return perms;
}
}
}