【開發完成(待 code review)】
Branch:feature/issue-1474-t05-pricing(已 push,base = main,未 merge)
Commits:
-
ba8fee8 issue #1474: [API] T05 計價純計算模組(含單元測試)
-
35fd9cc issue #1474: [Docs] api/design.md §2.8(T05 pricing)、api-agent status 跟進
完成內容¶
純函式計價模組 com.hpigeopark.pricing(spec §6、§8.2),不碰 DB、不吃 Spring bean graph、Thread-safe。公開介面:
public final class PricingEngine {
public PricingEngine(); // 預設 Asia/Taipei 系統時鐘
public PricingEngine(Clock clock); // 測試注入 Clock.fixed(...)
public PriceBreakdown calculate(PricingRequest request);
}
M1 計算(spec §6.2 步驟 1、3):
-
PER_PERSON:subtotal = unitPrice × participantCount,groupCount = null
-
PER_GROUP:subtotal = unitPrice × CEILING(n ÷ activity.maxGroupSize)
- M1 無協議、無 coupon,
total == subtotal
輸出 PriceBreakdown 對齊 ERD §4.3 JSON 結構(computedAt/activity/priceTier/steps/subtotal/agreement/coupon/total);steps/agreement/coupon 為 M2 擴充位,已在 design.md §2.8 寫明擴充策略(不破壞 M1 呼叫端)。
整數金額全程 Math.multiplyExact 防溢位;非法輸入一律 IllegalArgumentException(SS3A-EXC-02/SS3A-SVC-15),交由 ExceptionHandlingController 轉 400 ErrorBody。
驗收測試(PricingEngineTest,純 JUnit,不碰 DB)¶
25 支測試全綠:
- 每人計價 6 支:1 人、ERD §4.3 範例(170 × 3 = 510)、進位邊界 43/44/100/130
- 每團計價進位邊界 5 支:HPICI5FB 中文團 1200/團、maxGroupSize=43,1/43/44/100/130 → 1/1/2/3/4 團
- 免費項目 2 支:每人 0、每團 0
- 非法輸入 10 支:人數 ≤ 0、PER_GROUP 缺或 0 maxGroupSize、單價負、計價單位 null、request/activity/priceTier/clock 為 null
- 明細結構 2 支:computedAt 由 Clock.fixed 驗證、subtotal == total、pricingUnit 落盤 code(per_person/per_group)
mvn test:37/37 綠(12 既有 + 25 新增;pricing 區塊 < 0.1 秒)。
範圍外(留給後續 ticket)¶
- T06(#1475)建單時呼叫本模組取得明細 → 寫入
hp_orders.price_breakdown、hp_booking.unit_price / line_amount / group_count 快照
- M2 協議價/coupon 擴充:依 design.md §2.8 擴充策略
冒出的決策¶
無需使用者裁示;所有欄位命名/大小寫/整數進位皆可從 spec §1.5/§6.4 與 ERD §4.3 推導,已於 design.md §2.8「衍生/對齊的推導決策」逐項記錄。
下一步¶
建議 coordinator 取得使用者同意後將狀態改為 Under Review;branch 已 push,等 PR / merge。