| | |
| | | using DocumentServiceAPI.Application.UserAndLogin.ViewMode; |
| | | using DocumentServiceAPI.Model; |
| | | using DocumentServiceAPI.Model.cyDocumentModel; |
| | | using DocumentServiceAPI.Model.Permissions; |
| | | using DocumentServiceAPI.Model.UserInfoModel; |
| | | using DocumentServiceAPI.Services.IService; |
| | | using DocumentServiceAPI.Utility; |
| | | using Furion.Logging.Extensions; |
| | | using MapsterMapper; |
| | |
| | | /// </summary> |
| | | public class UserService : IUserService, IScoped |
| | | { |
| | | /// <summary> |
| | | /// TenantPermissions在Redis中的键值 |
| | | /// </summary> |
| | | public const string TenantPermissions_RedisKey = "TenantPermissionsKen:"; |
| | | private ISqlSugarClient _db { get; set; } |
| | | private EmployeeRepository _employeeRepository{ get; set; } |
| | | private IMapper _mapper { get; set; } |
| | | public UserService(ISqlSugarClient db, EmployeeRepository employeeRepository, IMapper mapper) |
| | | private IRedisCacheService _cacheService { get; set; } |
| | | |
| | | public UserService(ISqlSugarClient db, EmployeeRepository employeeRepository, IMapper mapper , IRedisCacheService cacheService) |
| | | { |
| | | _db = db; |
| | | _employeeRepository= employeeRepository; |
| | | _employeeRepository = employeeRepository; |
| | | _mapper = mapper; |
| | | _cacheService = cacheService; |
| | | } |
| | | /// <summary> |
| | | /// 员工详情 |
| | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 租户是否已经超时过期 |
| | | /// </summary> |
| | | /// <param name="TenderID">租户ID</param> |
| | | /// <returns> true 代表没有超时有权限使用,false 代表没有权限使用了</returns> |
| | | public async Task<bool> TenderHasPermissions( int TenderID) |
| | | { |
| | | var Key = TenantPermissions_RedisKey + TenderID.ToString(); |
| | | var tp= _cacheService.Get<TenantPermissions>(TenantPermissions_RedisKey+ TenderID.ToString()); |
| | | if(tp == null ) |
| | | { |
| | | tp= await _db.Queryable<TenantPermissions>().Where(x=>x.TenantId == TenderID).FirstAsync(); |
| | | if (tp != null) |
| | | _cacheService.Add<TenantPermissions>(Key, tp, 300); |
| | | else |
| | | return false; |
| | | } |
| | | if (tp.OverTime > DateTime.Now) |
| | | return true; |
| | | return false; |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 租户是否已经超时过期 根据token中包含的TID 识别是否有权限 |
| | | /// </summary> |
| | | /// <returns> true 代表没有超时有权限使用,false 代表没有权限使用了</returns> |
| | | public async Task<bool> TenderHasPermissions() |
| | | { |
| | | var jwtinfo= GetJwtInfo(); |
| | | if(jwtinfo != null&&jwtinfo.TEID!=null ) |
| | | { |
| | | var Key = TenantPermissions_RedisKey + jwtinfo.TEID.ToString(); |
| | | var tp = _cacheService.Get<TenantPermissions>(TenantPermissions_RedisKey + jwtinfo.TEID.ToString()); |
| | | if (tp == null) |
| | | { |
| | | tp = await _db.Queryable<TenantPermissions>().Where(x => x.TenantId == jwtinfo.TEID).FirstAsync(); |
| | | if (tp == null) |
| | | _cacheService.Add<TenantPermissions>(Key, tp, 300); |
| | | else |
| | | return false; |
| | | } |
| | | |
| | | if (tp.OverTime > DateTime.Now) |
| | | return true; |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | |
| | | |