liaoxujun@qq.com
2023-09-01 a7981690ac9480ce932c9a9436e952022165e2a9
DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs
@@ -3,7 +3,9 @@
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;
@@ -23,14 +25,21 @@
    /// </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>
        /// 员工详情
@@ -120,21 +129,21 @@
                 
             }
              ).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;
        }
@@ -379,6 +388,55 @@
        }
        /// <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;
        }
    }