Skip to content

站内信模块

654 words
3 min
  • 通过站内信模块,可以发布公告、通知、消息等。
  • 通过站内信模块,用户可以发送站内信给其他用户。

如何集成

  • 在对应的层添加对应的引用
  • 添加 DependsOn(typeof(NotificationManagementXxxModule)) 特性到对应模块
    • Lion.AbpPro.NotificationManagement.Application
    • Lion.AbpPro.NotificationManagement.Application.Contracts
    • Lion.AbpPro.NotificationManagement.Domain
    • Lion.AbpPro.NotificationManagement.Domain.Shared
    • Lion.AbpPro.NotificationManagement.EntityFrameworkCore
    • Lion.AbpPro.NotificationManagement.HttpApi
    • Lion.AbpPro.NotificationManagement.HttpApi.Client
  • 在自己的dbcontext中实现接口:INotificationManagementDbContext
  • 在 EntityFrameworkCore 层添加数据库配置在 AbpProDbContext.cs 的 OnModelCreating()方法中添加 builder.ConfigureNotificationManagement();

如何配置单独数据库

  • 数据库连接名称:NotificationManagement
  • 在appsetting.json下配置
json
 "ConnectionStrings": {
    "Default": "Data Source=localhost;Database=LionAbpProDB;uid=root;pwd=mypassword;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true",
    "NotificationManagement": "Data Source=localhost;Database=NotificationManagement;uid=root;pwd=mypassword;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true"
  }

配置不同租户的数据库连接

  • 在租户管理的数据库连接字符串管理中配置
  • 这个要事先把表结构生成

如何修改表前缀

  • NotificationManagementDbProperties.DbTablePrefix
    • 重新指定即可
csharp
public static class NotificationManagementDbProperties
{
    public static string DbTablePrefix { get; set; } = "Abp";
    public static string DbSchema { get; set; } = null;
    public const string  ConnectionStringName = "NotificationManagement";
}

数据库连接

如果没有指定NotificationManagement数据连接名称,都会使用Default的数据库连接.

功能

  • 可以发送warning、information、error类型的站内信。
  • 可以发送广播类型的站内信。
  • 可以发送给指定人员。

后端发布通告

  • 注入IMessageManager既可以发送消息
csharp
namespace Lion.AbpPro.SignalR;

public interface IMessageManager
{
    /// <summary>
    /// 发送消息
    /// </summary>
    /// <param name="title">消息标题</param>
    /// <param name="content">消息内容</param>
    /// <param name="messageType">消息类型</param>
    /// <param name="messageLevel">消息级别</param>
    /// <param name="senderUserId">消息发送人,如果是广播消息,不需要传递</param>
    /// <param name="senderUserName">消息发送人userName</param>
    /// <param name="receiverUserId">消息接受人,如果是广播消息,不需要传递</param>
    /// <param name="receiverUserName">消息接受人userName,如果是广播消息,不需要传递</param>
    /// <param name="tenantId">租户Id</param>
    /// <param name="isPersistent">是否持久化,如果ture会在消息管理中出现,并且右上角也会存在</param>
    /// <returns></returns>
    Task SendMessageAsync(
        string title,
         string content, 
         MessageType messageType,
         MessageLevel messageLevel, 
         Guid senderUserId, 
         string senderUserName, 
         Guid? receiverUserId = null, 
         string receiverUserName = "",
         Guid? tenantId = null, 
         bool isPersistent = true);
}
  • 调用结果展示

前端发布通告

  • 系统管理->通告管理->发布通告

配置

注意

  • 部署之后需要启用websocket功能,否则前端无法连上signalr

表结构说明

Notification 表结构:

字段名描述类型
IdIdGuid
Title消息标题string
Content消息内容string
MessageType消息类型MessageType
MessageLevel消息等级MessageLevel
SenderId创建人发送人
NotificationSubscriptions消息订阅者集合List
IsDeleted是否删除bool
DeleterId删除人Guid?
DeletionTime删除时间DateTime
LastModifierId最后修改人Guid?
LastModificationTime最后修改时间DateTime
CreatorId创建人Guid?
CreationTime创建时间DateTime

NotificationSubscription 表结构:

字段名描述类型
IdIdGuid
ReceiveId接收人Guid
Read是否已读bool
ReadTime已读时间DateTime?
IsDeleted是否删除bool
DeleterId删除人Guid?
DeletionTime删除时间DateTime
LastModifierId最后修改人Guid?
LastModificationTime最后修改时间DateTime
CreatorId创建人Guid?
CreationTime创建时间DateTime

如有转载或 CV 的请标注本站原文地址