Skip to content

Module Overview — Complaint Case Lifecycle

1. Complaint workflow thực tế đang được tách thành 3 lớp

LớpThành phầnVai trò
FE shellOverview, Create, Detail + dialog componentsRender list, create form, detail/timeline và action dialogs
Lifecycle enginecomplaintScheduleResolve, complaintScheduleApprove, complaintScheduleReject, complaintScheduleRequestSupplement, complaintScheduleSupplementValidate trạng thái và ghi transition thật
Audit + permissioncomplaint_schedule_history, complaint_permission_*, complaintScheduleList, complaintScheduleDetailQuyết định ai thấy gì, ai làm gì, timeline ghi thế nào

Điểm quan trọng là complaint create chưa nằm trong lifecycle engine. FE tạo trực tiếp bản ghi complaint_schedule, sau đó các action backend mới tiếp quản vòng đời hồ sơ.

2. Surface map

FE routes

RouteDạng UIVai trò
/complaintpageList, filter, search
/complaint/createdialog routeTạo complaint mới
/complaint/:iddialog routeXem detail, timeline và thao tác tiếp theo

Backend actions

ActionVai trò
complaintScheduleListTrả list theo creator / branch permission / full-view role
complaintScheduleDetailTrả detail + timeline + complaint_action_role
complaintScheduleResolveResolver tiếp nhận và giải trình
complaintScheduleRequestSupplementApprover yêu cầu bổ sung
complaintScheduleSupplementResolver gửi bổ sung
complaintScheduleApproveApprover duyệt
complaintScheduleRejectApprover từ chối

Bảng dữ liệu chính

TableVai trò
complaint_scheduleBản ghi complaint trung tâm
complaint_schedule_historyTimeline/audit trail của từng bước
complaint_permission_branchBật/tắt permission theo branch
complaint_permission_resolverResolver theo branch
complaint_permission_approverApprover theo branch

3. State machine chuẩn theo code

text
Create complaint
  -> status = new_complaint
  -> history = new_history_complaint

new_complaint
  -> resolve
  -> pending_inspection_complaint
  -> history = receive_history_complaint

pending_inspection_complaint
  -> approve
  -> approved_complaint
  -> history = approved_history_complaint

pending_inspection_complaint
  -> reject
  -> rejected_complaint
  -> history = rejected_history_complaint

pending_inspection_complaint
  -> request supplement
  -> pending_supplement_complaint
  -> history = request_supplement_history_complaint

pending_supplement_complaint
  -> supplement
  -> pending_inspection_complaint
  -> history = process_supplement_history_complaint

Step UI mapping ở FE

Complaint statusStep bar
new_complaintStep 0
pending_inspection_complaintStep 1
pending_supplement_complaintStep 1
approved_complaintStep 2
rejected_complaintStep 2

Điều này cho thấy FE coi pending_inspectionpending_supplement là cùng một pha "đang xử lý", dù business semantics khác nhau.

4. Permission model tổng quát

List/detail visibility

Complaint được xem nếu thỏa một trong các điều kiện:

  1. user là người tạo complaint,
  2. user có branch permission qua complaint_permission_resolver hoặc complaint_permission_approver,
  3. user thuộc full-view role.

Full-view roles

  • it_leader
  • it_staff
  • audit_leader
  • audit_staff
  • accountant_leader
  • accountant_staff
  • customer_service_leader
  • customer_service_staff
  • bod

Action role trong detail

complaint_action_roleĐiều kiện business
resolvecomplaint đang new_complaint và user là resolver của branch
approvecomplaint đang pending_inspection_complaint và user là approver của branch
supplementcomplaint đang pending_supplement_complaint và user là resolver của branch
viewcác trường hợp còn lại

FE không tự tính role này. Detail dialog render nút theo contract backend trả về.

5. Runtime facts dễ bị bỏ sót

Create path là direct insert

  • CreateNewComplaintTicket là mutation insert_complaint_schedule.
  • FE đồng thời insert một dòng history với new_history_complaint.
  • Không có backend action chuyên biệt để validate create semantics ngoài constraint ở FE/DB.

Detail có 2 nguồn dữ liệu

SourceKhi nào dùngGhi chú
complaintScheduleDetailcomplaint management flowCó permission guard + timeline + complaint_action_role
ComplaintDetail(where)customer contextFE ép complaint_action_role = view

Điều này có nghĩa cùng một complaint nhưng ở customer workspace có thể được hiển thị theo semantics read-only khác detail của module complaint.

Timeline là first-class surface

  • ComplaintTimeline render complaint_schedule_history.
  • Các action backend đều insert history riêng sau khi update complaint.
  • QA nếu chỉ test status cuối mà không test history.contents/files sẽ bỏ sót audit correctness.

6. Findings nổi bật

IDFinding
MO-F01Complaint create path bypass backend action layer, nên validation create hiện bị chia giữa FE và DB.
MO-F02complaint_action_role là contract trung tâm; nếu drift với backend permission guard thì FE sẽ hiện nút không chạy được hoặc ẩn sai nút.
MO-F03pending_supplement được FE gộp vào cùng step với pending_inspection, có thể che mất nuance "chờ resolver phản hồi".
MO-F04Nhiều action backend đang check quyền theo logic khác complaintScheduleDetail, có dấu hiệu bug thật ở guard layer.