| Line 629... |
Line 629... |
| 629 |
loginDetails.getFofoId(),
|
629 |
loginDetails.getFofoId(),
|
| 630 |
Optional.of(TicketStatus.OPENED.equals(ticketStatus)),
|
630 |
Optional.of(TicketStatus.OPENED.equals(ticketStatus)),
|
| 631 |
sortOrder);
|
631 |
sortOrder);
|
| 632 |
}
|
632 |
}
|
| 633 |
if (tickets == null) tickets = new ArrayList<>();
|
633 |
if (tickets == null) tickets = new ArrayList<>();
|
| - |
|
634 |
return renderTicketsAsCsv(tickets, "Tickets_" + ticketStatus.name());
|
| - |
|
635 |
}
|
| - |
|
636 |
|
| - |
|
637 |
// Download every manager ticket the current user can see in the panel's filter —
|
| - |
|
638 |
// tickets escalated to this user (or all tickets in the user's categories for CRM).
|
| - |
|
639 |
// Requires L2+ position, mirroring populateManagerTicketModel.
|
| - |
|
640 |
@GetMapping(value = "/cs/downloadManagerTickets")
|
| - |
|
641 |
public ResponseEntity<?> downloadManagerTickets(HttpServletRequest request,
|
| - |
|
642 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
| - |
|
643 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
| - |
|
644 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
| - |
|
645 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
| - |
|
646 |
@RequestParam(name = "search", required = false) String searchText) throws Exception {
|
| - |
|
647 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
648 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| - |
|
649 |
|
| - |
|
650 |
List<Position> positions = positionRepository.selectAllByAuthUserId(authUser.getId());
|
| - |
|
651 |
boolean isAboveL1 = positions.stream().anyMatch(p -> p.getEscalationType() != EscalationType.L1);
|
| - |
|
652 |
if (!isAboveL1) {
|
| - |
|
653 |
throw new ProfitMandiBusinessException("ManagerTicket", 0, "Access denied: requires at least L2 position");
|
| - |
|
654 |
}
|
| - |
|
655 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
| - |
|
656 |
List<Integer> userCategoryIds = positionRepository.selectCategoryIdsByAuthUserId(authUser.getId());
|
| - |
|
657 |
Optional<Boolean> resolvedOpt = ticketStatus.equals(TicketStatus.RESOLVED)
|
| - |
|
658 |
? Optional.empty()
|
| - |
|
659 |
: Optional.of(TicketStatus.CLOSED.equals(ticketStatus));
|
| - |
|
660 |
|
| - |
|
661 |
List<Ticket> tickets;
|
| - |
|
662 |
long total;
|
| - |
|
663 |
if (isCrmUser) {
|
| - |
|
664 |
total = ticketRepository.selectAllTicketsPaginatedCount(
|
| - |
|
665 |
resolvedOpt, ticketSearchType, searchTerm, searchText, userCategoryIds);
|
| - |
|
666 |
tickets = ticketRepository.selectAllTicketsPaginated(
|
| - |
|
667 |
resolvedOpt, sortOrder, ticketSearchType, searchTerm, searchText,
|
| - |
|
668 |
userCategoryIds, 0, (int) Math.max(1L, total));
|
| - |
|
669 |
} else {
|
| - |
|
670 |
total = ticketRepository.selectAllCountByManagerTicketPaginated(
|
| - |
|
671 |
authUser.getId(), resolvedOpt, ticketSearchType, searchTerm, searchText);
|
| - |
|
672 |
tickets = ticketRepository.selectAllManagerTicketPaginated(
|
| - |
|
673 |
authUser.getId(), sortOrder, resolvedOpt, ticketSearchType, searchTerm, searchText,
|
| - |
|
674 |
0, (int) Math.max(1L, total));
|
| - |
|
675 |
}
|
| - |
|
676 |
if (tickets == null) tickets = new ArrayList<>();
|
| - |
|
677 |
return renderTicketsAsCsv(tickets, "ManagerTickets_" + ticketStatus.name());
|
| - |
|
678 |
}
|
| - |
|
679 |
|
| - |
|
680 |
// Download every partner ticket the current user is a store-guy for. Mirrors
|
| - |
|
681 |
// populateMyPartnerTicketModel: always OPEN + drops RESOLVED via lastActivity check.
|
| - |
|
682 |
@GetMapping(value = "/cs/downloadPartnerTickets")
|
| - |
|
683 |
public ResponseEntity<?> downloadPartnerTickets(HttpServletRequest request) throws Exception {
|
| - |
|
684 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
685 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| - |
|
686 |
|
| - |
|
687 |
List<Ticket> tickets = new ArrayList<>();
|
| - |
|
688 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| - |
|
689 |
Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
|
| - |
|
690 |
|
| - |
|
691 |
if (fofoIds != null && !fofoIds.isEmpty()) {
|
| - |
|
692 |
List<Ticket> allPartnerTickets = ticketRepository.selectAllOpenTickets(new ArrayList<>(fofoIds));
|
| - |
|
693 |
if (allPartnerTickets != null && !allPartnerTickets.isEmpty()) {
|
| - |
|
694 |
tickets = allPartnerTickets.stream()
|
| - |
|
695 |
.filter(t -> t.getLastActivity() == null || t.getLastActivity() != ActivityType.RESOLVED)
|
| - |
|
696 |
.collect(Collectors.toList());
|
| - |
|
697 |
}
|
| - |
|
698 |
}
|
| - |
|
699 |
return renderTicketsAsCsv(tickets, "PartnerTickets_OPENED");
|
| - |
|
700 |
}
|
| 634 |
|
701 |
|
| - |
|
702 |
// Shared row-builder + CSV render for the three download endpoints. Given a ticket
|
| - |
|
703 |
// list, resolves every display field (partner, category, sub-category, first + last
|
| - |
|
704 |
// activity, assignees) and returns the CSV response.
|
| - |
|
705 |
private ResponseEntity<?> renderTicketsAsCsv(List<Ticket> tickets, String fileNamePrefix) throws Exception {
|
| 635 |
List<Integer> subCategoryIds = tickets.stream().map(Ticket::getSubCategoryId).collect(Collectors.toList());
|
706 |
List<Integer> subCategoryIds = tickets.stream().map(Ticket::getSubCategoryId).collect(Collectors.toList());
|
| 636 |
Map<Integer, TicketSubCategory> subMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
707 |
Map<Integer, TicketSubCategory> subMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| 637 |
if (subMap == null) subMap = new HashMap<>();
|
708 |
if (subMap == null) subMap = new HashMap<>();
|
| 638 |
Map<Integer, TicketCategory> catMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
709 |
Map<Integer, TicketCategory> catMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| 639 |
if (catMap == null) catMap = new HashMap<>();
|
710 |
if (catMap == null) catMap = new HashMap<>();
|
| Line 716... |
Line 787... |
| 716 |
|
787 |
|
| 717 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
788 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 718 |
Arrays.asList("Ticket Id", "Partner", "Category", "SubCategory", "Message",
|
789 |
Arrays.asList("Ticket Id", "Partner", "Category", "SubCategory", "Message",
|
| 719 |
"Created By", "Assigned To", "Created TimeStamp"),
|
790 |
"Created By", "Assigned To", "Created TimeStamp"),
|
| 720 |
rows);
|
791 |
rows);
|
| 721 |
return orderService.downloadReportInCsv(baos, rows, "Tickets_" + ticketStatus.name());
|
792 |
return orderService.downloadReportInCsv(baos, rows, fileNamePrefix);
|
| 722 |
}
|
793 |
}
|
| 723 |
|
794 |
|
| 724 |
private void populateMyTicketModel(HttpServletRequest request, SortOrder sortOrder, TicketStatus ticketStatus,
|
795 |
private void populateMyTicketModel(HttpServletRequest request, SortOrder sortOrder, TicketStatus ticketStatus,
|
| 725 |
TicketSearchType ticketSearchType, int searchTerm, int page, int pageSize,
|
796 |
TicketSearchType ticketSearchType, int searchTerm, int page, int pageSize,
|
| 726 |
String searchText, Model model) throws ProfitMandiBusinessException {
|
797 |
String searchText, Model model) throws ProfitMandiBusinessException {
|