| Line 533... |
Line 533... |
| 533 |
|
533 |
|
| 534 |
if (leadStatus.contains(LeadStatus.All)) {
|
534 |
if (leadStatus.contains(LeadStatus.All)) {
|
| 535 |
leadStatus.add(LeadStatus.pending);
|
535 |
leadStatus.add(LeadStatus.pending);
|
| 536 |
leadStatus.add(LeadStatus.notInterested);
|
536 |
leadStatus.add(LeadStatus.notInterested);
|
| 537 |
leadStatus.add(LeadStatus.finalized);
|
537 |
leadStatus.add(LeadStatus.finalized);
|
| - |
|
538 |
// NOTE: do NOT add followUp here. Follow-ups are pulled separately (undated) below,
|
| - |
|
539 |
// mirroring the on-screen view. Adding it here made the date query get skipped so the
|
| 538 |
leadStatus.add(LeadStatus.followUp);
|
540 |
// download collapsed to follow-ups only (original bug).
|
| 539 |
}
|
541 |
}
|
| 540 |
if (color.contains("All")) {
|
542 |
if (color.contains("All")) {
|
| 541 |
color.add("yellow");
|
543 |
color.add("yellow");
|
| 542 |
color.add("green");
|
544 |
color.add("green");
|
| 543 |
}
|
545 |
}
|
| Line 557... |
Line 559... |
| 557 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
559 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
| 558 |
leadFollowUp = leadRepository.selectByAssignAuthIdsAndStatus(authUserIds, LeadStatus.followUp);
|
560 |
leadFollowUp = leadRepository.selectByAssignAuthIdsAndStatus(authUserIds, LeadStatus.followUp);
|
| 559 |
leads.addAll(leadFollowUp);
|
561 |
leads.addAll(leadFollowUp);
|
| 560 |
}
|
562 |
}
|
| 561 |
} else {
|
563 |
} else {
|
| 562 |
// Date range selected: return ALL selected statuses (including follow-up) created within [start, end].
|
564 |
// Date range: non-follow-up statuses created within [start, end], PLUS all follow-ups
|
| 563 |
// Follow-up is now date-bounded via this same query instead of pulling every follow-up ever,
|
565 |
// (undated) — mirrors the on-screen view so the CSV matches what the user sees.
|
| 564 |
// which previously made a date-range download ignore the dates and drop non-follow-up statuses.
|
566 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 565 |
leads = leadRepository.selectAllByColorStatusAndBetweenCreatedDateAndAuthIds(leadStatus, authUserIds, color, startDateTime, endDateTime);
|
567 |
leads = leadRepository.selectAllByColorStatusAndBetweenCreatedDateAndAuthIds(leadStatus, authUserIds, color, startDateTime, endDateTime);
|
| - |
|
568 |
}
|
| - |
|
569 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
| - |
|
570 |
leadFollowUp = leadRepository.selectByAssignAuthIdsAndStatus(authUserIds, LeadStatus.followUp);
|
| - |
|
571 |
leads.addAll(leadFollowUp);
|
| - |
|
572 |
}
|
| 566 |
}
|
573 |
}
|
| 567 |
} else {
|
574 |
} else {
|
| 568 |
if (startDateTime == null) {
|
575 |
if (startDateTime == null) {
|
| 569 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
576 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 570 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color, LocalDateTime.now().minusMonths(1));
|
577 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color, LocalDateTime.now().minusMonths(1));
|
| Line 572... |
Line 579... |
| 572 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
579 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
| 573 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
580 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
| 574 |
leads.addAll(leadFollowUp);
|
581 |
leads.addAll(leadFollowUp);
|
| 575 |
}
|
582 |
}
|
| 576 |
} else {
|
583 |
} else {
|
| 577 |
// Date range selected: return ALL selected statuses (including follow-up) created within [start, end].
|
584 |
// Date range: non-follow-up statuses created within [start, end], PLUS all follow-ups
|
| - |
|
585 |
// (undated) — mirrors the on-screen view.
|
| - |
|
586 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 578 |
leads = leadRepository.selectAllByColorStatusAndBetweenCreatedDate(leadStatus, color, startDateTime, endDateTime);
|
587 |
leads = leadRepository.selectAllByColorStatusAndBetweenCreatedDate(leadStatus, color, startDateTime, endDateTime);
|
| - |
|
588 |
}
|
| - |
|
589 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
| - |
|
590 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
| - |
|
591 |
leads.addAll(leadFollowUp);
|
| - |
|
592 |
}
|
| 579 |
}
|
593 |
}
|
| 580 |
}
|
594 |
}
|
| 581 |
|
595 |
|
| 582 |
// Build activity map and auth map (SAME AS VIEW ENDPOINT)
|
596 |
// Build activity map and auth map (SAME AS VIEW ENDPOINT)
|
| - |
|
597 |
// Guard both lookups on a non-empty result: an empty list would generate an invalid
|
| - |
|
598 |
// "IN ()" and 500 (e.g. a date range with no leads), so an empty range yields an empty CSV.
|
| - |
|
599 |
Map<Integer, AuthUser> authIdAndAuthUserMap = new HashMap<>();
|
| 583 |
if (!leads.isEmpty()) {
|
600 |
if (!leads.isEmpty()) {
|
| 584 |
List<Integer> leadIds = leads.stream().map(Lead::getId).collect(Collectors.toList());
|
601 |
List<Integer> leadIds = leads.stream().map(Lead::getId).collect(Collectors.toList());
|
| 585 |
leadActivityMap = leadActivityRepository.selectAllByleadIds(leadIds).stream()
|
602 |
leadActivityMap = leadActivityRepository.selectAllByleadIds(leadIds).stream()
|
| 586 |
.collect(Collectors.groupingBy(LeadActivity::getLeadId));
|
603 |
.collect(Collectors.groupingBy(LeadActivity::getLeadId));
|
| - |
|
604 |
List<Integer> authIds = leads.stream().map(Lead::getAssignTo).collect(Collectors.toList());
|
| - |
|
605 |
authIdAndAuthUserMap = authRepository.selectByIds(authIds).stream()
|
| - |
|
606 |
.collect(Collectors.toMap(AuthUser::getId, x -> x));
|
| 587 |
}
|
607 |
}
|
| 588 |
List<Integer> authIds = leads.stream().map(Lead::getAssignTo).collect(Collectors.toList());
|
- |
|
| 589 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectByIds(authIds).stream()
|
- |
|
| 590 |
.collect(Collectors.toMap(AuthUser::getId, x -> x));
|
- |
|
| 591 |
|
608 |
|
| 592 |
// Build CSV rows (USE DIRECT LEAD PROPERTIES - NO ACTIVITY FALLBACK)
|
609 |
// Build CSV rows (USE DIRECT LEAD PROPERTIES - NO ACTIVITY FALLBACK)
|
| 593 |
List<List<?>> rows = new ArrayList<>();
|
610 |
List<List<?>> rows = new ArrayList<>();
|
| 594 |
for (Lead lead : leads) {
|
611 |
for (Lead lead : leads) {
|
| 595 |
List<LeadActivity> activities = leadActivityMap.get(lead.getId());
|
612 |
List<LeadActivity> activities = leadActivityMap.get(lead.getId());
|
| Line 781... |
Line 798... |
| 781 |
|
798 |
|
| 782 |
return "lead-close-paginated";
|
799 |
return "lead-close-paginated";
|
| 783 |
|
800 |
|
| 784 |
}
|
801 |
}
|
| 785 |
|
802 |
|
| - |
|
803 |
// Global lead search box: find ANY lead by name / mobile / outlet / city, no date filter needed.
|
| - |
|
804 |
@RequestMapping(value = "/globalLeadSearch")
|
| - |
|
805 |
public String globalLeadSearch(HttpServletRequest request,
|
| - |
|
806 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
| - |
|
807 |
Model model) {
|
| - |
|
808 |
List<Lead> leads = new ArrayList<>();
|
| - |
|
809 |
if (!searchTerm.trim().isEmpty()) {
|
| - |
|
810 |
leads = leadRepository.selectByGlobalSearch(searchTerm.trim(), 200);
|
| - |
|
811 |
if (!leads.isEmpty()) {
|
| - |
|
812 |
List<Integer> authIds = leads.stream().map(Lead::getAssignTo).collect(Collectors.toList());
|
| - |
|
813 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectByIds(authIds).stream()
|
| - |
|
814 |
.collect(Collectors.toMap(AuthUser::getId, x -> x));
|
| - |
|
815 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
| - |
|
816 |
}
|
| - |
|
817 |
}
|
| - |
|
818 |
model.addAttribute("leads", leads);
|
| - |
|
819 |
model.addAttribute("searchTerm", searchTerm);
|
| - |
|
820 |
return "lead-close-paginated";
|
| - |
|
821 |
}
|
| - |
|
822 |
|
| 786 |
@RequestMapping(value = "/getLeadActivity", method = RequestMethod.GET)
|
823 |
@RequestMapping(value = "/getLeadActivity", method = RequestMethod.GET)
|
| 787 |
public String getLeadActivity(HttpServletRequest request, @RequestParam int leadId, Model model) throws Exception {
|
824 |
public String getLeadActivity(HttpServletRequest request, @RequestParam int leadId, Model model) throws Exception {
|
| 788 |
List<LeadActivity> leadActivity = leadActivityRepository.selectBYLeadId(leadId);
|
825 |
List<LeadActivity> leadActivity = leadActivityRepository.selectBYLeadId(leadId);
|
| 789 |
|
826 |
|
| 790 |
LOGGER.info("leadActivity" + leadActivity);
|
827 |
LOGGER.info("leadActivity" + leadActivity);
|