From a7981690ac9480ce932c9a9436e952022165e2a9 Mon Sep 17 00:00:00 2001
From: liaoxujun@qq.com <liaoxujun@qq.com>
Date: 星期五, 01 九月 2023 09:57:15 +0800
Subject: [PATCH] 加入权限认证,加入日志输出到文件
---
DocumentServiceAPI.Web.Entry/DocServiceApiStartup.cs | 2 +
DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs | 62 ++++++++++++++++++++++++++++++-
DocumentServiceAPI.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user | 2
DocumentServiceAPI.Application/UserAndLogin/LogInController.cs | 8 ++++
DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj | 1
5 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/DocumentServiceAPI.Application/UserAndLogin/LogInController.cs b/DocumentServiceAPI.Application/UserAndLogin/LogInController.cs
index b9c52fd..1b8bb16 100644
--- a/DocumentServiceAPI.Application/UserAndLogin/LogInController.cs
+++ b/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,
diff --git a/DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs b/DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs
index 0d9c2d1..6b67007 100644
--- a/DocumentServiceAPI.Application/UserAndLogin/Services/UserService.cs
+++ b/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鍦≧edis涓殑閿��
+ /// </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 浠h〃娌℃湁瓒呮椂鏈夋潈闄愪娇鐢紝false 浠h〃娌℃湁鏉冮檺浣跨敤浜�</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 浠h〃娌℃湁瓒呮椂鏈夋潈闄愪娇鐢紝false 浠h〃娌℃湁鏉冮檺浣跨敤浜�</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;
+ }
+
}
diff --git a/DocumentServiceAPI.Web.Entry/DocServiceApiStartup.cs b/DocumentServiceAPI.Web.Entry/DocServiceApiStartup.cs
index 52e10eb..e558054 100644
--- a/DocumentServiceAPI.Web.Entry/DocServiceApiStartup.cs
+++ b/DocumentServiceAPI.Web.Entry/DocServiceApiStartup.cs
@@ -26,6 +26,8 @@
//娉ㄥ叆鏈嶅姟
services.AddScoped<IRedisCacheService, RedisCacheScService>();
}
+ services.AddFileLogging("Log/DocSericeApistatupLog.txt");
+
}
diff --git a/DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj b/DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj
index 70473c7..68cfc20 100644
--- a/DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj
+++ b/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" />
diff --git a/DocumentServiceAPI.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user b/DocumentServiceAPI.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user
index deeaaa7..23097f9 100644
--- a/DocumentServiceAPI.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user
+++ b/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>
\ No newline at end of file
--
Gitblit v1.9.1