feat: event lead rows carry attendance and source, with an attended filter

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 21:31:03 +08:00
1 parent cba2929a00
commit 3af5cccd59
16 files changed
+160 -55

No files matched your search

@@ -73,10 +73,11 @@ public class AdminEventLeadController {
@RequestParam(required = false) String status,
@RequestParam(required = false) Long interestId,
@RequestParam(required = false) String leadType,
@RequestParam(required = false) Boolean attended,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int size,
@RequestParam(required = false) Long companyId) {
return ResponseEntity.ok(adminEventLeadService.list(eventUuid, salespersonId, temperature, status, interestId, leadType, page, size, companyId));
return ResponseEntity.ok(adminEventLeadService.list(eventUuid, salespersonId, temperature, status, interestId, leadType, attended, page, size, companyId));
}
@AppAuth
@@ -31,8 +31,9 @@ public class AdminEventLeadExportController {
@RequestParam(required = false) String status,
@RequestParam(required = false) Long interestId,
@RequestParam(required = false) String leadType,
@RequestParam(required = false) Boolean attended,
@RequestParam(required = false) Long companyId) {
byte[] file = adminEventLeadService.export(eventUuid, salespersonId, temperature, status, interestId, leadType, companyId);
byte[] file = adminEventLeadService.export(eventUuid, salespersonId, temperature, status, interestId, leadType, attended, companyId);
// 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);
}
@@ -183,9 +183,9 @@ public class AdminEventLeadService {
// --- listing and edit ---
public Map<String, Object> list(String eventUuid, Long salespersonId, String temperature, String status, Long interestId,
String leadType, int page, int size, Long companyId) {
String leadType, Boolean attended, int page, int size, Long companyId) {
CompanyEvent event = loadEvent(eventUuid, companyId);
Map<String, Object> p = search(event, salespersonId, temperature, status, interestId, leadType, page, size);
Map<String, Object> p = search(event, salespersonId, temperature, status, interestId, leadType, attended, page, size);
List<Map<String, Object>> rows = p == null || p.get("content") == null ? List.of() : (List<Map<String, Object>>) p.get("content");
Map<Long, Map<String, Object>> interests = rows.isEmpty() ? Map.of() : interests(event.getCompanyId());
Map<Long, Map<String, Object>> users = new HashMap<>();
@@ -199,14 +199,14 @@ public class AdminEventLeadService {
}
/** The whole filtered listing as xlsx, paged 100 at a time. ponytail: buffers up to 20000 rows in memory; stream to the response if that grows. */
public byte[] export(String eventUuid, Long salespersonId, String temperature, String status, Long interestId, String leadType, Long companyId) {
public byte[] export(String eventUuid, Long salespersonId, String temperature, String status, Long interestId, String leadType, Boolean attended, Long companyId) {
User caller = caller();
CompanyEvent event = loadEvent(eventUuid, companyId);
Map<Long, Map<String, Object>> users = new HashMap<>();
Map<Long, Map<String, Object>>[] interests = new Map[1];
return LeadExport.build(caller.getUsername(), "event-leads:" + event.getUuid(), "Event leads",
List.of("Name", "Mobile", "Email", "Lead type", "Salesperson", "Temperature", "Status", "Interests", "Next follow-up"),
page -> search(event, salespersonId, temperature, status, interestId, leadType, page, LeadExport.PAGE),
List.of("Name", "Mobile", "Email", "Lead type", "Salesperson", "Temperature", "Status", "Interests", "Next follow-up", "Attended", "Source"),
page -> search(event, salespersonId, temperature, status, interestId, leadType, attended, page, LeadExport.PAGE),
r -> {
if (interests[0] == null) interests[0] = interests(event.getCompanyId());
Map<String, Object> m = view(r, interests[0], users);
@@ -215,10 +215,20 @@ public class AdminEventLeadService {
return Arrays.asList(m.get("name"), m.get("mobile"), m.get("email"), label(m.get("leadType")),
sp == null ? null : sp.get("name"), label(m.get("temperature")), label(m.get("status")),
String.join(", ", ((List<Map<String, Object>>) m.get("interests")).stream().map(i -> String.valueOf(i.get("name"))).toList()),
follow == null ? null : LocalDate.parse(follow));
follow == null ? null : LocalDate.parse(follow),
(boolean) m.get("attended") ? "Yes" : "No", sourceLabel(m.get("source")));
});
}
private static String sourceLabel(Object source) {
return switch (String.valueOf(source)) {
case "STAFF" -> "Staff";
case "QR" -> "QR";
case "INVITE" -> "Invite";
default -> source == null ? null : source.toString();
};
}
/** HOT becomes Hot. */
private static String label(Object code) {
String s = code == null ? null : code.toString();
@@ -226,7 +236,7 @@ public class AdminEventLeadService {
}
private Map<String, Object> search(CompanyEvent event, Long salespersonId, String temperature, String status, Long interestId,
String leadType, int page, int size) {
String leadType, Boolean attended, int page, int size) {
Map<String, Object> body = new LinkedHashMap<>();
body.put("companyId", event.getCompanyId());
body.put("eventUuid", event.getUuid());
@@ -235,6 +245,7 @@ public class AdminEventLeadService {
body.put("status", oneOf("status", status, STATUSES));
body.put("interestId", interestId);
body.put("leadType", oneOf("leadType", leadType, LEAD_TYPES));
body.put("attended", attended);
body.put("page", Math.max(page, 0));
body.put("size", size);
return restTemplateUtil.postForEntity(url(RestApiCounterServiceConstants.API_REST_COUNTER_EVENT_LEAD_FIND_BY_EVENT), MAP, body).getBody();
@@ -351,6 +362,8 @@ public class AdminEventLeadService {
m.put("nextFollowUpDate", d.get("nextFollowUpDate"));
m.put("notes", d.get("notes"));
m.put("capturedAt", d.get("capturedAt"));
m.put("attended", d.get("attendedAt") != null);
m.put("source", d.get("source"));
return m;
}
@@ -85,15 +85,15 @@ class AdminEventLeadControllerTest {
@Test
void listPassesFiltersAndPaging() throws Exception {
when(eventLeads.list(EV, 21L, "HOT", "OPEN", 3L, "NEW", 1, 25, null)).thenReturn(Map.of("content", List.of(), "totalElements", 0));
when(eventLeads.list(EV, 21L, "HOT", "OPEN", 3L, "NEW", false, 1, 25, null)).thenReturn(Map.of("content", List.of(), "totalElements", 0));
mvc.perform(get("/api/admin/event-leads/" + EV + "/leads").param("salespersonId", "21").param("temperature", "HOT")
.param("status", "OPEN").param("interestId", "3").param("leadType", "NEW").param("page", "1").param("size", "25"))
.param("status", "OPEN").param("interestId", "3").param("leadType", "NEW").param("attended", "false").param("page", "1").param("size", "25"))
.andExpect(status().isOk());
verify(eventLeads).list(EV, 21L, "HOT", "OPEN", 3L, "NEW", 1, 25, null);
verify(eventLeads).list(EV, 21L, "HOT", "OPEN", 3L, "NEW", false, 1, 25, null);
when(eventLeads.list(EV, null, null, null, null, null, 0, 20, null)).thenReturn(Map.of("content", List.of()));
when(eventLeads.list(EV, null, null, null, null, null, null, 0, 20, null)).thenReturn(Map.of("content", List.of()));
mvc.perform(get("/api/admin/event-leads/" + EV + "/leads")).andExpect(status().isOk());
verify(eventLeads).list(EV, null, null, null, null, null, 0, 20, null);
verify(eventLeads).list(EV, null, null, null, null, null, null, 0, 20, null);
}
@Test
@@ -56,10 +56,10 @@ class AdminLeadExportControllerTest {
@Test
void eventLeadExportPassesFiltersAndNamesTheFile() throws Exception {
AdminEventLeadService svc = mock(AdminEventLeadService.class);
when(svc.export("77", 22L, "HOT", "OPEN", 3L, "NEW", null)).thenReturn(new byte[]{9});
when(svc.export("77", 22L, "HOT", "OPEN", 3L, "NEW", true, null)).thenReturn(new byte[]{9});
MockMvc mvc = MockMvcBuilders.standaloneSetup(new AdminEventLeadExportController(svc)).build();
mvc.perform(get("/api/admin/event-leads/77/export").param("salespersonId", "22").param("temperature", "HOT")
.param("status", "OPEN").param("interestId", "3").param("leadType", "NEW")).andExpect(status().isOk())
.param("status", "OPEN").param("interestId", "3").param("leadType", "NEW").param("attended", "true")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", XLSX))
.andExpect(header().string("Content-Disposition", org.hamcrest.Matchers.matchesPattern("attachment; filename=\"event-leads-77-\\d{8}-\\d{4}\\.xlsx\"")))
.andExpect(content().bytes(new byte[]{9}));
@@ -70,7 +70,7 @@ class AdminLeadExportControllerTest {
// The service accepts " 77\r\n" (it trims before parsing); none of those characters may reach the header.
AdminEventLeadService svc = mock(AdminEventLeadService.class);
when(svc.export(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(),
org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any())).thenReturn(new byte[]{9});
org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any())).thenReturn(new byte[]{9});
MockMvc mvc = MockMvcBuilders.standaloneSetup(new AdminEventLeadExportController(svc)).build();
mvc.perform(get("/api/admin/event-leads/{uuid}/export", " 77\r\n")).andExpect(status().isOk())
.andExpect(header().string("Content-Disposition", org.hamcrest.Matchers.matchesPattern("attachment; filename=\"event-leads-77-\\d{8}-\\d{4}\\.xlsx\"")));
@@ -113,6 +113,8 @@ class AdminEventLeadExportTest {
r.put("status", "QUALIFIED");
r.put("nextFollowUpDate", "2027-01-20");
r.put("interestIds", List.of(3, 5));
r.put("attendedAt", i % 2 == 0 ? "2027-01-20T09:30:00" : null);
r.put("source", i % 2 == 0 ? "QR" : "INVITE");
return r;
}
@@ -127,7 +129,7 @@ class AdminEventLeadExportTest {
}
private byte[] export() {
return service.export(String.valueOf(EV), 22L, "HOT", null, 3L, null, null);
return service.export(String.valueOf(EV), 22L, "HOT", null, 3L, null, true, null);
}
private static Sheet sheet(byte[] bytes) throws Exception {
@@ -141,7 +143,7 @@ class AdminEventLeadExportTest {
assertThat(s.getSheetName()).isEqualTo("Event leads");
List<String> header = new ArrayList<>();
s.getRow(0).forEach(c -> header.add(c.getStringCellValue()));
assertThat(header).containsExactly("Name", "Mobile", "Email", "Lead type", "Salesperson", "Temperature", "Status", "Interests", "Next follow-up");
assertThat(header).containsExactly("Name", "Mobile", "Email", "Lead type", "Salesperson", "Temperature", "Status", "Interests", "Next follow-up", "Attended", "Source");
assertThat(s.getLastRowNum()).isEqualTo(2);
}
@@ -163,6 +165,10 @@ class AdminEventLeadExportTest {
assertThat(DateUtil.isCellDateFormatted(d)).isTrue();
assertThat(d.getCellStyle().getDataFormatString()).isEqualTo("dd/mm/yyyy");
assertThat(d.getDateCellValue().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate()).isEqualTo(LocalDate.of(2027, 1, 20));
assertThat(r.getCell(9).getStringCellValue()).isEqualTo("Yes");
assertThat(r.getCell(10).getStringCellValue()).isEqualTo("QR");
assertThat(s.getRow(2).getCell(9).getStringCellValue()).isEqualTo("No");
assertThat(s.getRow(2).getCell(10).getStringCellValue()).isEqualTo("Invite");
}
@Test
@@ -187,7 +193,7 @@ class AdminEventLeadExportTest {
verify(rest, times(3)).postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), bodies.capture());
for (Object b : bodies.getAllValues()) {
assertThat((Map<String, Object>) b).containsEntry("size", 100).containsEntry("eventUuid", EV).containsEntry("salespersonUserId", 22L)
.containsEntry("temperature", "HOT").containsEntry("interestId", 3L);
.containsEntry("temperature", "HOT").containsEntry("interestId", 3L).containsEntry("attended", true);
}
verify(rest, times(1)).getForEntity(eq(EVENT), any(ParameterizedTypeReference.class), eq(EV));
verify(rest, times(1)).getForEntity(eq(INTERESTS), any(ParameterizedTypeReference.class), eq(COMPANY));
@@ -209,7 +215,7 @@ class AdminEventLeadExportTest {
@Test
void invalidFilterIsStillRejectedBeforeAnything() {
assertThatThrownBy(() -> service.export(String.valueOf(EV), null, "BOILING", null, null, null, null))
assertThatThrownBy(() -> service.export(String.valueOf(EV), null, "BOILING", null, null, null, null, null))
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> assertThat(e.getCode()).isEqualTo("INVALID_VALUE"));
}
@@ -193,8 +193,8 @@ class AdminEventLeadServiceCompanyScopeTest {
void list_andExport_otherCompanysEventIsNotFoundForStaff() {
caller(5L, false);
stubEvent(9L);
assertEventNotFound(() -> service.list(String.valueOf(EV), null, null, null, null, null, 0, 20, null));
assertEventNotFound(() -> service.export(String.valueOf(EV), null, null, null, null, null, 9L));
assertEventNotFound(() -> service.list(String.valueOf(EV), null, null, null, null, null, null, 0, 20, null));
assertEventNotFound(() -> service.export(String.valueOf(EV), null, null, null, null, null, null, 9L));
verify(rest, never()).postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), any());
}
@@ -202,7 +202,7 @@ class AdminEventLeadServiceCompanyScopeTest {
void list_staffIgnoresRequestedCompany() {
caller(5L, false);
stubEvent(5L);
service.list(String.valueOf(EV), null, null, null, null, null, 0, 20, 9L);
service.list(String.valueOf(EV), null, null, null, null, null, null, 0, 20, 9L);
assertThat(sentOnce(SEARCH)).containsEntry("companyId", 5L).containsEntry("eventUuid", EV);
}
@@ -210,15 +210,15 @@ class AdminEventLeadServiceCompanyScopeTest {
void list_andExport_superRequestingAnotherCompanyThanTheEventsIsNotFound() {
caller(null, true);
stubEvent(9L);
assertEventNotFound(() -> service.list(String.valueOf(EV), null, null, null, null, null, 0, 20, 7L));
assertEventNotFound(() -> service.export(String.valueOf(EV), null, null, null, null, null, 7L));
assertEventNotFound(() -> service.list(String.valueOf(EV), null, null, null, null, null, null, 0, 20, 7L));
assertEventNotFound(() -> service.export(String.valueOf(EV), null, null, null, null, null, null, 7L));
}
@Test
void list_andExport_superWithoutCompanyUsesTheEventsCompany() {
caller(null, true);
stubEvent(9L);
service.list(String.valueOf(EV), null, null, null, null, null, 0, 20, null);
service.list(String.valueOf(EV), null, null, null, null, null, null, 0, 20, null);
assertThat(sentOnce(SEARCH)).containsEntry("companyId", 9L);
}
@@ -226,7 +226,7 @@ class AdminEventLeadServiceCompanyScopeTest {
void export_staffGetsOwnEventsRowsOnly() {
caller(5L, false);
stubEvent(5L);
service.export(String.valueOf(EV), null, null, null, null, null, 9L);
service.export(String.valueOf(EV), null, null, null, null, null, null, 9L);
assertThat(sentOnce(SEARCH)).containsEntry("companyId", 5L);
}
@@ -159,6 +159,7 @@ class AdminEventLeadServiceTest {
d.put("leadType", "NEW");
d.put("salespersonUserId", salespersonUserId);
d.put("status", "OPEN");
d.put("source", "STAFF");
d.put("interestIds", interestIds);
when(rest.getForEntity(eq(FIND), any(ParameterizedTypeReference.class), eq(EL))).thenReturn(ResponseEntity.ok(d));
}
@@ -369,7 +370,7 @@ class AdminEventLeadServiceTest {
when(rest.getForEntity(eq(EVENT), any(ParameterizedTypeReference.class), eq(1L))).thenReturn(ResponseEntity.ok().build());
assertCoded(() -> service.capture("1", capture(null, "Aisyah", "0123456789", null)), HttpStatus.NOT_FOUND, "EVENT_NOT_FOUND", null);
assertCoded(() -> service.list("not-a-number", null, null, null, null, null, 0, 20, null), HttpStatus.NOT_FOUND, "EVENT_NOT_FOUND", null);
assertCoded(() -> service.list("not-a-number", null, null, null, null, null, null, 0, 20, null), HttpStatus.NOT_FOUND, "EVENT_NOT_FOUND", null);
}
// --- salesperson from the team ---
@@ -485,7 +486,7 @@ class AdminEventLeadServiceTest {
when(rest.postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), any()))
.thenReturn(ResponseEntity.ok(Map.of("content", List.of(row), "totalElements", 1, "totalPages", 1, "number", 0, "size", 20)));
Map<String, Object> out = service.list(String.valueOf(EV), 22L, "HOT", "OPEN", 3L, "EXISTING", 0, 20, null);
Map<String, Object> out = service.list(String.valueOf(EV), 22L, "HOT", "OPEN", 3L, "EXISTING", null, 0, 20, null);
assertThat(sent(SEARCH)).containsEntry("companyId", COMPANY).containsEntry("eventUuid", EV).containsEntry("salespersonUserId", 22L)
.containsEntry("temperature", "HOT").containsEntry("status", "OPEN").containsEntry("interestId", 3L)
@@ -516,6 +517,37 @@ class AdminEventLeadServiceTest {
assertCoded(() -> service.get(String.valueOf(EV), String.valueOf(EL)), HttpStatus.NOT_FOUND, "EVENT_LEAD_NOT_FOUND", null);
}
@Test
void listingSendsAttendedFilterAndRowsShowAttendedAndSource() {
Map<String, Object> yes = new LinkedHashMap<>();
yes.put("eventLeadUuid", EL);
yes.put("eventUuid", EV);
yes.put("name", "Aisyah");
yes.put("attendedAt", "2027-01-20T09:30:00");
yes.put("source", "QR");
Map<String, Object> no = new LinkedHashMap<>(yes);
no.put("attendedAt", null);
no.put("source", "INVITE");
when(rest.postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), any()))
.thenReturn(ResponseEntity.ok(Map.of("content", List.of(yes, no), "totalElements", 2, "totalPages", 1, "number", 0, "size", 20)));
Map<String, Object> out = service.list(String.valueOf(EV), null, null, null, null, null, true, 0, 20, null);
assertThat(sent(SEARCH)).containsEntry("attended", true);
List<Map<String, Object>> rows = (List<Map<String, Object>>) out.get("content");
assertThat(rows.get(0)).containsEntry("attended", true).containsEntry("source", "QR");
assertThat(rows.get(1)).containsEntry("attended", false).containsEntry("source", "INVITE");
}
@Test
void getShowsAttendedAndSource() {
stubStored(EV, 21L, List.of(4L));
Map<String, Object> out = service.get(String.valueOf(EV), String.valueOf(EL));
assertThat(out).containsEntry("attended", false).containsEntry("source", "STAFF");
}
@Test
void getShowsSalespersonAndInterestsByName() {
stubStored(EV, 21L, List.of(4L));