| Line 28... |
Line 28... |
| 28 |
import org.springframework.transaction.annotation.Transactional;
|
28 |
import org.springframework.transaction.annotation.Transactional;
|
| 29 |
import org.springframework.ui.Model;
|
29 |
import org.springframework.ui.Model;
|
| 30 |
import org.springframework.web.bind.annotation.*;
|
30 |
import org.springframework.web.bind.annotation.*;
|
| 31 |
|
31 |
|
| 32 |
import javax.servlet.http.HttpServletRequest;
|
32 |
import javax.servlet.http.HttpServletRequest;
|
| 33 |
import javax.swing.*;
|
33 |
import javax.swing.SortOrder;
|
| 34 |
import java.time.LocalDateTime;
|
34 |
import java.time.LocalDateTime;
|
| 35 |
import java.util.*;
|
35 |
import java.util.*;
|
| 36 |
import java.util.stream.Collectors;
|
36 |
import java.util.stream.Collectors;
|
| 37 |
|
37 |
|
| 38 |
@Controller
|
38 |
@Controller
|
| Line 376... |
Line 376... |
| 376 |
}
|
376 |
}
|
| 377 |
|
377 |
|
| 378 |
@PostMapping(value = "/cs/updatePartnerPosition")
|
378 |
@PostMapping(value = "/cs/updatePartnerPosition")
|
| 379 |
public String updatePartnerPosition(HttpServletRequest request, @RequestParam(name = "regionId") int regionId, @RequestBody List<Integer> selectedFofoIds, @RequestParam(name = "positionId") int positionId, Model model) throws Exception {
|
379 |
public String updatePartnerPosition(HttpServletRequest request, @RequestParam(name = "regionId") int regionId, @RequestBody List<Integer> selectedFofoIds, @RequestParam(name = "positionId") int positionId, Model model) throws Exception {
|
| 380 |
|
380 |
|
| - |
|
381 |
// Validate positionId exists
|
| - |
|
382 |
Position position = positionRepository.selectById(positionId);
|
| - |
|
383 |
if (position == null) {
|
| - |
|
384 |
throw new ProfitMandiBusinessException("Position", positionId, "Position not found");
|
| - |
|
385 |
}
|
| - |
|
386 |
|
| - |
|
387 |
// Validate regionId exists (0 or 5 typically means "All Partners/Regions")
|
| - |
|
388 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
| - |
|
389 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
| - |
|
390 |
}
|
| - |
|
391 |
|
| - |
|
392 |
// Validate fofoIds exist
|
| - |
|
393 |
if (selectedFofoIds != null && !selectedFofoIds.isEmpty()) {
|
| - |
|
394 |
Map<Integer, CustomRetailer> validRetailers = retailerService.getFofoRetailers(false);
|
| - |
|
395 |
for (int fofoId : selectedFofoIds) {
|
| - |
|
396 |
if (!validRetailers.containsKey(fofoId)) {
|
| - |
|
397 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
| - |
|
398 |
}
|
| - |
|
399 |
}
|
| - |
|
400 |
}
|
| - |
|
401 |
|
| 381 |
partnerPositionRepository.delete(positionId);
|
402 |
partnerPositionRepository.delete(positionId);
|
| - |
|
403 |
if (selectedFofoIds != null) {
|
| 382 |
for (int fofoId : selectedFofoIds) {
|
404 |
for (int fofoId : selectedFofoIds) {
|
| 383 |
PartnerPosition partnerPosition = new PartnerPosition();
|
405 |
PartnerPosition partnerPosition = new PartnerPosition();
|
| 384 |
partnerPosition.setFofoId(fofoId);
|
406 |
partnerPosition.setFofoId(fofoId);
|
| 385 |
partnerPosition.setRegionId(regionId);
|
407 |
partnerPosition.setRegionId(regionId);
|
| 386 |
partnerPosition.setPositionId(positionId);
|
408 |
partnerPosition.setPositionId(positionId);
|
| 387 |
partnerPositionRepository.persist(partnerPosition);
|
409 |
partnerPositionRepository.persist(partnerPosition);
|
| - |
|
410 |
}
|
| 388 |
}
|
411 |
}
|
| 389 |
|
412 |
|
| 390 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
413 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 391 |
|
414 |
|
| 392 |
return "response";
|
415 |
return "response";
|
| Line 501... |
Line 524... |
| 501 |
} else {
|
524 |
} else {
|
| 502 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(), Optional.of(TicketStatus.OPENED.equals(ticketStatus)), sortOrder);
|
525 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(), Optional.of(TicketStatus.OPENED.equals(ticketStatus)), sortOrder);
|
| 503 |
size = ticketRepository.selectAllCountByCreator(loginDetails.getFofoId(), Optional.of(TicketStatus.OPENED.equals(ticketStatus)));
|
526 |
size = ticketRepository.selectAllCountByCreator(loginDetails.getFofoId(), Optional.of(TicketStatus.OPENED.equals(ticketStatus)));
|
| 504 |
}
|
527 |
}
|
| 505 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
528 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
| - |
|
529 |
if (authUserIdAndAuthUserMap == null) {
|
| - |
|
530 |
authUserIdAndAuthUserMap = new HashMap<>();
|
| - |
|
531 |
}
|
| 506 |
|
532 |
|
| 507 |
model.addAttribute("size", size);
|
533 |
model.addAttribute("size", size);
|
| 508 |
model.addAttribute("roleType", isAdmin);
|
534 |
model.addAttribute("roleType", isAdmin);
|
| 509 |
// Check if user is in CRM category (only CRM can send external communications)
|
535 |
// Check if user is in CRM category (only CRM can send external communications)
|
| 510 |
boolean isCrmUser = isAdmin && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
536 |
boolean isCrmUser = isAdmin && currentAuthUser != null && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
| 511 |
model.addAttribute("isCrmUser", isCrmUser);
|
537 |
model.addAttribute("isCrmUser", isCrmUser);
|
| 512 |
|
538 |
|
| 513 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
539 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
| 514 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
540 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| - |
|
541 |
if (subCategoryIdAndSubCategoryMap == null) {
|
| - |
|
542 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
| - |
|
543 |
}
|
| 515 |
|
544 |
|
| 516 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
545 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| - |
|
546 |
if (subCategoryIdAndCategoryMap == null) {
|
| - |
|
547 |
subCategoryIdAndCategoryMap = new HashMap<>();
|
| - |
|
548 |
}
|
| 517 |
|
549 |
|
| 518 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
550 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 519 |
|
551 |
|
| 520 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
552 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
| 521 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
553 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| Line 702... |
Line 734... |
| 702 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
734 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 703 |
Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
|
735 |
Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
|
| 704 |
|
736 |
|
| 705 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
737 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
| 706 |
if (fofoIds != null && !fofoIds.isEmpty()) {
|
738 |
if (fofoIds != null && !fofoIds.isEmpty()) {
|
| 707 |
for (Integer fofoId : fofoIds) {
|
739 |
// Batch fetch all open tickets for all fofoIds (fix N+1 query)
|
| 708 |
List<Ticket> partnerWiseTickets = ticketRepository.selectAllOpenTicketByRetailer(fofoId);
|
740 |
List<Ticket> allPartnerTickets = ticketRepository.selectAllOpenTickets(new ArrayList<>(fofoIds));
|
| 709 |
|
- |
|
| 710 |
if (partnerWiseTickets != null && !partnerWiseTickets.isEmpty()) {
|
741 |
if (allPartnerTickets != null && !allPartnerTickets.isEmpty()) {
|
| 711 |
// Filter tickets where last_activity is not "RESOLVED"
|
742 |
// Filter tickets where last_activity is not "RESOLVED"
|
| 712 |
List<Ticket> filteredTickets = partnerWiseTickets.stream()
|
743 |
tickets = allPartnerTickets.stream()
|
| 713 |
.filter(ticket -> ticket.getLastActivity() == null ||
|
744 |
.filter(ticket -> ticket.getLastActivity() == null ||
|
| 714 |
ticket.getLastActivity() != ActivityType.RESOLVED)
|
745 |
ticket.getLastActivity() != ActivityType.RESOLVED)
|
| 715 |
.collect(Collectors.toList());
|
746 |
.collect(Collectors.toList());
|
| 716 |
|
- |
|
| 717 |
tickets.addAll(filteredTickets);
|
- |
|
| 718 |
}
|
- |
|
| 719 |
}
|
747 |
}
|
| 720 |
}
|
748 |
}
|
| 721 |
|
749 |
|
| 722 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
750 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
| 723 |
|
751 |
|
| Line 730... |
Line 758... |
| 730 |
model.addAttribute("size", tickets.size());
|
758 |
model.addAttribute("size", tickets.size());
|
| 731 |
model.addAttribute("tickets", tickets);
|
759 |
model.addAttribute("tickets", tickets);
|
| 732 |
|
760 |
|
| 733 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
761 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
| 734 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
762 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| - |
|
763 |
if (subCategoryIdAndSubCategoryMap == null) {
|
| - |
|
764 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
| - |
|
765 |
}
|
| 735 |
|
766 |
|
| 736 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
767 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| - |
|
768 |
if (subCategoryIdAndCategoryMap == null) {
|
| - |
|
769 |
subCategoryIdAndCategoryMap = new HashMap<>();
|
| - |
|
770 |
}
|
| 737 |
|
771 |
|
| 738 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
772 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 739 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
773 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
| 740 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
774 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| 741 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
775 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
| Line 763... |
Line 797... |
| 763 |
model.addAttribute("selectedorderby", sortOrder);
|
797 |
model.addAttribute("selectedorderby", sortOrder);
|
| 764 |
model.addAttribute("tickets", tickets);
|
798 |
model.addAttribute("tickets", tickets);
|
| 765 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
799 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
| 766 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
800 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
| 767 |
model.addAttribute("searchTerm", searchTerm);
|
801 |
model.addAttribute("searchTerm", searchTerm);
|
| 768 |
model.addAttribute("authUserListMap", authUserListMap);
|
802 |
model.addAttribute("authUserListMap", authUserListMap != null ? authUserListMap : new HashMap<>());
|
| 769 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
803 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
| 770 |
|
804 |
|
| 771 |
model.addAttribute("subCategoryIdAndCategoryMap", subCategoryIdAndCategoryMap);
|
805 |
model.addAttribute("subCategoryIdAndCategoryMap", subCategoryIdAndCategoryMap);
|
| 772 |
|
806 |
|
| 773 |
model.addAttribute("activityMap", activityMap);
|
807 |
model.addAttribute("activityMap", activityMap);
|
| Line 815... |
Line 849... |
| 815 |
model.addAttribute("size", size);
|
849 |
model.addAttribute("size", size);
|
| 816 |
model.addAttribute("tickets", tickets);
|
850 |
model.addAttribute("tickets", tickets);
|
| 817 |
|
851 |
|
| 818 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
852 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
| 819 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
853 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| - |
|
854 |
if (subCategoryIdAndSubCategoryMap == null) {
|
| - |
|
855 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
| - |
|
856 |
}
|
| 820 |
|
857 |
|
| 821 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
858 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| - |
|
859 |
if (subCategoryIdAndCategoryMap == null) {
|
| - |
|
860 |
subCategoryIdAndCategoryMap = new HashMap<>();
|
| - |
|
861 |
}
|
| 822 |
|
862 |
|
| 823 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
863 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 824 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
864 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
| 825 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
865 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| 826 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
866 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|