Transform /mid-section-defect from TMTT-only backward analysis into a full-line bidirectional defect traceability center supporting all detection stations. Key changes: - Parameterized station detection: any workcenter group as detection station - Bidirectional tracing: backward (upstream attribution) + forward (downstream reject rates) - Dual query mode: date range OR LOT/工單/WAFER container-based seed resolution - Multi-select filters for upstream station, equipment model (RESOURCEFAMILYNAME), and loss reasons - Progressive 3-stage trace pipeline (seed-resolve → lineage → events) with streaming UI - Equipment model lookup via resource cache instead of SPECNAME - Session caching, auto-refresh, searchable MultiSelect with fuzzy matching - Remove legacy tmtt-defect module (fully superseded) - Archive openspec change artifacts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5.7 KiB
5.7 KiB
1. SQL Layer
- 1.1 Create
station_detection.sql— copytmtt_detection.sql, replace hardcoded TMTT filter with{{ STATION_FILTER }}/{{ STATION_FILTER_REJECTS }}placeholders, renameTMTT_EQUIPMENTID/NAME→DETECTION_EQUIPMENTID/NAME - 1.2 Create
downstream_rejects.sql— queryDW_MES_LOTREJECTHISTORYfor batched CONTAINERIDs withWORKCENTER_GROUPCASE WHEN, returning CONTAINERID, WORKCENTERNAME, WORKCENTER_GROUP, LOSSREASONNAME, EQUIPMENTNAME, REJECT_TOTAL_QTY, TXNDATE - 1.3 Modify
upstream_history.sql— addh.TRACKINQTY(with COALESCE to 0) toranked_historyCTE and final SELECT
2. Backend Service — Station Parameterization
- 2.1 Add
_build_station_filter(station_name, column_prefix)tomid_section_defect_service.py— readsWORKCENTER_GROUPSpatterns/exclude, builds OR-LIKE SQL with bind params - 2.2 Replace
_fetch_tmtt_data()with_fetch_station_detection_data(start_date, end_date, station)— usesstation_detection.sql+_build_station_filter() - 2.3 Update all public API signatures (
query_analysis,query_analysis_detail,export_csv,resolve_trace_seed_lots,build_trace_aggregation_from_events) to acceptstationanddirectionparams (default'測試'/'backward') - 2.4 Add station+direction to cache keys
- 2.5 Rename all internal
TMTT_→DETECTION_references (variables, dict keys, DIMENSION_MAP entries)
3. Backend Service — Forward Pipeline
- 3.1 Extract existing backward logic into
_run_backward_pipeline(start_date, end_date, station, loss_reasons) - 3.2 Add
_fetch_downstream_rejects(tracked_cids)— batch query usingdownstream_rejects.sql - 3.3 Implement
_attribute_forward_defects(detection_df, detection_cids, downstream_wip, downstream_rejects, station_order)— per-station reject rate using TRACKINQTY denominator - 3.4 Implement
_run_forward_pipeline(start_date, end_date, station, loss_reasons)— full 8-stage pipeline (detection → forward lineage → downstream WIP+rejects → attribution → KPI/charts/detail) - 3.5 Implement
_build_forward_kpi(),_build_forward_charts(),_build_forward_detail_table()builders - 3.6 Add direction dispatch in
query_analysis(): backward →_run_backward_pipeline(), forward →_run_forward_pipeline() - 3.7 Add
query_station_options()— returns ordered workcenter groups list
4. Backend Routes & EventFetcher
- 4.1 Update
mid_section_defect_routes.py— addstation+directionquery params to all endpoints, add station validation, addGET /station-optionsendpoint - 4.2 Update
trace_routes.py—_seed_resolve_mid_section_defect()passesstation; lineage stage uses direction to chooseresolve_full_genealogy()vsresolve_forward_tree(); events stage passes direction for domain selection - 4.3 Add
downstream_rejectsdomain toevent_fetcher.py— inSUPPORTED_EVENT_DOMAINSand_build_domain_sql(), loadingmid_section_defect/downstream_rejects.sql
5. Frontend — FilterBar & App
- 5.1 Update
FilterBar.vue— add station<select>dropdown (fetches from/station-optionson mount), add direction toggle button group (反向追溯/正向追溯), emit station+direction viaupdate-filters - 5.2 Update
App.vue— addstation: '測試'anddirection: 'backward'to filters reactive, include inbuildFilterParams(), add computedisForward, switch chart layout by direction, update page header to '製程不良追溯分析' with dynamic subtitle - 5.3 Update
useTraceProgress.js— adddownstream_rejectstoPROFILE_DOMAINS.mid_section_defectfor forward, updatecollectAllContainerIds()to supportchildren_mapfor forward direction
6. Frontend — Direction-Aware Components
- 6.1 Update
KpiCards.vue— acceptdirection+stationLabelprops, switch card labels between backward/forward modes - 6.2 Update
DetailTable.vue— acceptdirectionprop, switch column definitions between backward (existing) and forward (偵測設備, 偵測投入, 偵測不良, 下游到達站數, 下游不良總數, 下游不良率, 最差下游站) - 6.3 Add
.direction-togglestyles tostyle.css
7. Remove TMTT Defect Page
- 7.1 Delete
frontend/src/tmtt-defect/directory - 7.2 Delete
src/mes_dashboard/routes/tmtt_defect_routes.py - 7.3 Delete
src/mes_dashboard/services/tmtt_defect_service.py - 7.4 Delete
src/mes_dashboard/sql/tmtt_defect/directory - 7.5 Remove tmtt-defect registration from
nativeModuleRegistry.js,routeContracts.js,vite.config.js,page_status.json,routes/__init__.py,app.py,page_registry.py, and all migration baseline/config files - 7.6 Delete related test files and update remaining tests referencing tmtt-defect
8. Config & Metadata
- 8.1 Update
page_status.json— rename mid-section-defect page name from '中段製程不良追溯' to '製程不良追溯分析', remove tmtt-defect entry
9. Verification
- 9.1 Run
python -m pytest tests/test_mid_section_defect_*.py -v— all 22 tests pass - 9.2 Run
cd frontend && node --test— 69/69 frontend tests pass - 9.3 Run all change-relevant backend tests (app_factory, navigation_contract, full_modernization_gates, page_registry, portal_shell_wave_b_native_smoke) — 64/64 pass
- 9.4 Verify backward compat:
station=測試, direction=backwardproduces identical data (renamed columns) — 25,415 detail rows, DETECTION_EQUIPMENTNAME columns (no TMTT_), KPI/charts/genealogy all correct - 9.5 Verify forward basic:
station=成型 (order=4), direction=forward→ 8 downstream stations, 1,673 detail rows, downstream reject distribution: 測試 1.67%, 水吹砂 0.03%, 切彎腳 0.03%, 去膠 0.02%, 電鍍 0.01%, 移印 0.01%