Skip to main content

รายงานเพื่อนทั้งหมด (Report All Friends)

ภาพรวม

นี่คือรายงานหลักของระบบ แสดงตารางรายชื่อเพื่อน LINE ทั้งหมดของ OA พร้อม attribute ที่เลือกแสดงเป็นคอลัมน์ได้ ใช้สำหรับดูภาพรวมฐานเพื่อน กรองตามเงื่อนไขต่าง ๆ และส่งออกข้อมูลเป็นไฟล์ CSV

นอกจากนี้ยังรวมส่วนของ ประวัติการนำเข้าเพื่อน ที่แสดงว่าการนำเข้าแต่ละรอบ สำเร็จและล้มเหลวจำนวนเท่าใด

โมดูลนี้ นำตัวสร้าง query จากโมดูล lineuser มาใช้ซ้ำ เพื่อให้เงื่อนไขการกรองในหน้ารายงาน ตรงกับหน้าค้นหาเพื่อนอย่างสมบูรณ์

note

โมดูลจริงในโค้ดคือ internal/modules/report และชื่อ system module คือ report-all-friends ส่วนหน้าเอกสารนี้ใช้ slug all-friend-listing ตามข้อจำกัดการตั้งชื่อไฟล์ในที่เก็บเอกสาร

Business Flow

  1. ดูรายงานGET /api/report/all-friend คืนข้อมูลแบบแบ่งหน้า
    • กรองด้วย FilterGetLineUserDto ซึ่งเป็นชุดเดียวกับ GET /api/line-users/search
    • คอลัมน์ attribute ที่แสดงได้มาจาก GET /api/attribute-master/reportable
  2. ส่งออก CSVGET /api/report/all-friend/export ใช้เงื่อนไขเดียวกับข้อแรก แต่ stream ผลลัพธ์ลง response โดยตรงและไม่จำกัดจำนวนหน้า endpoint นี้ต้องการ policy export ซึ่งแยกออกจาก readAll
  3. ดูประวัติการนำเข้า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")

MethodRouteHandlerPolicy
GET/api/report/all-friendsvc.getReportAllFriendHandlerreadAll report-all-friends
GET/api/report/all-friend/exportsvc.getExportReportAllFriendHandlerexport report-all-friends
GET/api/report/import-historysvc.getImportHistoryHandlerreadAll 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