| Line 595... |
Line 595... |
| 595 |
model.addAttribute("date", FormattingUtils.format(LocalDateTime.now()));
|
595 |
model.addAttribute("date", FormattingUtils.format(LocalDateTime.now()));
|
| 596 |
|
596 |
|
| 597 |
return "today-fofo-offer";
|
597 |
return "today-fofo-offer";
|
| 598 |
}
|
598 |
}
|
| 599 |
|
599 |
|
| - |
|
600 |
// ===== Offer Partner & Target Management (Admin Only) =====
|
| - |
|
601 |
|
| - |
|
602 |
@RequestMapping(value = "/offer/partners", method = RequestMethod.GET)
|
| - |
|
603 |
public String getOfferPartners(HttpServletRequest request, @RequestParam int offerId, Model model) throws Exception {
|
| - |
|
604 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
605 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| - |
|
606 |
throw new ProfitMandiBusinessException("Unauthorized", "Unauthorized", "");
|
| - |
|
607 |
}
|
| - |
|
608 |
CreateOfferRequest offer = offerService.getOffer(0, offerId);
|
| - |
|
609 |
List<com.spice.profitmandi.dao.entity.catalog.OfferPartner> offerPartners = offerPartnerRepository.selectByOfferId(offerId);
|
| - |
|
610 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| - |
|
611 |
|
| - |
|
612 |
List<Integer> allFofoIds = fofoStoreRepository.selectActiveStores().stream()
|
| - |
|
613 |
.map(x -> x.getId()).collect(Collectors.toList());
|
| - |
|
614 |
Map<Integer, CustomRetailer> allRetailersMap = allFofoIds.stream()
|
| - |
|
615 |
.map(id -> customRetailerMap.get(id))
|
| - |
|
616 |
.filter(x -> x != null)
|
| - |
|
617 |
.collect(Collectors.toMap(CustomRetailer::getPartnerId, x -> x));
|
| - |
|
618 |
|
| - |
|
619 |
model.addAttribute("offer", offer);
|
| - |
|
620 |
model.addAttribute("offerId", offerId);
|
| - |
|
621 |
model.addAttribute("offerPartners", offerPartners);
|
| - |
|
622 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
| - |
|
623 |
model.addAttribute("allRetailersMap", allRetailersMap);
|
| - |
|
624 |
return "offer_partners";
|
| - |
|
625 |
}
|
| - |
|
626 |
|
| - |
|
627 |
@RequestMapping(value = "/offer/removePartners", method = RequestMethod.POST)
|
| - |
|
628 |
public ResponseEntity<?> removePartnersFromOffer(HttpServletRequest request,
|
| - |
|
629 |
@RequestParam int offerId, @RequestParam List<Integer> fofoIds,
|
| - |
|
630 |
@RequestParam(required = false, defaultValue = "false") boolean createNewOffer,
|
| - |
|
631 |
@RequestParam(required = false) List<Integer> targets) throws Exception {
|
| - |
|
632 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
633 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| - |
|
634 |
throw new ProfitMandiBusinessException("Unauthorized", "Unauthorized", "");
|
| - |
|
635 |
}
|
| - |
|
636 |
Offer offer = offerRepository.selectById(offerId);
|
| - |
|
637 |
YearMonth ym = YearMonth.from(offer.getStartDate());
|
| - |
|
638 |
|
| - |
|
639 |
offerService.removePartnersFromOffer(offerId, fofoIds);
|
| - |
|
640 |
|
| - |
|
641 |
Integer newOfferId = null;
|
| - |
|
642 |
String message;
|
| - |
|
643 |
if (createNewOffer && targets != null && !targets.isEmpty()) {
|
| - |
|
644 |
newOfferId = offerService.cloneOfferForPartners(offerId, fofoIds, targets);
|
| - |
|
645 |
message = "Partner(s) removed from Offer #" + offerId + ". New Offer #" + newOfferId + " created (Unpublished).";
|
| - |
|
646 |
} else {
|
| - |
|
647 |
message = "Partner(s) removed from Offer #" + offerId + ".";
|
| - |
|
648 |
}
|
| - |
|
649 |
|
| - |
|
650 |
oneDayCacheManager.getCache("allOffers").evict(ym);
|
| - |
|
651 |
redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
|
| - |
|
652 |
redisShortCacheManager.getCache("publishedOffersWithAchievement").clear();
|
| - |
|
653 |
|
| - |
|
654 |
Map<String, Object> response = new HashMap<>();
|
| - |
|
655 |
response.put("message", message);
|
| - |
|
656 |
response.put("newOfferId", newOfferId);
|
| - |
|
657 |
response.put("yearMonth", ym.toString());
|
| - |
|
658 |
return responseSender.ok(response);
|
| - |
|
659 |
}
|
| - |
|
660 |
|
| - |
|
661 |
@RequestMapping(value = "/offer/addPartners", method = RequestMethod.POST)
|
| - |
|
662 |
public ResponseEntity<?> addPartnersToOffer(HttpServletRequest request,
|
| - |
|
663 |
@RequestParam int offerId, @RequestParam List<Integer> fofoIds) throws Exception {
|
| - |
|
664 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
665 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| - |
|
666 |
throw new ProfitMandiBusinessException("Unauthorized", "Unauthorized", "");
|
| - |
|
667 |
}
|
| - |
|
668 |
offerService.addPartnersToOffer(offerId, fofoIds);
|
| - |
|
669 |
|
| - |
|
670 |
Offer offer = offerRepository.selectById(offerId);
|
| - |
|
671 |
YearMonth ym = YearMonth.from(offer.getStartDate());
|
| - |
|
672 |
oneDayCacheManager.getCache("allOffers").evict(ym);
|
| - |
|
673 |
redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
|
| - |
|
674 |
redisShortCacheManager.getCache("publishedOffersWithAchievement").clear();
|
| - |
|
675 |
|
| - |
|
676 |
Map<String, Object> response = new HashMap<>();
|
| - |
|
677 |
response.put("message", "Partner(s) added to Offer #" + offerId + ".");
|
| - |
|
678 |
response.put("yearMonth", ym.toString());
|
| - |
|
679 |
return responseSender.ok(response);
|
| - |
|
680 |
}
|
| - |
|
681 |
|
| - |
|
682 |
@RequestMapping(value = "/offer/updateTargets", method = RequestMethod.POST)
|
| - |
|
683 |
public ResponseEntity<?> updateOfferTargets(HttpServletRequest request,
|
| - |
|
684 |
@RequestParam int offerId, @RequestParam List<Integer> targets) throws Exception {
|
| - |
|
685 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
686 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| - |
|
687 |
throw new ProfitMandiBusinessException("Unauthorized", "Unauthorized", "");
|
| - |
|
688 |
}
|
| - |
|
689 |
offerService.updateOfferTargets(offerId, targets);
|
| - |
|
690 |
|
| - |
|
691 |
Offer offer = offerRepository.selectById(offerId);
|
| - |
|
692 |
YearMonth ym = YearMonth.from(offer.getStartDate());
|
| - |
|
693 |
oneDayCacheManager.getCache("allOffers").evict(ym);
|
| - |
|
694 |
redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
|
| - |
|
695 |
redisShortCacheManager.getCache("publishedOffersWithAchievement").clear();
|
| - |
|
696 |
|
| - |
|
697 |
return responseSender.ok("Targets updated for Offer #" + offerId);
|
| - |
|
698 |
}
|
| - |
|
699 |
|
| 600 |
}
|
700 |
}
|
| 601 |
|
701 |
|