Subversion Repositories SmartDukaan

Rev

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

Rev 34902 Rev 34962
Line 437... Line 437...
437
    private void sendCombinedSchemesNotification(List<Scheme> schemes) throws ProfitMandiBusinessException {
437
    private void sendCombinedSchemesNotification(List<Scheme> schemes) throws ProfitMandiBusinessException {
438
        if (schemes == null || schemes.isEmpty()) return;
438
        if (schemes == null || schemes.isEmpty()) return;
439
 
439
 
440
        SendNotificationModel sendNotificationModel = new SendNotificationModel();
440
        SendNotificationModel sendNotificationModel = new SendNotificationModel();
441
        StringBuilder messageBuilder = new StringBuilder();
441
        StringBuilder messageBuilder = new StringBuilder();
442
        StringBuilder titleBuilder = new StringBuilder();
-
 
443
        Set<Integer> allCatalogIds = new HashSet<>();
442
        Set<Integer> allCatalogIds = new HashSet<>();
-
 
443
        Set<String> allBrands = new HashSet<>();
-
 
444
        String schemeTypeLabel = null;
444
 
445
 
-
 
446
        Map<String, List<Scheme>> groupedByDate = schemes.stream()
-
 
447
                .filter(s -> ACTIVATION_SCHEME_TYPES.contains(s.getType()))
-
 
448
                .collect(Collectors.groupingBy(s ->
-
 
449
                    StringUtils.fromShortMonthDate(String.valueOf(s.getStartDateTime())) + " - " +
-
 
450
                        StringUtils.fromShortMonthDate(String.valueOf(s.getEndDateTime()))
-
 
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
 
445
        for (Scheme scheme : schemes) {
459
            for (Scheme scheme : groupedSchemes) {
446
            if (!ACTIVATION_SCHEME_TYPES.contains(scheme.getType())) {
460
                if (scheme.getType().equals(SchemeType.SPECIAL_SUPPORT)) {
-
 
461
                    schemeTypeLabel = "Special Support";
447
                continue;
462
                } else {
-
 
463
                    schemeTypeLabel = "Activation Scheme";
-
 
464
                }
-
 
465
 
-
 
466
                List<SchemeItem> schemeItems =
-
 
467
                        schemeItemRepository.selectBySchemeIds(Collections.singleton(scheme.getId()));
-
 
468
 
-
 
469
                Set<Integer> catalogIds = schemeItems.stream()
-
 
470
                        .map(SchemeItem::getCatalogId)
-
 
471
                        .collect(Collectors.toSet());
-
 
472
                allCatalogIds.addAll(catalogIds);
-
 
473
 
-
 
474
                List<String> itemBrand = itemRepository.selectAllByCatalogIds(catalogIds).stream()
-
 
475
                        .map(Item::getBrand)
-
 
476
                        .filter(Objects::nonNull)
-
 
477
                        .distinct()
-
 
478
                        .collect(Collectors.toList());
-
 
479
                allBrands.addAll(itemBrand);
-
 
480
 
-
 
481
                List<String> itemDescriptions = itemRepository.selectAllByCatalogIds(catalogIds).stream()
-
 
482
                        .filter(Utils.distinctByKey(Item::getCatalogItemId))
-
 
483
                        .map(Item::getItemDescriptionNoColor)
-
 
484
                        .collect(Collectors.toList());
-
 
485
 
-
 
486
                messageBuilder.append(String.format("%s of Rs.%s on Models: %s\n",
-
 
487
                        schemeTypeLabel,
-
 
488
                        FormattingUtils.formatDecimal(scheme.getAmount()),
-
 
489
                        String.join(", ", itemDescriptions)));
448
            }
490
            }
449
 
-
 
450
            String schemeTypeLabel = "Activation scheme";
-
 
451
            if (scheme.getType().equals(SchemeType.SPECIAL_SUPPORT)) {
-
 
452
                schemeTypeLabel = "Special Support";
-
 
453
            }
-
 
454
 
-
 
455
            List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(Collections.singleton(scheme.getId()));
-
 
456
            Set<Integer> catalogIds = schemeItems.stream().map(SchemeItem::getCatalogId).collect(Collectors.toSet());
-
 
457
            allCatalogIds.addAll(catalogIds);
-
 
458
 
-
 
459
            List<String> itemBrand = itemRepository.selectAllByCatalogIds(catalogIds).stream()
-
 
460
                    .filter(Utils.distinctByKey(Item::getCatalogItemId))
-
 
461
                    .map(Item::getBrand)
-
 
462
                    .collect(Collectors.toList());
-
 
463
 
-
 
464
            List<String> itemDescriptions = itemRepository.selectAllByCatalogIds(catalogIds).stream()
-
 
465
                    .filter(Utils.distinctByKey(Item::getCatalogItemId))
-
 
466
                    .map(Item::getItemDescriptionNoColor)
-
 
467
                    .collect(Collectors.toList());
-
 
468
 
-
 
469
            // Title line
-
 
470
            titleBuilder.append(String.format("%s of Rs.%s for %s\n",
-
 
471
                    schemeTypeLabel,
-
 
472
                    FormattingUtils.formatDecimal(scheme.getAmount()),
-
 
473
                    itemBrand.get(0)));
491
            messageBuilder.append("\n");
474
 
-
 
475
            // Message details
-
 
476
            messageBuilder.append(String.format("On Selected Models: %s\n", String.join(", ", itemDescriptions)));
-
 
477
            messageBuilder.append(String.format("Duration from - %s to %s\n\n",
-
 
478
                    FormattingUtils.formatDateMonth(scheme.getStartDateTime()),
-
 
479
                    FormattingUtils.formatDateMonth(scheme.getEndDateTime())));
-
 
480
        }
492
        }
481
 
493
 
482
        if (titleBuilder.length() == 0) return;
494
        if (allBrands.isEmpty() || schemeTypeLabel == null) return;
-
 
495
 
-
 
496
        String title = String.format("%s for %s",
-
 
497
                schemeTypeLabel,
-
 
498
                String.join(", ", allBrands));
483
 
499
 
484
        sendNotificationModel.setCampaignName("activationscheme");
500
        sendNotificationModel.setCampaignName("activationscheme");
485
        sendNotificationModel.setUrl("https://smartdukaan.com/pages/home/notifications");
501
        sendNotificationModel.setUrl("https://store.smartdukaan.com/pages/home/notifications");
486
        sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
502
        sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
487
        sendNotificationModel.setTitle(titleBuilder.toString().trim());
503
        sendNotificationModel.setTitle(title);
488
        sendNotificationModel.setMessage(messageBuilder.toString().trim());
504
        sendNotificationModel.setMessage(messageBuilder.toString().trim());
489
        sendNotificationModel.setType("url");
505
        sendNotificationModel.setType("url");
490
        sendNotificationModel.setMessageType(MessageType.scheme);
506
        sendNotificationModel.setMessageType(MessageType.scheme);
491
        notificationService.sendNotificationToAll(sendNotificationModel);
507
        notificationService.sendNotificationToAll(sendNotificationModel);
492
    }
508
    }