diff --git a/openspec/changes/add-lead-listing-export/design.md b/openspec/changes/add-lead-listing-export/design.md
index 220e103..37ce7d5 100644
--- a/openspec/changes/add-lead-listing-export/design.md
+++ b/openspec/changes/add-lead-listing-export/design.md
@@ -127,7 +127,7 @@ The shared helpers move from `AdminEventLeadService` to a small package-private
**Size limit:** the first page's `totalElements` is checked before any row is written. Above 20,000 the request fails with 422 `EXPORT_TOO_LARGE` and `details.limit = 20000`. `ponytail:` this is a synchronous export with a hard cap; move to an async, emailed export if the cap becomes a problem.
-**Writer:** POI `SXSSFWorkbook` with a 100-row window, writing straight to the response output stream.
+**Writer:** POI `SXSSFWorkbook` with a 100-row window. The file is written to a byte array and then returned, so a page that fails part-way still gives a clean JSON error. `ponytail:` this buffers up to the 20,000-row cap in memory; stream to the response if the cap is raised.
- **Header:** the first row holds the on-screen column labels in English, matching the portal's default messages.
- **Mobile:** written as a string cell, so it stays text.
- **Dates:** written as date cells with the `dd/mm/yyyy` format. Capture time uses `dd/mm/yyyy hh:mm`.
diff --git a/openspec/changes/add-lead-listing-export/tasks.md b/openspec/changes/add-lead-listing-export/tasks.md
index 5b1b30d..61bcf4c 100644
--- a/openspec/changes/add-lead-listing-export/tasks.md
+++ b/openspec/changes/add-lead-listing-export/tasks.md
@@ -52,7 +52,7 @@ Design: `design.md` (decision numbers below refer to it). All tasks run serially
- Scope: `solvway-mobile-api/src/**` (lead files)
- Verify: `mvn -T 1C -B -q -pl solvway-mobile-api -am verify`.
-- [ ] 3.2 Add both xlsx exports (design decision 5):
+- [x] 3.2 Add both xlsx exports (design decision 5):
- Add `poi-ooxml` 4.1.0 to `solvway-mobile-api/pom.xml` and record the `dependency:tree` result.
- Add the `export` endpoints for leads and event leads.
diff --git a/solvway-mobile-api/pom.xml b/solvway-mobile-api/pom.xml
index 3e451a0..7cf811f 100644
--- a/solvway-mobile-api/pom.xml
+++ b/solvway-mobile-api/pom.xml
@@ -107,6 +107,12 @@
groovy
3.0.8
+
+
+ org.apache.poi
+ poi-ooxml
+ 4.1.0
+
diff --git a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminEventLeadExportController.java b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminEventLeadExportController.java
new file mode 100644
index 0000000..6bb49bb
--- /dev/null
+++ b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminEventLeadExportController.java
@@ -0,0 +1,44 @@
+package com.solvway.mobile.api.controller.admin;
+
+import com.solvway.core.annotation.AppAuth;
+import com.solvway.mobile.api.service.AdminEventLeadService;
+import com.solvway.mobile.api.useraccess.AdminModule;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/** Event Leads Listing xlsx export. Separate from AdminEventLeadController, whose handlers all need BO_EVENT_LEADS alone. */
+@RestController
+@RequestMapping("/api/admin/event-leads")
+@RequiredArgsConstructor
+public class AdminEventLeadExportController {
+ private final AdminEventLeadService adminEventLeadService;
+
+ @AppAuth
+ @AdminModule(value = "BO_LEADS_EXPORT", also = "BO_EVENT_LEADS")
+ @GetMapping("/{eventUuid}/export")
+ public ResponseEntity export(@PathVariable String eventUuid,
+ @RequestParam(required = false) Long salespersonId,
+ @RequestParam(required = false) String temperature,
+ @RequestParam(required = false) String status,
+ @RequestParam(required = false) Long interestId,
+ @RequestParam(required = false) String leadType) {
+ byte[] file = adminEventLeadService.export(eventUuid, salespersonId, temperature, status, interestId, leadType);
+ // The service has already parsed the uuid as a number, so its digits are the canonical uuid; nothing else reaches the header.
+ return xlsx("event-leads-" + eventUuid.replaceAll("\\D", ""), file);
+ }
+
+ private static ResponseEntity xlsx(String prefix, byte[] bytes) {
+ String stamp = java.time.ZonedDateTime.now(java.time.ZoneId.of("Asia/Kuala_Lumpur")).format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd-HHmm"));
+ return ResponseEntity.ok()
+ .contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + prefix + "-" + stamp + ".xlsx\"")
+ .body(bytes);
+ }
+}
diff --git a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminLeadController.java b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminLeadController.java
index c9d8c10..05a7198 100644
--- a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminLeadController.java
+++ b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminLeadController.java
@@ -5,6 +5,8 @@ import com.solvway.mobile.api.dto.admin.AdminLeadUpdateRequest;
import com.solvway.mobile.api.service.AdminLeadService;
import com.solvway.mobile.api.useraccess.AdminModule;
import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -32,6 +34,21 @@ public class AdminLeadController {
return ResponseEntity.ok(adminLeadService.list(q, page, size));
}
+ @AppAuth
+ @AdminModule(value = "BO_LEADS_EXPORT", also = "BO_LEADS")
+ @GetMapping("/export")
+ public ResponseEntity export(@RequestParam(required = false) String q) {
+ return xlsx("leads", adminLeadService.export(q));
+ }
+
+ private static ResponseEntity xlsx(String prefix, byte[] bytes) {
+ String stamp = java.time.ZonedDateTime.now(java.time.ZoneId.of("Asia/Kuala_Lumpur")).format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd-HHmm"));
+ return ResponseEntity.ok()
+ .contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + prefix + "-" + stamp + ".xlsx\"")
+ .body(bytes);
+ }
+
@AppAuth
@AdminModule("BO_LEADS")
@GetMapping("/{leadUuid}")
diff --git a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/service/AdminEventLeadService.java b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/service/AdminEventLeadService.java
index d70a4b1..f55bff6 100644
--- a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/service/AdminEventLeadService.java
+++ b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/service/AdminEventLeadService.java
@@ -21,6 +21,7 @@ import org.springframework.web.client.HttpClientErrorException;
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -176,17 +177,7 @@ public class AdminEventLeadService {
String leadType, int page, int size) {
User caller = caller();
Event event = loadEvent(eventUuid);
- Map body = new LinkedHashMap<>();
- body.put("companyId", caller.getCompanyId());
- body.put("eventUuid", event.getUuid());
- body.put("salespersonUserId", salespersonId);
- body.put("temperature", oneOf("temperature", temperature, TEMPERATURES));
- body.put("status", oneOf("status", status, STATUSES));
- body.put("interestId", interestId);
- body.put("leadType", oneOf("leadType", leadType, LEAD_TYPES));
- body.put("page", Math.max(page, 0));
- body.put("size", size);
- Map p = restTemplateUtil.postForEntity(url(RestApiCounterServiceConstants.API_REST_COUNTER_EVENT_LEAD_FIND_BY_EVENT), MAP, body).getBody();
+ Map p = search(caller, event, salespersonId, temperature, status, interestId, leadType, page, size);
List