JydApp.Framework.Domain 1.0.11

dotnet add package JydApp.Framework.Domain --version 1.0.11
                    
NuGet\Install-Package JydApp.Framework.Domain -Version 1.0.11
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JydApp.Framework.Domain" Version="1.0.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JydApp.Framework.Domain" Version="1.0.11" />
                    
Directory.Packages.props
<PackageReference Include="JydApp.Framework.Domain" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JydApp.Framework.Domain --version 1.0.11
                    
#r "nuget: JydApp.Framework.Domain, 1.0.11"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JydApp.Framework.Domain@1.0.11
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JydApp.Framework.Domain&version=1.0.11
                    
Install as a Cake Addin
#tool nuget:?package=JydApp.Framework.Domain&version=1.0.11
                    
Install as a Cake Tool

JydApp.Framework

JydApp 通用应用层框架 —— 为景悦达多个垂直行业应用(配电室、安防管理、轨道安防、智慧体育、智慧医院)提供统一的后端基座。

架构概览

┌─────────────────────────────────────────────────────────────┐
│  垂直应用: PowerRoom / SafeGuard / TransitSecurity / ...     │
├─────────────────────────────────────────────────────────────┤
│  JydApp.Framework(本项目)                                  │
├──────────────────────┬──────────────────────────────────────┤
│  IotMatrix 物联网中台  │  JydGBS 视频平台 (CMS + SMS)         │
└──────────────────────┴──────────────────────────────────────┘

分层结构

JydApp.Framework.sln
├── 00-Core/
│   └── JydApp.Framework.Domain           领域层(实体、仓储接口、集成接口)
├── 01-Application/
│   └── JydApp.Framework.Application      应用层(服务接口+实现、DTO)
├── 02-Services/
│   ├── JydApp.Framework.Event            事件处理(MQ 消息处理器、定时任务)
│   └── JydApp.Framework.RuleEngine       规则引擎(图形化规则执行器)
├── 03-Infrastructure/
│   └── JydApp.Framework.Infrastructure   基础设施(DB、Redis、MQ、外部客户端)
└── 04-Presentation/
    └── JydApp.Framework.Api              API层(控制器、中间件、Hub)

技术栈

  • .NET 9 / ASP.NET Core Web API
  • SqlSugar ORM + PostgreSQL
  • FreeRedis (缓存、分布式锁)
  • RabbitMQ (消息队列)
  • SignalR (WebSocket 实时推送)
  • IotMatrix North API (物联网设备数据)
  • JydGBS (GB28181 视频平台)

快速开始

构建

cd JydApp.Framework
dotnet restore
dotnet build

垂直应用引用方式

// Program.cs
var builder = WebApplication.CreateBuilder(args);

// 1. 框架基础设施
builder.Services.AddAppFrameworkInfrastructure(builder.Configuration);

// 2. 应用服务自动注册(扫描框架 + 垂直应用程序集)
builder.Services.AddApplicationServices(
    typeof(YourApp.Application.SomeAppService).Assembly
);

// 3. 事件处理器注册
builder.Services.AddAppFrameworkEvent(
    typeof(YourApp.Event.SomeHandler).Assembly
);

// 4. API 配置
builder.Services.AddAppFrameworkApi(builder.Configuration);

var app = builder.Build();
app.UseAppFrameworkMiddleware();
app.MapControllers();
app.MapCommonHubs();
app.Run();

核心实体(30个)

身份与权限

实体 表名 说明
User sys_user 用户账户
Role sys_role 角色定义
Permission sys_permission 权限树(菜单/按钮/API)
UserRole sys_user_role 用户-角色绑定
RolePermission sys_role_permission 角色-权限绑定
Department sys_department 组织树
UserDepartment sys_user_department 用户-部门绑定
SubjectTarget sys_subject_target 通用授权绑定

空间与组织

| Area | app_area | 层级区域树 | | AreaDevice | app_area_device | 区域-设备绑定 | | AreaUser | app_area_user | 区域-用户访问绑定 |

IoT 核心

| Product | app_product | IoT 产品类型 | | Device | app_device | 设备实例 | | DataSyncLog | app_data_sync_log | IotMatrix 数据同步日志 |

告警与事件

| AlarmRecord | app_alarm_record | 告警记录(含 AI/门禁/周界/消防来源) | | EventRecord | app_event_record | 事件记录(客观事实,不需处理) | | EventAlarmRule | app_event_alarm_rule | 事件升级规则(事件→告警的匹配条件和升级参数) | | AlarmActionConfig | app_alarm_action_config | 告警联动配置 | | AlarmActionLog | app_alarm_action_log | 联动执行日志 | | StrategyRule | app_strategy_rule | 规则引擎规则 | | StrategyRecord | app_strategy_record | 规则执行记录 |

运维管理

| WorkOrder | app_work_order | 工单 | | Notification | app_notification | 系统通知 |

系统支撑

| DictionarySet | sys_dictionary_set | 数据字典组 | | DictionaryData | sys_dictionary_data | 字典值 | | CodeDefinition | sys_code_definition | 自动编码规则 | | File | sys_file | 文件上传记录 | | OperationLog | sys_operation_log | 操作审计日志 | | LoginLog | sys_login_log | 登录历史 |

工作流

| WfProcessDefinition | wf_process_definition | 流程模板 | | WfNodeDefinition | wf_node_definition | 流程节点 | | WfProcessInstance | wf_process_instance | 流程实例 | | WfTaskInstance | wf_task_instance | 待办任务 |

框架提供的应用服务

服务 接口 功能
认证 IAuthAppService 登录/刷新Token/登出
用户 IUserAppService CRUD + 密码管理 + 角色绑定
角色 IRoleAppService CRUD + 权限分配
权限 IPermissionAppService 权限树 CRUD
部门 IDepartmentAppService 部门树 CRUD
区域 IAreaAppService 区域树 CRUD
设备 IDeviceAppService 设备 CRUD + IotMatrix 关联
产品 IProductAppService 产品 CRUD + TSL 物模型
告警 IAlarmRecordAppService 告警 CRUD + 确认/恢复 + 详情聚合(GetDetailAsync) + 联动派发
事件 IEventRecordAppService 事件记录 CRUD + 统计
事件升级规则 IEventAlarmRuleAppService 事件升级规则 CRUD + 启停
事件评估 IEventAlarmEvaluator 事件→告警自动评估(规则匹配 + Redis 冷却)
通知 INotificationAppService 通知 CRUD + 已读/未读
字典 IDictionaryAppService 字典组/字典值 CRUD
同步 IIotMatrixSyncService IotMatrix 数据定期同步(产品+设备)
策略规则 IStrategyRuleAppService 规则引擎规则 CRUD + 启停
编码生成 ICodeGenerationService 自动编码生成
Redis IRedisService 缓存/Hash/分布式锁

IotMatrix 集成

数据流转

IotMatrix North API(X-Api-Key 认证)
│
├── RabbitMQ 推送(实时)
│   ├── Exchange: north.telemetry
│   │   └── {pk}.{dn}          → NorthTelemetryEventHandler  → Redis 缓存 + SignalR 推送
│   │
│   └── Exchange: north.events
│       ├── device.online.#     → DeviceStatusEventHandler    → 更新设备状态 + EventRecord + 规则评估
│       ├── device.offline.#    → DeviceStatusEventHandler    → 更新设备状态 + EventRecord + 规则评估
│       ├── alarm.#             → NorthAlarmEventHandler      → EventRecord → EventAlarmEvaluator → AlarmRecord + 联动
│       └── device.event.info.# → DeviceEventHandler          → EventRecord → EventAlarmEvaluator → 按规则升级
│
├── REST API(按需查询)
│   ├── GET  /products                       → 产品列表/详情/TSL 物模型
│   ├── GET  /devices                        → 设备列表/状态/标签
│   ├── GET  /devices/{id}/telemetry/latest  → 最新遥测(IotMatrix Redis)
│   ├── GET  /devices/{id}/telemetry/history → 历史遥测(IotMatrix InfluxDB)
│   ├── POST /devices/{id}/telemetry/reading → 表计抄读
│   ├── POST /devices/{id}/properties        → 设备属性控制
│   └── POST /devices/{id}/services/{name}   → 调用设备服务
│
└── 定时同步(IotMatrixSyncService)
    ├── ProductSyncTask(每 30 分钟)→ 同步产品 + TSL 物模型
    └── DeviceSyncTask(每 5 分钟) → 同步设备 + 关联产品

内置 MQ 消息处理器

处理器 Exchange Routing Key 功能
NorthTelemetryEventHandler north.telemetry # 遥测值写入 Redis(key: device:{iotMatrixId}:telemetry, TTL 5分钟)+ 更新设备最后活跃时间 + SignalR 推送到设备订阅组
DeviceStatusEventHandler north.events device.online.# / device.offline.# 通过 IotMatrixDeviceId 或 DeviceCode 查找本地设备 → 更新 OnlineStatus/LastOnlineTime → Redis 缓存 → SignalR 推送 → EventRecord(触发规则评估)
NorthAlarmEventHandler north.events alarm.# 触发:查设备→查区域→写入 EventRecord→后台触发 EventAlarmEvaluator→按规则创建 AlarmRecord→联动派发;恢复:查 IotMatrixEventId→更新状态为 Resolved→推送
DeviceEventHandler north.events device.event.info.# 处理 Info 级别设备事件(如门禁通行等非告警事件)→ 写入 EventRecord → 触发规则评估

数据同步服务(IotMatrixSyncService)

框架提供 IIotMatrixSyncService,由两个定时任务驱动:

  • ProductSyncTask:每 30 分钟,启动延迟 15 秒

    • 分页获取 IotMatrix 产品 → 新增/更新本地 Product 实体
    • 同步每个产品的 TSL(物模型)JSON
    • IotMatrix 中已删除的产品 → 本地标记 Status=0(停用,不删除)
  • DeviceSyncTask:每 5 分钟,启动延迟 30 秒

    • 分页获取 IotMatrix 设备 → 新增/更新本地 Device 实体
    • 通过 IotMatrixProductId 关联本地 Product
    • IotMatrix 中已删除的设备 → 本地标记 OnlineStatus="removed", Status=0(不删除,保留历史数据)
  • DataSyncLog:每次同步记录日志(sync_type, sync_status, total_count, success_count, error_message, end_time)

同步策略:只增不删。从 IotMatrix 删除设备后,本地设备不会被删除,仅标记为停用/已移除。这保证了告警记录、事件记录、工单等历史数据的引用完整性。

设计原则

  • 不缓存遥测到 PostgreSQL:最新值存 Redis(TTL 5分钟),历史查询透传 IotMatrix InfluxDB
  • 告警记录持久化:告警存本地 PostgreSQL,支持全生命周期管理
  • 设备/产品定期同步:IotMatrixSyncService 定时从 IotMatrix 同步,只增不删,保留数据引用完整性

告警系统

告警来源与类型

AlarmRecord 支持多种告警来源(AlarmSource):

  • device — 设备遥测越限(自动恢复: AutoRecoverable=true
  • ai — AI 视频分析检测
  • rule — 规则引擎触发
  • manual — 人工创建
  • access — 门禁系统
  • perimeter — 周界安防
  • fire — 消防系统

告警严重级别:Critical / Major / Minor / Warning

告警生命周期:Active → Acknowledged → Resolved

告警详情聚合(AlarmDetailDto)

IAlarmRecordAppService.GetDetailAsync 聚合告警弹窗所需的全部数据:

AlarmDetailDto(继承 AlarmRecordDto)
├── 基础告警信息(级别、来源、状态、时间...)
├── 设备信息(DeviceCode, ProductName, OnlineStatus, IpAddress, Location)
├── AI 证据(SnapshotUrl, VideoClipUrl, AiModelId, AiConfidence, CameraId)
└── ExtendedInfo(Dictionary<string, object>? —— 来自 IAlarmDetailEnricher)

IAlarmDetailEnricher — 垂直应用扩展点:

  • 框架提供 DefaultAlarmDetailEnricher(返回空)
  • 配电室可注入摄像头画面、电气参数
  • 校园可注入门禁记录、人脸识别截图
  • 注册方式:services.AddScoped<IAlarmDetailEnricher, YourEnricher>()

告警联动系统

告警触发 → AlarmActionDispatcher
               │ 查询 AlarmActionConfig(匹配来源/类型/级别/区域/设备)
               ▼
         IAlarmActionHandler 实现
         ├── NotifyAlarmActionHandler(框架内置:发通知)
         ├── LogAlarmActionHandler(框架内置:记日志)
         ├── WorkOrderHandler(垂直应用实现:创建工单)
         ├── EmergencyPlanHandler(垂直应用实现:执行预案)
         └── DeviceControlHandler(垂直应用实现:联动设备)

实时推送

Application 层: IRealTimePusher(抽象接口)
       ↓ 实现
Api 层: SignalRRealTimePusher(使用 IHubContext)
       ↓ 推送到 SignalR Group
SignalR Hub:
  ├── RealTimeDataHub   /hubs/realtime-data   设备遥测推送  Group: device:{deviceId}
  ├── AlarmHub          /hubs/alarms          告警推送      Group: alarms
  └── NotificationHub   /hubs/notifications   通知推送      Group: user:{userId}

IRealTimePusher 方法:

  • PushToDeviceAsync(deviceId, method, data) — 推送到设备订阅组
  • PushToAreaAsync(areaId, method, data) — 推送到区域订阅组
  • PushAlarmAsync(data) — 广播告警给所有订阅者
  • PushNotificationAsync(userId, data) — 推送到指定用户

扩展点

扩展维度 机制 垂直应用操作
添加实体 继承 BaseEntity,新建文件 SqlSugar CodeFirst 自动建表
添加服务 I{X}AppService + 实现,命名以 AppService 结尾 自动扫描注册
添加控制器 ASP.NET Core Controller 自动发现
添加 MQ 处理器 IMessageHandler<T> + [MessageQueueHandler] 传程序集到 AddAppFrameworkEvent()
添加定时任务 IScheduledTaskHandler + [ScheduledTask] 传程序集到 AddAppFrameworkEvent()
告警联动 实现 IAlarmActionHandler DI 注册
告警详情扩展 实现 IAlarmDetailEnricher DI 覆盖默认实现
规则引擎节点 实现 INodeExecutor 自动扫描注册
实体扩展字段 使用 Attributes JSONB 字段(Device, Area, AlarmRecord, EventRecord, WorkOrder) 无需改表
扩展表结构 1:1 关联表 或 继承加列 按需选择
覆盖框架服务 在框架 DI 注册之后注册自己的实现 后注册覆盖先注册

关键文件索引

src/
├── 00-Core/JydApp.Framework.Domain/
│   ├── Common/BaseEntity.cs                    实体基类(UUID PK + 审计 + 软删除)
│   ├── Entities/                               30个核心实体
│   ├── Repositories/IRepository.cs             泛型仓储接口
│   ├── IotMatrix/IIotMatrixClient.cs           IotMatrix North API 客户端接口 + DTO
│   └── MessageQueue/IMessageHandler.cs         消息处理器接口 + 消息模型
│
├── 01-Application/JydApp.Framework.Application/
│   ├── Services/ServiceInterfaces.cs           IIotMatrixSyncService, IStrategyRuleAppService 等接口
│   ├── IotMatrixSync/IotMatrixSyncService.cs   数据同步服务实现(只增不删策略)
│   ├── Alarms/
│   │   ├── IAlarmRecordAppService.cs           告警服务接口 + DTO(含 AlarmDetailDto)
│   │   ├── AlarmRecordAppService.cs            告警服务实现(含详情聚合 + 联动派发)
│   │   └── IAlarmDetailEnricher.cs             告警详情扩展接口 + 默认实现
│   ├── Events/
│   │   ├── EventAlarmEvaluator.cs              事件→告警升级评估器(规则匹配 + Redis 冷却)
│   │   └── EventAlarmRuleAppService.cs         事件升级规则 CRUD
│   └── Common/IRealTimePusher.cs               实时推送抽象接口
│
├── 02-Services/JydApp.Framework.Event/
│   ├── Handlers/
│   │   ├── NorthTelemetryEventHandler.cs       遥测 → Redis + SignalR
│   │   ├── DeviceStatusEventHandler.cs         在线/离线 → DB + Redis + SignalR + EventRecord
│   │   ├── NorthAlarmEventHandler.cs           告警触发/恢复 → EventRecord → 规则评估 → AlarmRecord + 联动
│   │   └── DeviceEventHandler.cs               设备 Info 事件 → EventRecord → 规则评估
│   └── Tasks/
│       └── IotMatrixSyncTasks.cs               ProductSyncTask(30min) + DeviceSyncTask(5min)
│
├── 03-Infrastructure/JydApp.Framework.Infrastructure/
│   └── IotMatrix/IotMatrixClient.cs            IIotMatrixClient HttpClient 实现
│
└── 04-Presentation/JydApp.Framework.Api/
    ├── RealTime/SignalRRealTimePusher.cs        IRealTimePusher 的 SignalR 实现
    └── Extensions/ServiceCollectionExtensions.cs DI 注册入口

配置项

{
  "ConnectionStrings": {
    "PostgreSQL": "Host=localhost;Port=5432;Database=jydapp;Username=postgres;Password=xxx"
  },
  "IotMatrix": {
    "ApiBaseUrl": "https://localhost:41774",
    "ApiKey": "your-api-key"
  },
  "RabbitMq": {
    "HostName": "localhost",
    "Port": 5672,
    "UserName": "guest",
    "Password": "guest",
    "Enabled": true
  },
  "Redis": {
    "ConnectionString": "localhost:6379",
    "Enabled": true,
    "KeyPrefix": "JydApp:"
  },
  "Jwt": {
    "SecretKey": "your-secret-key",
    "Issuer": "JydApp",
    "Audience": "JydApp",
    "AccessTokenExpireMinutes": 120,
    "RefreshTokenExpireDays": 7
  }
}

表命名约定

  • sys_ — 系统管理(用户、角色、权限、字典、文件、日志)
  • app_ — 通用业务(区域、设备、告警、工单、通知、规则)
  • wf_ — 工作流
  • 垂直应用使用各自前缀:prp_(配电室), sc_(安防), ts_(轨道), ss_(体育), sh_(医院)
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on JydApp.Framework.Domain:

Package Downloads
JydApp.Framework.Application

JydApp 通用应用层框架 - 应用层(服务接口与实现、DTO)

JydApp.AI.Rag

JydApp AI 模块 - RAG 知识库(文档解析/分片/PgVector 向量存储/管理 API)

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.11 53 6/13/2026
1.0.10 64 6/13/2026
1.0.9 65 6/13/2026
1.0.8 52 6/13/2026
1.0.4 181 4/16/2026
1.0.3 265 4/16/2026
1.0.2 194 4/16/2026
1.0.1 206 4/16/2026
1.0.0 179 4/16/2026