Browse Source

fix: 修复时区问题 #85

pull/89/head
王军 3 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)
{
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<LoginOutput> 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<string> 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<Claim>
@ -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)
};

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);
var result = ObjectMapper.Map<List<Volo.Abp.Identity.IdentityUser>, List<ExportIdentityUserOutput>>(source);
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>

19
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
/// </summary>
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)
{

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>
public class Notification : FullAuditedAggregateRoot<Guid>
public class Notification : FullAuditedAggregateRoot<Guid>
{
/// <summary>
/// 消息标题
@ -23,7 +23,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates
/// 消息类型
/// </summary>
public MessageType MessageType { get; private set; }
/// <summary>
/// 消息等级
/// </summary>
@ -101,15 +101,15 @@ namespace Lion.AbpPro.NotificationManagement.Notifications.Aggregates
{
MessageType = messageType;
}
private void SetMessageLevel(MessageLevel messageLevel)
{
MessageLevel = messageLevel;
}
/// <summary>
/// 新增非广播消息订阅人
/// </summary>
/// <param name="notificationSubscriptionId"></param>
/// <param name="receiveId"></param>
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
/// <summary>
/// 新增消息类型为广播订阅人
/// </summary>
/// <param name="notificationSubscriptionId"></param>
/// <param name="receiveId"></param>
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);
}
}

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>
public partial class NotificationSubscription : FullAuditedEntity<Guid>
public class NotificationSubscription : FullAuditedEntity<Guid>
{
/// <summary>
/// 订阅人
@ -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;
}
}
}

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)
{
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);

1
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
{

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.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<Login> _logger;
private readonly IHostEnvironment _hostEnvironment;
private readonly JwtOptions _jwtOptions;
private readonly IClock _clock;
public Login(IAccountAppService accountAppService,
ILogger<Login> logger,
IHostEnvironment hostEnvironment,
IOptionsSnapshot<JwtOptions> jwtOptions)
IOptionsSnapshot<JwtOptions> 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,
};

11
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<CustomPagedResultDto<PagingElasticSearchLogOutput>> PaingAsync(PagingElasticSearchLogInput input)
{
var IndexName = _configuration.GetValue<string>("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<Func<QueryContainerDescriptor<PagingElasticSearchLogDto>, 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()))
);
}

2
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;
}
}

Loading…
Cancel
Save