docs(app): 規劃「後端要加新的 ride 狀態碼」該怎麼做(跨三端,尚未動工) - #102
Merged
Conversation
第二十七輪把 App 補成「不認得的狀態碼不會讓訂單從畫面上消失」,但那只是不會壞。 真的要新增一個狀態碼是跨三端+有上線順序的事,先把清單與順序寫死, 等真的有產品理由時照著做,不要臨時想。 三件事寫進規劃: 1. 契約先定死:只增不改不重編號;號段有語意(admin 的 isRideCancellable 是 `status >= 0 && <= 2` 的**範圍判斷**,所以中途狀態新增時要把範圍判斷全改白名單); 後端是唯一真相來源。 2. 逐項清單**已逐條實查過位置**——後端最容易漏的是 repository 的三組白名單 (decides 誰查得到這張單);App 最關鍵的是 isActive/isTerminal 兩個白名單 與司機端 phase 的二分法推導;admin 兩支現在就存在的硬編碼一併記下。 3. 上線順序(比清單重要):先 App、再 admin、後端最後才開始「送出」新碼。 中間期舊版 App 靠第二十七輪的 UnknownPhaseContent 撐著——那一輪「前瞻性修補」 的價值就在這裡兌現。 順帶記下兩個與本題無關、但現在就存在的 admin 技術債: isRideCancellable 的範圍判斷、DashboardPage 硬編 status === 4/=== 9 算今日 完成/取消數(新增任何終態都會讓儀表板安靜地少算)。 驗收:docs-only;flutter analyze 無 issue、flutter test 448 passed(未受影響)。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
第二十七輪把 App 補成「不認得的狀態碼不會讓訂單從畫面上消失」——但那只是不會壞。真的要新增一個狀態碼是跨三端+有上線順序的事,這支把清單與順序先寫死,等真的有產品理由時照著做,不要臨時想。
這是規劃,沒有動任何程式碼(docs-only)。
什麼時候才該做
目前
0/1/2/3/4/9六碼夠用,沒有產品理由就不要加。已知會逼出新碼的情境有兩個:driver.arrived事件,後端不存 flag,所以重開 App 就看不出司機到了沒;契約先定死(這三條決定後面所有工作量)
4=completed/9=cancelled的語意永遠不動(ride_events歷史、admin 報表、三端常數都綁著它)。isRideCancellable是status >= 0 && status <= 2的範圍判斷。所以「新增一個語意上在中途、號碼卻大於 3 的狀態」會讓所有用大小比較判階段的程式碼失效——同一批必須把範圍判斷全改成白名單。can_accept、O3has_vehicle)。逐項清單(已逐條實查過位置)
後端最容易漏的一組是 repository 的三處白名單,因為它決定「誰查得到這張單」:
FindActiveByDriver={accepted, pickedUp}、乘客的進行中訂單 ={requested, assigned, accepted, pickedUp}、三支條件式 UPDATE 的WHERE status = ?。App 最關鍵的兩個是
RideStatus.isActive/isTerminal白名單(決定「訂單算不算還在跑」,漏改會讓行程卡永遠不消失或提早消失),以及司機端phase的二分法推導(status == pickedUp ? onTrip : enRouteToPickup)。Admin 兩支不改也不會壞(
RIDE_STATUS有?? String(status)退路),但另外兩支會安靜地出錯——見下。完整清單見 TODO 的該段。
上線順序(比清單重要)
外面有舊版 App,所以順序不能顛倒:
中間這段期間,舊版 App 靠第二十七輪的
UnknownPhaseContent撐著:看得到「行程進行中・狀態 N・請更新 App」,不會把訂單藏起來,也還能取消。那一輪「前瞻性修補」的價值就在這裡兌現。順帶記下兩個現在就存在的 admin 技術債
盤點時查到的,與加不加新碼無關,但加新碼會讓它們從「將就」變成「錯誤數字」:
isRideCancellable(status)用範圍判斷>= 0 && <= 2——新碼一律落在「不可取消」,若新狀態其實該可取消,會安靜地擋掉營運。DashboardPage.tsx:44-45硬編status === 4/=== 9算今日完成/取消數——新增任何終態都會讓儀表板安靜地少算。這兩條屬 line-fleet-admin,不在本 PR 範圍,已寫進規劃供後續認領。
驗收
docs-only。
flutter analyze無 issue、flutter test448 passed(未受影響)。🤖 Generated with Claude Code