Subversion Repositories SmartDukaan

Rev

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

Rev 34991 Rev 35060
Line 74... Line 74...
74
    private static final List<SchemeType> FULL_DAYS_CD_SCHEME_TYPES = Arrays.asList(SchemeType.CASH_DISCOUNT, SchemeType.CASH_DISCOUNT1);
74
    private static final List<SchemeType> FULL_DAYS_CD_SCHEME_TYPES = Arrays.asList(SchemeType.CASH_DISCOUNT, SchemeType.CASH_DISCOUNT1);
75
    private static final List<SchemeType> HALF_DAYS_CD_REJECT_SCHEME_TYPES = Arrays.asList(SchemeType.CASH_DISCOUNT1);
75
    private static final List<SchemeType> HALF_DAYS_CD_REJECT_SCHEME_TYPES = Arrays.asList(SchemeType.CASH_DISCOUNT1);
76
 
76
 
77
 
77
 
78
    private static final List<SchemeType> ACTIVATION_SCHEME_TYPES = Arrays.asList(SchemeType.SPECIAL_SUPPORT, SchemeType.SELLOUT);
78
    private static final List<SchemeType> ACTIVATION_SCHEME_TYPES = Arrays.asList(SchemeType.SPECIAL_SUPPORT, SchemeType.SELLOUT);
-
 
79
    private static final List<SchemeType> NOFITY_SCHEME_TYPES = Arrays.asList(SchemeType.SPECIAL_SUPPORT, SchemeType.SELLOUT, SchemeType.SELLIN);
79
 
80
 
80
    @Autowired
81
    @Autowired
81
    SchemeBlockedImeiRepository schemeBlockedImeiRepository;
82
    SchemeBlockedImeiRepository schemeBlockedImeiRepository;
82
    @Autowired
83
    @Autowired
83
    StateGstRateRepository stateGstRateRepository;
84
    StateGstRateRepository stateGstRateRepository;
Line 318... Line 319...
318
            this.sendCombinedSchemesNotification(schemes);
319
            this.sendCombinedSchemesNotification(schemes);
319
        }
320
        }
320
    }
321
    }
321
 
322
 
322
    private void sendSchemeNotification(Scheme scheme) throws ProfitMandiBusinessException {
323
    private void sendSchemeNotification(Scheme scheme) throws ProfitMandiBusinessException {
323
        if (ACTIVATION_SCHEME_TYPES.contains(scheme.getType())) {
324
        if (NOFITY_SCHEME_TYPES.contains(scheme.getType())) {
324
 
325
 
325
            SendNotificationModel sendNotificationModel = new SendNotificationModel();
326
            SendNotificationModel sendNotificationModel = new SendNotificationModel();
326
            List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(Collections.singleton(scheme.getId()));
327
            List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(Collections.singleton(scheme.getId()));
327
            Set<Integer> catalogIds = schemeItems.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
328
            Set<Integer> catalogIds = schemeItems.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
328
            List<String> itemDescriptions = itemRepository.selectAllByCatalogIds(catalogIds).stream().filter(Utils.distinctByKey(Item::getCatalogItemId))
329
            List<String> itemDescriptions = itemRepository.selectAllByCatalogIds(catalogIds).stream().filter(Utils.distinctByKey(Item::getCatalogItemId))
Line 339... Line 340...
339
            sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
340
            sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
340
            sendNotificationModel.setMessage(message);
341
            sendNotificationModel.setMessage(message);
341
            sendNotificationModel.setTitle(String.format(titleTemplate, schemeString, FormattingUtils.formatDecimal(scheme.getAmount()), org.apache.commons.lang3.StringUtils.abbreviate(String.join(", ", itemDescriptions), 25)));
342
            sendNotificationModel.setTitle(String.format(titleTemplate, schemeString, FormattingUtils.formatDecimal(scheme.getAmount()), org.apache.commons.lang3.StringUtils.abbreviate(String.join(", ", itemDescriptions), 25)));
342
            sendNotificationModel.setType("url");
343
            sendNotificationModel.setType("url");
343
            sendNotificationModel.setMessageType(MessageType.scheme);
344
            sendNotificationModel.setMessageType(MessageType.scheme);
-
 
345
            List<SchemeRegion> schemeRegionList = schemeRegionRepository.selectAllBySchemeIds(Arrays.asList(scheme.getId()));
-
 
346
            sendNotificationModel.setRegionIds(schemeRegionList.stream().map(x->x.getRegionId()).collect(Collectors.toList()));
344
            notificationService.sendNotificationToAll(sendNotificationModel);
347
            notificationService.sendNotificationToAll(sendNotificationModel);
345
        }
348
        }
346
    }
349
    }
347
 
350
 
348
    @Autowired
351
    @Autowired
Line 432... Line 435...
432
    @Autowired
435
    @Autowired
433
    OfferPayoutRepository offerPayoutRepository;
436
    OfferPayoutRepository offerPayoutRepository;
434
    @Autowired
437
    @Autowired
435
    AgeingService ageingService;
438
    AgeingService ageingService;
436
 
439
 
-
 
440
    @Override
437
    private void sendCombinedSchemesNotification(List<Scheme> schemes) throws ProfitMandiBusinessException {
441
    public void sendCombinedSchemesNotification(List<Scheme> schemes) throws ProfitMandiBusinessException {
438
        if (schemes == null || schemes.isEmpty()) return;
442
        if (schemes == null || schemes.isEmpty()) return;
439
 
443
 
440
        SendNotificationModel sendNotificationModel = new SendNotificationModel();
-
 
441
        StringBuilder messageBuilder = new StringBuilder();
-
 
442
        Set<Integer> allCatalogIds = new HashSet<>();
-
 
443
        Set<String> allBrands = new HashSet<>();
-
 
444
        String schemeTypeLabel = null;
-
 
445
 
-
 
446
        Map<String, List<Scheme>> groupedByDate = schemes.stream()
-
 
447
                .filter(s -> ACTIVATION_SCHEME_TYPES.contains(s.getType()))
-
 
448
                .collect(Collectors.groupingBy(s ->
-
 
449
                    String.valueOf(s.getStartDateTime()).substring(0, 10) + " - " +
-
 
450
                        String.valueOf(s.getEndDateTime()).substring(0, 10)
-
 
451
                ));
-
 
452
 
-
 
453
        for (Map.Entry<String, List<Scheme>> entry : groupedByDate.entrySet()) {
-
 
454
            String dateRange = entry.getKey();
-
 
455
            List<Scheme> groupedSchemes = entry.getValue();
-
 
456
 
-
 
457
            messageBuilder.append(String.format("Duration: %s\n", dateRange));
-
 
458
 
-
 
459
            for (Scheme scheme : groupedSchemes) {
-
 
460
                if (scheme.getType().equals(SchemeType.SPECIAL_SUPPORT)) {
-
 
461
                    schemeTypeLabel = "Special Support";
-
 
462
                } else {
-
 
463
                    schemeTypeLabel = "Activation Scheme";
-
 
464
                }
-
 
465
 
444
 
466
                List<SchemeItem> schemeItems =
445
        List<Scheme> filteredSchemes = schemes.stream()
-
 
446
                .filter(s -> NOFITY_SCHEME_TYPES.contains(s.getType())).collect(Collectors.toList());
-
 
447
 
-
 
448
        Map<Integer, Scheme> schemesMap = filteredSchemes.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
-
 
449
 
-
 
450
        Map<Integer, List<Integer>> schemeIdRegionIdsMap = schemeRegionRepository.selectAllBySchemeIds(new ArrayList<>(schemesMap.keySet()))
-
 
451
                .stream().collect(Collectors.groupingBy(SchemeRegion::getSchemeId,
467
                        schemeItemRepository.selectBySchemeIds(Collections.singleton(scheme.getId()));
452
                        Collectors.collectingAndThen(Collectors.mapping(SchemeRegion::getRegionId, Collectors.toList()),
-
 
453
                                list -> {
-
 
454
                                    list.sort(Integer::compareTo); // sort ascending
-
 
455
                                    return list;
-
 
456
                                })));
-
 
457
 
-
 
458
        Map<List<Integer>, Map<String, List<Scheme>>> groupedByRegionDate = filteredSchemes.stream()
-
 
459
                .collect(Collectors.groupingBy(s -> schemeIdRegionIdsMap.get(s.getId()), Collectors.groupingBy(s ->
-
 
460
                        String.valueOf(s.getStartDateTime()).substring(0, 10) + " - " +
-
 
461
                                String.valueOf(s.getEndDateTime()).substring(0, 10)
-
 
462
                )));
468
 
463
 
-
 
464
        for (Map.Entry<List<Integer>, Map<String, List<Scheme>>> regionIdsDateKeyset : groupedByRegionDate.entrySet()) {
-
 
465
            SendNotificationModel sendNotificationModel = new SendNotificationModel();
-
 
466
            StringBuilder messageBuilder = new StringBuilder();
-
 
467
            Set<Integer> allCatalogIds = new HashSet<>();
-
 
468
            Set<String> allBrands = new HashSet<>();
-
 
469
            String schemeTypeLabel = null;
-
 
470
            List<Integer> regionIds = regionIdsDateKeyset.getKey();
-
 
471
            for (Map.Entry<String, List<Scheme>> entry : regionIdsDateKeyset.getValue().entrySet()) {
-
 
472
                String dateRange = entry.getKey();
-
 
473
                List<Scheme> groupedSchemes = entry.getValue();
-
 
474
 
-
 
475
 
-
 
476
                messageBuilder.append(String.format("Duration: %s\n", dateRange));
-
 
477
 
-
 
478
                for (Scheme scheme : groupedSchemes) {
-
 
479
                    if (scheme.getType().equals(SchemeType.SPECIAL_SUPPORT)) {
-
 
480
                        schemeTypeLabel = "Special Support";
-
 
481
                    } else if (scheme.getType().equals(SchemeType.SELLOUT)) {
-
 
482
                        schemeTypeLabel = "Sellout Scheme";
-
 
483
                    } else if (scheme.getType().equals(SchemeType.SELLIN)) {
-
 
484
                        schemeTypeLabel = "Sellin Scheme";
-
 
485
                    }
-
 
486
 
-
 
487
                    List<SchemeItem> schemeItems =
-
 
488
                            schemeItemRepository.selectBySchemeIds(Collections.singleton(scheme.getId()));
-
 
489
 
469
                Set<Integer> catalogIds = schemeItems.stream()
490
                    Set<Integer> catalogIds = schemeItems.stream()
470
                        .map(SchemeItem::getCatalogId)
491
                            .map(SchemeItem::getCatalogId)
471
                        .collect(Collectors.toSet());
492
                            .collect(Collectors.toSet());
472
                allCatalogIds.addAll(catalogIds);
493
                    allCatalogIds.addAll(catalogIds);
473
 
494
 
474
                List<String> itemBrand = itemRepository.selectAllByCatalogIds(catalogIds).stream()
495
                    List<String> itemBrand = itemRepository.selectAllByCatalogIds(catalogIds).stream()
475
                        .map(Item::getBrand)
496
                            .map(Item::getBrand)
476
                        .filter(Objects::nonNull)
497
                            .filter(Objects::nonNull)
477
                        .distinct()
498
                            .distinct()
478
                        .collect(Collectors.toList());
499
                            .collect(Collectors.toList());
479
                allBrands.addAll(itemBrand);
500
                    allBrands.addAll(itemBrand);
480
 
501
 
481
                List<String> itemDescriptions = itemRepository.selectAllByCatalogIds(catalogIds).stream()
502
                    List<String> itemDescriptions = itemRepository.selectAllByCatalogIds(catalogIds).stream()
482
                        .filter(Utils.distinctByKey(Item::getCatalogItemId))
503
                            .filter(Utils.distinctByKey(Item::getCatalogItemId))
483
                        .map(Item::getItemDescriptionNoColor)
504
                            .map(Item::getItemDescriptionNoColor)
484
                        .collect(Collectors.toList());
505
                            .collect(Collectors.toList());
485
 
506
 
486
                messageBuilder.append(String.format("%s of Rs.%s on Models: %s\n",
507
                    messageBuilder.append(String.format("%s of Rs.%s on Models: %s\n",
487
                        schemeTypeLabel,
508
                            schemeTypeLabel,
488
                        FormattingUtils.formatDecimal(scheme.getAmount()),
509
                            FormattingUtils.formatDecimal(scheme.getAmount()),
489
                        String.join(", ", itemDescriptions)));
510
                            String.join(", ", itemDescriptions)));
-
 
511
                }
-
 
512
                messageBuilder.append("\n");
490
            }
513
            }
491
            messageBuilder.append("\n");
-
 
492
        }
-
 
493
 
514
 
494
        if (allBrands.isEmpty() || schemeTypeLabel == null) return;
515
            if (allBrands.isEmpty() || schemeTypeLabel == null) return;
-
 
516
 
-
 
517
            String title = String.format("%s for %s",
-
 
518
                    schemeTypeLabel,
-
 
519
                    String.join(", ", allBrands));
-
 
520
 
-
 
521
            sendNotificationModel.setCampaignName("activationscheme");
-
 
522
            sendNotificationModel.setUrl("https://store.smartdukaan.com/pages/home/notifications");
-
 
523
            sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
-
 
524
            sendNotificationModel.setTitle(title);
-
 
525
            sendNotificationModel.setMessage(messageBuilder.toString().trim());
-
 
526
            sendNotificationModel.setType("url");
-
 
527
            sendNotificationModel.setMessageType(MessageType.scheme);
-
 
528
            sendNotificationModel.setRegionIds(regionIds);
-
 
529
            System.out.println(sendNotificationModel);
-
 
530
            notificationService.sendNotification(sendNotificationModel);
-
 
531
        }
495
 
532
 
496
        String title = String.format("%s for %s",
-
 
497
                schemeTypeLabel,
-
 
498
                String.join(", ", allBrands));
-
 
499
 
-
 
500
        sendNotificationModel.setCampaignName("activationscheme");
-
 
501
        sendNotificationModel.setUrl("https://store.smartdukaan.com/pages/home/notifications");
-
 
502
        sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
-
 
503
        sendNotificationModel.setTitle(title);
-
 
504
        sendNotificationModel.setMessage(messageBuilder.toString().trim());
-
 
505
        sendNotificationModel.setType("url");
-
 
506
        sendNotificationModel.setMessageType(MessageType.scheme);
-
 
507
        notificationService.sendNotificationToAll(sendNotificationModel);
-
 
508
    }
533
    }
509
 
534
 
510
    //CDs would be rejected based on cdFreeDays
535
    //CDs would be rejected based on cdFreeDays
511
    public void processSchemeIn(int purchaseId, int retailerId) throws ProfitMandiBusinessException {
536
    public void processSchemeIn(int purchaseId, int retailerId) throws ProfitMandiBusinessException {
512
        LOGGER.info("Processing scheme in  for purchaseId - {}", purchaseId);
537
        LOGGER.info("Processing scheme in  for purchaseId - {}", purchaseId);