# 前端数据更新链路与字段映射

## 1. 前端数据点

| 组件 | 数据 | API 字段 | DB 表/列 |
|------|------|----------|----------|
| HeaderPanel | lastUpdated | situation.lastUpdated | situation.updated_at |
| HeaderPanel | powerIndex | usForces/iranForces.powerIndex | power_index |
| HeaderPanel | feedbackCount, shareCount | POST /api/feedback, /api/share | feedback, share_count |
| TimelinePanel | recentUpdates | situation.recentUpdates | situation_update |
| WarMap | keyLocations | usForces/iranForces.keyLocations | key_location |
| BaseStatusPanel | 基地统计 | keyLocations (status, damage_level) | key_location |
| CombatLossesPanel | 人员/平民伤亡 | combatLosses, civilianCasualtiesTotal | combat_losses |
| CombatLossesOtherPanel | 装备毁伤 | combatLosses (bases, aircraft, drones, …) | combat_losses |
| PowerChart | 雷达图 | powerIndex | power_index |
| WallStreetTrend | 美股趋势 | wallStreetInvestmentTrend | wall_street_trend |
| RetaliationGauge | 报复指数 | retaliationSentiment | retaliation_current/history |

**轮询**: `fetchSituation()` 加载，WebSocket `/ws` 每 3 秒广播。`GET /api/situation` → `getSituation()`。

## 2. 爬虫 → DB 字段映射

| 提取器输出 | DB 表 | 逻辑 |
|------------|-------|------|
| situation_update | situation_update | INSERT |
| combat_losses_delta | combat_losses | 增量叠加 (ADD) |
| retaliation | retaliation_current, retaliation_history | REPLACE / APPEND |
| wall_street | wall_street_trend | INSERT |
| key_location_updates | key_location | UPDATE status, damage_level WHERE name LIKE |

### combat_losses 字段对应

| 提取器 (us/iran) | DB 列 |
|------------------|-------|
| personnel_killed | personnel_killed |
| personnel_wounded | personnel_wounded |
| civilian_killed | civilian_killed |
| civilian_wounded | civilian_wounded |
| bases_destroyed | bases_destroyed |
| bases_damaged | bases_damaged |
| aircraft, warships, armor, vehicles | 同名 |
| drones, missiles, helicopters, submarines | 同名 |

## 3. 测试用例

运行: `npm run crawler:test:extraction`

| 用例 | 输入 | 预期 |
|------|------|------|
| 特朗普 1000 军事目标 | "特朗普说伊朗有1000个军事目标遭到袭击" | 不提取 bases_destroyed/bases_damaged |
| 阿萨德基地遭袭 | "阿萨德空军基地遭袭，损失严重" | 输出 key_location_updates |
| 美军伤亡 | "3名美军阵亡，另有5人受伤" | personnel_killed=3, personnel_wounded=5 |
| 伊朗平民 | "伊朗空袭造成伊拉克平民50人伤亡" | iran.civilian_killed=50 |
| 伊朗无人机 | "美军击落伊朗10架无人机" | iran.drones=10 |
| db_merge 增量 | 两次 merge 3+2 | personnel_killed=5 |

## 4. 注意事项

- **bases_***: 仅指已确认损毁/受损的基地；"军事目标"/targets 不填 bases_*。
- **正则 [\s\w]***: 会匹配数字，导致 (\d+) 只捕获末位；数字前用 `[^\d]*`。
- **伊朗平民**: 规则已支持 "伊朗空袭造成…平民" 归入 loss_ir。
- **key_location**: 需 name LIKE '%keyword%' 匹配，关键词见 extractor_rules.bases_all。
