using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace Infrastructure.Model
{
public class TokenModel
{
///
/// 用户id
///
public long UserId { get; set; }
///
/// 部门id
///
public long DeptId { get; set; }
///
/// 登录用户名
///
public string UserName { get; set; }
///
/// 用户昵称
///
public string NickName { get; set; }
///
/// 角色集合(eg:admin,common)
///
public List RoleKeys { get; set; } = [];
///
/// 角色集合(数据权限过滤使用)
///
public List Roles { get; set; }
///
/// Jwt过期时间
///
public DateTime ExpireTime { get; set; }
///
/// 租户ID
///
public string TenantId { get; set; }
///
/// 用户所有权限
///
public List Permissions { get; set; } = [];
public TokenModel()
{
}
public TokenModel(TokenModel info, List roles)
{
UserId = info.UserId;
UserName = info.UserName;
DeptId = info.DeptId;
Roles = roles;
NickName = info.NickName;
RoleKeys = roles.Select(f => f.RoleKey).ToList();
}
public bool HasPermission(string permission)
{
if (IsAdmin()) return true;
return Permissions != null && Permissions.Contains(permission);
}
///
/// 是否管理员
///
///
public bool IsAdmin()
{
return RoleKeys.Contains(GlobalConstant.AdminRole) || UserId == 1;
}
}
public class Roles
{
public long RoleId { get; set; }
public string RoleKey { get; set; }
public int DataScope { get; set; }
}
}