liaoxujun@qq.com
2023-09-01 a7981690ac9480ce932c9a9436e952022165e2a9
加入权限认证,加入日志输出到文件
5个文件已修改
75 ■■■■■ 已修改文件
DocumentServiceAPI.Application/UserAndLogin/LogInController.cs 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Web.Entry/DocServiceApiStartup.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Application/UserAndLogin/LogInController.cs
@@ -173,6 +173,14 @@
                    if (!needtoken)
                        throw Oops.Oh($"账户或者密码错误");
                }
                 var hasPermissions=   await _userService.TenderHasPermissions(Tender.TenderId);
                if(!hasPermissions)
                {
                    throw Oops.Oh($"集团用账号:{Tender.ItCode}使用期限已经过期或者没有使用权限");
                }
                    var token = _tokenService.CreateToken(new Model.JwtInfo
                    {
                        EID = Tender.EmployeeID,
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>
        /// 员工详情
@@ -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;
        }
    }
DocumentServiceAPI.Web.Entry/DocServiceApiStartup.cs
@@ -26,6 +26,8 @@
                //注入服务
                services.AddScoped<IRedisCacheService, RedisCacheScService>();
            }
            services.AddFileLogging("Log/DocSericeApistatupLog.txt");
         
        }
DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj
@@ -12,7 +12,6 @@
    <ItemGroup>
        <ProjectReference Include="..\DocumentFile.Service\DocumentFile.Service.csproj" />
        <ProjectReference Include="..\DocumentServiceAPI.Application\DocumentServiceAPI.Application.csproj" />
        <ProjectReference Include="..\DocumentServiceAPI.Core\DocumentServiceAPI.Core.csproj" />
        <ProjectReference Include="..\DocumentServiceAPI.Enum\DocumentServiceAPI.Enum.csproj" />
DocumentServiceAPI.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user
@@ -5,7 +5,7 @@
<Project>
  <PropertyGroup>
    <_PublishTargetUrl>D:\DocServiceAPI</_PublishTargetUrl>
    <History>True|2023-08-25T08:28:37.8668025Z;True|2023-08-25T15:17:17.9212851+08:00;True|2023-08-25T11:21:18.2228201+08:00;True|2023-08-03T11:23:49.7155745+08:00;True|2023-08-03T10:57:12.3860490+08:00;True|2023-08-02T17:29:04.8984231+08:00;True|2023-08-02T14:24:54.6607875+08:00;True|2023-08-02T13:12:00.3228236+08:00;</History>
    <History>True|2023-08-31T05:24:57.6027041Z;False|2023-08-31T13:21:45.8166199+08:00;False|2023-08-31T13:21:11.3863426+08:00;True|2023-08-25T16:28:37.8668025+08:00;True|2023-08-25T15:17:17.9212851+08:00;True|2023-08-25T11:21:18.2228201+08:00;True|2023-08-03T11:23:49.7155745+08:00;True|2023-08-03T10:57:12.3860490+08:00;True|2023-08-02T17:29:04.8984231+08:00;True|2023-08-02T14:24:54.6607875+08:00;True|2023-08-02T13:12:00.3228236+08:00;</History>
    <LastFailureDetails />
  </PropertyGroup>
</Project>