| Line 10... |
Line 10... |
| 10 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
10 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 11 |
import com.spice.profitmandi.common.util.StringUtils;
|
11 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 12 |
import com.spice.profitmandi.common.util.Utils;
|
12 |
import com.spice.profitmandi.common.util.Utils;
|
| 13 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
13 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 14 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
14 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| - |
|
15 |
import com.spice.profitmandi.dao.entity.catalog.SchemeRegion;
|
| 15 |
import com.spice.profitmandi.dao.entity.catalog.SchemesImeisModel;
|
16 |
import com.spice.profitmandi.dao.entity.catalog.SchemesImeisModel;
|
| 16 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
17 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 17 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
18 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 18 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
19 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 19 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
20 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 20 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
21 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 21 |
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
|
22 |
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
|
| 22 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
23 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
| 23 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
24 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
| 24 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
- |
|
| 25 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
- |
|
| 26 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
- |
|
| 27 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
25 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 28 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
26 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 29 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
27 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 30 |
import com.spice.profitmandi.service.NotificationService;
|
28 |
import com.spice.profitmandi.service.NotificationService;
|
| 31 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
29 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| Line 40... |
Line 38... |
| 40 |
import org.springframework.beans.factory.annotation.Autowired;
|
38 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 41 |
import org.springframework.beans.factory.annotation.Qualifier;
|
39 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 42 |
import org.springframework.cache.annotation.Cacheable;
|
40 |
import org.springframework.cache.annotation.Cacheable;
|
| 43 |
import org.springframework.stereotype.Component;
|
41 |
import org.springframework.stereotype.Component;
|
| 44 |
|
42 |
|
| - |
|
43 |
import javax.persistence.TypedQuery;
|
| 45 |
import javax.persistence.criteria.CriteriaBuilder;
|
44 |
import javax.persistence.criteria.CriteriaBuilder;
|
| 46 |
import javax.persistence.criteria.CriteriaQuery;
|
45 |
import javax.persistence.criteria.CriteriaQuery;
|
| 47 |
import javax.persistence.criteria.Predicate;
|
46 |
import javax.persistence.criteria.Predicate;
|
| 48 |
import javax.persistence.criteria.Root;
|
47 |
import javax.persistence.criteria.Root;
|
| 49 |
import java.text.MessageFormat;
|
48 |
import java.text.MessageFormat;
|
| Line 107... |
Line 106... |
| 107 |
|
106 |
|
| 108 |
@Autowired
|
107 |
@Autowired
|
| 109 |
private SchemeItemRepository schemeItemRepository;
|
108 |
private SchemeItemRepository schemeItemRepository;
|
| 110 |
|
109 |
|
| 111 |
@Autowired
|
110 |
@Autowired
|
| - |
|
111 |
private SchemeRegionRepository schemeRegionRepository;
|
| - |
|
112 |
|
| - |
|
113 |
@Autowired
|
| 112 |
private WalletService walletService;
|
114 |
private WalletService walletService;
|
| 113 |
|
115 |
|
| 114 |
@Autowired
|
116 |
@Autowired
|
| 115 |
private PurchaseRepository purchaseRepository;
|
117 |
private PurchaseRepository purchaseRepository;
|
| 116 |
|
118 |
|
| Line 139... |
Line 141... |
| 139 |
schemeItem.setSchemeId(scheme.getId());
|
141 |
schemeItem.setSchemeId(scheme.getId());
|
| 140 |
schemeItem.setCatalogId(catalogId);
|
142 |
schemeItem.setCatalogId(catalogId);
|
| 141 |
schemeItemRepository.persist(schemeItem);
|
143 |
schemeItemRepository.persist(schemeItem);
|
| 142 |
}
|
144 |
}
|
| 143 |
|
145 |
|
| - |
|
146 |
for (int regionId : createSchemeRequest.getRegionIds()) {
|
| - |
|
147 |
SchemeRegion schemeRegion = new SchemeRegion();
|
| - |
|
148 |
schemeRegion.setSchemeId(scheme.getId());
|
| - |
|
149 |
schemeRegion.setRegionId(regionId);
|
| - |
|
150 |
schemeRegionRepository.persist(schemeRegion);
|
| - |
|
151 |
}
|
| - |
|
152 |
|
| 144 |
}
|
153 |
}
|
| 145 |
|
154 |
|
| 146 |
private void validateCreateSchemeRequest(CreateSchemeRequest createSchemeRequest)
|
155 |
private void validateCreateSchemeRequest(CreateSchemeRequest createSchemeRequest)
|
| 147 |
throws ProfitMandiBusinessException {
|
156 |
throws ProfitMandiBusinessException {
|
| 148 |
if (createSchemeRequest.getName() == null || createSchemeRequest.getName().isEmpty()) {
|
157 |
if (createSchemeRequest.getName() == null || createSchemeRequest.getName().isEmpty()) {
|
| Line 306... |
Line 315... |
| 306 |
String message = "Duration from - " + FormattingUtils.formatDateMonth(scheme.getStartDateTime()) + " - " + FormattingUtils.formatDateMonth(scheme.getEndDateTime());
|
315 |
String message = "Duration from - " + FormattingUtils.formatDateMonth(scheme.getStartDateTime()) + " - " + FormattingUtils.formatDateMonth(scheme.getEndDateTime());
|
| 307 |
sendNotificationModel.setCampaignName("activationscheme");
|
316 |
sendNotificationModel.setCampaignName("activationscheme");
|
| 308 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/scheme/" + scheme.getId());
|
317 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/scheme/" + scheme.getId());
|
| 309 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
318 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| 310 |
sendNotificationModel.setMessage(message);
|
319 |
sendNotificationModel.setMessage(message);
|
| 311 |
sendNotificationModel.setTitle(String.format(titleTemplate, schemeString, FormattingUtils.formatDecimal(scheme.getAmount()), String.join(", ", itemDescriptions)));
|
320 |
sendNotificationModel.setTitle(String.format(titleTemplate, schemeString, FormattingUtils.formatDecimal(scheme.getAmount()), org.apache.commons.lang3.StringUtils.abbreviate(String.join(", ", itemDescriptions), 25)));
|
| 312 |
sendNotificationModel.setType("url");
|
321 |
sendNotificationModel.setType("url");
|
| 313 |
sendNotificationModel.setMessageType(MessageType.scheme);
|
322 |
sendNotificationModel.setMessageType(MessageType.scheme);
|
| 314 |
notificationService.sendNotificationToAll(sendNotificationModel);
|
323 |
notificationService.sendNotificationToAll(sendNotificationModel);
|
| 315 |
}
|
324 |
}
|
| 316 |
}
|
325 |
}
|
| Line 385... |
Line 394... |
| 385 |
YearMonth.from(purchase.getCreateTimestamp()));
|
394 |
YearMonth.from(purchase.getCreateTimestamp()));
|
| 386 |
// PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId,
|
395 |
// PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId,
|
| 387 |
// purchase.getCreateTimestamp().toLocalDate());
|
396 |
// purchase.getCreateTimestamp().toLocalDate());
|
| 388 |
|
397 |
|
| 389 |
List<Scheme> schemes = schemeRepository.selectActiveAll(Arrays.asList(SchemeType.IN), partnerType,
|
398 |
List<Scheme> schemes = schemeRepository.selectActiveAll(Arrays.asList(SchemeType.IN), partnerType,
|
| 390 |
purchase.getCreateTimestamp(), false);
|
399 |
purchase.getCreateTimestamp().toLocalDate(), false);
|
| - |
|
400 |
List<Integer> validSchemeIds = schemeRepository.selectSchemesByRetailerIdsSchemeIds(retailerId, schemes.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| - |
|
401 |
schemes = schemes.stream().filter(x -> validSchemeIds.contains(x.getId())).collect(Collectors.toList());
|
| 391 |
float totalCashback = 0;
|
402 |
float totalCashback = 0;
|
| - |
|
403 |
|
| 392 |
if (schemes.isEmpty()) {
|
404 |
if (schemes.isEmpty()) {
|
| 393 |
return;
|
405 |
return;
|
| 394 |
}
|
406 |
}
|
| 395 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchaseId);
|
407 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchaseId);
|
| 396 |
|
408 |
|
| Line 465... |
Line 477... |
| 465 |
scheme.setPartnerType(createSchemeRequest.getPartnerType());
|
477 |
scheme.setPartnerType(createSchemeRequest.getPartnerType());
|
| 466 |
scheme.setStartDateTime(createSchemeRequest.getStartDate());
|
478 |
scheme.setStartDateTime(createSchemeRequest.getStartDate());
|
| 467 |
scheme.setEndDateTime(createSchemeRequest.getEndDate());
|
479 |
scheme.setEndDateTime(createSchemeRequest.getEndDate());
|
| 468 |
scheme.setCreatedBy(creatorId);
|
480 |
scheme.setCreatedBy(creatorId);
|
| 469 |
scheme.setCashback(createSchemeRequest.isCashback());
|
481 |
scheme.setCashback(createSchemeRequest.isCashback());
|
| 470 |
scheme.setBasePlusGstCalc(createSchemeRequest.isBasePluseGstCalc());
|
- |
|
| 471 |
return scheme;
|
482 |
return scheme;
|
| 472 |
}
|
483 |
}
|
| 473 |
|
484 |
|
| 474 |
//Only in and activation margins are allowed to be rolled out more than twice
|
485 |
//Only in and activation margins are allowed to be rolled out more than twice
|
| 475 |
private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem) throws ProfitMandiBusinessException {
|
486 |
private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem) throws ProfitMandiBusinessException {
|
| Line 601... |
Line 612... |
| 601 |
// Remove Items that are eol now.
|
612 |
// Remove Items that are eol now.
|
| 602 |
Set<Integer> itemIdsSet = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds).stream()
|
613 |
Set<Integer> itemIdsSet = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds).stream()
|
| 603 |
.filter(x -> x.getEolDate() == null || x.getEolDate().isAfter(fofoOrder.getCreateTimestamp()))
|
614 |
.filter(x -> x.getEolDate() == null || x.getEolDate().isAfter(fofoOrder.getCreateTimestamp()))
|
| 604 |
.map(x -> x.getItemId()).collect(Collectors.toSet());
|
615 |
.map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 605 |
// Only consider inventory items that were not returned
|
616 |
// Only consider inventory items that were not returned
|
| - |
|
617 |
//ItemCriteria itemCriteria = new ItemCriteria();
|
| - |
|
618 |
//itemCriteria.setItemIds(new ArrayList<>(itemIdsSet));
|
| - |
|
619 |
//List<Integer> catalogIds = itemRepository.getCatalogIds(itemCriteria);
|
| 606 |
inventoryItems = inventoryItems.stream().filter(x -> itemIdsSet.contains(x.getItemId()))
|
620 |
inventoryItems = inventoryItems.stream().filter(x -> itemIdsSet.contains(x.getItemId()))
|
| 607 |
.collect(Collectors.toSet());
|
621 |
.collect(Collectors.toSet());
|
| 608 |
|
622 |
|
| 609 |
if (inventoryItems.size() == 0) {
|
623 |
if (inventoryItems.size() == 0) {
|
| 610 |
return 0;
|
624 |
return 0;
|
| Line 614... |
Line 628... |
| 614 |
|
628 |
|
| 615 |
List<SchemeType> allOutSchemeTypes = new ArrayList<>();
|
629 |
List<SchemeType> allOutSchemeTypes = new ArrayList<>();
|
| 616 |
allOutSchemeTypes.addAll(Arrays.asList(SchemeType.ACTIVATION, SchemeType.INVESTMENT, SchemeType.SPECIAL_SUPPORT));
|
630 |
allOutSchemeTypes.addAll(Arrays.asList(SchemeType.ACTIVATION, SchemeType.INVESTMENT, SchemeType.SPECIAL_SUPPORT));
|
| 617 |
allOutSchemeTypes.addAll(OUT_SCHEME_TYPES);
|
631 |
allOutSchemeTypes.addAll(OUT_SCHEME_TYPES);
|
| 618 |
List<Scheme> allActiveSchemes = schemeRepository.selectActiveAll(allOutSchemeTypes, partnerType,
|
632 |
List<Scheme> allActiveSchemes = schemeRepository.selectActiveAll(allOutSchemeTypes, partnerType,
|
| 619 |
fofoOrder.getCreateTimestamp(), false);
|
633 |
fofoOrder.getCreateTimestamp().toLocalDate(), false);
|
| 620 |
|
- |
|
| - |
|
634 |
List<Integer> validSchemeIds = schemeRepository.selectSchemesByRetailerIdsSchemeIds(retailerId, allActiveSchemes.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| - |
|
635 |
allActiveSchemes = allActiveSchemes.stream().filter(x -> validSchemeIds.contains(x.getId())).collect(Collectors.toList());
|
| 621 |
for (InventoryItem inventoryItem : inventoryItems) {
|
636 |
for (InventoryItem inventoryItem : inventoryItems) {
|
| 622 |
float itemCashback = 0;
|
637 |
float itemCashback = 0;
|
| 623 |
Set<Integer> schemeIds = new HashSet<>(
|
638 |
Set<Integer> schemeIds = new HashSet<>(
|
| 624 |
schemeItemRepository.selectSchemeIdByCatalogId(inventoryItem.getItem().getCatalogItemId()));
|
639 |
schemeItemRepository.selectSchemeIdByCatalogId(inventoryItem.getItem().getCatalogItemId()));
|
| 625 |
List<Scheme> itemActiveSchemes = allActiveSchemes.stream().filter(x -> schemeIds.contains(x.getId()))
|
640 |
List<Scheme> itemActiveSchemes = allActiveSchemes.stream().filter(x -> schemeIds.contains(x.getId()))
|
| Line 924... |
Line 939... |
| 924 |
@Override
|
939 |
@Override
|
| 925 |
@Cacheable(value = "itemSchemeCashback", cacheManager = "timeoutCacheManager")
|
940 |
@Cacheable(value = "itemSchemeCashback", cacheManager = "timeoutCacheManager")
|
| 926 |
public Map<Integer, Float> getCatalogSchemeCashBack() {
|
941 |
public Map<Integer, Float> getCatalogSchemeCashBack() {
|
| 927 |
Map<Integer, Float> itemCashbackMap = new HashMap<>();
|
942 |
Map<Integer, Float> itemCashbackMap = new HashMap<>();
|
| 928 |
Map<Integer, Scheme> cashbackSchemesMap = schemeRepository
|
943 |
Map<Integer, Scheme> cashbackSchemesMap = schemeRepository
|
| 929 |
.selectActiveAll(Arrays.asList(SchemeType.ACTIVATION, SchemeType.SPECIAL_SUPPORT), PartnerType.ALL, LocalDateTime.now(), false)
|
944 |
.selectActiveAll(Arrays.asList(SchemeType.ACTIVATION, SchemeType.SPECIAL_SUPPORT), PartnerType.ALL, LocalDate.now(), false)
|
| 930 |
.stream().filter(x -> x.getAmountType().equals(AmountType.FIXED))
|
945 |
.stream().filter(x -> x.getAmountType().equals(AmountType.FIXED))
|
| 931 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
946 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 932 |
if (cashbackSchemesMap.size() > 0) {
|
947 |
if (cashbackSchemesMap.size() > 0) {
|
| 933 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(cashbackSchemesMap.keySet());
|
948 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(cashbackSchemesMap.keySet());
|
| 934 |
schemeItems.stream().forEach(x -> {
|
949 |
schemeItems.stream().forEach(x -> {
|
| Line 946... |
Line 961... |
| 946 |
itemCashbackMap.remove(30213);
|
961 |
itemCashbackMap.remove(30213);
|
| 947 |
itemCashbackMap.remove(30756);
|
962 |
itemCashbackMap.remove(30756);
|
| 948 |
return itemCashbackMap;
|
963 |
return itemCashbackMap;
|
| 949 |
}
|
964 |
}
|
| 950 |
|
965 |
|
| - |
|
966 |
@Override
|
| - |
|
967 |
public List<Scheme> selectSchemeByPartnerTypeFofoId(PartnerType partnerType, LocalDate onDate, int catalogId, int fofoId, int offset, int limit) throws ProfitMandiBusinessException {
|
| - |
|
968 |
Session session = sessionFactory.getCurrentSession();
|
| - |
|
969 |
final TypedQuery<Scheme> typedQuery = session.createNamedQuery(
|
| - |
|
970 |
"Scheme.selectSchemeByModelsPartnerTypeFofoId", Scheme.class);
|
| - |
|
971 |
typedQuery.setParameter("catalogIds", Arrays.asList(catalogId));
|
| - |
|
972 |
typedQuery.setParameter("fofoIds", Arrays.asList(fofoId, 0));
|
| - |
|
973 |
typedQuery.setParameter("onDate", onDate.atStartOfDay());
|
| - |
|
974 |
typedQuery.setParameter("partnerTypes", Arrays.asList(partnerType, partnerType.ALL));
|
| - |
|
975 |
typedQuery.setFirstResult(offset);
|
| - |
|
976 |
if (limit != 0) {
|
| - |
|
977 |
typedQuery.setMaxResults(limit);
|
| - |
|
978 |
}
|
| - |
|
979 |
return typedQuery.getResultList();
|
| - |
|
980 |
}
|
| 951 |
|
981 |
|
| 952 |
@Override
|
982 |
@Override
|
| 953 |
public List<Scheme> selectSchemeByPartnerType(PartnerType partnerType, LocalDate onDate, int catalogId,
|
983 |
public List<Scheme> selectSchemeByPartnerType(PartnerType partnerType, LocalDate onDate, int catalogId,
|
| 954 |
boolean isAdmin, int offset, int limit) throws ProfitMandiBusinessException {
|
984 |
boolean isAdmin, int offset, int limit) throws ProfitMandiBusinessException {
|
| 955 |
Session session = sessionFactory.getCurrentSession();
|
985 |
Session session = sessionFactory.getCurrentSession();
|