รายงานเพื่อนทั้งหมด (Report All Friends)
ภาพรวม
นี่คือรายงานหลักของระบบ แสดงตารางรายชื่อเพื่อน LINE ทั้งหมดของ OA พร้อม attribute ที่เลือกแสดงเป็นคอลัมน์ได้ ใช้สำหรับดูภาพรวมฐานเพื่อน กรองตามเงื่อนไขต่าง ๆ และส่งออกข้อมูลเป็นไฟล์ CSV
นอกจากนี้ยังรวมส่วนของ ประวัติการนำเข้าเพื่อน ที่แสดงว่าการนำเข้าแต่ละรอบ สำเร็จและล้มเหลวจำนวนเท่าใด
โมดูลนี้ นำตัวสร้าง query จากโมดูล lineuser มาใช้ซ้ำ เพื่อให้เงื่อนไขการกรองในหน้ารายงาน ตรงกับหน้าค้นหาเพื่อนอย่างสมบูรณ์
โมดูลจริงในโค้ดคือ internal/modules/report และชื่อ system module คือ report-all-friends
ส่วนหน้าเอกสารนี้ใช้ slug all-friend-listing ตามข้อจำกัดการตั้งชื่อไฟล์ในที่เก็บเอกสาร
Business Flow
- ดูรายงาน —
GET /api/report/all-friendคืนข้อมูลแบบแบ่งหน้า- กรองด้วย
FilterGetLineUserDtoซึ่งเป็นชุดเดียวกับGET /api/line-users/search - คอลัมน์ attribute ที่แสดงได้มาจาก
GET /api/attribute-master/reportable
- กรองด้วย
- ส่งออก CSV —
GET /api/report/all-friend/exportใช้เงื่อนไขเดียวกับข้อแรก แต่ stream ผลลัพธ์ลง response โดยตรงและไม่จำกัดจำนวนหน้า endpoint นี้ต้องการ policyexportซึ่งแยกออกจากreadAll - ดูประวัติการนำเข้า —
GET /api/report/import-historyอ่านข้อมูลจากตารางline_user_importและline_user_import_detailแล้วแสดงผลของการนำเข้าแต่ละรอบ ครอบคลุมทั้งที่มาจาก LINE User Management และจาก Import Mapping หากอ่านข้อมูลไม่สำเร็จ ระบบตอบกลับด้วยข้อความFailed to find all line user importเป็น HTTP 500 ตามพฤติกรรมของระบบเดิม
ไฟล์และฟังก์ชันหลัก
โค้ดอยู่ที่ internal/modules/report/ ประกอบด้วย controller.go, service.go, dto.go
และ module.go
Route ทั้งหมดลงทะเบียนบน authed.Group("/report") และครอบด้วย
modulegate.ModuleGate(d, "report-all-friends")
| Method | Route | Handler | Policy |
|---|---|---|---|
| GET | /api/report/all-friend | svc.getReportAllFriendHandler | readAll report-all-friends |
| GET | /api/report/all-friend/export | svc.getExportReportAllFriendHandler | export report-all-friends |
| GET | /api/report/import-history | svc.getImportHistoryHandler | readAll report-all-friends |
ตัวแปรที่กำหนดพฤติกรรมข้อผิดพลาดคือ errFindAllLineUserImport ใน service.go
จุดเชื่อมต่อกับ Service อื่น
- Permission — ต้องผ่าน
ModuleGate("report-all-friends")และมีPolicyModuleReportAllFriendsเป็น metadata - ตารางที่เกี่ยวข้อง —
line_user,line_user_import,line_user_import_detail,attribute_master,system_attributeและline_oa - Cross-module — import
internal/modules/lineuserเพื่อใช้ query builder ร่วมกัน และใช้internal/core/validationตรวจสอบ query parameter - CSV export — เขียนผลลัพธ์ลง response แบบ stream เช่นเดียวกับการ export audience
- โมดูลที่เกี่ยวข้อง — LINE User Management, Attribute Master, Import Mapping, Audience Management และ Dashboard