feat: 网关管理模块 + RBAC权限认证 + 组织架构 + 审计日志
- 网关管理:GatewayEntity/Service/Controller CRUD + 测试连接;设备 GatewayId 外键关联 - JWT 认证:登录签发 Token(权限编码写入 Claims)、RequirePermission 权限过滤器、CurrentUser 上下文 - RBAC:用户/角色/权限实体与 CRUD,预定义 4 角色 + 6 权限种子(admin/admin123) - 组织架构:sys_org 固定层级树(公司/实验室/部门/班组白夜班),层级校验,用户挂 OrgId/岗位/技能标签 - 数据权限:角色 DataScope(全部/本组织及下级),用户列表按组织子树过滤 - 防锁死保护:禁止删/禁自己,保证至少一名活跃管理员,角色摘除 user:manage 前校验 - 审计日志:AuditRecorder 接入设备增删改/指令下发/登录登出/组织变更,AuditController 查询 - 设备指令下发按网关表取连接参数;设备列表支持 gatewayId/productId 筛选 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Model.Entity.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 审计日志表(记录所有关键操作)
|
||||
/// </summary>
|
||||
[SugarTable("sys_audit_log")]
|
||||
public class AuditLogEntity : BaseEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "UserId", ColumnDescription = "操作人用户Id")]
|
||||
public long UserId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "UserName", ColumnDescription = "操作人用户名", Length = 64, IsNullable = true)]
|
||||
public string? UserName { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "RoleId", ColumnDescription = "操作人角色Id(0=无/多角色)", DefaultValue = "0")]
|
||||
public long RoleId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "RoleName", ColumnDescription = "操作人角色名称", Length = 100, IsNullable = true)]
|
||||
public string? RoleName { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "OperationType", ColumnDescription = "操作类型(Create/Update/Delete/Login/Command等)", Length = 32, IsNullable = false)]
|
||||
public string OperationType { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "OperationTarget", ColumnDescription = "操作对象(如 IotDevice/Gateway/User/Role)", Length = 64, IsNullable = false)]
|
||||
public string OperationTarget { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "TargetId", ColumnDescription = "操作对象Id(0=无具体Id)", DefaultValue = "0")]
|
||||
public long TargetId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "DeviceId", ColumnDescription = "关联设备Id(0=无关设备)", DefaultValue = "0")]
|
||||
public long DeviceId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "OldValue", ColumnDescription = "操作前值(JSON)", ColumnDataType = "text", IsNullable = true)]
|
||||
public string? OldValue { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "NewValue", ColumnDescription = "操作后值(JSON)", ColumnDataType = "text", IsNullable = true)]
|
||||
public string? NewValue { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Ip", ColumnDescription = "操作IP", Length = 45, IsNullable = true)]
|
||||
public string? Ip { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Description", ColumnDescription = "操作描述", Length = 500, IsNullable = true)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "OperateTime", ColumnDescription = "操作时间", IsNullable = false)]
|
||||
public DateTime OperateTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Model.Entity.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 组织架构表(树形:公司/实验室/部门/班组,ParentId 自关联;班组带白/夜班)
|
||||
/// </summary>
|
||||
[SugarTable("sys_org")]
|
||||
public class OrgEntity : BaseEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "ParentId", ColumnDescription = "父级组织Id(0=根节点)", DefaultValue = "0")]
|
||||
public long ParentId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Name", ColumnDescription = "组织名称", Length = 100, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Code", ColumnDescription = "组织编码(唯一)", Length = 64, IsNullable = false)]
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>组织类型:1=公司, 2=实验室, 3=部门, 4=班组</summary>
|
||||
[SugarColumn(ColumnName = "OrgType", ColumnDescription = "组织类型(1公司/2实验室/3部门/4班组)", ColumnDataType = "smallint", DefaultValue = "3")]
|
||||
public byte OrgType { get; set; }
|
||||
|
||||
/// <summary>班组班次:0=非班组, 1=白班, 2=夜班</summary>
|
||||
[SugarColumn(ColumnName = "ShiftType", ColumnDescription = "班次(0非班组/1白班/2夜班)", ColumnDataType = "smallint", DefaultValue = "0")]
|
||||
public byte ShiftType { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Leader", ColumnDescription = "负责人", Length = 50, IsNullable = true)]
|
||||
public string? Leader { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Phone", ColumnDescription = "联系电话", Length = 20, IsNullable = true)]
|
||||
public string? Phone { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Sort", ColumnDescription = "排序号", DefaultValue = "0")]
|
||||
public int Sort { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Remark", ColumnDescription = "备注", Length = 500, IsNullable = true)]
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Model.Entity.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 权限表(功能权限码,如 device:view / device:edit / alert:confirm)
|
||||
/// </summary>
|
||||
[SugarTable("sys_permission")]
|
||||
public class PermissionEntity : BaseEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "Code", ColumnDescription = "权限编码(唯一,如 device:view)", Length = 64, IsNullable = false)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Name", ColumnDescription = "权限名称", Length = 100, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Group", ColumnDescription = "权限分组(如 device/alert/inspection/user)", Length = 64, IsNullable = true)]
|
||||
public string? Group { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "IsSystem", ColumnDescription = "是否系统内置(不可删除)", ColumnDataType = "smallint", DefaultValue = "0")]
|
||||
public byte IsSystem { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Sort", ColumnDescription = "排序号", DefaultValue = "0")]
|
||||
public int Sort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Model.Entity.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色表
|
||||
/// </summary>
|
||||
[SugarTable("sys_role")]
|
||||
public class RoleEntity : BaseEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "Code", ColumnDescription = "角色编码(唯一)", Length = 64, IsNullable = false)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Name", ColumnDescription = "角色名称", Length = 100, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "DataScope", ColumnDescription = "数据范围(1=全部,2=本实验室)", ColumnDataType = "smallint", DefaultValue = "2")]
|
||||
public byte DataScope { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "IsSystem", ColumnDescription = "是否系统内置角色(不可删除)", ColumnDataType = "smallint", DefaultValue = "0")]
|
||||
public byte IsSystem { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Sort", ColumnDescription = "排序号", DefaultValue = "0")]
|
||||
public int Sort { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Remark", ColumnDescription = "备注", Length = 500, IsNullable = true)]
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Model.Entity.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色-权限关联表(多对多)
|
||||
/// </summary>
|
||||
[SugarTable("sys_role_permission")]
|
||||
public class RolePermissionEntity : BaseEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "RoleId", ColumnDescription = "角色Id")]
|
||||
public long RoleId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "PermissionId", ColumnDescription = "权限Id")]
|
||||
public long PermissionId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Model.Entity.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户表
|
||||
/// </summary>
|
||||
[SugarTable("sys_user")]
|
||||
public class UserEntity : BaseEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "UserName", ColumnDescription = "用户名(登录账号)", Length = 64, IsNullable = false)]
|
||||
public string UserName { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "PasswordHash", ColumnDescription = "密码哈希", Length = 256, IsNullable = false)]
|
||||
public string PasswordHash { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "RealName", ColumnDescription = "真实姓名", Length = 100, IsNullable = true)]
|
||||
public string? RealName { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Email", ColumnDescription = "邮箱", Length = 128, IsNullable = true)]
|
||||
public string? Email { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Phone", ColumnDescription = "手机号", Length = 20, IsNullable = true)]
|
||||
public string? Phone { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "OrgId", ColumnDescription = "所属组织Id(公司/实验室/部门/班组任一节点,0=未分配)", DefaultValue = "0")]
|
||||
public long OrgId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Position", ColumnDescription = "岗位", Length = 64, IsNullable = true)]
|
||||
public string? Position { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "SkillTags", ColumnDescription = "技能标签(逗号分隔,如 Modbus,PLC,温度箱)", Length = 500, IsNullable = true)]
|
||||
public string? SkillTags { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "IsEnabled", ColumnDescription = "是否启用", ColumnDataType = "smallint", DefaultValue = "1")]
|
||||
public byte IsEnabled { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "LastLoginTime", ColumnDescription = "最后登录时间", IsNullable = true)]
|
||||
public DateTime? LastLoginTime { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Avatar", ColumnDescription = "头像URL", Length = 256, IsNullable = true)]
|
||||
public string? Avatar { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Remark", ColumnDescription = "备注", Length = 500, IsNullable = true)]
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Model.Entity.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户-角色关联表(多对多)
|
||||
/// </summary>
|
||||
[SugarTable("sys_user_role")]
|
||||
public class UserRoleEntity : BaseEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "UserId", ColumnDescription = "用户Id")]
|
||||
public long UserId { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "RoleId", ColumnDescription = "角色Id")]
|
||||
public long RoleId { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user