Files
X-Agents/teams/web/field-mapping.md
2026-03-11 14:26:47 +08:00

90 lines
2.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.
# 后端需求 - 字段映射保存与读取
## 问题描述
前端 Edit Mapping 页面中用户输入的字段中文映射名mapped_name在保存后第二次打开时丢失了。
## 原因分析
1. **保存时**:前端只保存了表级别信息,没有保存字段的中文映射
2. **加载时**:前端每次都从 `/database/check` 重新获取表结构,没有读取已保存的映射数据
## 需求
### 1. 保存字段映射
前端保存时需要传递每个字段的中文映射名,后端需要存储这些数据。
请求结构:
```json
{
"name": "数据库名",
"sub_tables": [
{
"parent_table": "users",
"sub_table_name": "用户表",
"sub_table_comment": "用户表",
"fields": [
{
"column_name": "id",
"mapped_name": "编号"
},
{
"column_name": "username",
"mapped_name": "用户名"
}
]
}
]
}
```
### 2. 返回字段映射
后端在返回表结构时,需要同时返回已保存的字段映射信息。
返回结构:
```json
{
"success": true,
"tables": [
{
"table_name": "users",
"table_comment": "用户表",
"ddl": "...",
"columns": [
{
"column_name": "id",
"data_type": "int",
"column_type": "int(10)",
"column_comment": "",
"mapped_name": "编号"
},
{
"column_name": "username",
"data_type": "varchar",
"column_type": "varchar(50)",
"column_comment": "用户名",
"mapped_name": "用户名"
}
]
}
]
}
```
### 3. 数据存储
- 可以在 `sub_table_info` 表中增加 `fields` JSON 字段存储字段映射
- 或者创建新的关联表 `sub_table_fields`
## 影响范围
- `server/internal/service/database_service.go` - Create/Update 方法
- `server/internal/model/` - 数据模型修改
- 子表映射的数据存储结构
## 优先级
高 - 用户输入的映射数据丢失影响使用体验