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
+56
View File
@@ -0,0 +1,56 @@
namespace Model.Dto.Config
{
/// <summary>
/// 网关 DTO
/// </summary>
public class GatewayDto
{
public string Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public int ProtocolType { get; set; }
// TCP
public string? Host { get; set; }
public int? Port { get; set; }
// 串口
public string? ComPort { get; set; }
public int? BaudRate { get; set; }
public byte? DataBits { get; set; }
public byte? StopBits { get; set; }
public byte? Parity { get; set; }
// S7
public string? CpuType { get; set; }
public byte? Rack { get; set; }
public byte? Slot { get; set; }
// 状态
public bool IsEnabled { get; set; }
public byte OnlineStatus { get; set; }
public DateTime? LastConnectedTime { get; set; }
public string? LastError { get; set; }
public string? Remark { get; set; }
public DateTime? CreateTime { get; set; }
}
/// <summary>
/// 网关下拉选项 DTO(设备表单选用)
/// </summary>
public class GatewayOptionDto
{
public string Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}
/// <summary>
/// 测试连接结果 DTO
/// </summary>
public class GatewayTestResultDto
{
public bool Success { get; set; }
public string Message { get; set; }
}
}
+5 -2
View File
@@ -25,8 +25,11 @@ namespace Model.Dto.Config
/// <summary>所属产品型号/名称(只读展示)</summary>
public string? ProductName { get; set; }
/// <summary>所属网关Code</summary>
public string GatewayCode { get; set; }
/// <summary>所属网关Idstring0=未分配)</summary>
public string GatewayId { get; set; }
/// <summary>所属网关名称(只读展示)</summary>
public string? GatewayName { get; set; }
/// <summary>从站地址</summary>
public byte SlaveId { get; set; }
+56
View File
@@ -0,0 +1,56 @@
namespace Model.Dto.System
{
/// <summary>
/// 组织架构树节点 DTO(嵌套子级;含数据权限摘要)
/// </summary>
public class OrgTreeDto
{
public string Id { get; set; }
public string ParentId { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public int OrgType { get; set; }
public int ShiftType { get; set; }
public string? Leader { get; set; }
public string? Phone { get; set; }
public int Sort { get; set; }
public string? Remark { get; set; }
public List<OrgTreeDto> Children { get; set; } = new();
/// <summary>直接挂靠用户数</summary>
public int UserCount { get; set; }
/// <summary>本组织及下级用户总数</summary>
public int TotalUserCount { get; set; }
/// <summary>数据权限摘要:本组织及下级用户的角色+数据范围(去重,如「实验室管理员·本组织及下级」)</summary>
public List<string> ScopeSummary { get; set; } = new();
}
/// <summary>
/// 组织架构编辑 DTO(新增/修改用)
/// </summary>
public class OrgDto
{
public string Id { get; set; }
public string ParentId { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public int OrgType { get; set; }
public int ShiftType { get; set; }
public string? Leader { get; set; }
public string? Phone { get; set; }
public int Sort { get; set; }
public string? Remark { get; set; }
}
/// <summary>
/// 组织下拉选项 DTO(用户表单选组织用)
/// </summary>
public class OrgOptionDto
{
public string Id { get; set; }
public string Name { get; set; }
public int OrgType { get; set; }
}
}
+37
View File
@@ -0,0 +1,37 @@
namespace Model.Dto.System
{
/// <summary>
/// 权限 DTO
/// </summary>
public class PermissionDto
{
public string Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public string? Group { get; set; }
public byte IsSystem { get; set; }
public int Sort { get; set; }
}
/// <summary>
/// 审计日志 DTO
/// </summary>
public class AuditLogDto
{
public string Id { get; set; }
public string UserId { get; set; }
public string? UserName { get; set; }
public string RoleId { get; set; }
public string? RoleName { get; set; }
public string OperationType { get; set; }
public string OperationTarget { get; set; }
public string TargetId { get; set; }
public string DeviceId { get; set; }
public string? OldValue { get; set; }
public string? NewValue { get; set; }
public string? Ip { get; set; }
public string? Description { get; set; }
public DateTime OperateTime { get; set; }
public DateTime? CreateTime { get; set; }
}
}
+31
View File
@@ -0,0 +1,31 @@
namespace Model.Dto.System
{
/// <summary>
/// 角色 DTO
/// </summary>
public class RoleDto
{
public string Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public byte DataScope { get; set; }
public byte IsSystem { get; set; }
public int Sort { get; set; }
public string? Remark { get; set; }
public DateTime? CreateTime { get; set; }
/// <summary>角色的权限Id列表(分配权限用)</summary>
public List<string>? PermissionIds { get; set; }
/// <summary>角色的权限编码列表(展示用)</summary>
public List<string>? PermissionCodes { get; set; }
}
/// <summary>
/// 角色下拉选项 DTO
/// </summary>
public class RoleOptionDto
{
public string Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}
}
+68
View File
@@ -0,0 +1,68 @@
namespace Model.Dto.System
{
/// <summary>
/// 用户 DTO
/// </summary>
public class UserDto
{
public string Id { get; set; }
public string UserName { get; set; }
public string? RealName { get; set; }
public string? Email { get; set; }
public string? Phone { get; set; }
public string OrgId { get; set; }
public string? OrgName { get; set; }
public string? Position { get; set; }
public string? SkillTags { get; set; }
public byte IsEnabled { get; set; }
public DateTime? LastLoginTime { get; set; }
public string? Avatar { get; set; }
public string? Remark { get; set; }
public DateTime? CreateTime { get; set; }
/// <summary>用户的角色Id列表(分配角色用)</summary>
public List<string>? RoleIds { get; set; }
/// <summary>用户的角色名称(展示用,逗号分隔)</summary>
public string? RoleNames { get; set; }
/// <summary>初始密码(仅新增用户时传入,不回显)</summary>
public string? InitialPassword { get; set; }
}
/// <summary>
/// 登录请求 DTO
/// </summary>
public class LoginDto
{
public string UserName { get; set; }
public string Password { get; set; }
}
/// <summary>
/// 登录结果 DTO
/// </summary>
public class LoginResultDto
{
public string Token { get; set; }
public string RefreshToken { get; set; }
public UserDto User { get; set; }
public List<string> Permissions { get; set; } = new();
}
/// <summary>
/// 修改密码 DTO
/// </summary>
public class ChangePasswordDto
{
public string OldPassword { get; set; }
public string NewPassword { get; set; }
}
/// <summary>
/// 用户下拉选项 DTO
/// </summary>
public class UserOptionDto
{
public string Id { get; set; }
public string UserName { get; set; }
public string? RealName { get; set; }
}
}
+127
View File
@@ -0,0 +1,127 @@
using SqlSugar;
namespace Model.Entity.Config
{
/// <summary>
/// 网关(通讯通道):TCP 类存 IP+端口,串口类存 COM+波特率,S7 类额外存 CPU/Rack/Slot。
/// 同一网关下多设备用从站号(SlaveId)区分。
/// </summary>
public class GatewayEntity : BaseEntity
{
/// <summary>
/// 网关编码(唯一,如 GW-ENV-01)
/// </summary>
[SugarColumn(ColumnDescription = "网关编码", Length = 64)]
public string Code { get; set; }
/// <summary>
/// 网关名称
/// </summary>
[SugarColumn(ColumnDescription = "网关名称", Length = 100)]
public string Name { get; set; }
/// <summary>
/// 通讯协议类型(决定连接参数组:TCP/Serial/S7
/// </summary>
[SugarColumn(ColumnDescription = "通讯协议类型")]
public IotDeviceProtocolEnum ProtocolType { get; set; } = IotDeviceProtocolEnum.ModbusTcp;
#region TCP ModbusTcp / Tcp / S7 使
/// <summary>
/// IP 地址
/// </summary>
[SugarColumn(ColumnDescription = "IP地址", Length = 50, IsNullable = true)]
public string? Host { get; set; }
/// <summary>
/// 端口号(ModbusTcp 默认 502S7 默认 102
/// </summary>
[SugarColumn(ColumnDescription = "端口号", IsNullable = true)]
public int? Port { get; set; }
#endregion
#region ModbusRtu / Serial 使
/// <summary>
/// 串口号(如 COM3
/// </summary>
[SugarColumn(ColumnDescription = "串口号", Length = 20, IsNullable = true)]
public string? ComPort { get; set; }
/// <summary>
/// 波特率(默认 9600
/// </summary>
[SugarColumn(ColumnDescription = "波特率", IsNullable = true)]
public int? BaudRate { get; set; }
/// <summary>
/// 数据位(默认 8
/// </summary>
[SugarColumn(ColumnDescription = "数据位", IsNullable = true)]
public byte? DataBits { get; set; }
/// <summary>
/// 停止位(1/2,默认 1
/// </summary>
[SugarColumn(ColumnDescription = "停止位", IsNullable = true)]
public byte? StopBits { get; set; }
/// <summary>
/// 校验位(0=None 1=Odd 2=Even,默认 0
/// </summary>
[SugarColumn(ColumnDescription = "校验位", IsNullable = true)]
public byte? Parity { get; set; }
#endregion
#region S7 S7
/// <summary>
/// S7 CPU 型号(如 S71200、S71500
/// </summary>
[SugarColumn(ColumnDescription = "S7 CPU型号", Length = 20, IsNullable = true)]
public string? CpuType { get; set; }
/// <summary>
/// S7 Rack(默认 0
/// </summary>
[SugarColumn(ColumnDescription = "S7 Rack", IsNullable = true)]
public byte? Rack { get; set; }
/// <summary>
/// S7 Slot(默认 1
/// </summary>
[SugarColumn(ColumnDescription = "S7 Slot", IsNullable = true)]
public byte? Slot { get; set; }
#endregion
#region
/// <summary>
/// 是否启用
/// </summary>
[SugarColumn(ColumnDescription = "是否启用")]
public bool IsEnabled { get; set; } = true;
/// <summary>
/// 在线状态(0=离线 1=在线 3=异常,由测试连接更新)
/// </summary>
[SugarColumn(ColumnDescription = "在线状态")]
public byte OnlineStatus { get; set; }
/// <summary>
/// 最后连接成功时间
/// </summary>
[SugarColumn(ColumnDescription = "最后连接时间", IsNullable = true)]
public DateTime? LastConnectedTime { get; set; }
/// <summary>
/// 最近错误
/// </summary>
[SugarColumn(ColumnDescription = "最近错误", Length = 500, IsNullable = true)]
public string? LastError { get; set; }
#endregion
/// <summary>
/// 备注
/// </summary>
[SugarColumn(ColumnDescription = "备注", Length = 500, IsNullable = true)]
public string? Remark { get; set; }
}
}
+3 -3
View File
@@ -34,10 +34,10 @@ namespace Model.Entity.Config
public long ProductId { get; set; }
/// <summary>
/// 所属网关Code(对应网关实体/通道的标识,连接时据此刻查找 IP/端口/串口
/// 所属网关Id(关联 GatewayEntity.Id0=未分配
/// </summary>
[SugarColumn(ColumnDescription = "所属网关Code", Length = 64)]
public string GatewayCode { get; set; }
[SugarColumn(ColumnDescription = "所属网关Id", DefaultValue = "0")]
public long GatewayId { get; set; }
/// <summary>
/// 从站地址(协议从站号,网关下区分设备)
+50
View File
@@ -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 = "操作人角色Id0=无/多角色)", 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 = "操作对象Id0=无具体Id", DefaultValue = "0")]
public long TargetId { get; set; }
[SugarColumn(ColumnName = "DeviceId", ColumnDescription = "关联设备Id0=无关设备)", 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; }
}
}
+40
View File
@@ -0,0 +1,40 @@
using SqlSugar;
namespace Model.Entity.System
{
/// <summary>
/// 组织架构表(树形:公司/实验室/部门/班组,ParentId 自关联;班组带白/夜班)
/// </summary>
[SugarTable("sys_org")]
public class OrgEntity : BaseEntity
{
[SugarColumn(ColumnName = "ParentId", ColumnDescription = "父级组织Id0=根节点)", 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; }
}
}
+26
View File
@@ -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; }
}
}
+29
View File
@@ -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; }
}
}
+47
View File
@@ -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; }
}
}
+17
View File
@@ -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; }
}
}
+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
}
}