| Line 322... |
Line 322... |
| 322 |
* this.processPreviousPurchases(scheme); } else if (scheme.getType() ==
|
322 |
* this.processPreviousPurchases(scheme); } else if (scheme.getType() ==
|
| 323 |
* SchemeType.OUT) { this.processPreviousSales(scheme); }
|
323 |
* SchemeType.OUT) { this.processPreviousSales(scheme); }
|
| 324 |
*/
|
324 |
*/
|
| 325 |
}
|
325 |
}
|
| 326 |
|
326 |
|
| - |
|
327 |
@Override
|
| - |
|
328 |
public void activeSchemeByIds(List<Scheme> schemes) throws ProfitMandiBusinessException {
|
| - |
|
329 |
if (schemes.size() > 0) {
|
| - |
|
330 |
for (Scheme scheme : schemes) {
|
| - |
|
331 |
if (scheme.getActiveTimestamp() != null || scheme.getExpireTimestamp() != null) {
|
| - |
|
332 |
continue;
|
| - |
|
333 |
}
|
| - |
|
334 |
scheme.setActiveTimestamp(LocalDateTime.now());
|
| - |
|
335 |
}
|
| - |
|
336 |
this.sendCombinedSchemesNotification(schemes);
|
| - |
|
337 |
}
|
| - |
|
338 |
}
|
| - |
|
339 |
|
| 327 |
private void sendSchemeNotification(Scheme scheme) throws ProfitMandiBusinessException {
|
340 |
private void sendSchemeNotification(Scheme scheme) throws ProfitMandiBusinessException {
|
| 328 |
if (ACTIVATION_SCHEME_TYPES.contains(scheme.getType())) {
|
341 |
if (ACTIVATION_SCHEME_TYPES.contains(scheme.getType())) {
|
| 329 |
|
342 |
|
| 330 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
343 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 331 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(Collections.singleton(scheme.getId()));
|
344 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(Collections.singleton(scheme.getId()));
|
| Line 348... |
Line 361... |
| 348 |
sendNotificationModel.setMessageType(MessageType.scheme);
|
361 |
sendNotificationModel.setMessageType(MessageType.scheme);
|
| 349 |
notificationService.sendNotificationToAll(sendNotificationModel);
|
362 |
notificationService.sendNotificationToAll(sendNotificationModel);
|
| 350 |
}
|
363 |
}
|
| 351 |
}
|
364 |
}
|
| 352 |
|
365 |
|
| - |
|
366 |
private void sendCombinedSchemesNotification(List<Scheme> schemes) throws ProfitMandiBusinessException {
|
| - |
|
367 |
if (schemes == null || schemes.isEmpty()) return;
|
| - |
|
368 |
|
| - |
|
369 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| - |
|
370 |
StringBuilder messageBuilder = new StringBuilder();
|
| - |
|
371 |
StringBuilder titleBuilder = new StringBuilder();
|
| - |
|
372 |
Set<Integer> allCatalogIds = new HashSet<>();
|
| - |
|
373 |
|
| - |
|
374 |
for (Scheme scheme : schemes) {
|
| - |
|
375 |
if (!ACTIVATION_SCHEME_TYPES.contains(scheme.getType())) {
|
| - |
|
376 |
continue;
|
| - |
|
377 |
}
|
| - |
|
378 |
|
| - |
|
379 |
String schemeTypeLabel = "Activation scheme";
|
| - |
|
380 |
if (scheme.getType().equals(SchemeType.SPECIAL_SUPPORT)) {
|
| - |
|
381 |
schemeTypeLabel = "Special Support";
|
| - |
|
382 |
}
|
| - |
|
383 |
|
| - |
|
384 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(Collections.singleton(scheme.getId()));
|
| - |
|
385 |
Set<Integer> catalogIds = schemeItems.stream().map(SchemeItem::getCatalogId).collect(Collectors.toSet());
|
| - |
|
386 |
allCatalogIds.addAll(catalogIds);
|
| - |
|
387 |
|
| - |
|
388 |
List<String> itemBrand = itemRepository.selectAllByCatalogIds(catalogIds).stream()
|
| - |
|
389 |
.filter(Utils.distinctByKey(Item::getCatalogItemId))
|
| - |
|
390 |
.map(Item::getBrand)
|
| - |
|
391 |
.collect(Collectors.toList());
|
| - |
|
392 |
|
| - |
|
393 |
List<String> itemDescriptions = itemRepository.selectAllByCatalogIds(catalogIds).stream()
|
| - |
|
394 |
.filter(Utils.distinctByKey(Item::getCatalogItemId))
|
| - |
|
395 |
.map(Item::getItemDescriptionNoColor)
|
| - |
|
396 |
.collect(Collectors.toList());
|
| - |
|
397 |
|
| - |
|
398 |
// Title line
|
| - |
|
399 |
titleBuilder.append(String.format("%s of Rs.%s for %s\n",
|
| - |
|
400 |
schemeTypeLabel,
|
| - |
|
401 |
FormattingUtils.formatDecimal(scheme.getAmount()),
|
| - |
|
402 |
itemBrand.get(0)));
|
| - |
|
403 |
|
| - |
|
404 |
// Message details
|
| - |
|
405 |
messageBuilder.append(String.format("On Selected Models: %s\n", String.join(", ", itemDescriptions)));
|
| - |
|
406 |
messageBuilder.append(String.format("Duration from - %s to %s\n\n",
|
| - |
|
407 |
FormattingUtils.formatDateMonth(scheme.getStartDateTime()),
|
| - |
|
408 |
FormattingUtils.formatDateMonth(scheme.getEndDateTime())));
|
| - |
|
409 |
}
|
| - |
|
410 |
|
| - |
|
411 |
if (titleBuilder.length() == 0) return;
|
| - |
|
412 |
|
| - |
|
413 |
sendNotificationModel.setCampaignName("activationscheme");
|
| - |
|
414 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| - |
|
415 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| - |
|
416 |
sendNotificationModel.setTitle(titleBuilder.toString().trim());
|
| - |
|
417 |
sendNotificationModel.setMessage(messageBuilder.toString().trim());
|
| - |
|
418 |
sendNotificationModel.setType("url");
|
| - |
|
419 |
sendNotificationModel.setMessageType(MessageType.scheme);
|
| - |
|
420 |
notificationService.sendNotificationToAll(sendNotificationModel);
|
| - |
|
421 |
}
|
| - |
|
422 |
|
| 353 |
@Override
|
423 |
@Override
|
| 354 |
public void expireSchemeById(int schemeId, LocalDateTime expiryTime) throws ProfitMandiBusinessException {
|
424 |
public void expireSchemeById(int schemeId, LocalDateTime expiryTime) throws ProfitMandiBusinessException {
|
| 355 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
425 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
| 356 |
if (scheme == null || scheme.getActiveTimestamp() == null) {
|
426 |
if (scheme == null || scheme.getActiveTimestamp() == null) {
|
| 357 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(),
|
427 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(),
|