# ELADMIN 后台管理系统 ELADMIN 是一个基于 Spring Boot 2.7.18、Spring Data JPA、JWT、Spring Security、Redis 和 Vue 的前后端分离的后台管理系统。该系统采用模块化设计,包含系统管理、代码生成、日志记录和工具集成等核心模块,提供完整的权限控制、用户管理、菜单管理、部门管理等企业级功能。 系统支持多种高级特性,包括基于 RBAC 的权限管理、数据权限控制、接口限流、定时任务调度、在线用户管理、S3 云存储集成、邮件发送和一键部署等运维功能。通过 @Query 注解实现灵活的查询条件构建,通过 @Limit 注解实现接口限流,通过 @Log 注解实现操作日志自动记录。 --- ## 认证授权 API ### 用户登录 登录授权接口,支持 RSA 加密密码传输和图形验证码校验,登录成功后返回 JWT Token 和用户信息。 ```bash # 获取验证码 curl -X GET "http://localhost:8000/auth/code" # 响应示例 # { # "img": "data:image/png;base64,...", # "uuid": "code-key-xxxx-xxxx" # } # 用户登录(密码需 RSA 公钥加密) curl -X POST "http://localhost:8000/auth/login" \ -H "Content-Type: application/json" \ -d '{ "username": "admin", "password": "RSA加密后的密码", "code": "验证码", "uuid": "验证码UUID" }' # 响应示例 # { # "token": "Bearer eyJhbGciOiJIUzI1NiJ9...", # "user": { # "username": "admin", # "nickName": "管理员", # "dept": {"id": 1, "name": "研发部"}, # "roles": [{"id": 1, "name": "超级管理员"}], # "dataScopes": [1, 2, 3] # } # } ``` ### 获取当前用户信息 获取当前登录用户的详细信息,包括角色、权限和数据范围。 ```bash curl -X GET "http://localhost:8000/auth/info" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "username": "admin", # "nickName": "管理员", # "authorities": [{"authority": "admin"}, {"authority": "user:list"}], # "dataScopes": [1, 2, 3] # } ``` ### 退出登录 注销当前用户的登录状态,清除在线用户信息。 ```bash curl -X DELETE "http://localhost:8000/auth/logout" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应: HTTP 200 OK ``` --- ## 用户管理 API ### 查询用户列表 分页查询用户列表,支持按部门、用户名、邮箱等条件过滤,自动应用数据权限控制。 ```bash curl -X GET "http://localhost:8000/api/users?page=0&size=10&deptId=1&blurry=admin" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "username": "admin", # "nickName": "管理员", # "email": "admin@eladmin.vip", # "phone": "18888888888", # "gender": "男", # "enabled": true, # "dept": {"id": 1, "name": "研发部"}, # "roles": [{"id": 1, "name": "超级管理员", "level": 1}] # } # ], # "totalElements": 1 # } ``` ### 新增用户 创建新用户,默认密码为 123456,需要 user:add 权限。 ```bash curl -X POST "http://localhost:8000/api/users" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "username": "testuser", "nickName": "测试用户", "email": "test@eladmin.vip", "phone": "13800138000", "gender": "男", "enabled": true, "dept": {"id": 2}, "roles": [{"id": 2}], "jobs": [{"id": 1}] }' # 响应: HTTP 201 Created ``` ### 修改用户 更新用户信息,自动进行角色级别权限校验。 ```bash curl -X PUT "http://localhost:8000/api/users" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "id": 2, "username": "testuser", "nickName": "测试用户修改", "email": "test2@eladmin.vip", "enabled": true, "dept": {"id": 2}, "roles": [{"id": 2}] }' # 响应: HTTP 204 No Content ``` ### 修改密码 用户修改自己的密码,需要提供旧密码验证。 ```bash curl -X POST "http://localhost:8000/api/users/updatePass" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "oldPass": "RSA加密的旧密码", "newPass": "RSA加密的新密码" }' # 响应: HTTP 200 OK ``` ### 删除用户 批量删除用户,自动校验操作者的角色权限级别。 ```bash curl -X DELETE "http://localhost:8000/api/users" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '[2, 3, 4]' # 响应: HTTP 200 OK ``` --- ## 角色管理 API ### 查询角色列表 分页查询角色列表,支持按名称模糊查询。 ```bash curl -X GET "http://localhost:8000/api/roles?page=0&size=10&blurry=管理" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "name": "超级管理员", # "level": 1, # "description": "拥有所有权限", # "dataScope": "全部", # "menus": [{"id": 1, "title": "系统管理"}], # "depts": [] # } # ], # "totalElements": 1 # } ``` ### 新增角色 创建新角色,需要 roles:add 权限且角色级别不能高于当前用户。 ```bash curl -X POST "http://localhost:8000/api/roles" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "name": "测试角色", "level": 3, "description": "测试角色描述", "dataScope": "本级" }' # 响应: HTTP 201 Created ``` ### 修改角色菜单 为角色分配菜单权限。 ```bash curl -X PUT "http://localhost:8000/api/roles/menu" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "id": 2, "menus": [{"id": 1}, {"id": 2}, {"id": 3}] }' # 响应: HTTP 204 No Content ``` --- ## 菜单管理 API ### 获取前端菜单 根据当前用户权限构建前端路由菜单树。 ```bash curl -X GET "http://localhost:8000/api/menus/build" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # [ # { # "name": "System", # "path": "/system", # "hidden": false, # "component": "Layout", # "meta": {"title": "系统管理", "icon": "system"}, # "children": [ # { # "name": "User", # "path": "user", # "component": "system/user/index", # "meta": {"title": "用户管理", "icon": "peoples"} # } # ] # } # ] ``` ### 查询菜单列表 查询菜单列表,支持按标题和日期范围过滤。 ```bash curl -X GET "http://localhost:8000/api/menus?blurry=用户&page=0&size=10" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "title": "用户管理", # "path": "user", # "component": "system/user/index", # "icon": "peoples", # "type": 1, # "permission": "user:list", # "pid": 0, # "subCount": 0 # } # ], # "totalElements": 1 # } ``` ### 新增菜单 创建新菜单项,支持目录、菜单和按钮三种类型。 ```bash curl -X POST "http://localhost:8000/api/menus" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "title": "测试菜单", "path": "test", "component": "system/test/index", "icon": "code", "type": 1, "permission": "test:list", "pid": 1, "sort": 999, "hidden": false, "cache": true }' # 响应: HTTP 201 Created ``` --- ## 部门管理 API ### 查询部门树 查询部门列表,自动构建树形结构。 ```bash curl -X GET "http://localhost:8000/api/dept?enabled=true" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "name": "研发部", # "enabled": true, # "pid": 0, # "subCount": 2, # "children": [ # {"id": 2, "name": "前端组", "pid": 1, "subCount": 0}, # {"id": 3, "name": "后端组", "pid": 1, "subCount": 0} # ] # } # ], # "totalElements": 3 # } ``` ### 新增部门 创建新部门。 ```bash curl -X POST "http://localhost:8000/api/dept" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "name": "测试部门", "enabled": true, "pid": 1, "sort": 10 }' # 响应: HTTP 201 Created ``` --- ## 定时任务 API ### 查询定时任务列表 分页查询定时任务列表。 ```bash curl -X GET "http://localhost:8000/api/jobs?page=0&size=10" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "jobName": "测试任务", # "beanName": "testTask", # "methodName": "run", # "params": "", # "cronExpression": "0 0 12 * * ?", # "isPause": false, # "description": "每天中午12点执行" # } # ], # "totalElements": 1 # } ``` ### 新增定时任务 创建新的定时任务,Bean 必须是 Spring 管理的 @Service。 ```bash curl -X POST "http://localhost:8000/api/jobs" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "jobName": "数据同步任务", "beanName": "dataSyncTask", "methodName": "sync", "params": "", "cronExpression": "0 0 2 * * ?", "isPause": false, "description": "每天凌晨2点同步数据" }' # 响应: HTTP 201 Created ``` ### 执行定时任务 立即执行指定的定时任务。 ```bash curl -X PUT "http://localhost:8000/api/jobs/exec/1" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应: HTTP 204 No Content ``` ### 暂停/恢复定时任务 切换定时任务的暂停状态。 ```bash curl -X PUT "http://localhost:8000/api/jobs/1" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应: HTTP 204 No Content ``` --- ## 代码生成 API ### 查询数据库表 获取数据库中的所有表信息。 ```bash curl -X GET "http://localhost:8000/api/generator/tables?name=sys&page=0&size=10" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "tableName": "sys_user", # "createTime": "2024-01-01", # "engine": "InnoDB", # "coding": "utf8mb4", # "remark": "用户表" # } # ], # "totalElements": 1 # } ``` ### 查询表字段 获取指定表的字段信息。 ```bash curl -X GET "http://localhost:8000/api/generator/columns?tableName=sys_user" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "columnName": "user_id", # "columnType": "bigint", # "keyType": "PRI", # "extra": "auto_increment", # "remark": "用户ID", # "notNull": true, # "listShow": true, # "formShow": true # } # ], # "totalElements": 10 # } ``` ### 生成代码 根据表结构生成 CRUD 代码,支持预览、生成和下载三种模式。 ```bash # 预览代码 (type=1) curl -X POST "http://localhost:8000/api/generator/sys_user/1" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应: 生成的代码预览 # 生成代码到项目 (type=0) curl -X POST "http://localhost:8000/api/generator/sys_user/0" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应: HTTP 200 OK # 下载代码压缩包 (type=2) curl -X POST "http://localhost:8000/api/generator/sys_user/2" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -o code.zip ``` --- ## 日志管理 API ### 查询操作日志 分页查询系统操作日志。 ```bash curl -X GET "http://localhost:8000/api/logs?page=0&size=10&blurry=登录" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "username": "admin", # "description": "用户登录", # "method": "POST", # "requestIp": "127.0.0.1", # "address": "本地", # "browser": "Chrome", # "time": 125, # "createTime": "2024-01-01 12:00:00" # } # ], # "totalElements": 100 # } ``` ### 查询错误日志 分页查询系统错误日志。 ```bash curl -X GET "http://localhost:8000/api/logs/error?page=0&size=10" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "username": "admin", # "description": "删除用户", # "method": "DELETE", # "requestIp": "127.0.0.1", # "createTime": "2024-01-01 12:00:00" # } # ], # "totalElements": 5 # } ``` ### 查询错误日志详情 获取错误日志的完整异常堆栈信息。 ```bash curl -X GET "http://localhost:8000/api/logs/error/1" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "id": 1, # "exception": "java.lang.NullPointerException\n\tat com.example.Service.method(Service.java:100)..." # } ``` --- ## 文件存储 API ### 本地存储 - 上传文件 上传文件到本地存储。 ```bash curl -X POST "http://localhost:8000/api/localStorage" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -F "name=测试文件" \ -F "file=@/path/to/file.pdf" # 响应: HTTP 201 Created ``` ### 本地存储 - 上传图片 上传图片文件,仅支持图片格式。 ```bash curl -X POST "http://localhost:8000/api/localStorage/pictures" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -F "file=@/path/to/image.png" # 响应示例 # { # "id": 1, # "realName": "image.png", # "name": "image", # "suffix": "png", # "path": "/file/pictures/20240101/xxx.png", # "type": "图片", # "size": "100KB" # } ``` ### S3 云存储 - 上传文件 上传文件到 S3 兼容的云存储服务。 ```bash curl -X POST "http://localhost:8000/api/s3Storage" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -F "file=@/path/to/document.pdf" # 响应示例 # { # "id": 1, # "errno": 0, # "data": ["https://cdn.example.com/uploads/2024/01/document.pdf"] # } ``` ### S3 云存储 - 查询文件 分页查询 S3 存储的文件列表。 ```bash curl -X GET "http://localhost:8000/api/s3Storage?page=0&size=10" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "fileName": "document.pdf", # "filePath": "uploads/2024/01/document.pdf", # "fileSize": "2MB", # "createTime": "2024-01-01 12:00:00" # } # ], # "totalElements": 10 # } ``` --- ## 邮件服务 API ### 配置邮件服务 配置 SMTP 邮件服务器信息。 ```bash curl -X PUT "http://localhost:8000/api/email" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "host": "smtp.qq.com", "port": "465", "user": "your-email@qq.com", "pass": "授权码", "fromUser": "ELADMIN系统" }' # 响应: HTTP 200 OK ``` ### 发送邮件 发送邮件到指定收件人。 ```bash curl -X POST "http://localhost:8000/api/email" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "tos": ["recipient@example.com"], "subject": "测试邮件", "content": "
邮件内容支持HTML格式
" }' # 响应: HTTP 200 OK ``` --- ## 部署运维 API ### 查询部署列表 查询应用部署配置列表。 ```bash curl -X GET "http://localhost:8000/api/deploy?page=0&size=10" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "appName": "eladmin-api", # "ip": "192.168.1.100", # "port": 8000, # "uploadPath": "/opt/apps/", # "deployPath": "/opt/apps/eladmin/", # "backupPath": "/opt/backup/", # "startScript": "./start.sh", # "deployScript": "./deploy.sh" # } # ], # "totalElements": 1 # } ``` ### 上传并部署 上传应用包并执行部署。 ```bash curl -X POST "http://localhost:8000/api/deploy/upload?id=1" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -F "file=@/path/to/app.jar" # 响应示例 # { # "error": 0, # "id": "app.jar" # } ``` ### 启动/停止服务 控制远程服务器上的应用服务。 ```bash # 启动服务 curl -X POST "http://localhost:8000/api/deploy/startServer" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{"id": 1}' # 响应: "服务启动成功" # 停止服务 curl -X POST "http://localhost:8000/api/deploy/stopServer" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{"id": 1}' # 响应: "服务停止成功" # 查看服务状态 curl -X POST "http://localhost:8000/api/deploy/serverStatus" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{"id": 1}' # 响应: "running" 或 "stopped" ``` --- ## 服务监控 API ### 获取服务器监控信息 获取服务器的 CPU、内存、磁盘等监控信息。 ```bash curl -X GET "http://localhost:8000/api/monitor" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "cpu": { # "name": "Intel Core i7", # "coreNum": 8, # "used": 25.5, # "free": 74.5 # }, # "memory": { # "total": "16GB", # "used": "8GB", # "free": "8GB", # "usageRate": 50.0 # }, # "disk": { # "total": "500GB", # "used": "200GB", # "free": "300GB", # "usageRate": 40.0 # }, # "jvm": { # "jdkVersion": "1.8.0_291", # "maxMemory": "4GB", # "usedMemory": "1.5GB", # "runTime": "10天5小时" # } # } ``` --- ## 字典管理 API ### 查询字典列表 查询系统字典配置。 ```bash curl -X GET "http://localhost:8000/api/dict?page=0&size=10&blurry=状态" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." # 响应示例 # { # "content": [ # { # "id": 1, # "name": "user_status", # "description": "用户状态", # "dictDetails": [ # {"id": 1, "label": "激活", "value": "true", "sort": 1}, # {"id": 2, "label": "禁用", "value": "false", "sort": 2} # ] # } # ], # "totalElements": 1 # } ``` ### 新增字典 创建新的字典配置。 ```bash curl -X POST "http://localhost:8000/api/dict" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \ -H "Content-Type: application/json" \ -d '{ "name": "order_status", "description": "订单状态" }' # 响应: HTTP 201 Created ``` --- ## 核心注解使用 ### @Query 查询注解 用于构建动态查询条件,支持多种查询类型。 ```java // 查询条件 DTO 示例 public class UserQueryCriteria { // 精确匹配 @Query private Long id; // 模糊查询 @Query(type = Query.Type.INNER_LIKE) private String username; // 多字段模糊搜索 @Query(blurry = "email,username,nickName") private String blurry; // 范围查询 @Query(type = Query.Type.BETWEEN) private List