| Line 23... |
Line 23... |
| 23 |
import com.spice.profitmandi.dao.model.DateRangeModel;
|
23 |
import com.spice.profitmandi.dao.model.DateRangeModel;
|
| 24 |
import com.spice.profitmandi.dao.model.UserCart;
|
24 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 25 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
25 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 26 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
26 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 27 |
import com.spice.profitmandi.dao.repository.cs.DemoPartnerAccessService;
|
27 |
import com.spice.profitmandi.dao.repository.cs.DemoPartnerAccessService;
|
| - |
|
28 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 28 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
29 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 29 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
30 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 30 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
31 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 31 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
32 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
| 32 |
import com.spice.profitmandi.service.AuthService;
|
33 |
import com.spice.profitmandi.service.AuthService;
|
| Line 137... |
Line 138... |
| 137 |
|
138 |
|
| 138 |
@Autowired
|
139 |
@Autowired
|
| 139 |
private DemoPartnerAccessService demoPartnerAccessService;
|
140 |
private DemoPartnerAccessService demoPartnerAccessService;
|
| 140 |
|
141 |
|
| 141 |
@Autowired
|
142 |
@Autowired
|
| - |
|
143 |
private PositionRepository positionRepository;
|
| - |
|
144 |
|
| - |
|
145 |
@Autowired
|
| 142 |
private RestClient restClient;
|
146 |
private RestClient restClient;
|
| 143 |
|
147 |
|
| 144 |
@Autowired
|
148 |
@Autowired
|
| 145 |
private RoleManager roleManager;
|
149 |
private RoleManager roleManager;
|
| 146 |
|
150 |
|
| Line 626... |
Line 630... |
| 626 |
|
630 |
|
| 627 |
LOGGER.info("Wrapper {}", wrapper);
|
631 |
LOGGER.info("Wrapper {}", wrapper);
|
| 628 |
return responseSender.ok(objectMapper.writeValueAsString(wrapper));
|
632 |
return responseSender.ok(objectMapper.writeValueAsString(wrapper));
|
| 629 |
}
|
633 |
}
|
| 630 |
|
634 |
|
| - |
|
635 |
/**
|
| - |
|
636 |
* React admin partner list. Broader than v1 {@link #getPartners}: Sales, RBM, ABM,
|
| - |
|
637 |
* Category, Training and BI positions all see their assigned partners (v1 only
|
| - |
|
638 |
* mapped Sales/RBM/ABM, so the other HO roles got an empty list), and any user
|
| - |
|
639 |
* with a Technology position sees every active partner across the catalogue —
|
| - |
|
640 |
* tech ops has no region/partner scope.
|
| - |
|
641 |
*
|
| - |
|
642 |
* Angular's /getPartners is intentionally unchanged. This method exists only so
|
| - |
|
643 |
* the v2 React route can call it without regressing the Angular v1 behaviour.
|
| - |
|
644 |
*/
|
| - |
|
645 |
public ResponseEntity<?> getPartnersV2(HttpServletRequest request, String gmailId, int offset, int limit)
|
| - |
|
646 |
throws ProfitMandiBusinessException {
|
| - |
|
647 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| - |
|
648 |
if (authUser == null) {
|
| - |
|
649 |
LOGGER.warn("No auth user found for gmailId: {}", gmailId);
|
| - |
|
650 |
return responseSender.badRequest("No user found for the provided email");
|
| - |
|
651 |
}
|
| - |
|
652 |
|
| - |
|
653 |
// Expanded HO roster for assigned-partner visibility. If you need another
|
| - |
|
654 |
// category to see partners on the React page, add it here — nothing else.
|
| - |
|
655 |
List<Integer> partnerVisibleCategoryIds = Arrays.asList(
|
| - |
|
656 |
ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
| - |
|
657 |
ProfitMandiConstants.TICKET_CATEGORY_RBM,
|
| - |
|
658 |
ProfitMandiConstants.TICKET_CATEGORY_ABM,
|
| - |
|
659 |
ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
| - |
|
660 |
ProfitMandiConstants.TICKET_CATEGORY_TRAINING,
|
| - |
|
661 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
|
| - |
|
662 |
|
| - |
|
663 |
Set<String> emails = new HashSet<>();
|
| - |
|
664 |
boolean isTechUser = positionRepository.selectAllByAuthUserId(authUser.getId()).stream()
|
| - |
|
665 |
.anyMatch(p -> p != null && p.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_TECHNOLOGY);
|
| - |
|
666 |
|
| - |
|
667 |
if (isTechUser) {
|
| - |
|
668 |
// Tech ops override: union of every partner any HO user is mapped to.
|
| - |
|
669 |
// Using the mapping (not a bare fofo-store scan) keeps the "active +
|
| - |
|
670 |
// assigned" filter that the rest of the admin uses, so tech sees the
|
| - |
|
671 |
// same universe operators see, not a wider raw-DB set.
|
| - |
|
672 |
Map<String, Set<String>> fullMap = csService.getAuthUserPartnerEmailMappingByCategoryIds(partnerVisibleCategoryIds);
|
| - |
|
673 |
for (Set<String> perUser : fullMap.values()) {
|
| - |
|
674 |
if (perUser != null) emails.addAll(perUser);
|
| - |
|
675 |
}
|
| - |
|
676 |
} else {
|
| - |
|
677 |
Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMappingByCategoryIds(partnerVisibleCategoryIds);
|
| - |
|
678 |
Set<String> mine = storeGuyMap.get(authUser.getEmailId().toLowerCase());
|
| - |
|
679 |
if (mine != null) {
|
| - |
|
680 |
emails.addAll(mine);
|
| - |
|
681 |
}
|
| - |
|
682 |
}
|
| - |
|
683 |
emails.addAll(demoPartnerAccessService.getDemoPartnerEmails(authUser.getId()));
|
| - |
|
684 |
|
| - |
|
685 |
if (emails.isEmpty()) {
|
| - |
|
686 |
LOGGER.info("No partner emails found for v2 user: {}", gmailId);
|
| - |
|
687 |
return responseSender.ok(new ArrayList<>());
|
| - |
|
688 |
}
|
| - |
|
689 |
|
| - |
|
690 |
List<User> users = userRepository.selectAllByEmails(new ArrayList<>(emails), offset, limit);
|
| - |
|
691 |
List<Partner> partners = new ArrayList<>();
|
| - |
|
692 |
for (User user : users) {
|
| - |
|
693 |
try {
|
| - |
|
694 |
Integer accountKey = userAccountRepository.selectSaholicAccountKeySafe(user.getId());
|
| - |
|
695 |
if (accountKey == null) {
|
| - |
|
696 |
LOGGER.warn("No usable saholic account for userId: {}", user.getId());
|
| - |
|
697 |
continue;
|
| - |
|
698 |
}
|
| - |
|
699 |
com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(accountKey);
|
| - |
|
700 |
if (userInfo == null) {
|
| - |
|
701 |
LOGGER.warn("No user info found for accountKey: {}", accountKey);
|
| - |
|
702 |
continue;
|
| - |
|
703 |
}
|
| - |
|
704 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
|
| - |
|
705 |
if (customRetailer == null) {
|
| - |
|
706 |
LOGGER.warn("No custom retailer found for userInfoId: {}", userInfo.getId());
|
| - |
|
707 |
continue;
|
| - |
|
708 |
}
|
| - |
|
709 |
Partner partner = new Partner();
|
| - |
|
710 |
partner.setBusinessName(customRetailer.getBusinessName());
|
| - |
|
711 |
partner.setPartnerId(customRetailer.getPartnerId());
|
| - |
|
712 |
partner.setCartId(customRetailer.getCartId());
|
| - |
|
713 |
partner.setEmail(customRetailer.getEmail());
|
| - |
|
714 |
partner.setGstNumber(customRetailer.getGstNumber());
|
| - |
|
715 |
partner.setDisplayName(customRetailer.getDisplayName());
|
| - |
|
716 |
partner.setStoreCode(customRetailer.getCode());
|
| - |
|
717 |
partner.setCity(customRetailer.getAddress() != null ? customRetailer.getAddress().getCity() : null);
|
| - |
|
718 |
partner.setUserId(user.getId());
|
| - |
|
719 |
partners.add(partner);
|
| - |
|
720 |
} catch (Exception e) {
|
| - |
|
721 |
LOGGER.error("Error processing partner for userId: {}", user.getId(), e);
|
| - |
|
722 |
}
|
| - |
|
723 |
}
|
| - |
|
724 |
return responseSender.ok(partners);
|
| - |
|
725 |
}
|
| - |
|
726 |
|
| 631 |
@RequestMapping(value = "/getPartners", method = RequestMethod.GET)
|
727 |
@RequestMapping(value = "/getPartners", method = RequestMethod.GET)
|
| 632 |
@ApiImplicitParams({
|
728 |
@ApiImplicitParams({
|
| 633 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
729 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 634 |
public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
|
730 |
public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
|
| 635 |
@RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit)
|
731 |
@RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit)
|