operations_project/apps/operation/README.md
2025-05-20 15:57:10 +08:00

527 lines
14 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.

# Operation 模块接口文档
## 基础 URL
所有接口的基础路径: `/api/operation/`
## 通用响应格式
所有接口都返回以下格式的响应:
```json
{
"code": 200, // 状态码200表示成功
"message": "操作成功", // 操作结果描述
"data": {} // 数据内容,具体格式根据接口不同而变化
}
```
分页接口的响应格式:
```json
{
"code": 200,
"message": "获取数据成功",
"data": {
"count": 100, // 总记录数
"next": "http://example.com/api/operation/xxx/?page=2", // 下一页链接没有下一页则为null
"previous": null, // 上一页链接没有上一页则为null
"results": [], // 当前页的数据列表
"page": 1, // 当前页码
"pages": 10, // 总页数
"page_size": 10 // 每页记录数
}
}
```
## 接口列表
### 1. 运营账号管理
#### 1.1 获取运营账号列表
- **URL**: `/operators/`
- **方法**: GET
- **参数**:
- `page`: 页码默认1
- `page_size`: 每页记录数默认10
- **响应示例**:
```json
{
"code": 200,
"message": "获取运营账号列表成功",
"data": {
"count": 10,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"username": "operator1",
"real_name": "张三",
"email": "zhangsan@example.com",
"phone": "13800138000",
"position": "editor",
"department": "内容部",
"is_active": true,
"created_at": "2023-09-01T10:00:00Z",
"updated_at": "2023-09-01T10:00:00Z"
}
],
"page": 1,
"pages": 1,
"page_size": 10
}
}
```
#### 1.2 获取运营账号详情
- **URL**: `/operators/{id}/`
- **方法**: GET
- **响应示例**:
```json
{
"code": 200,
"message": "获取运营账号详情成功",
"data": {
"id": 1,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"username": "operator1",
"real_name": "张三",
"email": "zhangsan@example.com",
"phone": "13800138000",
"position": "editor",
"department": "内容部",
"is_active": true,
"created_at": "2023-09-01T10:00:00Z",
"updated_at": "2023-09-01T10:00:00Z"
}
}
```
#### 1.3 创建运营账号
- **URL**: `/operators/`
- **方法**: POST
- **请求参数**:
```json
{
"username": "operator1",
"password": "password123",
"real_name": "张三",
"email": "zhangsan@example.com",
"phone": "13800138000",
"position": "editor",
"department": "内容部"
}
```
- **响应示例**: 同详情接口
#### 1.4 更新运营账号
- **URL**: `/operators/{id}/`
- **方法**: PUT/PATCH
- **请求参数**: 同创建接口PATCH 可部分更新
- **响应示例**: 同详情接口
#### 1.5 删除运营账号
- **URL**: `/operators/{id}/`
- **方法**: DELETE
- **响应示例**:
```json
{
"code": 200,
"message": "运营账号已停用",
"data": null
}
```
### 2. 平台账号管理
#### 2.1 获取平台账号列表
- **URL**: `/platforms/`
- **方法**: GET
- **参数**:
- `page`: 页码默认1
- `page_size`: 每页记录数默认10
- **响应示例**:
```json
{
"code": 200,
"message": "获取平台账号列表成功",
"data": {
"count": 10,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"operator": 1,
"operator_name": "张三",
"status": "active",
"followers_count": 1000,
"description": "测试账号",
"tags": ["科技", "数码"],
"profile_image": "https://example.com/image.jpg",
"last_posting": "2023-09-01T10:00:00Z",
"created_at": "2023-09-01T10:00:00Z",
"updated_at": "2023-09-01T10:00:00Z",
"last_login": "2023-09-01T10:00:00Z",
"platforms": [
{
"platform_name": "youtube",
"account_url": "https://youtube.com/channel/123",
"account_id": "channel123",
"account_name": "测试频道"
}
],
"name": "youtube"
}
],
"page": 1,
"pages": 1,
"page_size": 10
}
}
```
#### 2.2 获取平台账号详情
- **URL**: `/platforms/{id}/`
- **方法**: GET
- **响应示例**: 类似列表但无分页
#### 2.3 创建平台账号
- **URL**: `/platforms/`
- **方法**: POST
- **请求参数**:
```json
{
"operator": 1,
"name": "Shizuku",
"status": "active",
"followers_count": 1000,
"description": "测试频道",
"tags": ["Vlogs", "Foodie"],
"profile_image": "https://example.com/image.jpg",
"platforms": [
{
"platform_name": "youtube",
"account_name": "测试频道",
"account_id": "channel123",
"account_url": "https://youtube.com/channel/123"
}
]
}
```
- **响应示例**: 同详情接口
#### 2.4 更新平台账号
- **URL**: `/platforms/{id}/`
- **方法**: PUT/PATCH
- **请求参数**: 同创建接口PATCH 可部分更新
- **响应示例**: 同详情接口
#### 2.5 删除平台账号
- **URL**: `/platforms/{id}/`
- **方法**: DELETE
- **响应示例**:
```json
{
"code": 200,
"message": "平台账号已删除",
"data": null
}
```
#### 2.6 更新粉丝数
- **URL**: `/platforms/{id}/update_followers/`
- **方法**: POST
- **请求参数**:
```json
{
"followers_count": 2000
}
```
- **响应示例**: 同详情接口
#### 2.7 更新账号资料
- **URL**: `/platforms/{id}/update_profile/`
- **方法**: POST
- **请求参数**:
```json
{
"tags": ["科技", "数码"],
"profile_image": "https://example.com/new_image.jpg",
"last_posting": "2023-09-02T10:00:00Z"
}
```
- **响应示例**: 同详情接口
### 3. 视频管理
#### 3.1 获取视频列表
- **URL**: `/videos/`
- **方法**: GET
- **参数**:
- `page`: 页码默认1
- `page_size`: 每页记录数默认10
- **响应示例**:
```json
{
"code": 200,
"message": "获取视频列表成功",
"data": {
"count": 10,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"platform_account": 1,
"platform_account_name": "测试频道",
"platform_name": "youtube",
"title": "测试视频",
"description": "这是一个测试视频",
"video_url": "https://youtube.com/watch?v=123",
"local_path": "/path/to/video.mp4",
"thumbnail_url": "https://example.com/thumb.jpg",
"status": "published",
"views_count": 1000,
"likes_count": 100,
"comments_count": 50,
"shares_count": 20,
"tags": ["测试", "视频"],
"publish_time": "2023-09-01T10:00:00Z",
"video_id": "v123",
"created_at": "2023-09-01T10:00:00Z",
"updated_at": "2023-09-01T10:00:00Z"
}
],
"page": 1,
"pages": 1,
"page_size": 10
}
}
```
#### 3.2 获取视频详情
- **URL**: `/videos/{id}/`
- **方法**: GET
- **响应示例**: 类似列表但无分页
#### 3.3 创建视频
- **URL**: `/videos/`
- **方法**: POST
- **请求参数**:
```json
{
"platform_account": 1,
"title": "测试视频",
"description": "这是一个测试视频",
"status": "draft",
"tags": ["测试", "视频"]
}
```
- **响应示例**: 同详情接口
#### 3.4 更新视频信息
- **URL**: `/videos/{id}/`
- **方法**: PUT/PATCH
- **请求参数**: 同创建接口PATCH 可部分更新
- **响应示例**: 同详情接口
#### 3.5 删除视频
- **URL**: `/videos/{id}/`
- **方法**: DELETE
- **响应示例**:
```json
{
"code": 200,
"message": "视频记录已删除",
"data": null
}
```
#### 3.6 更新视频统计数据
- **URL**: `/videos/{id}/update_stats/`
- **方法**: POST
- **请求参数**:
```json
{
"views_count": 2000,
"likes_count": 200,
"comments_count": 100,
"shares_count": 50
}
```
- **响应示例**:
```json
{
"code": 200,
"message": "视频统计数据更新成功",
"data": {
"id": 1,
"title": "测试视频",
"views_count": 2000,
"likes_count": 200,
"comments_count": 100,
"shares_count": 50
}
}
```
#### 3.7 发布视频
- **URL**: `/videos/{id}/publish/`
- **方法**: POST
- **请求参数**:
```json
{
"video_url": "https://youtube.com/watch?v=123"
}
```
- **响应示例**:
```json
{
"code": 200,
"message": "视频已成功发布",
"data": {
"id": 1,
"title": "测试视频",
"status": "published",
"video_url": "https://youtube.com/watch?v=123",
"publish_time": "2023-09-02T10:00:00Z"
}
}
```
#### 3.8 上传视频
- **URL**: `/videos/upload_video/`
- **方法**: POST
- **请求参数**:
- `video_file`: 视频文件(multipart/form-data)
- `platform_account`: 平台账号ID
- `title`: 视频标题
- `description`: 视频描述
- `tags`: 视频标签
- **响应示例**:
```json
{
"code": 200,
"message": "视频上传成功",
"data": {
"id": 1,
"title": "测试视频",
"status": "draft"
}
}
```
#### 3.9 手动发布视频
- **URL**: `/videos/{id}/manual_publish/`
- **方法**: POST
- **请求参数**:
```json
{
"video_url": "https://youtube.com/watch?v=123"
}
```
- **响应示例**:
```json
{
"code": 200,
"message": "视频发布成功",
"data": {
"id": 1,
"title": "测试视频",
"status": "published",
"video_url": "https://youtube.com/watch?v=123",
"publish_time": "2023-09-02T10:00:00Z"
}
}
```
## 字段说明
### 运营账号(OperatorAccount)
| 字段名 | 类型 | 说明 |
|------------|-----------|--------------------------------------------------|
| id | Integer | 自增主键ID |
| uuid | UUID | 唯一标识符 |
| username | String | 用户名 |
| password | String | 密码(创建/更新时传入,不会在响应中返回) |
| real_name | String | 真实姓名 |
| email | String | 邮箱 |
| phone | String | 电话号码 |
| position | String | 职位,可选值: editor(编辑)、planner(策划)、operator(运营)、admin(管理员) |
| department | String | 部门 |
| is_active | Boolean | 是否在职 |
| created_at | Datetime | 创建时间 |
| updated_at | Datetime | 更新时间 |
### 平台账号(PlatformAccount)
| 字段名 | 类型 | 说明 |
|----------------|-----------|--------------------------------------------------|
| id | Integer | 自增主键ID |
| operator | Integer | 关联运营账号ID |
| operator_name | String | 运营账号名称(只读) |
| name | String | 自定义账户名称,可用于分类和识别不同平台的账号 |
| platforms | Array | 平台信息数组包含平台名称、账号名称、账号ID、账号URL |
| status | String | 账号状态,可选值: active(正常)、restricted(限流)、suspended(封禁)、inactive(未激活) |
| followers_count| Integer | 粉丝数 |
| description | String | 账号描述 |
| tags | Array | 标签数组 |
| profile_image | String | 账号头像URL |
| last_posting | Datetime | 最后发布时间 |
| created_at | Datetime | 创建时间 |
| updated_at | Datetime | 更新时间 |
| last_login | Datetime | 最后登录时间 |
### 视频(Video)
| 字段名 | 类型 | 说明 |
|----------------------|-----------|--------------------------------------------------|
| id | Integer | 自增主键ID |
| platform_account | Integer | 关联平台账号ID |
| platform_account_name| String | 平台账号名称(只读) |
| platform_name | String | 平台名称(只读) |
| title | String | 视频标题 |
| description | String | 视频描述 |
| video_url | String | 视频URL |
| local_path | String | 本地存储路径 |
| thumbnail_url | String | 缩略图URL |
| status | String | 视频状态,可选值: draft(草稿)、scheduled(已排期)、published(已发布)、failed(失败)、deleted(已删除) |
| views_count | Integer | 观看次数 |
| likes_count | Integer | 点赞数 |
| comments_count | Integer | 评论数 |
| shares_count | Integer | 分享数 |
| tags | Array | 标签数组 |
| publish_time | Datetime | 发布时间 |
| video_id | String | 视频ID |
| created_at | Datetime | 创建时间 |
| updated_at | Datetime | 更新时间 |
</rewritten_file>