| Line 581... |
Line 581... |
| 581 |
}
|
581 |
}
|
| 582 |
}
|
582 |
}
|
| 583 |
LocalDate startDate = ProfitMandiConstants.SCRATCH_OFFER_START_DATE;
|
583 |
LocalDate startDate = ProfitMandiConstants.SCRATCH_OFFER_START_DATE;
|
| 584 |
LocalDate endDate = ProfitMandiConstants.SCRATCH_OFFER_END_DATE;
|
584 |
LocalDate endDate = ProfitMandiConstants.SCRATCH_OFFER_END_DATE;
|
| 585 |
boolean specificPriceOffer = ProfitMandiConstants.SPECIFIC_PRICE_OFFER;
|
585 |
boolean specificPriceOffer = ProfitMandiConstants.SPECIFIC_PRICE_OFFER;
|
| - |
|
586 |
boolean randomOffer = ProfitMandiConstants.RANDOM_OFFER;
|
| 586 |
|
587 |
|
| 587 |
if (isSmartPhonePurchased) {
|
588 |
if (isSmartPhonePurchased) {
|
| 588 |
if (LocalDateTime.now().isAfter(startDate.atStartOfDay()) && LocalDateTime.now().isBefore(endDate.atTime(Utils.MAX_TIME))) {
|
589 |
if (LocalDateTime.now().isAfter(startDate.atStartOfDay()) && LocalDateTime.now().isBefore(endDate.atTime(Utils.MAX_TIME))) {
|
| 589 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
590 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
| 590 |
try {
|
591 |
try {
|
| Line 593... |
Line 594... |
| 593 |
// TODO Auto-generated catch block
|
594 |
// TODO Auto-generated catch block
|
| 594 |
e.printStackTrace();
|
595 |
e.printStackTrace();
|
| 595 |
}
|
596 |
}
|
| 596 |
if (specificPriceOffer) {
|
597 |
if (specificPriceOffer) {
|
| 597 |
this.createSpecificPriceScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId(), maxPurchaseValue);
|
598 |
this.createSpecificPriceScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId(), maxPurchaseValue);
|
| - |
|
599 |
} else if (randomOffer) {
|
| - |
|
600 |
this.createRandomScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
|
| - |
|
601 |
LOGGER.info("randomOffer {}", randomOffer);
|
| 598 |
} else {
|
602 |
} else {
|
| 599 |
this.createScratchOffer(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
|
603 |
this.createScratchOffer(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
|
| 600 |
}
|
604 |
}
|
| 601 |
|
605 |
|
| 602 |
}
|
606 |
}
|
| Line 714... |
Line 718... |
| 714 |
}
|
718 |
}
|
| 715 |
|
719 |
|
| 716 |
|
720 |
|
| 717 |
private void createSpecificPriceScratchOffer(String invoiceNumber, int customerId, float purchaseAmount) {
|
721 |
private void createSpecificPriceScratchOffer(String invoiceNumber, int customerId, float purchaseAmount) {
|
| 718 |
ScratchedGift selectedGift = getSelectedGift(purchaseAmount);
|
722 |
ScratchedGift selectedGift = getSelectedGift(purchaseAmount);
|
| - |
|
723 |
List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
|
| - |
|
724 |
if (scratchOffers.size() == 0) {
|
| - |
|
725 |
ScratchOffer so2 = new ScratchOffer();
|
| - |
|
726 |
so2.setInvoiceNumber(invoiceNumber);
|
| - |
|
727 |
so2.setScratched(false);
|
| - |
|
728 |
so2.setCreatedTimestamp(LocalDateTime.now());
|
| - |
|
729 |
so2.setExpiredTimestamp(ProfitMandiConstants.SCRATCH_OFFER_END_DATE.plusDays(3).atTime(LocalTime.MAX));
|
| - |
|
730 |
so2.setOfferName(selectedGift);
|
| - |
|
731 |
so2.setCustomerId(customerId);
|
| - |
|
732 |
so2.setUnlockedAt(LocalDateTime.now());
|
| - |
|
733 |
scratchOfferRepository.persist(so2);
|
| - |
|
734 |
}
|
| - |
|
735 |
}
|
| 719 |
|
736 |
|
| - |
|
737 |
private void createRandomScratchOffer(String invoiceNumber, int customerId) {
|
| - |
|
738 |
ScratchedGift selectedGift = getScratchedGiftRandomAccordingQuantity(customerId);
|
| 720 |
List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
|
739 |
List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
|
| 721 |
if (scratchOffers.size() == 0) {
|
740 |
if (scratchOffers.size() == 0) {
|
| 722 |
ScratchOffer so2 = new ScratchOffer();
|
741 |
ScratchOffer so2 = new ScratchOffer();
|
| 723 |
so2.setInvoiceNumber(invoiceNumber);
|
742 |
so2.setInvoiceNumber(invoiceNumber);
|
| 724 |
so2.setScratched(false);
|
743 |
so2.setScratched(false);
|
| Line 823... |
Line 842... |
| 823 |
|
842 |
|
| 824 |
}
|
843 |
}
|
| 825 |
return gift;
|
844 |
return gift;
|
| 826 |
}
|
845 |
}
|
| 827 |
|
846 |
|
| - |
|
847 |
private ScratchedGift getScratchedGiftRandomAccordingQuantity(int customerId) {
|
| - |
|
848 |
RandomCollection<ScratchedGift> map1 = new RandomCollection<ScratchedGift>().
|
| - |
|
849 |
add(50d, ScratchedGift.SOLOR_LAMP)
|
| - |
|
850 |
.add(100d, ScratchedGift.BLUETOOTH_SPEAKER)
|
| - |
|
851 |
.add(150d, ScratchedGift.RED_WATER_BOTTLE)
|
| - |
|
852 |
.add(200d, ScratchedGift.GIFT_BOWL)
|
| - |
|
853 |
.add(100d, ScratchedGift.EARBUDS);
|
| - |
|
854 |
|
| - |
|
855 |
ScratchedGift gift = ScratchedGift.BLNT;
|
| - |
|
856 |
|
| - |
|
857 |
Random random = new Random();
|
| - |
|
858 |
int rand;
|
| - |
|
859 |
while (true) {
|
| - |
|
860 |
rand = random.nextInt(6);
|
| - |
|
861 |
if (rand != 0) break;
|
| - |
|
862 |
}
|
| - |
|
863 |
|
| - |
|
864 |
List<ScratchOffer> lastScratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(customerId, ProfitMandiConstants.LAST_SCRATCH_OFFER_START_DATE, ProfitMandiConstants.LAST_SCRATCH_OFFER_END_DATE);
|
| - |
|
865 |
|
| - |
|
866 |
if (lastScratchOffers.isEmpty()) {
|
| - |
|
867 |
gift = map1.next();
|
| - |
|
868 |
} else {
|
| - |
|
869 |
gift = ScratchedGift.RED_WATER_BOTTLE;
|
| - |
|
870 |
LOGGER.info("RED_WATER_BOTTLE {}", gift);
|
| - |
|
871 |
}
|
| - |
|
872 |
return gift;
|
| - |
|
873 |
}
|
| - |
|
874 |
|
| 828 |
private HygieneData createAndGetHygieneData(int id, int fofoId) {
|
875 |
private HygieneData createAndGetHygieneData(int id, int fofoId) {
|
| 829 |
HygieneData hygieneData = new HygieneData();
|
876 |
HygieneData hygieneData = new HygieneData();
|
| 830 |
hygieneData.setOrderId(id);
|
877 |
hygieneData.setOrderId(id);
|
| 831 |
hygieneData.setFofoId(fofoId);
|
878 |
hygieneData.setFofoId(fofoId);
|
| 832 |
hygieneData.setCreatedTimestamp(LocalDateTime.now());
|
879 |
hygieneData.setCreatedTimestamp(LocalDateTime.now());
|