| Line 266... |
Line 266... |
| 266 |
public static final String APP_DOWNLOAD_BILLING_TEMPLATE_ID = "1507163542403945677";
|
266 |
public static final String APP_DOWNLOAD_BILLING_TEMPLATE_ID = "1507163542403945677";
|
| 267 |
|
267 |
|
| 268 |
public static final String APP_DOWNLOAD_BILLING_OFFER = "Dear Customer, Thank you for purchasing from SmartDukaan pls click %s to download our app to see you invoice and special offers. SmartDukaan";
|
268 |
public static final String APP_DOWNLOAD_BILLING_OFFER = "Dear Customer, Thank you for purchasing from SmartDukaan pls click %s to download our app to see you invoice and special offers. SmartDukaan";
|
| 269 |
|
269 |
|
| 270 |
static Map<Double, List<ScratchedGift>> GIFT_SERIES = new TreeMap<>(Comparator.reverseOrder());
|
270 |
static Map<Double, List<ScratchedGift>> GIFT_SERIES = new TreeMap<>(Comparator.reverseOrder());
|
| 271 |
private final Map<Integer, LocalDate> partnerNeckbandTracking = new HashMap<>();
|
- |
|
| 272 |
|
271 |
|
| 273 |
// Define eligible partners for LED & Microwave Oven
|
272 |
// Define eligible partners for LED & Microwave Oven
|
| 274 |
private static final Set<Integer> PREMIUM_ELIGIBLE_PARTNERS = new HashSet<>(Arrays.asList(175139287, 159690067));
|
273 |
private static final Set<Integer> PREMIUM_ELIGIBLE_PARTNERS = new HashSet<>(Arrays.asList(175139615, 175139583));
|
| 275 |
private static Map<ScratchedGift, Integer> GIFT_QUANTITIES = new HashMap<>();
|
274 |
private static Map<ScratchedGift, Integer> GIFT_QUANTITIES = new HashMap<>();
|
| 276 |
private final Map<ScratchedGift, LocalDate> premiumGiftTracking = new HashMap<>();
|
- |
|
| 277 |
List<Double> PRICE_RANGE = Arrays.asList(0.0, Double.MAX_VALUE);
|
275 |
List<Double> PRICE_RANGE = Arrays.asList(0.0, Double.MAX_VALUE);
|
| 278 |
|
276 |
|
| 279 |
static {
|
277 |
static {
|
| 280 |
GIFT_QUANTITIES.put(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, 500);
|
278 |
GIFT_QUANTITIES.put(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, 500);
|
| 281 |
GIFT_QUANTITIES.put(ScratchedGift.NECK_BAND, 280);
|
279 |
GIFT_QUANTITIES.put(ScratchedGift.NECK_BAND, 280);
|
| Line 283... |
Line 281... |
| 283 |
GIFT_QUANTITIES.put(ScratchedGift.MICROWAVE_OVEN, 1);
|
281 |
GIFT_QUANTITIES.put(ScratchedGift.MICROWAVE_OVEN, 1);
|
| 284 |
}
|
282 |
}
|
| 285 |
|
283 |
|
| 286 |
static {
|
284 |
static {
|
| 287 |
GIFT_SERIES.put(0.0, Arrays.asList(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, ScratchedGift.NECK_BAND));
|
285 |
GIFT_SERIES.put(0.0, Arrays.asList(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, ScratchedGift.NECK_BAND));
|
| 288 |
GIFT_SERIES.put(50001.0, Arrays.asList(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, ScratchedGift.NECK_BAND, ScratchedGift.MICROWAVE_OVEN, ScratchedGift.LED));
|
286 |
GIFT_SERIES.put(30001.0, Arrays.asList(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, ScratchedGift.NECK_BAND, ScratchedGift.MICROWAVE_OVEN, ScratchedGift.LED));
|
| 289 |
}
|
287 |
}
|
| 290 |
|
288 |
|
| 291 |
private void persistNonSerializedWithCustomSerialNumber(CustomFofoOrderItem customFofoOrderItem, int orderItemId) {
|
289 |
private void persistNonSerializedWithCustomSerialNumber(CustomFofoOrderItem customFofoOrderItem, int orderItemId) {
|
| 292 |
// Create a new instance of FofoNonSerializeSerial
|
290 |
// Create a new instance of FofoNonSerializeSerial
|
| 293 |
for (String accSerialNumber : customFofoOrderItem.getCustomSerialNumbers()) {
|
291 |
for (String accSerialNumber : customFofoOrderItem.getCustomSerialNumbers()) {
|
| Line 810... |
Line 808... |
| 810 |
}
|
808 |
}
|
| 811 |
}
|
809 |
}
|
| 812 |
|
810 |
|
| 813 |
@Override
|
811 |
@Override
|
| 814 |
public ScratchedGift getSelectedGift(double purchaseAmount, int fofoId) throws ProfitMandiBusinessException {
|
812 |
public ScratchedGift getSelectedGift(double purchaseAmount, int fofoId) throws ProfitMandiBusinessException {
|
| - |
|
813 |
Map<ScratchedGift, Long> scratchOfferCountMap = scratchOfferRepository.countOffersByDateRange(
|
| 815 |
Map<ScratchedGift, Long> scratchOfferCountMap = scratchOfferRepository.countOffersByDateRange(ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
|
814 |
ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE
|
| - |
|
815 |
);
|
| - |
|
816 |
LOGGER.info("scratchOfferCountMap {}", scratchOfferCountMap);
|
| - |
|
817 |
|
| - |
|
818 |
LocalDateTime startDateTime = ProfitMandiConstants.SCRATCH_OFFER_START_DATE.atStartOfDay();
|
| - |
|
819 |
LocalDateTime endDateTime = ProfitMandiConstants.SCRATCH_OFFER_END_DATE.atStartOfDay().plusDays(1);
|
| - |
|
820 |
|
| 816 |
RandomCollection<ScratchedGift> giftRandomCollection = createDynamicGiftSeries(scratchOfferCountMap, purchaseAmount, fofoId);
|
821 |
RandomCollection<ScratchedGift> giftRandomCollection = createDynamicGiftSeries(scratchOfferCountMap, purchaseAmount, fofoId);
|
| - |
|
822 |
|
| 817 |
if (giftRandomCollection.size() > 0) {
|
823 |
if (giftRandomCollection.size() > 0) {
|
| 818 |
ScratchedGift selectedGift = giftRandomCollection.next();
|
824 |
ScratchedGift selectedGift = giftRandomCollection.next();
|
| 819 |
// Restrict Neckband per partner per day
|
- |
|
| 820 |
if (selectedGift == ScratchedGift.NECK_BAND) {
|
- |
|
| 821 |
LocalDate lastGivenDate = partnerNeckbandTracking.get(fofoId);
|
- |
|
| 822 |
if (lastGivenDate != null && lastGivenDate.equals(LocalDate.now())) {
|
- |
|
| 823 |
LOGGER.info("Neckband already given today for partner {}", fofoId);
|
- |
|
| 824 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF; // Provide an alternate gift
|
- |
|
| 825 |
}
|
- |
|
| 826 |
// Update tracking for Neckband distribution
|
- |
|
| 827 |
partnerNeckbandTracking.put(fofoId, LocalDate.now());
|
- |
|
| 828 |
}
|
- |
|
| 829 |
|
825 |
|
| 830 |
// Restrict LED & Microwave Oven to eligible partners only
|
826 |
// 🛑 Ensure one LED for 175139615 and one Oven for 175139583
|
| 831 |
if ((selectedGift == ScratchedGift.LED || selectedGift == ScratchedGift.MICROWAVE_OVEN)) {
|
827 |
if (selectedGift == ScratchedGift.LED || selectedGift == ScratchedGift.MICROWAVE_OVEN) {
|
| 832 |
if (!PREMIUM_ELIGIBLE_PARTNERS.contains(fofoId)) {
|
828 |
if (!PREMIUM_ELIGIBLE_PARTNERS.contains(fofoId)) {
|
| 833 |
LOGGER.info("Partner {} not eligible for {}", fofoId, selectedGift);
|
829 |
LOGGER.info("Partner {} not eligible for {}", fofoId, selectedGift);
|
| 834 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF; // Give alternate gift
|
830 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF; // Default alternate gift
|
| 835 |
}
|
831 |
}
|
| 836 |
|
832 |
|
| 837 |
// Ensure only one LED and one Microwave Oven per day
|
833 |
// Restrict LED to Partner 175139615 and Oven to Partner 175139583
|
| 838 |
LocalDate lastGivenDate = premiumGiftTracking.get(selectedGift);
|
834 |
if ((selectedGift == ScratchedGift.LED && fofoId != 175139615) ||
|
| 839 |
if (lastGivenDate != null && lastGivenDate.equals(LocalDate.now())) {
|
835 |
(selectedGift == ScratchedGift.MICROWAVE_OVEN && fofoId != 175139583)) {
|
| 840 |
LOGGER.info("{} already given today", selectedGift);
|
836 |
LOGGER.info("Partner {} not eligible for {}", fofoId, selectedGift);
|
| 841 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
|
837 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
|
| 842 |
}
|
838 |
}
|
| 843 |
|
839 |
|
| 844 |
// Mark the gift as given today
|
840 |
// Ensure only one LED and one Microwave Oven per day
|
| - |
|
841 |
long ledCount = scratchOfferCountMap.getOrDefault(ScratchedGift.LED, 0L);
|
| - |
|
842 |
long ovenCount = scratchOfferCountMap.getOrDefault(ScratchedGift.MICROWAVE_OVEN, 0L);
|
| 845 |
premiumGiftTracking.put(selectedGift, LocalDate.now());
|
843 |
if ((selectedGift == ScratchedGift.LED || selectedGift == ScratchedGift.MICROWAVE_OVEN)
|
| - |
|
844 |
&& (ledCount > 0 && ovenCount > 0)) {
|
| - |
|
845 |
LOGGER.info("Both LED and Microwave Oven already given today.");
|
| - |
|
846 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
|
| - |
|
847 |
}
|
| 846 |
}
|
848 |
}
|
| 847 |
|
849 |
|
| 848 |
// Restrict LED & Microwave Oven to eligible partners only
|
850 |
// 🛑 Ensure only one Neckband per partner per day
|
| 849 |
if ((selectedGift == ScratchedGift.LED || selectedGift == ScratchedGift.MICROWAVE_OVEN)) {
|
851 |
if (selectedGift == ScratchedGift.NECK_BAND) {
|
| 850 |
if (!PREMIUM_ELIGIBLE_PARTNERS.contains(fofoId)) {
|
852 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoId(fofoId, startDateTime, endDateTime, 0, 0);
|
| 851 |
LOGGER.info("Partner {} not eligible for {}", fofoId, selectedGift);
|
853 |
List<String> invoiceNumbers = fofoOrders.stream().map(FofoOrder::getInvoiceNumber).collect(Collectors.toList());
|
| 852 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF; // Give alternate gift
|
854 |
List<ScratchOffer> offers = scratchOfferRepository.selectByInvoiceNumbers(invoiceNumbers);
|
| 853 |
}
|
855 |
LOGGER.info("offers for partner {}", offers);
|
| 854 |
|
856 |
|
| 855 |
// Ensure only one LED and one Microwave Oven per day
|
- |
|
| 856 |
LocalDate lastGivenDate = premiumGiftTracking.get(selectedGift);
|
857 |
boolean neckbandGivenToday = offers.stream().anyMatch(offer -> offer.getOfferName() == ScratchedGift.NECK_BAND);
|
| 857 |
if (lastGivenDate != null && lastGivenDate.equals(LocalDate.now())) {
|
858 |
if (neckbandGivenToday) {
|
| 858 |
LOGGER.info("{} already given today", selectedGift);
|
859 |
LOGGER.info("Neckband already given today for partner {}", fofoId);
|
| 859 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
|
860 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
|
| 860 |
}
|
861 |
}
|
| 861 |
|
- |
|
| 862 |
// Mark the gift as given today
|
- |
|
| 863 |
premiumGiftTracking.put(selectedGift, LocalDate.now());
|
- |
|
| 864 |
}
|
862 |
}
|
| 865 |
|
863 |
|
| 866 |
return selectedGift;
|
864 |
return selectedGift;
|
| 867 |
} else {
|
- |
|
| 868 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
|
- |
|
| 869 |
}
|
865 |
}
|
| - |
|
866 |
|
| - |
|
867 |
return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
|
| 870 |
}
|
868 |
}
|
| 871 |
|
869 |
|
| 872 |
public RandomCollection<ScratchedGift> createDynamicGiftSeries(Map<ScratchedGift, Long> soldGiftCountMap,
|
- |
|
| 873 |
Double sellingPrice, int fofoId)
|
- |
|
| 874 |
throws ProfitMandiBusinessException {
|
- |
|
| 875 |
|
870 |
|
| - |
|
871 |
public RandomCollection<ScratchedGift> createDynamicGiftSeries(Map<ScratchedGift, Long> soldGiftContMap, Double sellingPrice, int fofoId) throws ProfitMandiBusinessException {
|
| 876 |
int index = 0;
|
872 |
int index = 0;
|
| 877 |
RandomCollection<ScratchedGift> randomCollection = new RandomCollection<>();
|
873 |
RandomCollection<ScratchedGift> randomCollection = new RandomCollection<>();
|
| 878 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
|
874 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
|
| 879 |
LOGGER.info("partnerType {}", partnerType);
|
875 |
LOGGER.info("partnerType {}", partnerType);
|
| 880 |
|
876 |
|
| Line 883... |
Line 879... |
| 883 |
sellingPrice = 0.0;
|
879 |
sellingPrice = 0.0;
|
| 884 |
}
|
880 |
}
|
| 885 |
|
881 |
|
| 886 |
for (int i = 0; i < PRICE_RANGE.size(); i++) {
|
882 |
for (int i = 0; i < PRICE_RANGE.size(); i++) {
|
| 887 |
Double price = PRICE_RANGE.get(i);
|
883 |
Double price = PRICE_RANGE.get(i);
|
| - |
|
884 |
Double nextPrice = Double.MAX_VALUE;
|
| - |
|
885 |
if (i != PRICE_RANGE.size() - 1) {
|
| 888 |
Double nextPrice = (i != PRICE_RANGE.size() - 1) ? PRICE_RANGE.get(i + 1) : Double.MAX_VALUE;
|
886 |
nextPrice = PRICE_RANGE.get(i + 1);
|
| 889 |
|
887 |
}
|
| 890 |
if (sellingPrice >= price && sellingPrice < nextPrice) {
|
888 |
if (sellingPrice >= price && sellingPrice < nextPrice) {
|
| 891 |
int divisor = PRICE_RANGE.size() - index;
|
889 |
int divisor = PRICE_RANGE.size() - index;
|
| 892 |
LOGGER.info("Processing price range: {}, sellingPrice: {}", price, sellingPrice);
|
890 |
LOGGER.info("Processing price range: {}, sellingPrice: {}", price, sellingPrice);
|
| 893 |
|
891 |
|
| 894 |
for (ScratchedGift gift : GIFT_SERIES.get(price)) {
|
892 |
for (ScratchedGift gift : GIFT_SERIES.get(price)) {
|
| 895 |
int remainingQty = GIFT_QUANTITIES.get(gift) - soldGiftCountMap.getOrDefault(gift, 0L).intValue();
|
893 |
int remainingQty = GIFT_QUANTITIES.get(gift) - soldGiftContMap.getOrDefault(gift, 0L).intValue();
|
| 896 |
LOGGER.info("Checking gift: {}, remainingQty: {}", gift, remainingQty);
|
894 |
LOGGER.info("Checking gift: {}, remainingQty: {}", gift, remainingQty);
|
| 897 |
|
895 |
|
| 898 |
if (remainingQty > 0) {
|
896 |
if (remainingQty > 0) {
|
| 899 |
int weight = (remainingQty > divisor) ? remainingQty / divisor : remainingQty;
|
897 |
int weight = (remainingQty > divisor) ? remainingQty / divisor : remainingQty;
|
| 900 |
|
- |
|
| 901 |
if (gift == ScratchedGift.NECK_BAND) {
|
- |
|
| 902 |
LocalDate lastGivenDate = partnerNeckbandTracking.get(fofoId);
|
- |
|
| 903 |
if (lastGivenDate == null || !lastGivenDate.equals(LocalDate.now())) {
|
- |
|
| 904 |
randomCollection.add(weight, gift);
|
898 |
randomCollection.add(weight, gift);
|
| 905 |
}
|
- |
|
| 906 |
} else if (gift == ScratchedGift.LED || gift == ScratchedGift.MICROWAVE_OVEN) {
|
- |
|
| 907 |
if (PREMIUM_ELIGIBLE_PARTNERS.contains(fofoId) && !premiumGiftTracking.containsKey(gift)) {
|
- |
|
| 908 |
randomCollection.add(weight, gift);
|
- |
|
| 909 |
}
|
- |
|
| 910 |
} else {
|
- |
|
| 911 |
randomCollection.add(weight, gift);
|
899 |
LOGGER.info("Added gift: {}, weight: {}", gift, weight);
|
| 912 |
}
|
- |
|
| 913 |
}
|
900 |
}
|
| 914 |
}
|
901 |
}
|
| 915 |
break;
|
902 |
break; // Exit the loop once the correct price range is processed
|
| 916 |
}
|
903 |
}
|
| 917 |
index++;
|
904 |
index++;
|
| 918 |
}
|
905 |
}
|
| 919 |
|
906 |
|
| - |
|
907 |
// If no gifts were added, log and handle potential issues here
|
| 920 |
if (randomCollection.size() == 0) {
|
908 |
if (randomCollection.size() == 0) {
|
| 921 |
LOGGER.info("No gifts added for sellingPrice: {} in createDynamicGiftSeries", sellingPrice);
|
909 |
LOGGER.info("No gifts added for sellingPrice: {} in createDynamicGiftSeries", sellingPrice);
|
| 922 |
}
|
910 |
}
|
| 923 |
|
911 |
|
| - |
|
912 |
LOGGER.info("randomCollectionSize {}, partnerType {}, sellingPrice {}", randomCollection.size(), partnerType, sellingPrice);
|
| 924 |
return randomCollection;
|
913 |
return randomCollection;
|
| 925 |
}
|
914 |
}
|
| 926 |
|
915 |
|
| 927 |
|
916 |
|
| 928 |
|
917 |
|