Browse Source

fix: 修复时区问题 #85

pull/89/head
王军 4 years ago
parent
commit
a77985ed6d
  1. 10
      aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/AccountAppService.cs
  2. 2
      aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/UserAppService.cs
  3. 19
      aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Domain/Settings/BasicManagementSettingDefinitionProvider.cs
  4. 15
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/Notification.cs
  5. 6
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/NotificationSubscription.cs
  6. 8
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs
  7. 1
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs
  8. 8
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs
  9. 11
      aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/LionAbpProLogAppService.cs
  10. 2
      aspnet-core/services/src/Lion.AbpPro.Application/Jobs/TestJob.cs

10
aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Users/AccountAppService.cs

@ -29,7 +29,7 @@ namespace Lion.AbpPro.BasicManagement.Users
public async Task<LoginOutput> LoginAsync(LoginInput input) public async Task<LoginOutput> LoginAsync(LoginInput input)
{ {
var result = await _signInManager.PasswordSignInAsync(input.Name, input.Password, false, true); var result = await _signInManager.PasswordSignInAsync(input.Name, input.Password, false, true);
if (result.IsNotAllowed) if (result.IsNotAllowed)
{ {
throw new BusinessException(BasicManagementErrorCodes.UserLockedOut); throw new BusinessException(BasicManagementErrorCodes.UserLockedOut);
@ -46,7 +46,6 @@ namespace Lion.AbpPro.BasicManagement.Users
#region 私有方法 #region 私有方法
private async Task<LoginOutput> BuildResult(IdentityUser user) private async Task<LoginOutput> BuildResult(IdentityUser user)
{ {
if (!user.IsActive) throw new BusinessException(BasicManagementErrorCodes.UserLockedOut); 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, private string GenerateJwt(Guid userId, string userName, string name, string email,
string tenantId, List<string> roles) string tenantId, List<string> roles)
{ {
var dateNow = DateTime.Now; var dateNow = Clock.Now;
var expirationTime = dateNow + TimeSpan.FromHours(_jwtOptions.ExpirationTime); var expirationTime = dateNow.AddHours(_jwtOptions.ExpirationTime);
var key = Encoding.ASCII.GetBytes(_jwtOptions.SecurityKey); var key = Encoding.ASCII.GetBytes(_jwtOptions.SecurityKey);
var claims = new List<Claim> var claims = new List<Claim>
@ -90,7 +89,8 @@ namespace Lion.AbpPro.BasicManagement.Users
var tokenDescriptor = new SecurityTokenDescriptor() var tokenDescriptor = new SecurityTokenDescriptor()
{ {
Subject = new ClaimsIdentity(claims), Subject = new ClaimsIdentity(claims),
Expires = expirationTime, Expires = expirationTime, // token 过期时间
NotBefore = dateNow, // token 签发时间
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key),
SecurityAlgorithms.HmacSha256Signature) SecurityAlgorithms.HmacSha256Signature)
}; };

2
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); .GetListAsync(request.Sorting, request.MaxResultCount, request.SkipCount, request.Filter);
var result = ObjectMapper.Map<List<Volo.Abp.Identity.IdentityUser>, List<ExportIdentityUserOutput>>(source); var result = ObjectMapper.Map<List<Volo.Abp.Identity.IdentityUser>, List<ExportIdentityUserOutput>>(source);
var bytes = await _excelExporter.ExportAsByteArray<ExportIdentityUserOutput>(result); var bytes = await _excelExporter.ExportAsByteArray<ExportIdentityUserOutput>(result);
return new XlsxFileResult(bytes: bytes, fileDownloadName: $"用户导出列表{DateTime.Now:yyyyMMdd}"); return new XlsxFileResult(bytes: bytes, fileDownloadName: $"用户导出列表{Clock.Now:yyyyMMdd}");
} }
/// <summary> /// <summary>

19
aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Domain/Settings/BasicManagementSettingDefinitionProvider.cs

@ -1,6 +1,7 @@
using Lion.AbpPro.BasicManagement.Localization; using Lion.AbpPro.BasicManagement.Localization;
using Volo.Abp.Localization; using Volo.Abp.Localization;
using Volo.Abp.Settings; using Volo.Abp.Settings;
using Volo.Abp.Timing;
namespace Lion.AbpPro.BasicManagement.Settings; namespace Lion.AbpPro.BasicManagement.Settings;
@ -18,6 +19,22 @@ public class BasicManagementSettingDefinitionProvider : SettingDefinitionProvide
/// </summary> /// </summary>
private static void OverrideDefaultSettings(ISettingDefinitionContext context) 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") context.GetOrNull("Abp.Identity.Password.RequiredLength")
.WithProperty(BasicManagementSettings.Group.Default, .WithProperty(BasicManagementSettings.Group.Default,
BasicManagementSettings.Group.SystemManagement) BasicManagementSettings.Group.SystemManagement)
@ -54,7 +71,7 @@ public class BasicManagementSettingDefinitionProvider : SettingDefinitionProvide
.WithProperty(BasicManagementSettings.ControlType.Default, .WithProperty(BasicManagementSettings.ControlType.Default,
BasicManagementSettings.ControlType.TypeCheckBox); BasicManagementSettings.ControlType.TypeCheckBox);
} }
private static LocalizableString L(string name) private static LocalizableString L(string name)
{ {

15
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/Notification.cs

@ -3,7 +3,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates
/// <summary> /// <summary>
/// 消息通知 /// 消息通知
/// </summary> /// </summary>
public class Notification : FullAuditedAggregateRoot<Guid> public class Notification : FullAuditedAggregateRoot<Guid>
{ {
/// <summary> /// <summary>
/// 消息标题 /// 消息标题
@ -23,7 +23,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates
/// 消息类型 /// 消息类型
/// </summary> /// </summary>
public MessageType MessageType { get; private set; } public MessageType MessageType { get; private set; }
/// <summary> /// <summary>
/// 消息等级 /// 消息等级
/// </summary> /// </summary>
@ -101,15 +101,15 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates
{ {
MessageType = messageType; MessageType = messageType;
} }
private void SetMessageLevel(MessageLevel messageLevel) private void SetMessageLevel(MessageLevel messageLevel)
{ {
MessageLevel = messageLevel; MessageLevel = messageLevel;
} }
/// <summary> /// <summary>
/// 新增非广播消息订阅人 /// 新增非广播消息订阅人
/// </summary> /// </summary>
/// <param name="notificationSubscriptionId"></param>
/// <param name="receiveId"></param>
public void AddNotificationSubscription(Guid notificationSubscriptionId, Guid receiveId) public void AddNotificationSubscription(Guid notificationSubscriptionId, Guid receiveId)
{ {
if (NotificationSubscriptions.Any(e => e.ReceiveId == receiveId)) return; if (NotificationSubscriptions.Any(e => e.ReceiveId == receiveId)) return;
@ -120,10 +120,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates
/// <summary> /// <summary>
/// 新增消息类型为广播订阅人 /// 新增消息类型为广播订阅人
/// </summary> /// </summary>
/// <param name="notificationSubscriptionId"></param> public void AddBroadCastNotificationSubscription(Guid notificationSubscriptionId, Guid receiveId, DateTime readTime)
/// <param name="receiveId"></param>
public void AddBroadCastNotificationSubscription(Guid notificationSubscriptionId,
Guid receiveId)
{ {
if (NotificationSubscriptions.Any(e => e.ReceiveId == receiveId)) if (NotificationSubscriptions.Any(e => e.ReceiveId == receiveId))
{ {
@ -132,7 +129,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates
else else
{ {
var temp = new NotificationSubscription(notificationSubscriptionId, receiveId); var temp = new NotificationSubscription(notificationSubscriptionId, receiveId);
temp.SetRead(); temp.SetRead(readTime);
NotificationSubscriptions.Add(temp); NotificationSubscriptions.Add(temp);
} }
} }

6
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/Aggregates/NotificationSubscription.cs

@ -3,7 +3,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates
/// <summary> /// <summary>
/// 消息订阅者 /// 消息订阅者
/// </summary> /// </summary>
public partial class NotificationSubscription : FullAuditedEntity<Guid> public class NotificationSubscription : FullAuditedEntity<Guid>
{ {
/// <summary> /// <summary>
/// 订阅人 /// 订阅人
@ -41,10 +41,10 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates
ReceiveId = receiveId; ReceiveId = receiveId;
} }
public void SetRead() public void SetRead(DateTime readTime)
{ {
Read = true; Read = true;
ReadTime = DateTime.Now; ReadTime = readTime;
} }
} }
} }

8
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) public async Task SetReadAsync(Guid id)
{ {
if (_currentUser is not { IsAuthenticated: true }) throw new AbpAuthorizationException(); if (_currentUser is not { IsAuthenticated: true }) throw new AbpAuthorizationException();
var notification = await _notificationRepository.FindByIdAsync(id); var notification = await _notificationRepository.FindByIdAsync(id);
if (notification == null) throw new NotificationManagementDomainException(NotificationManagementErrorCodes.MessageNotExist); if (notification == null) throw new NotificationManagementDomainException(NotificationManagementErrorCodes.MessageNotExist);
if (notification.MessageType == MessageType.BroadCast) if (notification.MessageType == MessageType.BroadCast)
{ {
//如果类型是广播消息,用户设置为已读,在插入一条数据 //如果类型是广播消息,用户设置为已读,在插入一条数据
notification.AddBroadCastNotificationSubscription(GuidGenerator.Create(), _currentUser.GetId()); notification.AddBroadCastNotificationSubscription(GuidGenerator.Create(), _currentUser.GetId(), Clock.Now);
return; return;
} }
else else
@ -205,7 +205,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
var notificationSubscription = notification.NotificationSubscriptions.FirstOrDefault(e => e.ReceiveId == _currentUser.GetId()); var notificationSubscription = notification.NotificationSubscriptions.FirstOrDefault(e => e.ReceiveId == _currentUser.GetId());
if (notificationSubscription == null) if (notificationSubscription == null)
throw new NotificationManagementDomainException(NotificationManagementErrorCodes.UserUnSubscription); throw new NotificationManagementDomainException(NotificationManagementErrorCodes.UserUnSubscription);
notificationSubscription.SetRead(); notificationSubscription.SetRead(Clock.Now);
} }
await _notificationRepository.UpdateAsync(notification); await _notificationRepository.UpdateAsync(notification);

1
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs

@ -1,6 +1,7 @@
using Hangfire.Redis; using Hangfire.Redis;
using Swagger; using Swagger;
using Volo.Abp.BackgroundJobs.Hangfire; using Volo.Abp.BackgroundJobs.Hangfire;
using Volo.Abp.Timing;
namespace Lion.AbpPro namespace Lion.AbpPro
{ {

8
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;
using Lion.AbpPro.BasicManagement.Users.Dtos; using Lion.AbpPro.BasicManagement.Users.Dtos;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Abp.Timing;
namespace Lion.AbpPro.Pages namespace Lion.AbpPro.Pages
@ -13,14 +14,17 @@ namespace Lion.AbpPro.Pages
private readonly ILogger<Login> _logger; private readonly ILogger<Login> _logger;
private readonly IHostEnvironment _hostEnvironment; private readonly IHostEnvironment _hostEnvironment;
private readonly JwtOptions _jwtOptions; private readonly JwtOptions _jwtOptions;
private readonly IClock _clock;
public Login(IAccountAppService accountAppService, public Login(IAccountAppService accountAppService,
ILogger<Login> logger, ILogger<Login> logger,
IHostEnvironment hostEnvironment, IHostEnvironment hostEnvironment,
IOptionsSnapshot<JwtOptions> jwtOptions) IOptionsSnapshot<JwtOptions> jwtOptions,
IClock clock)
{ {
_accountAppService = accountAppService; _accountAppService = accountAppService;
_logger = logger; _logger = logger;
_hostEnvironment = hostEnvironment; _hostEnvironment = hostEnvironment;
_clock = clock;
_jwtOptions = jwtOptions.Value; _jwtOptions = jwtOptions.Value;
} }
@ -42,7 +46,7 @@ namespace Lion.AbpPro.Pages
{ {
var options = new CookieOptions var options = new CookieOptions
{ {
Expires = DateTime.Now.AddHours(_jwtOptions.ExpirationTime), Expires = _clock.Now.AddHours(_jwtOptions.ExpirationTime),
SameSite = SameSiteMode.Unspecified, SameSite = SameSiteMode.Unspecified,
}; };

11
aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/LionAbpProLogAppService.cs

@ -1,24 +1,27 @@
namespace Lion.AbpPro.ElasticSearches namespace Lion.AbpPro.ElasticSearches
{ {
[Authorize] [Authorize]
public class LionAbpProLogAppService : ElasticsearchBasicService,ILionAbpProLogAppService public class LionAbpProLogAppService : ElasticsearchBasicService, ILionAbpProLogAppService
{ {
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
// 时区 // 时区
private const string TimeZone = "Asia/Shanghai"; private const string TimeZone = "Asia/Shanghai";
public LionAbpProLogAppService( public LionAbpProLogAppService(
IElasticsearchProvider elasticsearchProvider, IElasticsearchProvider elasticsearchProvider,
IConfiguration configuration) : base(elasticsearchProvider) IConfiguration configuration) : base(elasticsearchProvider)
{ {
_configuration = configuration; _configuration = configuration;
} }
[Authorize(Policy = AbpProPermissions.SystemManagement.ES)] [Authorize(Policy = AbpProPermissions.SystemManagement.ES)]
public async Task<CustomPagedResultDto<PagingElasticSearchLogOutput>> PaingAsync(PagingElasticSearchLogInput input) public async Task<CustomPagedResultDto<PagingElasticSearchLogOutput>> PaingAsync(PagingElasticSearchLogInput input)
{ {
var IndexName = _configuration.GetValue<string>("ElasticSearch:SearchIndexFormat"); var IndexName = _configuration.GetValue<string>("ElasticSearch:SearchIndexFormat");
// 默认查询当天 // 默认查询当天
input.StartCreationTime = input.StartCreationTime?.AddMilliseconds(-1) ??DateTime.Now.Date.AddMilliseconds(-1); input.StartCreationTime = input.StartCreationTime?.AddMilliseconds(-1) ?? Clock.Now.Date.AddMilliseconds(-1);
input.EndCreationTime =input.EndCreationTime?.AddDays(1).AddMilliseconds(-1) ??DateTime.Now.Date.AddDays(1).AddMilliseconds(-1); input.EndCreationTime = input.EndCreationTime?.AddDays(1).AddMilliseconds(-1) ?? Clock.Now.Date.AddDays(1).AddMilliseconds(-1);
var mustFilters = new List<Func<QueryContainerDescriptor<PagingElasticSearchLogDto>, QueryContainer>>(); var mustFilters = new List<Func<QueryContainerDescriptor<PagingElasticSearchLogDto>, QueryContainer>>();
if (input.StartCreationTime.HasValue) if (input.StartCreationTime.HasValue)
{ {
@ -36,7 +39,7 @@ namespace Lion.AbpPro.ElasticSearches
{ {
mustFilters.Add 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()))
); );
} }

2
aspnet-core/services/src/Lion.AbpPro.Application/Jobs/TestJob.cs

@ -4,7 +4,7 @@ namespace Lion.AbpPro.Jobs
{ {
public Task ExecuteAsync() public Task ExecuteAsync()
{ {
Console.WriteLine($"job 测试- {DateTime.Now}"); Console.WriteLine($"job 测试");
return Task.CompletedTask; return Task.CompletedTask;
} }
} }

Loading…
Cancel
Save