Files
app-api/docs/headphone-impedance.md
2026-07-06 10:41:41 +08:00

57 lines
2.0 KiB
Markdown
Raw Permalink 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.
# 用户上报耳机阻抗(最新值)需求文档
## 背景与目标
- 用户在设备上报其耳机阻抗值,用于后续业务使用(本需求仅覆盖**存储**与**去重更新**规则)。
- 一个 **MAC 地址代表一个用户**
- 一个用户可以上报/维护多个耳机(以“耳机品牌 + 耳机型号”区分)。
## 核心字段
- 设备:`Luxsin-X8` / `Luxsin-X9`
- 阻抗值:整数,单位 Ω
- 耳机品牌:字符串
- 耳机型号:字符串
- 设备 MAC 地址:字符串(用户标识)
- 设备 IP 地址:服务端获取(与 `reportDevInfo` 接口一致),落库保存**最新值**
## 去重与更新规则(关键)
- 唯一判定条件:`mac_addr + headphone_brand + headphone_model`
- 品牌/型号的对比规则:对比前做 `trim`(去首尾空格)+ `lower`(忽略大小写)
- 若命中同一条(按上述规则),则:
- 更新最新 `impedance_ohm`
- 覆盖更新 `device_model`
- 覆盖更新 `ip_addr`
- 更新 `update_at`
- 不保留历史:同一条记录始终反映该用户该耳机的**最新阻抗值**
## 数据库设计
### 表
- 表名:`user_headphone_impedance`
- 建表脚本:`sql/user_headphone_impedance.sql`
### 字段说明
- `mac_addr`:用户标识(设备 MAC
- `device_model`:设备型号(`Luxsin-X8/Luxsin-X9`
- `impedance_ohm`:阻抗整数(Ω)
- `headphone_brand` / `headphone_model`:原始输入(用于展示/回显)
- `headphone_brand_norm` / `headphone_model_norm`:归一化值(trim+lower,用于唯一索引与去重)
- `ip_addr`:服务端获取的设备 IP(最新值)
- `create_at` / `update_at`:创建/更新时间
### 索引
- 唯一索引:`uniq_mac_brand_model(mac_addr, headphone_brand_norm, headphone_model_norm)`
- 辅助索引:`idx_mac(mac_addr)``idx_device_model(device_model)`
## 非目标(本期不做)
- 不做历史版本/上报流水表
- 不做品牌/型号的字典化与关联(仅存字符串)
- 不在文档中定义具体 API(仅描述存储需求与规则)