| Line 576... |
Line 576... |
| 576 |
} catch (Exception e) {
|
576 |
} catch (Exception e) {
|
| 577 |
// TODO Auto-generated catch block
|
577 |
// TODO Auto-generated catch block
|
| 578 |
e.printStackTrace();
|
578 |
e.printStackTrace();
|
| 579 |
}
|
579 |
}
|
| 580 |
if (specificPriceOffer) {
|
580 |
if (specificPriceOffer) {
|
| 581 |
this.createSpecificPriceScratchOffer(fofoId, fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId(), purchaseAmount);
|
581 |
this.createSpecificPriceScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId(), purchaseAmount);
|
| 582 |
} else {
|
582 |
} else {
|
| 583 |
this.createScratchOffer(fofoId, fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
|
583 |
this.createScratchOffer(fofoId, fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
|
| 584 |
}
|
584 |
}
|
| 585 |
|
585 |
|
| 586 |
}
|
586 |
}
|
| Line 664... |
Line 664... |
| 664 |
}
|
664 |
}
|
| 665 |
scratchOfferRepository.persist(so2);
|
665 |
scratchOfferRepository.persist(so2);
|
| 666 |
}
|
666 |
}
|
| 667 |
}
|
667 |
}
|
| 668 |
|
668 |
|
| 669 |
private void createSpecificPriceScratchOffer(int fofoId, String invoiceNumber, int customerId, float purchaseAmount) {
|
669 |
static Map<Double, RandomCollection<ScratchedGift>> GIFT_SERIES = new TreeMap<>(Comparator.reverseOrder());
|
| 670 |
|
670 |
|
| - |
|
671 |
static {
|
| - |
|
672 |
RandomCollection<ScratchedGift> map1 = new RandomCollection<ScratchedGift>().
|
| - |
|
673 |
add(100d, ScratchedGift.GIFT_BOWL);
|
| - |
|
674 |
GIFT_SERIES.put(0.0, map1);
|
| 671 |
Map<Double, ScratchedGift> giftSeries = new HashMap<>();
|
675 |
//Map<ScratchedGift, Double> map2 = new HashMap<>();
|
| - |
|
676 |
RandomCollection<ScratchedGift> map2 = new RandomCollection<ScratchedGift>()
|
| 672 |
giftSeries.put(12000.0, ScratchedGift.GIFT_BOWL);
|
677 |
.add(40d, ScratchedGift.GIFT_BOWL)
|
| 673 |
giftSeries.put(25000.0, ScratchedGift.NECK_BAND);
|
678 |
.add(20d, ScratchedGift.NECK_BAND)
|
| - |
|
679 |
.add(30d, ScratchedGift.FLASKNMUG)
|
| - |
|
680 |
.add(10d, ScratchedGift.ELECTRIC_KETTLE);
|
| - |
|
681 |
GIFT_SERIES.put(10001.0, map2);
|
| - |
|
682 |
RandomCollection<ScratchedGift> map3 = new RandomCollection<ScratchedGift>()
|
| - |
|
683 |
.add(25d, ScratchedGift.GIFT_BOWL)
|
| - |
|
684 |
.add(30d, ScratchedGift.NECK_BAND)
|
| - |
|
685 |
.add(10d, ScratchedGift.SPEAKER)
|
| - |
|
686 |
.add(25d, ScratchedGift.FLASKNMUG)
|
| - |
|
687 |
.add(10d, ScratchedGift.ELECTRIC_KETTLE);
|
| - |
|
688 |
GIFT_SERIES.put(18001.0, map3);
|
| - |
|
689 |
RandomCollection<ScratchedGift> map4 = new RandomCollection<ScratchedGift>()
|
| - |
|
690 |
.add(30d, ScratchedGift.NECK_BAND)
|
| - |
|
691 |
.add(20d, ScratchedGift.SPEAKER)
|
| 674 |
giftSeries.put(25001.0, ScratchedGift.BT_SOUNDBAR);
|
692 |
.add(20d, ScratchedGift.FLASKNMUG)
|
| - |
|
693 |
.add(30d, ScratchedGift.ELECTRIC_KETTLE);
|
| - |
|
694 |
GIFT_SERIES.put(25001.0, map4);
|
| - |
|
695 |
RandomCollection<ScratchedGift> map5 = new RandomCollection<ScratchedGift>()
|
| - |
|
696 |
.add(40d, ScratchedGift.SPEAKER)
|
| - |
|
697 |
.add(60d, ScratchedGift.SMART_WATCH);
|
| - |
|
698 |
|
| - |
|
699 |
GIFT_SERIES.put(50001.0, map5);
|
| - |
|
700 |
}
|
| 675 |
|
701 |
|
| - |
|
702 |
|
| - |
|
703 |
private void createSpecificPriceScratchOffer(String invoiceNumber, int customerId, float purchaseAmount) {
|
| 676 |
ScratchedGift selectedGift = getSelectedGift(purchaseAmount, giftSeries);
|
704 |
ScratchedGift selectedGift = getSelectedGift(purchaseAmount);
|
| 677 |
|
705 |
|
| 678 |
List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
|
706 |
List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
|
| 679 |
if (scratchOffers.size() == 0) {
|
707 |
if (scratchOffers.size() == 0) {
|
| 680 |
ScratchOffer so2 = new ScratchOffer();
|
708 |
ScratchOffer so2 = new ScratchOffer();
|
| 681 |
so2.setInvoiceNumber(invoiceNumber);
|
709 |
so2.setInvoiceNumber(invoiceNumber);
|
| Line 687... |
Line 715... |
| 687 |
so2.setUnlockedAt(LocalDateTime.now());
|
715 |
so2.setUnlockedAt(LocalDateTime.now());
|
| 688 |
scratchOfferRepository.persist(so2);
|
716 |
scratchOfferRepository.persist(so2);
|
| 689 |
}
|
717 |
}
|
| 690 |
}
|
718 |
}
|
| 691 |
|
719 |
|
| - |
|
720 |
@Override
|
| 692 |
private ScratchedGift getSelectedGift(double purchaseAmount, Map<Double, ScratchedGift> giftSeries) {
|
721 |
public ScratchedGift getSelectedGift(double purchaseAmount) {
|
| - |
|
722 |
//Iterating map in reverse order of values
|
| 693 |
for (Map.Entry<Double, ScratchedGift> entry : giftSeries.entrySet()) {
|
723 |
for (Map.Entry<Double, RandomCollection<ScratchedGift>> entry : GIFT_SERIES.entrySet()) {
|
| 694 |
if (purchaseAmount <= entry.getKey()) {
|
724 |
if (purchaseAmount >= entry.getKey()) {
|
| 695 |
return entry.getValue();
|
725 |
return entry.getValue().next();
|
| 696 |
}
|
- |
|
| 697 |
if (purchaseAmount > 25000) {
|
- |
|
| 698 |
return ScratchedGift.BT_SOUNDBAR;
|
- |
|
| 699 |
}
|
726 |
}
|
| 700 |
}
|
727 |
}
|
| 701 |
return ScratchedGift.BLNT; // Default gift if no match found
|
728 |
return ScratchedGift.BLNT; // Default gift if no match found
|
| 702 |
}
|
729 |
}
|
| 703 |
|
730 |
|