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:
2026-09-10 17:31:39 +08:00
co-authored by Claude Sonnet 4.6
parent 3059befcf5
commit 6aca0297bb
48 changed files with 3583 additions and 52 deletions
+309 -2
View File
@@ -1,9 +1,11 @@
using Model.Dto.Asset;
using Model.Dto.Config;
using Model.Dto.Inspection;
using Model.Dto.System;
using Model.Entity.Asset;
using Model.Entity.Config;
using Model.Entity.Inspection;
using Model.Entity.System;
namespace Model.Mapper
{
@@ -410,7 +412,7 @@ namespace Model.Mapper
Name = entity.Name,
DeviceType = entity.DeviceType,
ProductId = entity.ProductId.ToString(),
GatewayCode = entity.GatewayCode,
GatewayId = entity.GatewayId.ToString(),
SlaveId = entity.SlaveId,
Manufacturer = entity.Manufacturer,
Description = entity.Description,
@@ -445,7 +447,7 @@ namespace Model.Mapper
Name = dto.Name,
DeviceType = dto.DeviceType,
ProductId = ParseId(dto.ProductId),
GatewayCode = dto.GatewayCode,
GatewayId = ParseId(dto.GatewayId),
SlaveId = dto.SlaveId,
Manufacturer = dto.Manufacturer,
Description = dto.Description,
@@ -485,6 +487,99 @@ namespace Model.Mapper
}
#endregion
#region
/// <summary>
/// GatewayEntity → GatewayDto
/// </summary>
public static GatewayDto ToDto(this GatewayEntity entity)
{
if (entity == null) return null;
return new GatewayDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name,
ProtocolType = (int)entity.ProtocolType,
Host = entity.Host,
Port = entity.Port,
ComPort = entity.ComPort,
BaudRate = entity.BaudRate,
DataBits = entity.DataBits,
StopBits = entity.StopBits,
Parity = entity.Parity,
CpuType = entity.CpuType,
Rack = entity.Rack,
Slot = entity.Slot,
IsEnabled = entity.IsEnabled,
OnlineStatus = entity.OnlineStatus,
LastConnectedTime = entity.LastConnectedTime,
LastError = entity.LastError,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
/// <summary>
/// List&lt;GatewayEntity&gt; → List&lt;GatewayDto&gt;
/// </summary>
public static List<GatewayDto> ToDtoList(this List<GatewayEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<GatewayDto>();
}
/// <summary>
/// GatewayDto → GatewayEntity(入参映射)
/// </summary>
public static GatewayEntity ToEntity(this GatewayDto dto)
{
if (dto == null) return null;
return new GatewayEntity
{
Id = ParseId(dto.Id),
Code = dto.Code,
Name = dto.Name,
ProtocolType = (IotDeviceProtocolEnum)dto.ProtocolType,
Host = dto.Host,
Port = dto.Port,
ComPort = dto.ComPort,
BaudRate = dto.BaudRate,
DataBits = dto.DataBits,
StopBits = dto.StopBits,
Parity = dto.Parity,
CpuType = dto.CpuType,
Rack = dto.Rack,
Slot = dto.Slot,
IsEnabled = dto.IsEnabled,
OnlineStatus = dto.OnlineStatus,
LastConnectedTime = dto.LastConnectedTime,
LastError = dto.LastError,
Remark = dto.Remark
};
}
/// <summary>
/// GatewayEntity → GatewayOptionDto(下拉选项)
/// </summary>
public static GatewayOptionDto ToOptionDto(this GatewayEntity entity)
{
if (entity == null) return null;
return new GatewayOptionDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name
};
}
/// <summary>
/// List&lt;GatewayEntity&gt; → List&lt;GatewayOptionDto&gt;
/// </summary>
public static List<GatewayOptionDto> ToOptionDtoList(this List<GatewayEntity> entities)
{
return entities?.Select(e => e.ToOptionDto()).ToList() ?? new List<GatewayOptionDto>();
}
#endregion
#region
/// <summary>
/// ProductCategoryEntity → ProductCategoryDto
@@ -935,5 +1030,217 @@ namespace Model.Mapper
};
}
#endregion
#region
public static UserDto ToDto(this UserEntity entity)
{
if (entity == null) return null;
return new UserDto
{
Id = entity.Id.ToString(),
UserName = entity.UserName,
RealName = entity.RealName,
Email = entity.Email,
Phone = entity.Phone,
OrgId = entity.OrgId.ToString(),
Position = entity.Position,
SkillTags = entity.SkillTags,
IsEnabled = entity.IsEnabled,
LastLoginTime = entity.LastLoginTime,
Avatar = entity.Avatar,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
public static List<UserDto> ToDtoList(this List<UserEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<UserDto>();
public static UserEntity ToEntity(this UserDto dto)
{
if (dto == null) return null;
return new UserEntity
{
Id = ParseId(dto.Id),
UserName = dto.UserName,
RealName = dto.RealName,
Email = dto.Email,
Phone = dto.Phone,
OrgId = ParseId(dto.OrgId),
Position = dto.Position,
SkillTags = dto.SkillTags,
IsEnabled = dto.IsEnabled,
Avatar = dto.Avatar,
Remark = dto.Remark
};
}
public static UserOptionDto ToOptionDto(this UserEntity entity)
{
if (entity == null) return null;
return new UserOptionDto { Id = entity.Id.ToString(), UserName = entity.UserName, RealName = entity.RealName };
}
public static List<UserOptionDto> ToOptionDtoList(this List<UserEntity> entities)
=> entities?.Select(e => e.ToOptionDto()).ToList() ?? new List<UserOptionDto>();
#endregion
#region
public static RoleDto ToDto(this RoleEntity entity)
{
if (entity == null) return null;
return new RoleDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name,
DataScope = entity.DataScope,
IsSystem = entity.IsSystem,
Sort = entity.Sort,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
public static List<RoleDto> ToDtoList(this List<RoleEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<RoleDto>();
public static RoleEntity ToEntity(this RoleDto dto)
{
if (dto == null) return null;
return new RoleEntity
{
Id = ParseId(dto.Id),
Code = dto.Code,
Name = dto.Name,
DataScope = dto.DataScope,
IsSystem = dto.IsSystem,
Sort = dto.Sort,
Remark = dto.Remark
};
}
public static RoleOptionDto ToOptionDto(this RoleEntity entity)
{
if (entity == null) return null;
return new RoleOptionDto { Id = entity.Id.ToString(), Code = entity.Code, Name = entity.Name };
}
public static List<RoleOptionDto> ToOptionDtoList(this List<RoleEntity> entities)
=> entities?.Select(e => e.ToOptionDto()).ToList() ?? new List<RoleOptionDto>();
#endregion
#region
public static PermissionDto ToDto(this PermissionEntity entity)
{
if (entity == null) return null;
return new PermissionDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name,
Group = entity.Group,
IsSystem = entity.IsSystem,
Sort = entity.Sort
};
}
public static List<PermissionDto> ToDtoList(this List<PermissionEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<PermissionDto>();
public static PermissionEntity ToEntity(this PermissionDto dto)
{
if (dto == null) return null;
return new PermissionEntity
{
Id = ParseId(dto.Id),
Code = dto.Code,
Name = dto.Name,
Group = dto.Group,
IsSystem = dto.IsSystem,
Sort = dto.Sort
};
}
#endregion
#region
public static OrgTreeDto ToTreeDto(this OrgEntity entity)
{
if (entity == null) return null;
return new OrgTreeDto
{
Id = entity.Id.ToString(),
ParentId = entity.ParentId.ToString(),
Name = entity.Name,
Code = entity.Code,
OrgType = entity.OrgType,
ShiftType = entity.ShiftType,
Leader = entity.Leader,
Phone = entity.Phone,
Sort = entity.Sort,
Remark = entity.Remark
};
}
public static OrgDto ToDto(this OrgEntity entity)
{
if (entity == null) return null;
return new OrgDto
{
Id = entity.Id.ToString(),
ParentId = entity.ParentId.ToString(),
Name = entity.Name,
Code = entity.Code,
OrgType = entity.OrgType,
ShiftType = entity.ShiftType,
Leader = entity.Leader,
Phone = entity.Phone,
Sort = entity.Sort,
Remark = entity.Remark
};
}
public static List<OrgDto> ToDtoList(this List<OrgEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<OrgDto>();
public static OrgEntity ToEntity(this OrgDto dto)
{
if (dto == null) return null;
return new OrgEntity
{
Id = ParseId(dto.Id),
ParentId = ParseId(dto.ParentId),
Name = dto.Name,
Code = dto.Code,
OrgType = (byte)dto.OrgType,
ShiftType = (byte)dto.ShiftType,
Leader = dto.Leader,
Phone = dto.Phone,
Sort = dto.Sort,
Remark = dto.Remark
};
}
public static OrgOptionDto ToOptionDto(this OrgEntity entity)
{
if (entity == null) return null;
return new OrgOptionDto { Id = entity.Id.ToString(), Name = entity.Name, OrgType = entity.OrgType };
}
public static List<OrgOptionDto> ToOptionDtoList(this List<OrgEntity> entities)
=> entities?.Select(e => e.ToOptionDto()).ToList() ?? new List<OrgOptionDto>();
#endregion
#region
public static AuditLogDto ToDto(this AuditLogEntity entity)
{
if (entity == null) return null;
return new AuditLogDto
{
Id = entity.Id.ToString(),
UserId = entity.UserId.ToString(),
UserName = entity.UserName,
RoleId = entity.RoleId.ToString(),
RoleName = entity.RoleName,
OperationType = entity.OperationType,
OperationTarget = entity.OperationTarget,
TargetId = entity.TargetId.ToString(),
DeviceId = entity.DeviceId.ToString(),
OldValue = entity.OldValue,
NewValue = entity.NewValue,
Ip = entity.Ip,
Description = entity.Description,
OperateTime = entity.OperateTime,
CreateTime = entity.CreateTime
};
}
public static List<AuditLogDto> ToDtoList(this List<AuditLogEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<AuditLogDto>();
#endregion
}
}