You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.7 KiB
C#

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
{
/// <summary>
/// 部门表Service
/// </summary>
public partial class SysPermissionService : BaseServices<UserPermission>, ISysPermissionService
{
IBaseRepository<UserPermission> dal;
ISysRoleService roleService;
ISysMenuService menuService;
ISysUserRoleService userRoleService;
public SysPermissionService(IBaseRepository<UserPermission> dal, ISysRoleService roleService, ISysMenuService menuService, ISysUserRoleService userRoleService)
{
this.dal = dal;
base.BaseDal = dal;
this.roleService = roleService;
this.menuService = menuService;
this.userRoleService = userRoleService;
}
/// <summary>
/// 获取角色数据权限
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<List<string>> GetRolePermission(int userId)
{
List<string> roles = new List<string>();
// 管理员拥有所有权限
if (UserView.IsAdmin(userId))
{
roles.Add("admin");
}
else
{
var roleList = await QueryMuchAsync<SysUser, SysUserRole, SysRole, SysRole>(
(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;
}
/// <summary>
/// 获取菜单数据权限
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<List<string>> GetMenuPermission(int userId)
{
List<string> perms = new List<string>();
// 管理员拥有所有权限
if (UserView.IsAdmin(userId))
{
perms.Add("*:*:*");
}
else
{
perms.AddRange(await menuService.SelectMenuPermsByUserId(userId));
}
return perms;
}
}
}