[CLAUDE] Docs+Skill: chốt Session 16 wrap-up — drastic refactor flat workflow (Chunk D)
Session 16 (2026-05-08) docs/skill/memory wrap-up: STATUS.md: - Last updated Session 16 (2 commit Chunk A+B) - Phase summary count (20→21 mig, 96→77 test, 57→55 bảng) - Recently Done row Session 16 chi tiết (drastic refactor hoàn tất) - Phase enum simplified semantic post-Mig 21 HANDOFF.md: - TL;DR Session 16 prepend với 2 chunk + Chunk C SKIP rationale - Per-chunk implementation chi tiết (Domain + Mig 21 + Service + Tests + FE Designer) - 8 cảnh báo Session 17+: UAT live test / old data migration / Sample seed / Budget N-stage / schema-diagram / skill refresh / tests flat / Hard blockers Ops migration-todos.md: Phase 9 + Session 16 block 2 chunk done + 7 defer task Session log NEW `2026-05-08-0500-drastic-refactor-flat-workflow.md`: - Bối cảnh resume từ S15 defer - Spec implementation (Phase enum, state machine, schema Mig 21) - Per-chunk Chunk A + Chunk B detail - Chunk C skip rationale - Memory `feedback_drastic_refactor_scope` validation: scope estimate 30% accurate (3h actual vs 10h conservative) - Plan organization sau S16 Skill ef-core-migration: - description + heading: 20→21 migration - + Mig 21 row "RefactorWorkflowToFlatModel" với detail (4 ALTER + 2 ALTER + DROP TABLE × 2 + DROP COLUMN × 2 + restore simple unique × 2) - Total 57→55 bảng (-2 InnerStep tables) - Tests: 96→77 (drop 19 legacy) CLAUDE.md root: - Migration count 20→21 - DB tables 57→55 - Workflow flat description thay N-stage description docs/rules.md §7: 96→77 test (Mig 21 simplified) Memory `project_solution_erp.md`: - Add "Tổng sau session 16" block với drastic refactor details 🎉 Session 16 wrap-up. Cumulative since session start (S15 wrap-up `38d10b7`): 4 commit (S15 wrap-up was final S15) + 3 commit Session 16 (A `dbb0089` + B `88a5be1` + D current). Defer Session 17+ priority: 1. UAT live test workflow flat (3 phòng × N cấp realistic) 2. Old PE/HĐ legacy phase data migration 3. Sample data seed (Task 2 carry-over) 4. Hard blockers Ops Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
103
docs/HANDOFF.md
103
docs/HANDOFF.md
@ -1,6 +1,107 @@
|
||||
# HANDOFF — Brief 5 phút cho session tiếp theo
|
||||
|
||||
**Last updated:** 2026-05-07 (Session 15 — **Tooltip diagnose "Lưu & Gửi Duyệt" silent disabled (commit `835cc7f`). Plan drastic refactor flat workflow user chốt → attempt 12 file edits Domain/Configurations, realize scope ~8-10h vượt session, REVERT clean. State 96 test pass, 20 mig.**)
|
||||
**Last updated:** 2026-05-08 (Session 16 — **🎯 DRASTIC REFACTOR DONE: flat workflow Phòng × Cấp + Mig 21 + Service rewrite + FE Designer rewrite. 2 commit Chunk A+B. 96 → 77 test pass (drop 19 legacy). Backward compat: legacy phase 2-9+98 enum giữ cho data cũ.**)
|
||||
|
||||
## TL;DR Session 16 (08/05 — Drastic refactor flat workflow EXECUTE)
|
||||
|
||||
Resume từ Session 15 defer plan. Per memory `feedback_drastic_refactor_scope.md`: dedicated session, fresh context, conservative buffer.
|
||||
|
||||
**Spec:** Workflow flat list (Phòng × Cấp × Approvers). Mỗi step = 1 (Phòng × Cấp). Service iterate steps OrderBy Order, advance pointer. Phase enum simplify ChoDuyet=10. Pin WorkflowDefinitionId.
|
||||
|
||||
**2 chunk per-commit (5-6 chunk plan rút gọn vì BE tightly coupled):**
|
||||
|
||||
### Chunk A (`dbb0089`) — All BE: Domain + Mig 21 + Service + Tests
|
||||
|
||||
**Domain entities:**
|
||||
- Phase enum (PE + Contract): + ChoDuyet=10 generic intermediate. Legacy 2-6 + 98 deprecated (giữ enum cho data cũ).
|
||||
- WorkflowStep + DepartmentId Guid? FK Restrict + PositionLevel int?
|
||||
- PurchaseEvaluation/Contract + CurrentWorkflowStepIndex int? + RejectedAtStepIndex int?
|
||||
- DROP class WorkflowStepInnerStep + nav (PE + Contract)
|
||||
- DROP *DepartmentApproval.InnerStepId column
|
||||
|
||||
**EF Configurations:**
|
||||
- DROP InnerStep config (PE + Contract) → table dropped
|
||||
- WorkflowStep config + DeptId/PositionLevel + FK Restrict
|
||||
- DepartmentApprovals: restore simple unique non-filtered (Mig 19/20 filtered split reverse)
|
||||
|
||||
**ApplicationDbContext:** DROP DbSet<*WorkflowStepInnerStep> × 2
|
||||
|
||||
**Migration 21** `RefactorWorkflowToFlatModel` GỘP:
|
||||
- 4 ALTER (PE/Contract +CurrentStepIndex +RejectedAtStepIndex)
|
||||
- 2 ALTER (WorkflowStep +DepartmentId +PositionLevel) PE + Contract
|
||||
- DROP TABLE × 2 (PEWorkflowStepInnerSteps + WorkflowStepInnerSteps Mig 18+20)
|
||||
- DROP COLUMN × 2 (*DeptApproval.InnerStepId)
|
||||
- DROP filtered indexes Mig 19/20
|
||||
- RESTORE simple UNIQUE (TargetId, Phase, Dept, Stage) non-filtered × 2
|
||||
|
||||
**Service rewrite (PE + Contract WorkflowService.TransitionAsync):**
|
||||
- DangSoanThao → ChoDuyet (Drafter trình, init idx=0)
|
||||
- ChoDuyet → ChoDuyet (advance idx per approve)
|
||||
- ChoDuyet → DaDuyet/DaPhatHanh (idx ≥ steps.Count → terminal, gen mã HĐ Contract)
|
||||
- ChoDuyet → DangSoanThao (Trả lại — save RejectedAtStepIndex)
|
||||
- ChoDuyet → TuChoi (Từ chối — khoá vĩnh viễn)
|
||||
- Resume Drafter (DangSoanThao + RejectedAtStepIndex≠null) → ChoDuyet jump-back
|
||||
- Match approver: actor.Dept == step.Dept AND actor.PositionLevel >= step.PositionLevel (OR-of-many cùng cấp/dept) OR Approvers.Kind=User|Role match
|
||||
- Admin role bypass policy
|
||||
|
||||
**App CQRS:** WorkflowStepDto + WorkflowStepInput drop InnerStep, add DepartmentId/DepartmentName/PositionLevel (PE + Contract mirror).
|
||||
|
||||
**Tests:**
|
||||
- DROP `PeNStageApprovalTests.cs` (6) + `ContractNStageApprovalTests.cs` (6) + `PeTwoStageApprovalTests.cs` (7) — legacy
|
||||
- UPDATE `PeWorkflowAdminTests` signature for new flat input
|
||||
- **96 → 77 test pass** (-19 legacy)
|
||||
|
||||
**3-file rule** Mig 21 commit đủ (.cs + Designer + Snapshot).
|
||||
|
||||
### Chunk B (`88a5be1`) — FE Designer + types
|
||||
|
||||
**PeWorkflowsPage + WorkflowsPage rewrite (~210 LOC each):**
|
||||
- Drop InnerStepDto + EditInnerStep types
|
||||
- Drop PHASE_OPTIONS (auto-assign ChoDuyet=10 behind scenes)
|
||||
- StepDto + EditStep + departmentId, departmentName, positionLevel
|
||||
- Designer step UI rewrite: Tên + Phòng Select + Cấp Select + SLA + Approvers (Role/User optional fallback). Drop InnerSteps sub-section.
|
||||
- DefinitionCard view: badge Phòng emerald + Cấp NV/PP/TP violet
|
||||
- Save payload: phase=10 (ChoDuyet)
|
||||
- Hint amber: "User cùng Phòng + Cấp ≥ step → duyệt được (OR-of-many)"
|
||||
|
||||
**types/purchaseEvaluation.ts (fe-admin + fe-user mirror):** + ChoDuyet=10 enum + label "Đang duyệt" + color amber. Legacy 2-6 + 98 keep.
|
||||
|
||||
**Chunk C (FE PeWorkflowPanel) SKIPPED** — existing UI compatible (workflow.nextPhases BE-driven, 3-button Trả lại/Từ chối Session 14 reuse với target=DangSoanThao/TuChoi pattern).
|
||||
|
||||
### Verify
|
||||
|
||||
- ✅ dotnet build SolutionErp.slnx 0 error
|
||||
- ✅ dotnet ef database update Mig 21 LocalDB applied OK
|
||||
- ✅ dotnet test 77 pass (54 Domain + 23 Infra)
|
||||
- ✅ npm build fe-admin + fe-user pass
|
||||
|
||||
### Cumulative sau Session 16
|
||||
|
||||
| | Trước S16 | Sau S16 |
|
||||
|---|---:|---:|
|
||||
| BE LOC | ~15800 | ~15500 (-300 service simplified) |
|
||||
| Migrations | 20 | **21** |
|
||||
| DB tables | 57 | **55** (-2 InnerStep tables) |
|
||||
| Tests | 96 | **77** (-19 legacy N-stage/2-stage) |
|
||||
| FE pages | 32 | 32 (rewrite existing 2 designer) |
|
||||
|
||||
## ⚠️ CẢNH BÁO Session 17+
|
||||
|
||||
1. **UAT live test** — workflow flat ready. Tạo new workflow definition qua `/system/pe-workflows/:typeCode` với 3 phòng × N cấp setup. Verify Drafter trình → cấp 1 phòng A → cấp 2 phòng A → cấp 1 phòng B → ... → DaDuyet flow.
|
||||
|
||||
2. **Old PE/HĐ pinned legacy workflow definitions** (phase=ChoPurchasing/ChoCCM/etc) — service rewrite chỉ handle ChoDuyet=10 + DangSoanThao/DaDuyet. Old data ở phase 2-6 sẽ stuck (admin manual transition required). Recommend: data migration script convert old workflow → new flat model (defer).
|
||||
|
||||
3. **Approver explicit (Role/User Approvers list)** — fallback nếu user không match Dept+PositionLevel của step. Cho phép user external (không thuộc dept) duyệt qua Role match (vd Admin) hoặc User explicit.
|
||||
|
||||
4. **Bypass cấp dưới cùng dept** — User TP với CanBypassReview=true cùng dept và PositionLevel cao hơn step.PositionLevel → duyệt qua. KHÔNG batch upsert NV+PP rows như Mig 18 N-stage trước (đơn giản hóa: 1 step approve = 1 row).
|
||||
|
||||
5. **N-stage tests dropped** — 19 test legacy (Mig 18, 20 N-stage + Mig 16 2-stage). Có thể viết test mới cho flat workflow flow nếu UAT phát sinh bug. Defer.
|
||||
|
||||
6. **Sample data N-stage seed** task vẫn pending (Session 14). Block trên DesignTime vs Runtime DB gotcha + DbInitializer seed flow.
|
||||
|
||||
7. **Budget N-stage** vẫn defer (cần versioned WF migration trước).
|
||||
|
||||
8. **schema-diagram §17-21 update** defer cron audit 2026-06-01.
|
||||
|
||||
## TL;DR Session 15 (07/05 — Tooltip diagnose + drastic refactor DEFER)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user