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:
@@ -14,7 +14,7 @@ namespace Service.Interface.Config
|
||||
/// <summary>
|
||||
/// 分页查询设备列表(支持关键字搜索编号/名称/类型,可按所属产品筛选)
|
||||
/// </summary>
|
||||
Task<Result<List<IotDeviceDto>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total, string? keyword, long? productId = null);
|
||||
Task<Result<List<IotDeviceDto>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total, string? keyword, long? productId = null, long? gatewayId = null);
|
||||
|
||||
/// <summary>
|
||||
/// 根据 Id 获取设备详情
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
namespace Service.Interface
|
||||
using Model;
|
||||
using Model.Dto.Config;
|
||||
using Model.Entity.Config;
|
||||
using ORM;
|
||||
using SqlSugar;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace Service.Interface.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// 网关管理 服务接口
|
||||
/// </summary>
|
||||
public interface IGatewayService
|
||||
{
|
||||
// TODO: 定义 网关管理 相关方法
|
||||
Task<Result<List<GatewayDto>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total, string? keyword = null, int? protocolType = null);
|
||||
Task<Result<GatewayDto>> GetByIdAsync(long id);
|
||||
Task<Result<GatewayDto>> AddAsync(GatewayDto dto);
|
||||
Task<Result<GatewayDto>> UpdateAsync(GatewayDto dto);
|
||||
Task<Result> DeleteAsync(long id);
|
||||
Task<Result<GatewayTestResultDto>> TestConnectionAsync(long id);
|
||||
Task<Result<List<GatewayOptionDto>>> GetOptionsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using Model;
|
||||
using Model.Dto.System;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Service.Interface
|
||||
{
|
||||
/// <summary>
|
||||
/// 审计日志 服务接口
|
||||
/// </summary>
|
||||
public interface IAuditLogService
|
||||
{
|
||||
/// <summary>分页查询审计日志(可按操作人/操作类型/操作对象/时间段筛选)</summary>
|
||||
Task<Result<List<AuditLogDto>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total,
|
||||
string? keyword = null, string? operationType = null, string? operationTarget = null,
|
||||
DateTime? startTime = null, DateTime? endTime = null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace Service.Interface
|
||||
{
|
||||
/// <summary>
|
||||
/// 审计日志记录器:业务服务注入后一行代码记录关键操作(操作人/角色自动取自当前登录上下文)
|
||||
/// </summary>
|
||||
public interface IAuditRecorder
|
||||
{
|
||||
/// <summary>
|
||||
/// 记录一条审计日志
|
||||
/// </summary>
|
||||
/// <param name="operationType">操作类型(Create/Update/Delete/Login/Command等)</param>
|
||||
/// <param name="operationTarget">操作对象(IotDevice/Gateway/User/Role等)</param>
|
||||
/// <param name="targetId">操作对象Id</param>
|
||||
/// <param name="deviceId">关联设备Id(0=无关)</param>
|
||||
/// <param name="oldValue">操作前值(JSON 或摘要)</param>
|
||||
/// <param name="newValue">操作后值(JSON 或摘要)</param>
|
||||
/// <param name="ip">操作IP(null 自动留空)</param>
|
||||
/// <param name="description">操作描述</param>
|
||||
Task RecordAsync(string operationType, string operationTarget, long targetId,
|
||||
long deviceId = 0, string? oldValue = null, string? newValue = null,
|
||||
string? ip = null, string? description = null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Model;
|
||||
using Model.Dto.System;
|
||||
|
||||
namespace Service.Interface
|
||||
{
|
||||
/// <summary>
|
||||
/// 认证授权 服务接口(登录 / 当前用户 / 修改密码)
|
||||
/// </summary>
|
||||
public interface IAuthService
|
||||
{
|
||||
/// <summary>用户名密码登录,签发 JWT 并返回用户信息+权限列表</summary>
|
||||
Task<Result<LoginResultDto>> LoginAsync(LoginDto dto, string? ip);
|
||||
|
||||
/// <summary>退出登录(记录审计日志,JWT 无状态因此不做服务端吊销)</summary>
|
||||
Task<Result> LogoutAsync();
|
||||
|
||||
/// <summary>获取当前登录用户信息 + 权限列表</summary>
|
||||
Task<Result<LoginResultDto>> GetMeAsync();
|
||||
|
||||
/// <summary>当前用户修改自己的密码</summary>
|
||||
Task<Result> ChangePasswordAsync(ChangePasswordDto dto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Service.Interface
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前登录用户上下文(从 JWT Claims 解析,IOT_API 实现注入)
|
||||
/// </summary>
|
||||
public interface ICurrentUser
|
||||
{
|
||||
bool IsAuthenticated { get; }
|
||||
long UserId { get; }
|
||||
string UserName { get; }
|
||||
List<long> RoleIds { get; }
|
||||
List<string> RoleNames { get; }
|
||||
/// <summary>当前用户拥有的权限编码列表(登录时写入 Token)</summary>
|
||||
List<string> Permissions { get; }
|
||||
/// <summary>数据范围(1=全部, 2=本实验室)</summary>
|
||||
byte DataScope { get; }
|
||||
bool HasPermission(string code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Model;
|
||||
using Model.Dto.System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Service.Interface
|
||||
{
|
||||
/// <summary>
|
||||
/// 组织架构管理 服务接口(公司/实验室/部门/班组树)
|
||||
/// </summary>
|
||||
public interface IOrgService
|
||||
{
|
||||
/// <summary>完整组织树(嵌套子级)</summary>
|
||||
Task<Result<List<OrgTreeDto>>> GetTreeAsync();
|
||||
|
||||
/// <summary>新增组织节点</summary>
|
||||
Task<Result<OrgDto>> AddAsync(OrgDto dto);
|
||||
|
||||
/// <summary>修改组织节点(系统节点层级类型变更需校验无子级)</summary>
|
||||
Task<Result<OrgDto>> UpdateAsync(OrgDto dto);
|
||||
|
||||
/// <summary>删除组织节点(有子级或有用户挂靠时不可删)</summary>
|
||||
Task<Result> DeleteAsync(long id);
|
||||
|
||||
/// <summary>组织下拉选项(平铺)</summary>
|
||||
Task<Result<List<OrgOptionDto>>> GetOptionsAsync();
|
||||
|
||||
/// <summary>取指定组织及其全部子孙组织 Id(数据权限过滤用)</summary>
|
||||
Task<List<long>> GetSubtreeIdsAsync(long orgId);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
using Model;
|
||||
using Model.Dto.System;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Service.Interface
|
||||
{
|
||||
/// <summary>
|
||||
@@ -5,6 +11,27 @@ namespace Service.Interface
|
||||
/// </summary>
|
||||
public interface IRoleService
|
||||
{
|
||||
// TODO: 定义 角色权限管理 相关方法
|
||||
/// <summary>分页查询角色列表(关键字匹配编码/名称)</summary>
|
||||
Task<Result<List<RoleDto>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total, string? keyword = null);
|
||||
|
||||
Task<Result<RoleDto>> GetByIdAsync(long id);
|
||||
|
||||
/// <summary>新增角色(校验编码唯一)</summary>
|
||||
Task<Result<RoleDto>> AddAsync(RoleDto dto);
|
||||
|
||||
/// <summary>修改角色(系统内置角色不允许改编码)</summary>
|
||||
Task<Result<RoleDto>> UpdateAsync(RoleDto dto);
|
||||
|
||||
/// <summary>删除角色(系统内置角色不可删;有关联用户时不可删)</summary>
|
||||
Task<Result> DeleteAsync(long id);
|
||||
|
||||
/// <summary>分配权限(全量覆盖该角色的权限关联)</summary>
|
||||
Task<Result> AssignPermissionsAsync(long roleId, List<long> permissionIds);
|
||||
|
||||
/// <summary>角色下拉选项</summary>
|
||||
Task<Result<List<RoleOptionDto>>> GetOptionsAsync();
|
||||
|
||||
/// <summary>查询全部权限列表</summary>
|
||||
Task<Result<List<PermissionDto>>> GetPermissionsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
using Model;
|
||||
using Model.Dto.System;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Service.Interface
|
||||
{
|
||||
/// <summary>
|
||||
@@ -5,6 +11,30 @@ namespace Service.Interface
|
||||
/// </summary>
|
||||
public interface IUserService
|
||||
{
|
||||
// TODO: 定义 用户管理 相关方法
|
||||
/// <summary>分页查询用户列表(关键字匹配用户名/姓名,可按角色、组织节点筛选;受数据范围约束)</summary>
|
||||
Task<Result<List<UserDto>>> GetPagedAsync(int pageIndex, int pageSize, RefAsync<int> total, string? keyword = null, long? roleId = null, long? orgId = null);
|
||||
|
||||
Task<Result<UserDto>> GetByIdAsync(long id);
|
||||
|
||||
/// <summary>新增用户(校验用户名唯一,密码必填,可同时分配角色)</summary>
|
||||
Task<Result<UserDto>> AddAsync(UserDto dto);
|
||||
|
||||
/// <summary>修改用户(不改密码,角色走 AssignRoles)</summary>
|
||||
Task<Result<UserDto>> UpdateAsync(UserDto dto);
|
||||
|
||||
/// <summary>删除用户(软删,同时清理角色关联)</summary>
|
||||
Task<Result> DeleteAsync(long id);
|
||||
|
||||
/// <summary>分配角色(全量覆盖该用户的角色关联)</summary>
|
||||
Task<Result> AssignRolesAsync(long userId, List<long> roleIds);
|
||||
|
||||
/// <summary>管理员重置用户密码</summary>
|
||||
Task<Result> ResetPasswordAsync(long userId, string newPassword);
|
||||
|
||||
/// <summary>启用/禁用用户</summary>
|
||||
Task<Result> SetEnabledAsync(long userId, bool enabled);
|
||||
|
||||
/// <summary>用户下拉选项</summary>
|
||||
Task<Result<List<UserOptionDto>>> GetOptionsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user