Subversion Repositories SmartDukaan

Rev

Rev 34338 | Rev 34341 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34338 Rev 34340
Line 265... Line 265...
265
 
265
 
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
    // Define eligible partners for LED & Microwave Oven
270
    List<Double> PRICE_RANGE = Arrays.asList(0.0, 12001.0, 35001.0, Double.MAX_VALUE);
271
    private static final Set<Integer> PREMIUM_ELIGIBLE_PARTNERS = new HashSet<>(Arrays.asList(175139287, 159690067));
271
 
272
 
272
    static Map<Double, List<ScratchedGift>> GIFT_SERIES = new TreeMap<>(Comparator.reverseOrder());
273
    static Map<Double, List<ScratchedGift>> GIFT_SERIES = new TreeMap<>(Comparator.reverseOrder());
273
 
274
 
-
 
275
    static {
-
 
276
        GIFT_QUANTITIES.put(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, 500);
-
 
277
        GIFT_QUANTITIES.put(ScratchedGift.NECK_BAND, 280);
-
 
278
        GIFT_QUANTITIES.put(ScratchedGift.LED, 1);
-
 
279
        GIFT_QUANTITIES.put(ScratchedGift.MICROWAVE_OVEN, 1);
-
 
280
    }
-
 
281
 
-
 
282
    static {
-
 
283
        GIFT_SERIES.put(0.0, Arrays.asList(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, ScratchedGift.NECK_BAND));
-
 
284
        GIFT_SERIES.put(50001.0, Arrays.asList(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, ScratchedGift.NECK_BAND, ScratchedGift.MICROWAVE_OVEN, ScratchedGift.LED));
-
 
285
    }
-
 
286
 
-
 
287
    private final Map<Integer, LocalDate> partnerNeckbandTracking = new HashMap<>();
-
 
288
 
274
    private void persistNonSerializedWithCustomSerialNumber(CustomFofoOrderItem customFofoOrderItem, int orderItemId) {
289
    private void persistNonSerializedWithCustomSerialNumber(CustomFofoOrderItem customFofoOrderItem, int orderItemId) {
275
        // Create a new instance of FofoNonSerializeSerial
290
        // Create a new instance of FofoNonSerializeSerial
276
        for (String accSerialNumber : customFofoOrderItem.getCustomSerialNumbers()) {
291
        for (String accSerialNumber : customFofoOrderItem.getCustomSerialNumbers()) {
277
            if (!accSerialNumber.isEmpty()) {
292
            if (!accSerialNumber.isEmpty()) {
278
                FofoNonSerializeSerial nonSerializeSerial = new FofoNonSerializeSerial();
293
                FofoNonSerializeSerial nonSerializeSerial = new FofoNonSerializeSerial();
Line 348... Line 363...
348
            scratchOfferRepository.persist(so2);
363
            scratchOfferRepository.persist(so2);
349
        }
364
        }
350
    }
365
    }
351
 
366
 
352
    private static Map<ScratchedGift, Integer> GIFT_QUANTITIES = new HashMap<>();
367
    private static Map<ScratchedGift, Integer> GIFT_QUANTITIES = new HashMap<>();
-
 
368
    private final Map<ScratchedGift, LocalDate> premiumGiftTracking = new HashMap<>();
-
 
369
    List<Double> PRICE_RANGE = Arrays.asList(0.0, Double.MAX_VALUE);
353
 
370
 
354
    static {
-
 
355
        GIFT_QUANTITIES.put(ScratchedGift.CASSROLE, 120);
-
 
356
        GIFT_QUANTITIES.put(ScratchedGift.NECK_BAND, 920);
-
 
357
        GIFT_QUANTITIES.put(ScratchedGift.JUICE_JUG, 160);
-
 
358
        GIFT_QUANTITIES.put(ScratchedGift.INSULATED_FLASK, 140);
-
 
359
        GIFT_QUANTITIES.put(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, 500);
-
 
360
        GIFT_QUANTITIES.put(ScratchedGift.EW, 1500);
-
 
361
    }
-
 
362
 
-
 
363
    static {
-
 
364
        GIFT_SERIES.put(0.0, Arrays.asList(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, ScratchedGift.EW));
-
 
365
        GIFT_SERIES.put(12001.0, Arrays.asList(ScratchedGift.CASSROLE, ScratchedGift.NECK_BAND, ScratchedGift.JUICE_JUG, ScratchedGift.INSULATED_FLASK));
-
 
366
        GIFT_SERIES.put(35001.0, Arrays.asList(ScratchedGift.CASSROLE, ScratchedGift.NECK_BAND, ScratchedGift.JUICE_JUG, ScratchedGift.INSULATED_FLASK));
-
 
367
    }
-
 
368
 
371
 
369
    @Override
372
    @Override
370
    public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals) throws Exception {
373
    public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals) throws Exception {
371
        LOGGER.info("fofoId -- {} Order Request -- {}", fofoId, createOrderRequest);
374
        LOGGER.info("fofoId -- {} Order Request -- {}", fofoId, createOrderRequest);
372
        CustomCustomer customCustomer = createOrderRequest.getCustomer();
375
        CustomCustomer customCustomer = createOrderRequest.getCustomer();
Line 809... Line 812...
809
        }
812
        }
810
    }
813
    }
811
 
814
 
812
    @Override
815
    @Override
813
    public ScratchedGift getSelectedGift(double purchaseAmount, int fofoId) throws ProfitMandiBusinessException {
816
    public ScratchedGift getSelectedGift(double purchaseAmount, int fofoId) throws ProfitMandiBusinessException {
814
        //Iterating map in reverse order of values
-
 
815
        Map<ScratchedGift, Long> scratchOfferCountMap = scratchOfferRepository.countOffersByDateRange(ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
817
        Map<ScratchedGift, Long> scratchOfferCountMap = scratchOfferRepository.countOffersByDateRange(ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
816
        RandomCollection<ScratchedGift> giftRandomCollection = createDynamicGiftSeries(scratchOfferCountMap, purchaseAmount, fofoId);
818
        RandomCollection<ScratchedGift> giftRandomCollection = createDynamicGiftSeries(scratchOfferCountMap, purchaseAmount, fofoId);
817
        if (giftRandomCollection.size() > 0) {
819
        if (giftRandomCollection.size() > 0) {
818
            return giftRandomCollection.next();
820
            ScratchedGift selectedGift = giftRandomCollection.next();
-
 
821
            // Restrict Neckband per partner per day
-
 
822
            if (selectedGift == ScratchedGift.NECK_BAND) {
-
 
823
                LocalDate lastGivenDate = partnerNeckbandTracking.get(fofoId);
-
 
824
                if (lastGivenDate != null && lastGivenDate.equals(LocalDate.now())) {
-
 
825
                    LOGGER.info("Neckband already given today for partner {}", fofoId);
-
 
826
                    return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;  // Provide an alternate gift
-
 
827
                }
-
 
828
                // Update tracking for Neckband distribution
-
 
829
                partnerNeckbandTracking.put(fofoId, LocalDate.now());
-
 
830
            }
-
 
831
 
-
 
832
            // Restrict LED & Microwave Oven to eligible partners only
-
 
833
            if ((selectedGift == ScratchedGift.LED || selectedGift == ScratchedGift.MICROWAVE_OVEN)) {
-
 
834
                if (!PREMIUM_ELIGIBLE_PARTNERS.contains(fofoId)) {
-
 
835
                    LOGGER.info("Partner {} not eligible for {}", fofoId, selectedGift);
-
 
836
                    return ScratchedGift.ACCESSORIES_50_PERCENT_OFF; // Give alternate gift
-
 
837
                }
-
 
838
 
-
 
839
                // Ensure only one LED and one Microwave Oven per day
-
 
840
                LocalDate lastGivenDate = premiumGiftTracking.get(selectedGift);
-
 
841
                if (lastGivenDate != null && lastGivenDate.equals(LocalDate.now())) {
-
 
842
                    LOGGER.info("{} already given today", selectedGift);
-
 
843
                    return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
-
 
844
                }
-
 
845
 
819
        } else if (purchaseAmount < 35000) {
846
                // Mark the gift as given today
-
 
847
                premiumGiftTracking.put(selectedGift, LocalDate.now());
-
 
848
            }
-
 
849
 
-
 
850
            // Restrict LED & Microwave Oven to eligible partners only
-
 
851
            if ((selectedGift == ScratchedGift.LED || selectedGift == ScratchedGift.MICROWAVE_OVEN)) {
-
 
852
                if (!PREMIUM_ELIGIBLE_PARTNERS.contains(fofoId)) {
-
 
853
                    LOGGER.info("Partner {} not eligible for {}", fofoId, selectedGift);
-
 
854
                    return ScratchedGift.ACCESSORIES_50_PERCENT_OFF; // Give alternate gift
-
 
855
                }
-
 
856
 
-
 
857
                // Ensure only one LED and one Microwave Oven per day
-
 
858
                LocalDate lastGivenDate = premiumGiftTracking.get(selectedGift);
-
 
859
                if (lastGivenDate != null && lastGivenDate.equals(LocalDate.now())) {
-
 
860
                    LOGGER.info("{} already given today", selectedGift);
-
 
861
                    return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
-
 
862
                }
-
 
863
 
820
            // Default gift if no match found
864
                // Mark the gift as given today
-
 
865
                premiumGiftTracking.put(selectedGift, LocalDate.now());
-
 
866
            }
-
 
867
 
821
            return ScratchedGift.EW;
868
            return selectedGift;
822
        } else {
869
        } else {
823
            return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
870
            return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
824
        }
871
        }
825
    }
872
    }
826
 
873
 
827
    public RandomCollection<ScratchedGift> createDynamicGiftSeries(Map<ScratchedGift, Long> soldGiftContMap, Double sellingPrice, int fofoId) throws ProfitMandiBusinessException {
874
    public RandomCollection<ScratchedGift> createDynamicGiftSeries(Map<ScratchedGift, Long> soldGiftCountMap,
-
 
875
                                                                   Double sellingPrice, int fofoId)
-
 
876
            throws ProfitMandiBusinessException {
-
 
877
 
828
        int index = 0;
878
        int index = 0;
829
        RandomCollection<ScratchedGift> randomCollection = new RandomCollection<>();
879
        RandomCollection<ScratchedGift> randomCollection = new RandomCollection<>();
830
        PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
880
        PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
831
        LOGGER.info("partnerType {}", partnerType);
881
        LOGGER.info("partnerType {}", partnerType);
832
 
882
 
Line 835... Line 885...
835
            sellingPrice = 0.0;
885
            sellingPrice = 0.0;
836
        }
886
        }
837
 
887
 
838
        for (int i = 0; i < PRICE_RANGE.size(); i++) {
888
        for (int i = 0; i < PRICE_RANGE.size(); i++) {
839
            Double price = PRICE_RANGE.get(i);
889
            Double price = PRICE_RANGE.get(i);
840
            Double nextPrice = Double.MAX_VALUE;
-
 
841
            if (i != PRICE_RANGE.size() - 1) {
-
 
842
                nextPrice = PRICE_RANGE.get(i + 1);
890
            Double nextPrice = (i != PRICE_RANGE.size() - 1) ? PRICE_RANGE.get(i + 1) : Double.MAX_VALUE;
843
            }
891
 
844
            if (sellingPrice >= price && sellingPrice < nextPrice) {
892
            if (sellingPrice >= price && sellingPrice < nextPrice) {
845
                int divisor = PRICE_RANGE.size() - index;
893
                int divisor = PRICE_RANGE.size() - index;
846
                LOGGER.info("Processing price range: {}, sellingPrice: {}", price, sellingPrice);
894
                LOGGER.info("Processing price range: {}, sellingPrice: {}", price, sellingPrice);
847
 
895
 
848
                for (ScratchedGift gift : GIFT_SERIES.get(price)) {
896
                for (ScratchedGift gift : GIFT_SERIES.get(price)) {
849
                    int remainingQty = GIFT_QUANTITIES.get(gift) - soldGiftContMap.getOrDefault(gift, 0L).intValue();
897
                    int remainingQty = GIFT_QUANTITIES.get(gift) - soldGiftCountMap.getOrDefault(gift, 0L).intValue();
850
                    LOGGER.info("Checking gift: {}, remainingQty: {}", gift, remainingQty);
898
                    LOGGER.info("Checking gift: {}, remainingQty: {}", gift, remainingQty);
851
 
899
 
852
                    if (remainingQty > 0) {
900
                    if (remainingQty > 0) {
853
                        int weight = (remainingQty > divisor) ? remainingQty / divisor : remainingQty;
901
                        int weight = (remainingQty > divisor) ? remainingQty / divisor : remainingQty;
-
 
902
 
-
 
903
                        if (gift == ScratchedGift.NECK_BAND) {
-
 
904
                            LocalDate lastGivenDate = partnerNeckbandTracking.get(fofoId);
-
 
905
                            if (lastGivenDate == null || !lastGivenDate.equals(LocalDate.now())) {
854
                        randomCollection.add(weight, gift);
906
                                randomCollection.add(weight, gift);
-
 
907
                            }
-
 
908
                        } else if (gift == ScratchedGift.LED || gift == ScratchedGift.MICROWAVE_OVEN) {
-
 
909
                            if (PREMIUM_ELIGIBLE_PARTNERS.contains(fofoId) && !premiumGiftTracking.containsKey(gift)) {
-
 
910
                                randomCollection.add(weight, gift);
-
 
911
                            }
-
 
912
                        } else {
855
                        LOGGER.info("Added gift: {}, weight: {}", gift, weight);
913
                            randomCollection.add(weight, gift);
-
 
914
                        }
856
                    }
915
                    }
857
                }
916
                }
858
                break; // Exit the loop once the correct price range is processed
917
                break;
859
            }
918
            }
860
            index++;
919
            index++;
861
        }
920
        }
862
 
921
 
863
        // If no gifts were added, log and handle potential issues here
-
 
864
        if (randomCollection.size() == 0) {
922
        if (randomCollection.size() == 0) {
865
            LOGGER.info("No gifts added for sellingPrice: {} in createDynamicGiftSeries", sellingPrice);
923
            LOGGER.info("No gifts added for sellingPrice: {} in createDynamicGiftSeries", sellingPrice);
866
        }
924
        }
867
 
925
 
868
        LOGGER.info("randomCollectionSize {}, partnerType {}, sellingPrice {}", randomCollection.size(), partnerType, sellingPrice);
-
 
869
        return randomCollection;
926
        return randomCollection;
870
    }
927
    }
871
 
928
 
872
 
929
 
873
 
930