EasyArchive 提供完整的 RESTful API,所有接口统一使用 /api/v1 作为前缀,采用 JSON 格式进行数据交换。
| 项目 | 说明 |
|---|---|
| Base URL | http://localhost:8789/api/v1 |
| 认证方式 | JWT Bearer Token |
| 请求格式 | application/json |
| 响应格式 | application/json |
| 字符编码 | UTF-8 |
{
"code": "SUCCESS",
"message": "操作成功",
"requestId": "req-xxxxx",
"data": { ... }
}响应码说明:
| 码值 | 说明 |
|---|---|
SUCCESS |
操作成功 |
INVALID_PARAM |
参数校验失败 |
RESOURCE_NOT_FOUND |
资源不存在 |
PERMISSION_DENIED |
权限不足 |
SYSTEM_ERROR |
系统内部错误 |
BUSINESS_ERROR |
业务逻辑错误 |
{
"code": "SUCCESS",
"data": {
"total": 100,
"page": 1,
"size": 10,
"items": [ ... ]
}
}所有需要认证的接口,在请求头中携带 JWT Token:
Authorization: Bearer <token>
POST /api/v1/auth/login
请求体:
{
"username": "admin",
"password": "admin"
}响应:
{
"code": "SUCCESS",
"data": {
"token": "eyJhbGciOiJIUzI1NiJ9.xxx.yyy",
"expiresIn": 86400
}
}POST /api/v1/auth/logout
鉴权: 需要
POST /api/v1/auth/me
鉴权: 需要
响应:
{
"code": "SUCCESS",
"data": {
"id": 1,
"username": "admin",
"role": "platform_admin",
"datasourcePermissions": [
{
"datasourceId": 1,
"permission": "MANAGE"
}
]
}
}POST /api/v1/auth/change-password
鉴权: 需要
请求体:
{
"oldPassword": "admin",
"newPassword": "new_password_123"
}GET /api/v1/datasources
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| enabled | boolean | 否 | 按启用状态过滤 |
鉴权: 需要
POST /api/v1/datasources
鉴权: 需要
请求体:
{
"name": "生产数据库",
"type": "MYSQL",
"host": "192.168.1.100",
"port": 3306,
"database": "order_db",
"username": "readonly",
"password": "******",
"enabled": true
}PUT /api/v1/datasources/{id}
鉴权: 需要
DELETE /api/v1/datasources/{id}
鉴权: 需要
路径参数:
| 参数 | 类型 | 说明 |
|---|---|---|
| id | Long | 数据源 ID |
POST /api/v1/datasources/test
鉴权: 需要
请求体:
{
"host": "192.168.1.100",
"port": 3306,
"database": "order_db",
"username": "readonly",
"password": "******"
}GET /api/v1/archive/groups
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| enableStatus | Integer | 否 | 按启用状态过滤 |
鉴权: 需要
GET /api/v1/archive/groups/page
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| enableStatus | Integer | 否 | 按启用状态过滤 |
| page | Integer | 否 | 页码,默认 1 |
| size | Integer | 否 | 每页大小,默认 10 |
鉴权: 需要
GET /api/v1/archive/groups/tree
鉴权: 需要
GET /api/v1/archive/groups/{id}
鉴权: 需要
GET /api/v1/archive/groups/{id}/overview
鉴权: 需要
POST /api/v1/archive/groups
鉴权: 需要
请求体:
{
"name": "订单归档分组",
"description": "订单表历史数据归档",
"enabled": true,
"ownerId": 1,
"notifyEnabled": true,
"notifyChannels": ["FEISHU", "IN_APP"],
"notifyUserIds": [1, 2],
"items": {
"byIdRules": [],
"byTimeRules": [
{
"sourceTable": "order",
"targetTable": "order_history",
"timeField": "created_at",
"keepDays": 90
}
]
}
}PUT /api/v1/archive/groups/{id}
鉴权: 需要
PATCH /api/v1/archive/groups/{id}/status
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| enableStatus | Integer | 是 | 0=禁用, 1=启用 |
鉴权: 需要
DELETE /api/v1/archive/groups/{id}
鉴权: 需要
PUT /api/v1/archive/groups/{id}/owner
鉴权: 需要
请求体:
{
"newOwnerUserId": 3
}POST /api/v1/archive/groups/{id}/trigger
鉴权: 需要
POST /api/v1/archive/groups/{id}/cancel-active-task
鉴权: 需要
请求体(可选):
{
"cancelReason": "手动取消"
}| 方法 | 路径 | 说明 | 鉴权 |
|---|---|---|---|
| GET | /api/v1/archive-group-items/by-id |
查询规则列表 | ✅ |
| POST | /api/v1/archive-group-items/by-id |
新增规则 | ✅ |
| PUT | /api/v1/archive-group-items/by-id/{id} |
更新规则 | ✅ |
| DELETE | /api/v1/archive-group-items/by-id/{id} |
删除规则 | ✅ |
按 ID 规则请求体:
{
"groupId": 1,
"sourceTable": "order",
"targetTable": "order_history",
"startId": 1,
"endId": 1000000,
"stepRds": 10000
}| 方法 | 路径 | 说明 | 鉴权 |
|---|---|---|---|
| GET | /api/v1/archive-group-items/by-time |
查询规则列表 | ✅ |
| POST | /api/v1/archive-group-items/by-time |
新增规则 | ✅ |
| PUT | /api/v1/archive-group-items/by-time/{id} |
更新规则 | ✅ |
| DELETE | /api/v1/archive-group-items/by-time/{id} |
删除规则 | ✅ |
按时间规则请求体:
{
"groupId": 1,
"sourceTable": "order_log",
"targetTable": "order_log_history",
"timeField": "created_at",
"startTime": "2023-01-01 00:00:00",
"keepDays": 90,
"stepMinutes": 60
}GET /api/v1/archive-tasks
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | Integer | 否 | 页码,默认 1 |
| size | Integer | 否 | 每页大小,默认 10 |
| status | Integer | 否 | 按任务状态过滤 |
| groupId | Long | 否 | 按分组 ID 过滤 |
鉴权: 需要
POST /api/v1/archive-tasks
鉴权: 需要
请求体:
{
"groupId": 1
}GET /api/v1/archive-tasks/{taskId}
鉴权: 需要
GET /api/v1/archive-tasks/{taskId}/logs
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | Integer | 否 | 页码,默认 1 |
| size | Integer | 否 | 每页大小,默认 20 |
鉴权: 需要
POST /api/v1/archive-tasks/{taskId}/cancel
鉴权: 需要
GET /api/v1/dashboard/overview
鉴权: 需要
响应:
{
"code": "SUCCESS",
"data": {
"taskStatusCounts": [
{ "status": 1, "count": 2 },
{ "status": 2, "count": 15 },
{ "status": 3, "count": 1 }
],
"datasourceStatusSummary": {
"enabled": 3,
"disabled": 1,
"total": 4
},
"dailyTaskTrend": [
{ "day": "2024-01-13", "submittedCount": 3, "successCount": 2, "failedCount": 1 },
{ "day": "2024-01-14", "submittedCount": 5, "successCount": 5, "failedCount": 0 },
{ "day": "2024-01-15", "submittedCount": 2, "successCount": 2, "failedCount": 0 }
],
"recentTasks": [ ... ],
"failedTasks": [ ... ]
}
}| 方法 | 路径 | 说明 | 鉴权 |
|---|---|---|---|
| GET | /api/v1/users |
查询用户列表 | ✅ |
| POST | /api/v1/users |
创建用户 | ✅ |
| PUT | /api/v1/users/{id} |
更新用户 | ✅ |
| DELETE | /api/v1/users/{id} |
删除用户 | ✅ |
创建用户请求体:
{
"username": "john",
"password": "password123",
"role": "archive_admin",
"enabled": true
}| 方法 | 路径 | 说明 | 鉴权 |
|---|---|---|---|
| GET | /api/v1/datasource-permissions |
查询权限列表 | ✅ |
| POST | /api/v1/datasource-permissions |
设置权限 | ✅ |
设置权限请求体:
{
"userId": 2,
"datasourceId": 1,
"permission": "MANAGE"
}| 方法 | 路径 | 说明 | 鉴权 |
|---|---|---|---|
| GET | /api/v1/notifications |
获取消息列表 | ✅ |
| GET | /api/v1/notifications/unread-count |
获取未读数 | ✅ |
GET /api/v1/operation-logs
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | Integer | 否 | 页码,默认 1 |
| size | Integer | 否 | 每页大小,默认 10 |
| module | String | 否 | 按模块过滤 |
| action | String | 否 | 按操作类型过滤 |
| startTime | String | 否 | 开始时间 |
| endTime | String | 否 | 结束时间 |
鉴权: 需要
| 错误码 | HTTP 状态码 | 说明 |
|---|---|---|
| INVALID_PARAM | 400 | 请求参数无效 |
| RESOURCE_NOT_FOUND | 404 | 资源不存在 |
| PERMISSION_DENIED | 403 | 权限不足 |
| AUTH_EXPIRED | 401 | Token 已过期 |
| UNAUTHORIZED | 401 | 未认证 |
| SYSTEM_ERROR | 500 | 系统内部错误 |
| BUSY | 503 | 系统忙,请稍后重试 |
const API_BASE = 'http://localhost:8789/api/v1';
// 登录
async function login(username: string, password: string) {
const resp = await fetch(`${API_BASE}/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
const { data } = await resp.json();
return data.token;
}
// 触发归档任务
async function triggerArchive(groupId: number, token: string) {
const resp = await fetch(`${API_BASE}/archive/groups/${groupId}/trigger`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
return await resp.json();
}import requests
API_BASE = 'http://localhost:8789/api/v1'
# 登录
resp = requests.post(f'{API_BASE}/auth/login', json={
'username': 'admin',
'password': 'admin'
})
token = resp.json()['data']['token']
headers = {'Authorization': f'Bearer {token}'}
# 查询任务列表
resp = requests.get(f'{API_BASE}/archive-tasks', headers=headers)
tasks = resp.json()['data']['items']# 登录
curl -X POST http://localhost:8789/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin"}'
# 获取任务列表
curl http://localhost:8789/api/v1/archive-tasks \
-H "Authorization: Bearer YOUR_TOKEN"