thread-master/docs/product/demand-radar/tasks/T531-daily-quota-truncation...

52 lines
1.9 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.

# T531 — daily-quota-truncation-and-metering
> Status: `done`
> Milestone: `M2`
> Kind: `feat`
> Est. change: `~160 lines`
## Goal
完成後系統應:當日商機達方案上限時依分數保留高分、記 `truncated_count` 且**不視為錯誤**;巡的耗用以既有 meter`radar.` source 記帳。
## Depends on
- T530
## Inputs
- Spec`../spec.md` §4.2.6、§4.9、§5.5、§9.5QT-01、QT-02、§6RG-04 不新增 meter
- 既有:`apps/backend/internal/module/usage/**`meter、`source`、BYOK 與 platform gate
## Outputs
### 程式變更(預期路徑)
| 路徑 | 動作 | 說明 |
|------|------|------|
| `apps/backend/internal/module/radar/usecase/quota.go` | add | 讀當日已建立數+方案 `max_daily_opportunities`,回可建立額度 |
| `apps/backend/internal/module/radar/usecase/judge_persist.go` | edit | 判定完成後依 `intent_score` 由高至低取前 N 建立,其餘計入 `truncated_count` |
| `apps/backend/internal/module/radar/usecase/metering.go` | add | `web_search/radar.sweep`、`ai_research/radar.judge` 記帳;累加 Sweep `credits_used` |
### 行為變更
- 截斷是**正常結果**Sweep 成功、回應帶 `truncated_count`今日頁顯示提示T545T551
- 平台點數耗盡(非 BYOK沿用既有 platform gate 錯誤行為;**watch 不被刪除或停用**QT-02
- 為了先判分再截斷判定筆數的硬上限為方案每日上限spec §7 效能邊界)。
## Out of scope
- 用量頁的 source 聚合呈現T590
- 前端提示文案T551
## Acceptance
- [x] SW-05命中 40、上限 30 → 建立 30 筆最高分、`truncated_count=10`
- [x] QT-01已達上限再 sweep → 不新增、回應帶 `truncated_count`、**非錯誤**
- [x] RG-04`soft_caps` 四分項加總仍等於 `monthly_credits`
- [x] 指令:
```bash
cd apps/backend && go test ./internal/module/radar/... ./internal/module/usage/... -count=1
```