datai/docs/archive/api-docs/integration/DataiIntegrationBatchController/0009-sync-batch-data.md

134 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 接口文档:同步批次数据
## 接口信息
- **接口名称**: 同步批次数据
- **接口路径**: /integration/batch/{id}/sync
- **请求方法**: POST
- **模块归属**: 数据批次管理
- **版本号**: v1.0
- **创建日期**: 2026-01-09
- **最后更新**: 2026-01-09
## 功能描述
同步指定批次的数据,执行数据同步操作并更新批次状态和统计信息。
## 请求参数
### 路径参数
| 参数名 | 类型 | 必填 | 描述 | 示例 |
|--------|------|------|------|------|
| id | Integer | 是 | 批次ID | 1 |
## 响应数据
### 成功响应
**HTTP 状态码**: 200 OK
```json
{
"code": 200,
"message": "操作成功",
"data": {
"success": true,
"message": "批次数据同步成功",
"batchId": 1,
"api": "Account",
"label": "账户",
"syncNum": 1000
}
}
```
### 失败响应
**HTTP 状态码**: 400/401/404/500
```json
{
"code": 404,
"message": "批次不存在",
"data": null
}
```
## 接口示例
### 请求示例
```bash
curl -X POST "http://localhost:8080/integration/batch/1/sync" \
-H "Authorization: Bearer [token]"
```
### 响应示例
**成功**:
```json
{
"code": 200,
"message": "操作成功",
"data": {
"success": true,
"message": "批次数据同步成功",
"batchId": 1,
"api": "Account",
"label": "账户",
"syncNum": 1000
}
}
```
**失败**:
```json
{
"code": 404,
"message": "批次不存在",
"data": null
}
```
## 错误处理
- **401 未授权**: 用户没有访问权限
- **404 未找到**: 批次不存在
- **500 服务器错误**: 服务器内部错误,可能是数据库连接失败或同步操作失败等
## 注意事项
- 接口需要 `integration:batch:sync` 权限
- 批次ID必须为整数类型
- 同步操作可能需要较长时间,请确保网络连接稳定
- 同步过程中会更新批次状态和统计信息
## 相关接口
- [获取批次同步统计信息](http://localhost:8080/integration/batch/{id}/statistics) - 获取批次同步统计信息
- [重试失败的批次](http://localhost:8080/integration/batch/{id}/retry) - 重试失败的批次
## 实现细节
- 接口通过调用 `dataiIntegrationBatchService.syncBatchData(id)` 方法同步批次数据
- 会执行完整的数据同步流程,包括数据查询、处理和保存
- 同步完成后会更新批次状态和统计信息
- 会记录同步历史和日志信息
## 测试信息
### 测试环境
- **环境**: 开发环境
- **版本**: v1.0
### 测试用例
| 测试场景 | 输入参数 | 预期结果 | 实际结果 | 状态 |
|----------|----------|----------|----------|------|
| 同步存在的批次 | id=1存在 | 操作成功,返回同步结果 | 操作成功,返回同步结果 | 通过 |
| 同步不存在的批次 | id=999不存在 | 操作失败,返回错误信息 | 操作失败,返回错误信息 | 通过 |
| 同步数据量较大的批次 | id=2数据量大 | 操作成功,返回同步结果 | 操作成功,返回同步结果 | 通过 |