NotificationManager.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using Abp;
  5. using Abp.Dependency;
  6. using Abp.Domain.Entities;
  7. using Abp.Notifications;
  8. using Abp.Runtime.Session;
  9. using ContractService.Configuration;
  10. using ContractService.LegalContract;
  11. using IwbZero.Runtime.Session;
  12. namespace ContractService.CommonManager.Notifications
  13. {
  14. public class NotificationManager : INotificationManager, ISingletonDependency
  15. {
  16. private readonly INotificationPublisher _notificationPublisher;
  17. private readonly IwbSession _abpSession;
  18. public NotificationManager(INotificationPublisher notificationPublisher, IwbSession abpSession)
  19. {
  20. _notificationPublisher = notificationPublisher;
  21. _abpSession = abpSession;
  22. }
  23. public async Task WelcomeToSystemAsync()
  24. {
  25. await _notificationPublisher.PublishAsync(
  26. IwbNotificationName.WelcomeMsg, new MessageNotificationData("欢迎登陆"), severity: NotificationSeverity.Success,
  27. userIds: new[] { _abpSession.ToUserIdentifier() });
  28. }
  29. /// <summary>
  30. /// 发送给指定用户消息(info)
  31. /// </summary>
  32. /// <param name="user"></param>
  33. /// <param name="message"></param>
  34. /// <returns></returns>
  35. public async Task SendMsgAsync(UserIdentifier user, string message)
  36. {
  37. await SendMsgAsync(user, message, NotificationSeverity.Info);
  38. }
  39. /// <summary>
  40. /// 发送给指定用户消息
  41. /// </summary>
  42. /// <param name="user"></param>
  43. /// <param name="message"></param>
  44. /// <param name="severity"></param>
  45. /// <returns></returns>
  46. public async Task SendMsgAsync(UserIdentifier user, string message, NotificationSeverity severity)
  47. {
  48. await _notificationPublisher.PublishAsync(
  49. IwbNotificationName.SendMsg,
  50. new MessageNotificationData(message), severity: severity, userIds: new[] { user });
  51. }
  52. /// <summary>
  53. /// 发送某种消息给订阅用户(Info)
  54. /// </summary>
  55. /// <param name="msgName">消息唯一名称</param>
  56. /// <param name="message"></param>
  57. /// <returns></returns>
  58. public async Task SendMsgAsync(string msgName, string message)
  59. {
  60. await SendMsgAsync(msgName, message, NotificationSeverity.Info);
  61. }
  62. /// <summary>
  63. /// 发送某种消息给订阅用户
  64. /// </summary>
  65. /// <param name="msgName">消息唯一名称</param>
  66. /// <param name="message"></param>
  67. /// <param name="severity"></param>
  68. /// <returns></returns>
  69. public async Task SendMsgAsync(string msgName, string message, NotificationSeverity severity)
  70. {
  71. await _notificationPublisher.PublishAsync(msgName, new MessageNotificationData(message), severity: severity);
  72. }
  73. /// <summary>
  74. /// 发送某种消息给指定用户(带发送人)
  75. /// </summary>
  76. /// <param name="user"></param>
  77. /// <param name="msgName"></param>
  78. /// <param name="data"></param>
  79. /// <param name="severity"></param>
  80. /// <returns></returns>
  81. public async Task SendMessageAsync(UserIdentifier user, string msgName, SendMsgNotificationData data, NotificationSeverity severity)
  82. {
  83. await _notificationPublisher.PublishAsync(msgName, data, severity: severity, userIds: new[] { user });
  84. }
  85. /// <summary>
  86. /// 发送某种消息给订阅用户(带发送人)
  87. /// </summary>
  88. /// <param name="msgName"></param>
  89. /// <param name="data"></param>
  90. /// <param name="severity"></param>
  91. /// <returns></returns>
  92. public async Task SendMessageAsync(string msgName, SendMsgNotificationData data, NotificationSeverity severity)
  93. {
  94. await _notificationPublisher.PublishAsync(msgName, data, severity: severity);
  95. }
  96. /// <summary>
  97. /// 关键点提醒通知
  98. /// </summary>
  99. /// <param name="users"></param>
  100. /// <param name="data"></param>
  101. /// <returns></returns>
  102. public async Task SendKeyPointAlarmMsg(List<UserIdentifier> users, KeyPointNotificationData data)
  103. {
  104. data.IsAlarm = true;
  105. await _notificationPublisher.PublishAsync(IwbNotificationName.KeyPointAlarm, data,new EntityIdentifier(typeof(LegalContractKeyPointInfo),data.Id),
  106. NotificationSeverity.Info, users.ToArray());
  107. }
  108. /// <summary>
  109. /// 关键点过期通知
  110. /// </summary>
  111. /// <param name="users"></param>
  112. /// <param name="data"></param>
  113. /// <returns></returns>
  114. public async Task SendKeyPointExpireMsg(List<UserIdentifier> users, KeyPointNotificationData data)
  115. {
  116. data.IsAlarm = false;
  117. await _notificationPublisher.PublishAsync(IwbNotificationName.KeyPointAlarm, data, new EntityIdentifier(typeof(LegalContractKeyPointInfo), data.Id),
  118. NotificationSeverity.Warn, users.ToArray());
  119. }
  120. }
  121. [Serializable]
  122. public class SendMsgNotificationData : NotificationData
  123. {
  124. public string SenderUserName { get; set; }
  125. public string Message { get; set; }
  126. public SendMsgNotificationData(string senderUserName, string message)
  127. {
  128. SenderUserName = senderUserName;
  129. Message = message;
  130. }
  131. }
  132. }