| | |
| | | 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> |
| | | /// 员工详情 |
| | |
| | | |
| | | } |
| | | ).WithCache( 10).ToListAsync(); |
| | | //不再选择租户 |
| | | //var ten = await _db.Queryable<TenantInfo>().Where(x => x.IsEn == true && x.IsDel != true && x.ItCode == ItCode) |
| | | // .Select(x => new TenderVM |
| | | // { |
| | | |
| | | var ten = await _db.Queryable<TenantInfo>().Where(x => x.IsEn == true && x.IsDel != true && x.ItCode == ItCode) |
| | | .Select(x => new TenderVM |
| | | { |
| | | // Description = x.Description, |
| | | // ItCode = ItCode, |
| | | // Name = x.Name, |
| | | // TenderId = x.Id, |
| | | // IsTender = true |
| | | |
| | | Description = x.Description, |
| | | ItCode = ItCode, |
| | | Name = x.Name, |
| | | TenderId = x.Id, |
| | | IsTender = true |
| | | |
| | | } |
| | | ).WithCache(10).ToListAsync() ; |
| | | ten.AddRange(tentlist); |
| | | return ten; |
| | | // } |
| | | // ).WithCache(10).ToListAsync() ; |
| | | //ten.AddRange(tentlist); |
| | | return tentlist; |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | }).WithCache(20).FirstAsync(); |
| | | |
| | | if (TenantID != null) |
| | | { |
| | | //add by zyyao 2023-10-17 租户信息增加 |
| | | var permissions = _db.Queryable<TenantPermissions>().Where(x => x.IsDel == false && x.IsEn == true && x.TenantId == TenantID).ToList(); |
| | | var permissions1 = permissions.Where(x => x.PermissionsType == TenantPermissionsType.Manage).FirstOrDefault(); |
| | | if (permissions1 != null && Tenant!=null) |
| | | { |
| | | Tenant.UnitMaxCount = permissions1.UnitMaxCount; |
| | | Tenant.EmployeeMaxCount = permissions1.EmployeeMaxCount; |
| | | Tenant.WendangOverTimeCount = permissions1.OverTime.Subtract(DateTime.Now).Days+1; |
| | | |
| | | } |
| | | var permissions2 = permissions.Where(x => x.PermissionsType == TenantPermissionsType.Document).FirstOrDefault(); |
| | | if (permissions2 != null && Tenant != null) |
| | | { |
| | | Tenant.BiaoshuOverTimeCount = permissions2.OverTime.Subtract(DateTime.Now).Days + 1; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | return new RetUserInfo |
| | | { |
| | |
| | | |
| | | } |
| | | |
| | | /// <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; |
| | | } |
| | | |
| | | } |
| | | |
| | | |