Subversion Repositories SmartDukaan

Rev

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

Rev 33873 Rev 33895
Line 252... Line 252...
252
    private UpgradeOfferRepository upgradeOfferRepository;
252
    private UpgradeOfferRepository upgradeOfferRepository;
253
 
253
 
254
    @Autowired
254
    @Autowired
255
    private SmartCartService smartCartService;
255
    private SmartCartService smartCartService;
256
 
256
 
-
 
257
    @Autowired
-
 
258
    private PartnerTypeChangeService partnerTypeChangeService;
-
 
259
 
257
    @Value("${prod}")
260
    @Value("${prod}")
258
    private boolean prodEnv;
261
    private boolean prodEnv;
259
 
262
 
260
    private static final String SMS_GATEWAY = "http://api.pinnacle.in/index.php/sms/send";
263
    private static final String SMS_GATEWAY = "http://api.pinnacle.in/index.php/sms/send";
261
    private static final String SENDER = "SMTDKN";
264
    private static final String SENDER = "SMTDKN";
Line 742... Line 745...
742
        }
745
        }
743
    }
746
    }
744
    private static Map<ScratchedGift, Integer> GIFT_QUANTITIES = new HashMap<>();
747
    private static Map<ScratchedGift, Integer> GIFT_QUANTITIES = new HashMap<>();
745
 
748
 
746
    static {
749
    static {
747
        GIFT_QUANTITIES.put(ScratchedGift.MINI_LUNCH_BOX, 500);
-
 
748
        GIFT_QUANTITIES.put(ScratchedGift.THREE_SET_CONTAINER, 250);
-
 
749
        GIFT_QUANTITIES.put(ScratchedGift.CASSROLE, 250);
750
        GIFT_QUANTITIES.put(ScratchedGift.CASSROLE, 120);
750
        GIFT_QUANTITIES.put(ScratchedGift.INSULATED_FLASK, 250);
751
        GIFT_QUANTITIES.put(ScratchedGift.NECK_BAND, 920);
751
        GIFT_QUANTITIES.put(ScratchedGift.JUICE_JUG, 250);
752
        GIFT_QUANTITIES.put(ScratchedGift.JUICE_JUG, 160);
752
        GIFT_QUANTITIES.put(ScratchedGift.JUICER, 11);
-
 
753
        GIFT_QUANTITIES.put(ScratchedGift.HAIR_DRYER, 16);
753
        GIFT_QUANTITIES.put(ScratchedGift.INSULATED_FLASK, 140);
754
        GIFT_QUANTITIES.put(ScratchedGift.CHOPPER, 20);
-
 
755
        GIFT_QUANTITIES.put(ScratchedGift.BOTTLE, 12);
-
 
756
        GIFT_QUANTITIES.put(ScratchedGift.ELECTRIC_KETTLE, 137);
754
        GIFT_QUANTITIES.put(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, 1000);
757
        GIFT_QUANTITIES.put(ScratchedGift.BOWL_SET, 134);
-
 
758
        GIFT_QUANTITIES.put(ScratchedGift.BOTTLE_MUG, 28);
-
 
759
        GIFT_QUANTITIES.put(ScratchedGift.EW, 1000);
755
        GIFT_QUANTITIES.put(ScratchedGift.EW, 3000);
760
    }
756
    }
761
 
757
 
762
    static {
758
    static {
763
        GIFT_SERIES.put(0.0, Arrays.asList(ScratchedGift.MINI_LUNCH_BOX, ScratchedGift.BOWL_SET, ScratchedGift.THREE_SET_CONTAINER, ScratchedGift.BOTTLE, ScratchedGift.BOTTLE_MUG));
759
        GIFT_SERIES.put(0.0, Arrays.asList(ScratchedGift.ACCESSORIES_50_PERCENT_OFF, ScratchedGift.EW));
764
        GIFT_SERIES.put(20001.0, Arrays.asList(ScratchedGift.CASSROLE, ScratchedGift.INSULATED_FLASK, ScratchedGift.JUICE_JUG));
760
        GIFT_SERIES.put(12001.0, Arrays.asList(ScratchedGift.CASSROLE, ScratchedGift.NECK_BAND, ScratchedGift.JUICE_JUG, ScratchedGift.INSULATED_FLASK, ScratchedGift.ACCESSORIES_50_PERCENT_OFF, ScratchedGift.EW));
765
        GIFT_SERIES.put(25001.0, Arrays.asList(ScratchedGift.ELECTRIC_KETTLE));
-
 
766
        GIFT_SERIES.put(35001.0, Arrays.asList(ScratchedGift.JUICER, ScratchedGift.HAIR_DRYER, ScratchedGift.CHOPPER));
761
        GIFT_SERIES.put(35001.0, Arrays.asList(ScratchedGift.CASSROLE, ScratchedGift.NECK_BAND, ScratchedGift.JUICE_JUG, ScratchedGift.INSULATED_FLASK, ScratchedGift.ACCESSORIES_50_PERCENT_OFF));
767
    }
762
    }
768
 
763
 
769
    List<Double> PRICE_RANGE = Arrays.asList(0.0, 20001.0, 25001.0, 35001.0);
764
    List<Double> PRICE_RANGE = Arrays.asList(0.0, 12001.0,35001.0);
770
 
765
 
771
    @Override
766
    @Override
772
    public void processScratchOffer(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
767
    public void processScratchOffer(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
773
        boolean isSmartPhonePurchased = false;
768
        boolean isSmartPhonePurchased = false;
774
        float maxPurchaseValue = 0;
769
        float maxPurchaseValue = 0;
Line 797... Line 792...
797
                } catch (Exception e) {
792
                } catch (Exception e) {
798
                    // TODO Auto-generated catch block
793
                    // TODO Auto-generated catch block
799
                    e.printStackTrace();
794
                    e.printStackTrace();
800
                }
795
                }
801
                if (specificPriceOffer) {
796
                if (specificPriceOffer) {
802
                    this.createSpecificPriceScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId(), maxPurchaseValue);
797
                    this.createSpecificPriceScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId(),fofoOrder.getFofoId(), maxPurchaseValue);
803
                } else if (randomOffer) {
798
                } else if (randomOffer) {
804
                    this.createRandomScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
799
                    this.createRandomScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
805
                    LOGGER.info("randomOffer {}", randomOffer);
800
                    LOGGER.info("randomOffer {}", randomOffer);
806
                } else {
801
                } else {
807
                    this.createScratchOffer(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
802
                    this.createScratchOffer(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
Line 810... Line 805...
810
            }
805
            }
811
        }
806
        }
812
    }
807
    }
813
 
808
 
814
    @Override
809
    @Override
815
    public ScratchedGift getSelectedGift(double purchaseAmount) {
810
    public ScratchedGift getSelectedGift(double purchaseAmount,int fofoId) throws ProfitMandiBusinessException {
816
        //Iterating map in reverse order of values
811
        //Iterating map in reverse order of values
817
        Map<ScratchedGift, Long> scratchOfferCountMap = scratchOfferRepository.countOffersByDateRange(ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
812
        Map<ScratchedGift, Long> scratchOfferCountMap = scratchOfferRepository.countOffersByDateRange(ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
818
 
-
 
819
        RandomCollection<ScratchedGift> giftRandomCollection = createDynamicGiftSeries(scratchOfferCountMap, purchaseAmount);
813
        RandomCollection<ScratchedGift> giftRandomCollection = createDynamicGiftSeries(scratchOfferCountMap, purchaseAmount,fofoId);
820
        if (giftRandomCollection.size() > 0) {
814
        if (giftRandomCollection.size() > 0) {
821
            return giftRandomCollection.next();
815
            return giftRandomCollection.next();
822
        } else if (purchaseAmount < 35000) {
816
        } else if (purchaseAmount < 35000) {
823
            // Default gift if no match found
817
            // Default gift if no match found
824
            return ScratchedGift.EW;
818
            return ScratchedGift.EW;
825
        } else {
819
        } else {
826
            return ScratchedGift.BLNT;
820
            return ScratchedGift.ACCESSORIES_50_PERCENT_OFF;
827
        }
821
        }
828
    }
822
    }
829
 
823
 
830
    public RandomCollection<ScratchedGift> createDynamicGiftSeries(Map<ScratchedGift, Long> soldGiftContMap, Double sellingPrice) {
824
    public RandomCollection<ScratchedGift> createDynamicGiftSeries(Map<ScratchedGift, Long> soldGiftContMap, Double sellingPrice, int fofoId) throws ProfitMandiBusinessException {
831
        int index = 0;
825
        int index = 0;
832
        RandomCollection<ScratchedGift> randomCollection = new RandomCollection<>();
826
        RandomCollection<ScratchedGift> randomCollection = new RandomCollection<>();
-
 
827
        PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId,LocalDate.now());
-
 
828
        LOGGER.info("partnerType {}",partnerType);
-
 
829
        if (partnerType.equals(PartnerType.BRONZE)) {
-
 
830
            LOGGER.info("partnerType if- {}",partnerType);
-
 
831
            sellingPrice = 0.0;
-
 
832
        }
833
        for (Double price : PRICE_RANGE) {
833
        for (Double price : PRICE_RANGE) {
834
            if (sellingPrice >= price) {
834
            if (sellingPrice >= price) {
835
                int divisor = PRICE_RANGE.size() - index;
835
                int divisor = PRICE_RANGE.size() - index;
836
                for (ScratchedGift gift : GIFT_SERIES.get(price)) {
836
                for (ScratchedGift gift : GIFT_SERIES.get(price)) {
837
                    int remainingQty = GIFT_QUANTITIES.get(gift) - soldGiftContMap.getOrDefault(gift, 0l).intValue();
837
                    int remainingQty = GIFT_QUANTITIES.get(gift) - soldGiftContMap.getOrDefault(gift, 0l).intValue();
Line 881... Line 881...
881
 
881
 
882
        GIFT_SERIES.put(50001.0, map5);
882
        GIFT_SERIES.put(50001.0, map5);
883
    }*/
883
    }*/
884
 
884
 
885
 
885
 
886
    private void createSpecificPriceScratchOffer(String invoiceNumber, int customerId, float purchaseAmount) {
886
    private void createSpecificPriceScratchOffer(String invoiceNumber, int customerId, int fofoId, float purchaseAmount) throws ProfitMandiBusinessException {
887
        ScratchedGift selectedGift = getSelectedGift(purchaseAmount);
887
        ScratchedGift selectedGift = getSelectedGift(purchaseAmount,fofoId);
888
        List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
888
        List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
889
        if (scratchOffers.size() == 0) {
889
        if (scratchOffers.size() == 0) {
890
            ScratchOffer so2 = new ScratchOffer();
890
            ScratchOffer so2 = new ScratchOffer();
891
            so2.setInvoiceNumber(invoiceNumber);
891
            so2.setInvoiceNumber(invoiceNumber);
892
            so2.setScratched(false);
892
            so2.setScratched(false);