Incident Management — Luồng xử lý trong code
Trang này dành cho kỹ sư: map hành vi domain tới file/class chính. Đường dẫn tính từ gốc repo.
Frontend staff/admin
| Thành phần | File | Vai trò |
|---|---|---|
| List page | Tuke/app/[curl]/incident-management/index.tsx | Tabs Active/Closed, filter, permission create, open drawer. |
| Detail page | Tuke/app/[curl]/incident-management/[id]/index.tsx | Hiện incident detail, attendees, attachments, workflow actions, history. |
| Create/edit form | Tuke/app/[curl]/incident-management/components/IncidentForm.tsx | Incident fields, site/course, attendee context. |
| Drawer create/edit | components/IncidentFormDrawer.tsx | Gọi create/update service, redirect detail. |
| Workflow actions | components/WorkflowActions.tsx | Submit/review/approve/send/close/reopen/cancel. |
| Attachments | components/AttachmentSection.tsx | Upload/download/delete file attachment. |
| Generated reports | components/GeneratedAttachmentSection.tsx | Generate/download generated PDF. |
| Notification history | components/NotificationHistoryTimeline.tsx | Hiện notification jobs liên quan incident. |
| Client API wrapper | services/incident-management.ts | Map UI calls tới backend routes. |
Backend staff/admin API
Tux/src/Tux.Api/Controllers/IncidentManagementController.cs
| Route | Service method | Hành vi |
|---|---|---|
GET /api/incident-management/incidents | SearchAsync | Search list theo status/filter/scope. |
GET /{id} | GetDetailAsync | Load detail, attendees, attachments, acknowledgements, actions. |
POST / | CreateDraftAsync | Tạo draft incident. |
POST /{id}/update | UpdateDraftAsync | Sửa incident khi editable. |
POST /{id}/submit | SubmitAsync | Chuyển Submitted, ghi history, enqueue notification. |
POST /{id}/start-review | StartReviewAsync | Chuyển Under Review. |
POST /{id}/request-changes | RequestChangesAsync | Chuyển Changes Requested, lưu comment. |
POST /{id}/approve | ApproveAsync | Chuyển Approved, ghi approval metadata. |
POST /{id}/send-to-customer | SendToCustomerAsync | Tạo acknowledgements, status Sent To Customer, enqueue notification. |
POST /{id}/generate-pdf | GeneratePdfAsync | Render và lưu generated PDF. |
GET /{id}/notification-history | GetNotificationHistoryAsync | Trả notification jobs cho incident. |
Interface tổng hợp ở Tux/src/Tux.Core/Interfaces/IIncidentManagementService.cs.
Backend service
Tux/src/Services/Tux.Service/IncidentManagementService.cs là nơi giữ domain behavior:
Các helper quan trọng:
| Helper | Vai trò |
|---|---|
GetIncidentPermissionLevelAsync | Resolve create/view/full-control behavior. |
GetEditableIncidentAsync | Guard incident có được sửa hay không. |
GetAllowedActions | Tính action theo status + permission. |
SaveHistoryAsync | Ghi EntityHistory/snapshot cho lifecycle. |
BuildPdfDatasetAsync | Gom data cho report PDF. |
MergePdfAttachmentsAsync | Nối file PDF attachment vào report nếu đủ điều kiện. |
Customer portal
| Thành phần | File | Vai trò |
|---|---|---|
| Customer list | Tuke/app/[curl]/incidents/index.tsx | Hiện incident acknowledgements của account hiện tại. |
| Customer detail | Tuke/app/[curl]/incidents/[id]/index.tsx | Hiện detail, generated PDF, form acknowledge/sign. |
| Customer service wrapper | Tuke/app/[curl]/incidents/services/incidents.ts | Gọi ConsumerForm endpoints. |
| Controller | Tux/src/Tux.Api/Controllers/Consumer/ConsumerFormController.cs | Routes customer-facing. |
| Service | Tux/src/Services/Tux.Service.Consumer/ConsumerFormService.cs | Scope by account + acknowledgement, submit acknowledgement/signature. |
Notification worker
| Thành phần | File | Vai trò |
|---|---|---|
| Generator | Tux/src/Workers/Tux.Workers.Notification.Generator/Generator.cs | Xử lý notification scheduler, render output. |
HandleIncidentSentToCustomerAsync | Cùng file | Load incident/contact/template và queue email/SMS/user message khi applicable. |
| Platform flow | Platform → Luồng codebase | Giải thích IncidentSubmitted trong event-derived notification flow. |
Tìm nhanh khi debug
bash
rg -n "IncidentManagementService|IncidentManagementController|ConsumerFormController" Tux/src
rg -n "IncidentStatus|sendToCustomerIncident|generateIncidentPdf" 'Tuke/app/[curl]/incident-management'
rg -n "ConsumerForm/incidents|getCustomerIncident" 'Tuke/app/[curl]/incidents'Tiếp theo: Dữ liệu & bảng đọc/ghi.