|
|
@ -43,7 +43,6 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
public async Task ChangeUserNotificationReadStateAsync(Guid? tenantId, Guid userId, long notificationId, NotificationReadState readState) |
|
|
public async Task ChangeUserNotificationReadStateAsync(Guid? tenantId, Guid userId, long notificationId, NotificationReadState readState) |
|
|
{ |
|
|
{ |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
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); |
|
|
@ -51,13 +50,11 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
[UnitOfWork] |
|
|
public async Task DeleteNotificationAsync(NotificationInfo notification) |
|
|
public async Task DeleteNotificationAsync(NotificationInfo notification) |
|
|
{ |
|
|
{ |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
{ |
|
|
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
{ |
|
|
{ |
|
|
var notify = await NotificationRepository.GetByIdAsync(notification.GetId()); |
|
|
var notify = await NotificationRepository.GetByIdAsync(notification.GetId()); |
|
|
@ -66,13 +63,11 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
[UnitOfWork] |
|
|
public async Task DeleteUserNotificationAsync(Guid? tenantId, Guid userId, long notificationId) |
|
|
public async Task DeleteUserNotificationAsync(Guid? tenantId, Guid userId, long notificationId) |
|
|
{ |
|
|
{ |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
{ |
|
|
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
{ |
|
|
{ |
|
|
var notify = await UserNotificationRepository.GetByIdAsync(userId, notificationId); |
|
|
var notify = await UserNotificationRepository.GetByIdAsync(userId, notificationId); |
|
|
@ -81,13 +76,11 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
[UnitOfWork] |
|
|
public async Task DeleteUserSubscriptionAsync(Guid? tenantId, Guid userId, string notificationName) |
|
|
public async Task DeleteUserSubscriptionAsync(Guid? tenantId, Guid userId, string notificationName) |
|
|
{ |
|
|
{ |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
{ |
|
|
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
{ |
|
|
{ |
|
|
var userSubscribe = await UserSubscribeRepository.GetUserSubscribeAsync(notificationName, userId); |
|
|
var userSubscribe = await UserSubscribeRepository.GetUserSubscribeAsync(notificationName, userId); |
|
|
@ -96,7 +89,6 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<NotificationInfo> GetNotificationOrNullAsync(Guid? tenantId, long notificationId) |
|
|
public async Task<NotificationInfo> GetNotificationOrNullAsync(Guid? tenantId, long notificationId) |
|
|
{ |
|
|
{ |
|
|
@ -148,16 +140,36 @@ 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] |
|
|
[UnitOfWork] |
|
|
public async Task InsertNotificationAsync(NotificationInfo notification) |
|
|
public async Task InsertNotificationAsync(NotificationInfo notification) |
|
|
{ |
|
|
{ |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
{ |
|
|
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
{ |
|
|
{ |
|
|
|
|
|
// var notifyId = notification.GetId();
|
|
|
var notifyId = SnowflakeIdGenerator.Create(); |
|
|
var notifyId = SnowflakeIdGenerator.Create(); |
|
|
// 保存主键,防止前端js long类型溢出
|
|
|
// 保存主键,防止前端js long类型溢出
|
|
|
notification.Data["id"] = notifyId.ToString(); |
|
|
// notification.Data["id"] = notifyId.ToString();
|
|
|
|
|
|
|
|
|
var notify = new Notification(notifyId, notification.Name, |
|
|
var notify = new Notification(notifyId, notification.Name, |
|
|
notification.Data.GetType().AssemblyQualifiedName, |
|
|
notification.Data.GetType().AssemblyQualifiedName, |
|
|
@ -176,32 +188,28 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
[UnitOfWork] |
|
|
public async Task InsertUserNotificationAsync(NotificationInfo notification, Guid userId) |
|
|
public async Task InsertUserNotificationAsync(NotificationInfo notification, Guid userId) |
|
|
{ |
|
|
{ |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
{ |
|
|
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
{ |
|
|
{ |
|
|
var userNotification = new UserNotification(notification.GetId(), userId); |
|
|
var userNotification = new UserNotification(notification.GetId(), userId, notification.TenantId); |
|
|
await UserNotificationRepository.InsertAsync(userNotification); |
|
|
await UserNotificationRepository.InsertAsync(userNotification); |
|
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
[UnitOfWork] |
|
|
public async Task InsertUserSubscriptionAsync(Guid? tenantId, UserIdentifier identifier, string notificationName) |
|
|
public async Task InsertUserSubscriptionAsync(Guid? tenantId, UserIdentifier identifier, string notificationName) |
|
|
{ |
|
|
{ |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
{ |
|
|
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName) |
|
|
var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId) |
|
|
{ |
|
|
{ |
|
|
CreationTime = Clock.Now |
|
|
CreationTime = Clock.Now |
|
|
}; |
|
|
}; |
|
|
@ -211,20 +219,18 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
[UnitOfWork] |
|
|
public async Task InsertUserSubscriptionAsync(Guid? tenantId, IEnumerable<UserIdentifier> identifiers, string notificationName) |
|
|
public async Task InsertUserSubscriptionAsync(Guid? tenantId, IEnumerable<UserIdentifier> identifiers, string notificationName) |
|
|
{ |
|
|
{ |
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
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) |
|
|
foreach (var identifier in identifiers) |
|
|
{ |
|
|
{ |
|
|
userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName)); |
|
|
userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await UserSubscribeRepository.InsertUserSubscriptionAsync(userSubscribes); |
|
|
await UserSubscribeRepository.InsertUserSubscriptionAsync(userSubscribes); |
|
|
@ -232,7 +238,6 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> IsSubscribedAsync(Guid? tenantId, Guid userId, string notificationName) |
|
|
public async Task<bool> IsSubscribedAsync(Guid? tenantId, Guid userId, string notificationName) |
|
|
{ |
|
|
{ |
|
|
@ -240,15 +245,23 @@ namespace LINGYUN.Abp.MessageService.Notifications |
|
|
return await UserSubscribeRepository.UserSubscribeExistsAysnc(notificationName, userId); |
|
|
return await UserSubscribeRepository.UserSubscribeExistsAysnc(notificationName, userId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
public async Task InsertUserNotificationsAsync(NotificationInfo notification, IEnumerable<Guid> userIds) |
|
|
public async Task InsertUserNotificationsAsync(NotificationInfo notification, IEnumerable<Guid> userIds) |
|
|
|
|
|
{ |
|
|
|
|
|
// 添加工作单元
|
|
|
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|
|
|
|
|
using (CurrentTenant.Change(notification.TenantId)) |
|
|
{ |
|
|
{ |
|
|
var userNofitications = new List<UserNotification>(); |
|
|
var userNofitications = new List<UserNotification>(); |
|
|
foreach (var userId in userIds) |
|
|
foreach (var userId in userIds) |
|
|
{ |
|
|
{ |
|
|
var userNofitication = new UserNotification(notification.GetId(), userId); |
|
|
var userNofitication = new UserNotification(notification.GetId(), userId, notification.TenantId); |
|
|
userNofitications.Add(userNofitication); |
|
|
userNofitications.Add(userNofitication); |
|
|
} |
|
|
} |
|
|
await UserNotificationRepository.InsertUserNotificationsAsync(userNofitications); |
|
|
await UserNotificationRepository.InsertUserNotificationsAsync(userNofitications); |
|
|
|
|
|
|
|
|
|
|
|
await unitOfWork.SaveChangesAsync(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|