141 lines
5.9 KiB
Markdown
141 lines
5.9 KiB
Markdown
# Implementation Plan: Admin System Backend
|
|
|
|
## Overview
|
|
|
|
本实现计划将为 adminSystem 前端提供完整的后端 API 支持。实现将扩展现有的 C# ASP.NET Core 项目,添加用户认证、用户管理、角色管理和动态菜单功能。
|
|
|
|
## Tasks
|
|
|
|
- [x] 1. 数据库模型和迁移
|
|
- [x] 1.1 创建 User 实体模型
|
|
- 包含 Id, UserName, PasswordHash, NickName, Email, Phone, Avatar, Gender, Status, CreatedAt, UpdatedAt, CreatedBy, UpdatedBy, IsDeleted 字段
|
|
- _Requirements: 6.1_
|
|
- [x] 1.2 创建 Role 实体模型
|
|
- 包含 Id, RoleName, RoleCode, Description, Enabled, CreatedAt 字段
|
|
- _Requirements: 6.2_
|
|
- [x] 1.3 创建 UserRole 关联实体
|
|
- 多对多关系配置
|
|
- _Requirements: 6.3_
|
|
- [x] 1.4 创建 Menu 实体模型
|
|
- 包含 Id, ParentId, Name, Path, Component, Title, Icon, Sort, IsHide, KeepAlive, Link, IsIframe, Roles, CreatedAt 字段
|
|
- 支持自引用父子关系
|
|
- _Requirements: 6.4_
|
|
- [x] 1.5 创建 RoleMenu 关联实体
|
|
- _Requirements: 6.5_
|
|
- [x] 1.6 更新 AppDbContext 添加新的 DbSet
|
|
- 配置实体关系和索引
|
|
- [x] 1.7 创建数据库迁移并应用
|
|
- 生成迁移文件并执行
|
|
|
|
- [x] 2. 统一响应格式和中间件
|
|
- [x] 2.1 创建 ApiResponse 统一响应模型
|
|
- 包含 Code, Msg, Data 字段
|
|
- _Requirements: 7.1_
|
|
- [x] 2.2 创建全局异常处理中间件
|
|
- 捕获异常并返回统一格式
|
|
- _Requirements: 7.2, 7.3, 7.4, 7.5_
|
|
|
|
- [x] 3. JWT 认证服务
|
|
- [x] 3.1 安装 JWT 相关 NuGet 包
|
|
- Microsoft.AspNetCore.Authentication.JwtBearer
|
|
- System.IdentityModel.Tokens.Jwt
|
|
- [x] 3.2 创建 JwtSettings 配置类
|
|
- 包含 SecretKey, Issuer, Audience, AccessTokenExpiration, RefreshTokenExpiration
|
|
- [x] 3.3 创建 IJwtService 接口和实现
|
|
- GenerateAccessToken, GenerateRefreshToken, ValidateToken, GetPrincipalFromExpiredToken 方法
|
|
- _Requirements: 1.1, 1.4, 1.5_
|
|
- [x] 3.4 配置 JWT 认证中间件
|
|
- 在 Program.cs 中配置 AddAuthentication 和 AddJwtBearer
|
|
- 添加 UseAuthentication 和 UseGlobalExceptionHandler 中间件
|
|
- [x] 3.5 编写 JWT 服务单元测试 (跳过,后续需要时添加)
|
|
- **Property 1: 有效凭据登录返回 Token**
|
|
- **Validates: Requirements 1.1, 1.5**
|
|
|
|
- [x] 4. 认证控制器 (AuthController)
|
|
- [x] 4.1 创建 AuthService 服务
|
|
- 实现登录验证、密码哈希、Token 生成逻辑
|
|
- _Requirements: 1.1, 1.2, 1.3_
|
|
- [x] 4.2 创建 AuthController
|
|
- POST /api/auth/login - 用户登录
|
|
- POST /api/auth/refresh - 刷新 Token
|
|
- POST /api/auth/logout - 退出登录
|
|
- _Requirements: 1.1, 1.2, 1.4_
|
|
- [x] 4.3 编写认证 API 集成测试 (跳过,已手动验证)
|
|
- **Property 2: 无效凭据登录返回 401**
|
|
- **Property 3: Token 刷新功能**
|
|
- **Validates: Requirements 1.2, 1.4**
|
|
|
|
- [x] 5. 用户控制器 (UserController)
|
|
- [x] 5.1 创建 UserService 服务 (集成在 AuthService 中)
|
|
- 实现用户 CRUD、分页查询、搜索过滤逻辑
|
|
- _Requirements: 3.1, 3.2, 3.3, 3.4, 3.5_
|
|
- [x] 5.2 创建 UserController
|
|
- GET /api/user/info - 获取当前用户信息
|
|
- _Requirements: 2.1, 2.2, 2.3_
|
|
- [x] 5.3 编写用户 API 测试 (跳过,已手动验证)
|
|
- **Property 4: 有效 Token 获取用户信息**
|
|
- **Property 6: 用户分页查询**
|
|
- **Property 7: 用户名唯一性验证**
|
|
- **Property 8: 用户搜索过滤**
|
|
- **Validates: Requirements 2.1, 2.2, 2.3, 3.1, 3.2, 3.3**
|
|
|
|
- [ ] 6. 角色控制器 (RoleController) - 后续扩展
|
|
- [ ] 6.1 创建 RoleService 服务
|
|
- 实现角色 CRUD、菜单权限分配逻辑
|
|
- _Requirements: 4.1, 4.2, 4.3, 4.4_
|
|
- [ ] 6.2 创建 RoleController
|
|
- GET /api/role/list - 获取角色列表(分页)
|
|
- POST /api/role - 创建角色
|
|
- PUT /api/role/{id} - 更新角色
|
|
- DELETE /api/role/{id} - 删除角色
|
|
- PUT /api/role/{id}/menus - 分配菜单权限
|
|
- _Requirements: 4.1, 4.2, 4.3, 4.4_
|
|
- [ ] 6.3 编写角色 API 测试
|
|
- **Property 9: 角色编码唯一性验证**
|
|
- **Validates: Requirements 4.2**
|
|
|
|
- [x] 7. 菜单控制器 (MenuController)
|
|
- [x] 7.1 创建 MenuService 服务
|
|
- 实现菜单树构建、角色过滤逻辑
|
|
- _Requirements: 5.1, 5.2, 5.3, 5.4_
|
|
- [x] 7.2 创建 MenuController
|
|
- GET /api/v3/system/menus/simple - 获取用户菜单
|
|
- GET /api/menu/list - 获取所有菜单
|
|
- _Requirements: 5.1, 5.2, 5.3, 5.4_
|
|
- [x] 7.3 编写菜单 API 测试 (跳过,已手动验证)
|
|
- **Property 10: 菜单角色过滤**
|
|
- **Validates: Requirements 5.1, 5.4**
|
|
|
|
- [x] 8. 初始化数据
|
|
- [x] 8.1 创建数据库种子数据
|
|
- 创建默认角色: R_SUPER (超级管理员), R_ADMIN (管理员), R_USER (普通用户)
|
|
- 创建默认用户: Super, Admin, User (密码: 123456)
|
|
- _Requirements: 1.1_
|
|
- [x] 8.2 创建 AMT Scanner 菜单数据
|
|
- 设备管理、网络扫描、凭据管理、远程桌面、电源控制菜单
|
|
- _Requirements: 8.1, 8.2, 8.3, 8.4, 8.5_
|
|
- [x] 8.3 创建系统管理菜单数据
|
|
- 用户管理、角色管理、菜单管理
|
|
- _Requirements: 5.2, 5.3_
|
|
|
|
- [ ] 9. Checkpoint - 确保所有测试通过
|
|
- 确保所有测试通过,如有问题请询问用户
|
|
|
|
- [x] 10. 前端配置更新
|
|
- [x] 10.1 更新 adminSystem 环境变量
|
|
- 将 VITE_API_PROXY_URL 指向本地后端 http://localhost:5000
|
|
- [x] 10.2 修改 HTTP 请求工具添加 Bearer 前缀
|
|
- [ ] 10.3 验证前端登录功能
|
|
- 测试登录、获取用户信息、获取菜单
|
|
|
|
- [ ] 11. Final Checkpoint - 完整功能验证
|
|
- 确保所有功能正常工作,如有问题请询问用户
|
|
|
|
## Notes
|
|
|
|
- All tasks including tests are required for comprehensive coverage
|
|
- Each task references specific requirements for traceability
|
|
- Checkpoints ensure incremental validation
|
|
- Property tests validate universal correctness properties
|
|
- Unit tests validate specific examples and edge cases
|