From a77985ed6d229e1fbf09a888dca8a498d0edc41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=9B?= <510423039@qq.com> Date: Tue, 17 Jan 2023 18:06:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20#85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Users/AccountAppService.cs | 10 +++++----- .../Users/UserAppService.cs | 2 +- ...asicManagementSettingDefinitionProvider.cs | 19 ++++++++++++++++++- .../Notifications/Aggregates/Notification.cs | 15 ++++++--------- .../Aggregates/NotificationSubscription.cs | 6 +++--- .../Notifications/NotificationManager.cs | 8 ++++---- .../AbpProHttpApiHostModule.cs | 1 + .../Pages/Login.cshtml.cs | 8 ++++++-- .../LionAbpProLogAppService.cs | 11 +++++++---- .../Lion.AbpPro.Application/Jobs/TestJob.cs | 2 +- 10 files changed, 52 insertions(+), 30 deletions(-) diff --git a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/AccountAppService.cs b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/AccountAppService.cs index fa074b95..3ffe2f59 100644 --- a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/AccountAppService.cs +++ b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/AccountAppService.cs @@ -29,7 +29,7 @@ namespace Lion.AbpPro.BasicManagement.Users public async Task LoginAsync(LoginInput input) { var result = await _signInManager.PasswordSignInAsync(input.Name, input.Password, false, true); - + if (result.IsNotAllowed) { throw new BusinessException(BasicManagementErrorCodes.UserLockedOut); @@ -46,7 +46,6 @@ namespace Lion.AbpPro.BasicManagement.Users #region 私有方法 - private async Task BuildResult(IdentityUser user) { if (!user.IsActive) throw new BusinessException(BasicManagementErrorCodes.UserLockedOut); @@ -67,8 +66,8 @@ namespace Lion.AbpPro.BasicManagement.Users private string GenerateJwt(Guid userId, string userName, string name, string email, string tenantId, List roles) { - var dateNow = DateTime.Now; - var expirationTime = dateNow + TimeSpan.FromHours(_jwtOptions.ExpirationTime); + var dateNow = Clock.Now; + var expirationTime = dateNow.AddHours(_jwtOptions.ExpirationTime); var key = Encoding.ASCII.GetBytes(_jwtOptions.SecurityKey); var claims = new List @@ -90,7 +89,8 @@ namespace Lion.AbpPro.BasicManagement.Users var tokenDescriptor = new SecurityTokenDescriptor() { Subject = new ClaimsIdentity(claims), - Expires = expirationTime, + Expires = expirationTime, // token 过期时间 + NotBefore = dateNow, // token 签发时间 SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; diff --git a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/UserAppService.cs b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/UserAppService.cs index e60b86da..2d676b26 100644 --- a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/UserAppService.cs +++ b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/UserAppService.cs @@ -72,7 +72,7 @@ namespace Lion.AbpPro.BasicManagement.Users .GetListAsync(request.Sorting, request.MaxResultCount, request.SkipCount, request.Filter); var result = ObjectMapper.Map, List>(source); var bytes = await _excelExporter.ExportAsByteArray(result); - return new XlsxFileResult(bytes: bytes, fileDownloadName: $"用户导出列表{DateTime.Now:yyyyMMdd}"); + return new XlsxFileResult(bytes: bytes, fileDownloadName: $"用户导出列表{Clock.Now:yyyyMMdd}"); } /// diff --git a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Domain/Settings/BasicManagementSettingDefinitionProvider.cs b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Domain/Settings/BasicManagementSettingDefinitionProvider.cs index a93badc3..fae9db6f 100644 --- a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Domain/Settings/BasicManagementSettingDefinitionProvider.cs +++ b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Domain/Settings/BasicManagementSettingDefinitionProvider.cs @@ -1,6 +1,7 @@ using Lion.AbpPro.BasicManagement.Localization; using Volo.Abp.Localization; using Volo.Abp.Settings; +using Volo.Abp.Timing; namespace Lion.AbpPro.BasicManagement.Settings; @@ -18,6 +19,22 @@ public class BasicManagementSettingDefinitionProvider : SettingDefinitionProvide /// private static void OverrideDefaultSettings(ISettingDefinitionContext context) { + context.Add( + new SettingDefinition(TimingSettingNames.TimeZone, + "China Standard Time", + L("DisplayName:Abp.Timing.Timezone"), + L("Description:Abp.Timing.Timezone")) + .WithProperty(BasicManagementSettings.Group.Default, + BasicManagementSettings.Group.SystemManagement) + .WithProperty(BasicManagementSettings.ControlType.Default, + BasicManagementSettings.ControlType.TypeText)); + + context.GetOrNull("Abp.Identity.Password.RequiredLength") + .WithProperty(BasicManagementSettings.Group.Default, + BasicManagementSettings.Group.SystemManagement) + .WithProperty(BasicManagementSettings.ControlType.Default, + BasicManagementSettings.ControlType.Number); + context.GetOrNull("Abp.Identity.Password.RequiredLength") .WithProperty(BasicManagementSettings.Group.Default, BasicManagementSettings.Group.SystemManagement) @@ -54,7 +71,7 @@ public class BasicManagementSettingDefinitionProvider : SettingDefinitionProvide .WithProperty(BasicManagementSettings.ControlType.Default, BasicManagementSettings.ControlType.TypeCheckBox); } - + private static LocalizableString L(string name) { diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/Notification.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/Notification.cs index a2722aa4..7fc5b534 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/Notification.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/Notification.cs @@ -3,7 +3,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates /// /// 消息通知 /// - public class Notification : FullAuditedAggregateRoot + public class Notification : FullAuditedAggregateRoot { /// /// 消息标题 @@ -23,7 +23,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates /// 消息类型 /// public MessageType MessageType { get; private set; } - + /// /// 消息等级 /// @@ -101,15 +101,15 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates { MessageType = messageType; } + private void SetMessageLevel(MessageLevel messageLevel) { MessageLevel = messageLevel; } + /// /// 新增非广播消息订阅人 /// - /// - /// public void AddNotificationSubscription(Guid notificationSubscriptionId, Guid receiveId) { if (NotificationSubscriptions.Any(e => e.ReceiveId == receiveId)) return; @@ -120,10 +120,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates /// /// 新增消息类型为广播订阅人 /// - /// - /// - public void AddBroadCastNotificationSubscription(Guid notificationSubscriptionId, - Guid receiveId) + public void AddBroadCastNotificationSubscription(Guid notificationSubscriptionId, Guid receiveId, DateTime readTime) { if (NotificationSubscriptions.Any(e => e.ReceiveId == receiveId)) { @@ -132,7 +129,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates else { var temp = new NotificationSubscription(notificationSubscriptionId, receiveId); - temp.SetRead(); + temp.SetRead(readTime); NotificationSubscriptions.Add(temp); } } diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/NotificationSubscription.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/NotificationSubscription.cs index 444de089..683f299f 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/NotificationSubscription.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/NotificationSubscription.cs @@ -3,7 +3,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates /// /// 消息订阅者 /// - public partial class NotificationSubscription : FullAuditedEntity + public class NotificationSubscription : FullAuditedEntity { /// /// 订阅人 @@ -41,10 +41,10 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates ReceiveId = receiveId; } - public void SetRead() + public void SetRead(DateTime readTime) { Read = true; - ReadTime = DateTime.Now; + ReadTime = readTime; } } } \ No newline at end of file diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs index 7e130d96..06d8c899 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs @@ -190,14 +190,14 @@ namespace Lion.AbpPro.NotificationManagement.Notifications public async Task SetReadAsync(Guid id) { if (_currentUser is not { IsAuthenticated: true }) throw new AbpAuthorizationException(); - + var notification = await _notificationRepository.FindByIdAsync(id); - + if (notification == null) throw new NotificationManagementDomainException(NotificationManagementErrorCodes.MessageNotExist); if (notification.MessageType == MessageType.BroadCast) { //如果类型是广播消息,用户设置为已读,在插入一条数据 - notification.AddBroadCastNotificationSubscription(GuidGenerator.Create(), _currentUser.GetId()); + notification.AddBroadCastNotificationSubscription(GuidGenerator.Create(), _currentUser.GetId(), Clock.Now); return; } else @@ -205,7 +205,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications var notificationSubscription = notification.NotificationSubscriptions.FirstOrDefault(e => e.ReceiveId == _currentUser.GetId()); if (notificationSubscription == null) throw new NotificationManagementDomainException(NotificationManagementErrorCodes.UserUnSubscription); - notificationSubscription.SetRead(); + notificationSubscription.SetRead(Clock.Now); } await _notificationRepository.UpdateAsync(notification); diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs index 1ef70872..c5216c07 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs @@ -1,6 +1,7 @@ using Hangfire.Redis; using Swagger; using Volo.Abp.BackgroundJobs.Hangfire; +using Volo.Abp.Timing; namespace Lion.AbpPro { diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs index fc9e191d..40c0e50c 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs @@ -3,6 +3,7 @@ using Lion.AbpPro.BasicManagement.ConfigurationOptions; using Lion.AbpPro.BasicManagement.Users; using Lion.AbpPro.BasicManagement.Users.Dtos; using Microsoft.AspNetCore.Mvc.RazorPages; +using Volo.Abp.Timing; namespace Lion.AbpPro.Pages @@ -13,14 +14,17 @@ namespace Lion.AbpPro.Pages private readonly ILogger _logger; private readonly IHostEnvironment _hostEnvironment; private readonly JwtOptions _jwtOptions; + private readonly IClock _clock; public Login(IAccountAppService accountAppService, ILogger logger, IHostEnvironment hostEnvironment, - IOptionsSnapshot jwtOptions) + IOptionsSnapshot jwtOptions, + IClock clock) { _accountAppService = accountAppService; _logger = logger; _hostEnvironment = hostEnvironment; + _clock = clock; _jwtOptions = jwtOptions.Value; } @@ -42,7 +46,7 @@ namespace Lion.AbpPro.Pages { var options = new CookieOptions { - Expires = DateTime.Now.AddHours(_jwtOptions.ExpirationTime), + Expires = _clock.Now.AddHours(_jwtOptions.ExpirationTime), SameSite = SameSiteMode.Unspecified, }; diff --git a/aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/LionAbpProLogAppService.cs b/aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/LionAbpProLogAppService.cs index 3c31c193..6da7b8cf 100644 --- a/aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/LionAbpProLogAppService.cs +++ b/aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/LionAbpProLogAppService.cs @@ -1,24 +1,27 @@ namespace Lion.AbpPro.ElasticSearches { [Authorize] - public class LionAbpProLogAppService : ElasticsearchBasicService,ILionAbpProLogAppService + public class LionAbpProLogAppService : ElasticsearchBasicService, ILionAbpProLogAppService { private readonly IConfiguration _configuration; + // 时区 private const string TimeZone = "Asia/Shanghai"; + public LionAbpProLogAppService( IElasticsearchProvider elasticsearchProvider, IConfiguration configuration) : base(elasticsearchProvider) { _configuration = configuration; } + [Authorize(Policy = AbpProPermissions.SystemManagement.ES)] public async Task> PaingAsync(PagingElasticSearchLogInput input) { var IndexName = _configuration.GetValue("ElasticSearch:SearchIndexFormat"); // 默认查询当天 - input.StartCreationTime = input.StartCreationTime?.AddMilliseconds(-1) ??DateTime.Now.Date.AddMilliseconds(-1); - input.EndCreationTime =input.EndCreationTime?.AddDays(1).AddMilliseconds(-1) ??DateTime.Now.Date.AddDays(1).AddMilliseconds(-1); + input.StartCreationTime = input.StartCreationTime?.AddMilliseconds(-1) ?? Clock.Now.Date.AddMilliseconds(-1); + input.EndCreationTime = input.EndCreationTime?.AddDays(1).AddMilliseconds(-1) ?? Clock.Now.Date.AddDays(1).AddMilliseconds(-1); var mustFilters = new List, QueryContainer>>(); if (input.StartCreationTime.HasValue) { @@ -36,7 +39,7 @@ namespace Lion.AbpPro.ElasticSearches { mustFilters.Add ( - t =>t.MatchPhrase(f => f.Field(fd => fd.Message).Query(input.Filter.Trim())) + t => t.MatchPhrase(f => f.Field(fd => fd.Message).Query(input.Filter.Trim())) ); } diff --git a/aspnet-core/services/src/Lion.AbpPro.Application/Jobs/TestJob.cs b/aspnet-core/services/src/Lion.AbpPro.Application/Jobs/TestJob.cs index afb67df8..f4a2b438 100644 --- a/aspnet-core/services/src/Lion.AbpPro.Application/Jobs/TestJob.cs +++ b/aspnet-core/services/src/Lion.AbpPro.Application/Jobs/TestJob.cs @@ -4,7 +4,7 @@ namespace Lion.AbpPro.Jobs { public Task ExecuteAsync() { - Console.WriteLine($"job 测试- {DateTime.Now}"); + Console.WriteLine($"job 测试"); return Task.CompletedTask; } }