| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.offers;
|
1 |
package com.spice.profitmandi.service.offers;
|
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
- |
|
| 4 |
import java.io.InputStream;
|
- |
|
| 5 |
import java.time.LocalDate;
|
- |
|
| 6 |
import java.time.YearMonth;
|
- |
|
| 7 |
import java.util.ArrayList;
|
- |
|
| 8 |
import java.util.Arrays;
|
- |
|
| 9 |
import java.util.Collections;
|
- |
|
| 10 |
import java.util.HashMap;
|
- |
|
| 11 |
import java.util.HashSet;
|
- |
|
| 12 |
import java.util.Iterator;
|
- |
|
| 13 |
import java.util.LinkedHashMap;
|
- |
|
| 14 |
import java.util.List;
|
- |
|
| 15 |
import java.util.Map;
|
- |
|
| 16 |
import java.util.Set;
|
- |
|
| 17 |
import java.util.stream.Collectors;
|
- |
|
| 18 |
|
- |
|
| 19 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 20 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 21 |
import org.apache.poi.ss.usermodel.Cell;
|
- |
|
| 22 |
import org.apache.poi.ss.usermodel.CellType;
|
- |
|
| 23 |
import org.apache.poi.ss.usermodel.Row;
|
- |
|
| 24 |
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
- |
|
| 25 |
import org.apache.poi.xssf.usermodel.XSSFRow;
|
- |
|
| 26 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
- |
|
| 27 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
- |
|
| 28 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 29 |
import org.springframework.cache.CacheManager;
|
- |
|
| 30 |
import org.springframework.cache.annotation.Cacheable;
|
- |
|
| 31 |
import org.springframework.stereotype.Component;
|
- |
|
| 32 |
|
- |
|
| 33 |
import com.google.common.collect.Lists;
|
3 |
import com.google.common.collect.Lists;
|
| 34 |
import com.google.gson.Gson;
|
4 |
import com.google.gson.Gson;
|
| 35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 36 |
import com.spice.profitmandi.common.model.PartnerTargetModel;
|
6 |
import com.spice.profitmandi.common.model.PartnerTargetModel;
|
| 37 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
7 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| Line 41... |
Line 11... |
| 41 |
import com.spice.profitmandi.dao.entity.catalog.TargetSlab;
|
11 |
import com.spice.profitmandi.dao.entity.catalog.TargetSlab;
|
| 42 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
12 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 43 |
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
|
13 |
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
|
| 44 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
14 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 45 |
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
|
15 |
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
|
| 46 |
import com.spice.profitmandi.dao.repository.catalog.ItemCriteriaRepository;
|
- |
|
| 47 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
16 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
| 48 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
- |
|
| 49 |
import com.spice.profitmandi.dao.repository.catalog.OfferTargetSlabRepository;
|
- |
|
| 50 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
- |
|
| 51 |
import com.spice.profitmandi.service.user.RetailerService;
|
17 |
import com.spice.profitmandi.service.user.RetailerService;
|
| - |
|
18 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
19 |
import org.apache.logging.log4j.Logger;
|
| - |
|
20 |
import org.apache.poi.ss.usermodel.Cell;
|
| - |
|
21 |
import org.apache.poi.ss.usermodel.CellType;
|
| - |
|
22 |
import org.apache.poi.ss.usermodel.Row;
|
| - |
|
23 |
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
| - |
|
24 |
import org.apache.poi.xssf.usermodel.XSSFRow;
|
| - |
|
25 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
| - |
|
26 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
| - |
|
27 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
28 |
import org.springframework.cache.CacheManager;
|
| - |
|
29 |
import org.springframework.cache.annotation.Cacheable;
|
| - |
|
30 |
import org.springframework.stereotype.Component;
|
| - |
|
31 |
|
| - |
|
32 |
import java.io.IOException;
|
| - |
|
33 |
import java.io.InputStream;
|
| - |
|
34 |
import java.time.LocalDate;
|
| - |
|
35 |
import java.time.YearMonth;
|
| - |
|
36 |
import java.util.*;
|
| - |
|
37 |
import java.util.stream.Collectors;
|
| 52 |
|
38 |
|
| 53 |
@Component
|
39 |
@Component
|
| 54 |
public class OfferServiceImpl implements OfferService {
|
40 |
public class OfferServiceImpl implements OfferService {
|
| 55 |
|
41 |
|
| 56 |
private static final List<String> targets = Arrays.asList("Target 1", "Target 2", "Target 3", "Target 4",
|
42 |
private static final List<String> targets = Arrays.asList("Target 1", "Target 2", "Target 3", "Target 4",
|
| Line 73... |
Line 59... |
| 73 |
|
59 |
|
| 74 |
@Autowired
|
60 |
@Autowired
|
| 75 |
private TagListingRepository tagListingRepository;
|
61 |
private TagListingRepository tagListingRepository;
|
| 76 |
|
62 |
|
| 77 |
@Autowired
|
63 |
@Autowired
|
| 78 |
private OfferTargetSlabRepository targetSlabRepository;
|
64 |
private OfferTargetSlabRepository offerTargetSlabRepository;
|
| 79 |
|
65 |
|
| 80 |
@Autowired
|
66 |
@Autowired
|
| 81 |
CacheManager thirtyMinsTimeOutCacheManager;
|
67 |
CacheManager thirtyMinsTimeOutCacheManager;
|
| 82 |
|
68 |
|
| 83 |
|
69 |
|
| Line 224... |
Line 210... |
| 224 |
createOfferRequest.setPartnerCriteria(gson.fromJson(fromOffer.getPartnerCriteria(), PartnerCriteria.class));
|
210 |
createOfferRequest.setPartnerCriteria(gson.fromJson(fromOffer.getPartnerCriteria(), PartnerCriteria.class));
|
| 225 |
createOfferRequest.setId(fromOffer.getId());
|
211 |
createOfferRequest.setId(fromOffer.getId());
|
| 226 |
createOfferRequest.setCreatedOn(fromOffer.getCreatedTimestamp());
|
212 |
createOfferRequest.setCreatedOn(fromOffer.getCreatedTimestamp());
|
| 227 |
createOfferRequest.setItemCriteriaString(
|
213 |
createOfferRequest.setItemCriteriaString(
|
| 228 |
itemCriteriaRepository.getItemCriteriaDescription(createOfferRequest.getItemCriteria()));
|
214 |
itemCriteriaRepository.getItemCriteriaDescription(createOfferRequest.getItemCriteria()));
|
| 229 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = targetSlabRepository
|
215 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = offerTargetSlabRepository
|
| 230 |
.getByOfferId(fromOffer.getId());
|
216 |
.getByOfferId(fromOffer.getId());
|
| 231 |
createOfferRequest.setPartnerCriteriaString(
|
217 |
createOfferRequest.setPartnerCriteriaString(
|
| 232 |
retailerService.getPartnerCriteriaString(createOfferRequest.getPartnerCriteria()));
|
218 |
retailerService.getPartnerCriteriaString(createOfferRequest.getPartnerCriteria()));
|
| 233 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
219 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
| 234 |
for (com.spice.profitmandi.dao.model.ItemCriteriaPayout itemCriteriaPayout : createOfferRequest.getTargetSlabs()
|
220 |
for (com.spice.profitmandi.dao.model.ItemCriteriaPayout itemCriteriaPayout : createOfferRequest.getTargetSlabs()
|
| Line 263... |
Line 249... |
| 263 |
targetSlab1.setTargetDescription(targetSlab.getTargetDescription());
|
249 |
targetSlab1.setTargetDescription(targetSlab.getTargetDescription());
|
| 264 |
targetSlab1.setPayoutTarget(payoutSlab.getOnwardsAmount());
|
250 |
targetSlab1.setPayoutTarget(payoutSlab.getOnwardsAmount());
|
| 265 |
targetSlab1.setPayoutValue(payoutSlab.getPayoutAmount());
|
251 |
targetSlab1.setPayoutValue(payoutSlab.getPayoutAmount());
|
| 266 |
targetSlab1.setItemCriteriaId(itemCriteria.getId());
|
252 |
targetSlab1.setItemCriteriaId(itemCriteria.getId());
|
| 267 |
targetSlab1.setAmountType(itemCriteriaPayout.getAmountType());
|
253 |
targetSlab1.setAmountType(itemCriteriaPayout.getAmountType());
|
| 268 |
targetSlabRepository.persist(targetSlab1);
|
254 |
offerTargetSlabRepository.persist(targetSlab1);
|
| 269 |
}
|
255 |
}
|
| 270 |
}
|
256 |
}
|
| 271 |
}
|
257 |
}
|
| 272 |
}
|
258 |
}
|
| 273 |
|
259 |
|
| Line 282... |
Line 268... |
| 282 |
List<Offer> publishedOffers = offerRepository.selectAllPublishedMapByPartner(YearMonth.from(date)).get(fofoId);
|
268 |
List<Offer> publishedOffers = offerRepository.selectAllPublishedMapByPartner(YearMonth.from(date)).get(fofoId);
|
| 283 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
269 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
| 284 |
if (publishedOffers != null) {
|
270 |
if (publishedOffers != null) {
|
| 285 |
for (Offer offer : publishedOffers) {
|
271 |
for (Offer offer : publishedOffers) {
|
| 286 |
boolean found = false;
|
272 |
boolean found = false;
|
| 287 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = targetSlabRepository
|
273 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = offerTargetSlabRepository
|
| 288 |
.getByOfferId(offer.getId());
|
274 |
.getByOfferId(offer.getId());
|
| 289 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
275 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
| 290 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
276 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
| 291 |
this.setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
277 |
this.setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
| 292 |
Set<com.spice.profitmandi.service.offers.ItemCriteria> itemCriteriaSet = targetSlabs.stream()
|
278 |
Set<com.spice.profitmandi.service.offers.ItemCriteria> itemCriteriaSet = targetSlabs.stream()
|