|
|
|
@ -43,13 +43,11 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
|
public async Task ChangeUserNotificationReadStateAsync(Guid? tenantId, Guid userId, long notificationId, NotificationReadState readState) |
|
|
|
{ |
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
await UserNotificationRepository.ChangeUserNotificationReadStateAsync(userId, notificationId, readState); |
|
|
|
await UserNotificationRepository.ChangeUserNotificationReadStateAsync(userId, notificationId, readState); |
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -57,14 +55,12 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
|
public async Task DeleteNotificationAsync(NotificationInfo notification) |
|
|
|
{ |
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
|
{ |
|
|
|
var notify = await NotificationRepository.GetByIdAsync(notification.GetId()); |
|
|
|
await NotificationRepository.DeleteAsync(notify.Id); |
|
|
|
var notify = await NotificationRepository.GetByIdAsync(notification.GetId()); |
|
|
|
await NotificationRepository.DeleteAsync(notify.Id); |
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -72,14 +68,12 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
|
public async Task DeleteUserNotificationAsync(Guid? tenantId, Guid userId, long notificationId) |
|
|
|
{ |
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
var notify = await UserNotificationRepository.GetByIdAsync(userId, notificationId); |
|
|
|
await UserNotificationRepository.DeleteAsync(notify.Id); |
|
|
|
var notify = await UserNotificationRepository.GetByIdAsync(userId, notificationId); |
|
|
|
await UserNotificationRepository.DeleteAsync(notify.Id); |
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -87,14 +81,12 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
|
public async Task DeleteUserSubscriptionAsync(Guid? tenantId, Guid userId, string notificationName) |
|
|
|
{ |
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
var userSubscribe = await UserSubscribeRepository.GetUserSubscribeAsync(notificationName, userId); |
|
|
|
await UserSubscribeRepository.DeleteAsync(userSubscribe.Id); |
|
|
|
var userSubscribe = await UserSubscribeRepository.GetUserSubscribeAsync(notificationName, userId); |
|
|
|
await UserSubscribeRepository.DeleteAsync(userSubscribe.Id); |
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -148,33 +140,52 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync(Guid? tenantId, string userName) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
var userSubscriptions = await UserSubscribeRepository.GetUserSubscribesByNameAsync(userName); |
|
|
|
|
|
|
|
var userSubscriptionInfos = new List<NotificationSubscriptionInfo>(); |
|
|
|
|
|
|
|
userSubscriptions.ForEach(us => userSubscriptionInfos.Add( |
|
|
|
new NotificationSubscriptionInfo |
|
|
|
{ |
|
|
|
UserId = us.UserId, |
|
|
|
TenantId = us.TenantId, |
|
|
|
NotificationName = us.NotificationName |
|
|
|
})); |
|
|
|
|
|
|
|
return userSubscriptionInfos; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
|
public async Task InsertNotificationAsync(NotificationInfo notification) |
|
|
|
{ |
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
|
// var notifyId = notification.GetId();
|
|
|
|
var notifyId = SnowflakeIdGenerator.Create(); |
|
|
|
// 保存主键,防止前端js long类型溢出
|
|
|
|
// notification.Data["id"] = notifyId.ToString();
|
|
|
|
|
|
|
|
var notify = new Notification(notifyId, notification.Name, |
|
|
|
notification.Data.GetType().AssemblyQualifiedName, |
|
|
|
JsonSerializer.Serialize(notification.Data), notification.NotificationSeverity) |
|
|
|
{ |
|
|
|
var notifyId = SnowflakeIdGenerator.Create(); |
|
|
|
// 保存主键,防止前端js long类型溢出
|
|
|
|
notification.Data["id"] = notifyId.ToString(); |
|
|
|
|
|
|
|
var notify = new Notification(notifyId, notification.Name, |
|
|
|
notification.Data.GetType().AssemblyQualifiedName, |
|
|
|
JsonSerializer.Serialize(notification.Data), notification.NotificationSeverity) |
|
|
|
{ |
|
|
|
CreationTime = Clock.Now, |
|
|
|
Type = notification.NotificationType, |
|
|
|
ExpirationTime = Clock.Now.AddDays(60) |
|
|
|
}; |
|
|
|
notify.SetTenantId(notification.TenantId); |
|
|
|
CreationTime = Clock.Now, |
|
|
|
Type = notification.NotificationType, |
|
|
|
ExpirationTime = Clock.Now.AddDays(60) |
|
|
|
}; |
|
|
|
notify.SetTenantId(notification.TenantId); |
|
|
|
|
|
|
|
await NotificationRepository.InsertAsync(notify); |
|
|
|
await NotificationRepository.InsertAsync(notify); |
|
|
|
|
|
|
|
notification.Id = notify.NotificationId.ToString(); |
|
|
|
notification.Id = notify.NotificationId.ToString(); |
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -182,14 +193,12 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
|
public async Task InsertUserNotificationAsync(NotificationInfo notification, Guid userId) |
|
|
|
{ |
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
|
{ |
|
|
|
var userNotification = new UserNotification(notification.GetId(), userId); |
|
|
|
await UserNotificationRepository.InsertAsync(userNotification); |
|
|
|
var userNotification = new UserNotification(notification.GetId(), userId, notification.TenantId); |
|
|
|
await UserNotificationRepository.InsertAsync(userNotification); |
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -197,19 +206,17 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
|
public async Task InsertUserSubscriptionAsync(Guid? tenantId, UserIdentifier identifier, string notificationName) |
|
|
|
{ |
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
|
|
|
|
var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName) |
|
|
|
{ |
|
|
|
CreationTime = Clock.Now |
|
|
|
}; |
|
|
|
var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId) |
|
|
|
{ |
|
|
|
CreationTime = Clock.Now |
|
|
|
}; |
|
|
|
|
|
|
|
await UserSubscribeRepository.InsertAsync(userSubscription); |
|
|
|
await UserSubscribeRepository.InsertAsync(userSubscription); |
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -217,20 +224,18 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
|
public async Task InsertUserSubscriptionAsync(Guid? tenantId, IEnumerable<UserIdentifier> identifiers, string notificationName) |
|
|
|
{ |
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
{ |
|
|
|
var userSubscribes = new List<UserSubscribe>(); |
|
|
|
var userSubscribes = new List<UserSubscribe>(); |
|
|
|
|
|
|
|
foreach(var identifier in identifiers) |
|
|
|
{ |
|
|
|
userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName)); |
|
|
|
} |
|
|
|
foreach (var identifier in identifiers) |
|
|
|
{ |
|
|
|
userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId)); |
|
|
|
} |
|
|
|
|
|
|
|
await UserSubscribeRepository.InsertUserSubscriptionAsync(userSubscribes); |
|
|
|
await UserSubscribeRepository.InsertUserSubscriptionAsync(userSubscribes); |
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -240,15 +245,23 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
|
return await UserSubscribeRepository.UserSubscribeExistsAysnc(notificationName, userId); |
|
|
|
} |
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
|
public async Task InsertUserNotificationsAsync(NotificationInfo notification, IEnumerable<Guid> userIds) |
|
|
|
{ |
|
|
|
var userNofitications = new List<UserNotification>(); |
|
|
|
foreach(var userId in userIds) |
|
|
|
// 添加工作单元
|
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
|
{ |
|
|
|
var userNofitication = new UserNotification(notification.GetId(), userId); |
|
|
|
userNofitications.Add(userNofitication); |
|
|
|
var userNofitications = new List<UserNotification>(); |
|
|
|
foreach (var userId in userIds) |
|
|
|
{ |
|
|
|
var userNofitication = new UserNotification(notification.GetId(), userId, notification.TenantId); |
|
|
|
userNofitications.Add(userNofitication); |
|
|
|
} |
|
|
|
await UserNotificationRepository.InsertUserNotificationsAsync(userNofitications); |
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
await UserNotificationRepository.InsertUserNotificationsAsync(userNofitications); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|