Files
yidaima/RuoYi-Vue/docs/superpowers/specs/2026-07-08-ai-usage-cny-cost-design.md

43 lines
1.6 KiB
Markdown
Raw Normal View History

# AI Usage CNY Cost Design
## Goal
AI 用量统计中的费用按人民币统计和展示,匹配 DeepSeek 模型价格表中的人民币单价。
## Scope
本次只调整现有 AI 用量统计的费用口径和展示:
- 后端费用计算使用人民币单价。
- `costCents` 继续表示人民币分。
- 管理端费用卡片和列表费用使用人民币符号展示。
- 数据库字段名 `cost_usd` 和 Java 属性 `costUsd` 暂时保留,作为兼容字段承载人民币金额,避免本次引入数据库迁移和历史数据改写。
## Pricing
DeepSeek V4 Flash:
- 缓存命中输入0.02 元 / 1M tokens
- 缓存未命中输入1 元 / 1M tokens
- 输出2 元 / 1M tokens
DeepSeek V4 Pro:
- 缓存命中输入0.025 元 / 1M tokens
- 缓存未命中输入3 元 / 1M tokens
- 输出6 元 / 1M tokens
未知 DeepSeek 模型沿用 Flash 单价。
## Data Flow
`HttpDeepSeekClient` 读取模型返回的 `usage``AiUsageRecorder` 调用 `AiCostCalculator` 计算费用并写入用量流水。`AiUsageLedgerMapper` 汇总流水金额,管理端页面通过 `/generator/aiUsage/list``/generator/aiUsage/summary` 读取并展示。
## UI
摘要卡片从 `费用 USD` 改为 `费用 CNY`。金额格式从 `$0.00000000` 改为 `¥0.00000000`,保留最多 8 位小数并去掉末尾多余 0。
## Testing
更新 `AiCostCalculatorTest`,先用旧实现验证人民币价格期望失败,再改实现使 Flash、Pro、无缓存拆分和分单位取整测试通过。更新 `AiUsageRecorderTest`,确认流水和 scope 中记录的是人民币金额。