| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.offers;
|
1 |
package com.spice.profitmandi.service.offers;
|
| 2 |
|
2 |
|
| 3 |
import java.io.FileInputStream;
|
- |
|
| 4 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| 5 |
import java.io.InputStream;
|
4 |
import java.io.InputStream;
|
| 6 |
import java.time.LocalDate;
|
5 |
import java.time.LocalDate;
|
| 7 |
import java.time.YearMonth;
|
6 |
import java.time.YearMonth;
|
| 8 |
import java.util.ArrayList;
|
7 |
import java.util.ArrayList;
|
| 9 |
import java.util.Arrays;
|
8 |
import java.util.Arrays;
|
| 10 |
import java.util.Collections;
|
9 |
import java.util.Collections;
|
| 11 |
import java.util.Comparator;
|
10 |
import java.util.Comparator;
|
| 12 |
import java.util.HashMap;
|
11 |
import java.util.HashMap;
|
| - |
|
12 |
import java.util.HashSet;
|
| 13 |
import java.util.Iterator;
|
13 |
import java.util.Iterator;
|
| - |
|
14 |
import java.util.LinkedHashMap;
|
| 14 |
import java.util.List;
|
15 |
import java.util.List;
|
| 15 |
import java.util.Map;
|
16 |
import java.util.Map;
|
| 16 |
import java.util.Set;
|
17 |
import java.util.Set;
|
| 17 |
import java.util.stream.Collectors;
|
18 |
import java.util.stream.Collectors;
|
| 18 |
|
19 |
|
| Line 24... |
Line 25... |
| 24 |
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
25 |
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
| 25 |
import org.apache.poi.xssf.usermodel.XSSFRow;
|
26 |
import org.apache.poi.xssf.usermodel.XSSFRow;
|
| 26 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
27 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
| 27 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
28 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
| 28 |
import org.springframework.beans.factory.annotation.Autowired;
|
29 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
30 |
import org.springframework.cache.annotation.Cacheable;
|
| 29 |
import org.springframework.stereotype.Component;
|
31 |
import org.springframework.stereotype.Component;
|
| 30 |
|
32 |
|
| - |
|
33 |
import com.google.common.collect.Lists;
|
| 31 |
import com.google.gson.Gson;
|
34 |
import com.google.gson.Gson;
|
| 32 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 33 |
import com.spice.profitmandi.common.model.PartnerTargetModel;
|
36 |
import com.spice.profitmandi.common.model.PartnerTargetModel;
|
| 34 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
37 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 35 |
import com.spice.profitmandi.dao.entity.catalog.ItemCriteria;
|
38 |
import com.spice.profitmandi.dao.entity.catalog.ItemCriteria;
|
| 36 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
39 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
| - |
|
40 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 37 |
import com.spice.profitmandi.dao.entity.catalog.TargetSlab;
|
41 |
import com.spice.profitmandi.dao.entity.catalog.TargetSlab;
|
| - |
|
42 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 38 |
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
|
43 |
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
|
| 39 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
44 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 40 |
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
|
45 |
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
|
| 41 |
import com.spice.profitmandi.dao.repository.catalog.ItemCriteriaRepository;
|
46 |
import com.spice.profitmandi.dao.repository.catalog.ItemCriteriaRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
47 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 43 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
48 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
| 44 |
import com.spice.profitmandi.dao.repository.catalog.OfferTargetSlabRepository;
|
49 |
import com.spice.profitmandi.dao.repository.catalog.OfferTargetSlabRepository;
|
| - |
|
50 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 45 |
import com.spice.profitmandi.service.user.RetailerService;
|
51 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 46 |
|
52 |
|
| 47 |
@Component
|
53 |
@Component
|
| 48 |
public class OfferServiceImpl implements OfferService {
|
54 |
public class OfferServiceImpl implements OfferService {
|
| 49 |
|
55 |
|
| Line 64... |
Line 70... |
| 64 |
|
70 |
|
| 65 |
@Autowired
|
71 |
@Autowired
|
| 66 |
private ItemRepository itemRepository;
|
72 |
private ItemRepository itemRepository;
|
| 67 |
|
73 |
|
| 68 |
@Autowired
|
74 |
@Autowired
|
| - |
|
75 |
private TagListingRepository tagListingRepository;
|
| - |
|
76 |
|
| - |
|
77 |
@Autowired
|
| 69 |
private OfferTargetSlabRepository targetSlabRepository;
|
78 |
private OfferTargetSlabRepository targetSlabRepository;
|
| 70 |
|
79 |
|
| 71 |
private static final Logger LOGGER = LogManager.getLogger(OfferServiceImpl.class);
|
80 |
private static final Logger LOGGER = LogManager.getLogger(OfferServiceImpl.class);
|
| 72 |
|
81 |
|
| 73 |
@Override
|
82 |
@Override
|
| Line 97... |
Line 106... |
| 97 |
createOfferRequest.setId(offer.getId());
|
106 |
createOfferRequest.setId(offer.getId());
|
| 98 |
}
|
107 |
}
|
| 99 |
|
108 |
|
| 100 |
@Override
|
109 |
@Override
|
| 101 |
public List<CreateOfferRequest> getPublishedOffers(int fofoId, YearMonth yearMonth) {
|
110 |
public List<CreateOfferRequest> getPublishedOffers(int fofoId, YearMonth yearMonth) {
|
| 102 |
List<Offer> publishedOffers = offerRepository
|
- |
|
| 103 |
.selectAllPublishedMapByPartner(yearMonth).get(fofoId);
|
111 |
List<Offer> publishedOffers = offerRepository.selectAllPublishedMapByPartner(yearMonth).get(fofoId);
|
| 104 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
112 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
| 105 |
if (publishedOffers != null) {
|
113 |
if (publishedOffers != null) {
|
| 106 |
for (Offer offer : publishedOffers) {
|
114 |
for (Offer offer : publishedOffers) {
|
| 107 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = targetSlabRepository
|
- |
|
| 108 |
.getByOfferId(offer.getId());
|
- |
|
| 109 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
115 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
| 110 |
createOfferRequest.getItemCriteria();
|
- |
|
| 111 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
- |
|
| 112 |
createOfferRequests.add(createOfferRequest);
|
116 |
createOfferRequests.add(createOfferRequest);
|
| - |
|
117 |
setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
| 113 |
|
118 |
|
| 114 |
}
|
119 |
}
|
| 115 |
for (CreateOfferRequest createOfferRequest : createOfferRequests) {
|
- |
|
| 116 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.SELLIN)) {
|
- |
|
| 117 |
} else {
|
120 |
}
|
| 118 |
long amount = offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId) == null ? 0
|
- |
|
| 119 |
: offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId);
|
121 |
return createOfferRequests;
|
| - |
|
122 |
}
|
| 120 |
|
123 |
|
| 121 |
com.spice.profitmandi.dao.model.TargetSlab currentSlab = createOfferRequest.getTargetSlabs()
|
124 |
private void setCriteriaPayoutAchieved(int fofoId, CreateOfferRequest createOfferRequest) {
|
| 122 |
.stream().filter(x -> x.getOnwardsAmount() <= amount)
|
125 |
Map<Integer, Long> criteriaTransactionMap = null;
|
| - |
|
126 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.SELLIN)) {
|
| - |
|
127 |
criteriaTransactionMap = offerRepository.getPartnerWisePurchaseSum(createOfferRequest).get(fofoId);
|
| - |
|
128 |
} else {
|
| - |
|
129 |
criteriaTransactionMap = offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId);
|
| - |
|
130 |
}
|
| 123 |
.max(Comparator.comparing(x -> x.getOnwardsAmount())).orElse(null);
|
131 |
LOGGER.info("I am here ------- {}", createOfferRequest.getId());
|
| - |
|
132 |
List<com.spice.profitmandi.dao.model.ItemCriteriaPayout> itemCriteriaPayouts = createOfferRequest
|
| - |
|
133 |
.getTargetSlabs().get(0).getItemCriteriaPayouts();
|
| 124 |
|
134 |
|
| - |
|
135 |
for (com.spice.profitmandi.dao.model.ItemCriteriaPayout itemCriteriaPayout : itemCriteriaPayouts) {
|
| - |
|
136 |
itemCriteriaPayout.setNextSlab(null);
|
| - |
|
137 |
LOGGER.info("I am here --- {}", itemCriteriaPayout.getPayoutSlabs());
|
| - |
|
138 |
long saleAmount = 0;
|
| - |
|
139 |
if (criteriaTransactionMap != null
|
| - |
|
140 |
&& criteriaTransactionMap.containsKey(itemCriteriaPayout.getItemCriteria().getId())) {
|
| - |
|
141 |
saleAmount = criteriaTransactionMap.get(itemCriteriaPayout.getItemCriteria().getId());
|
| - |
|
142 |
}
|
| - |
|
143 |
itemCriteriaPayout.setAchievedValue(saleAmount);
|
| 125 |
com.spice.profitmandi.dao.model.TargetSlab nextSlab = createOfferRequest.getTargetSlabs().stream()
|
144 |
List<com.spice.profitmandi.service.offers.PayoutSlab> payoutSlabs = itemCriteriaPayout.getPayoutSlabs();
|
| - |
|
145 |
for (int i = 0; i < payoutSlabs.size(); i++) {
|
| - |
|
146 |
com.spice.profitmandi.service.offers.PayoutSlab beginSlab = payoutSlabs.get(i);
|
| - |
|
147 |
com.spice.profitmandi.service.offers.PayoutSlab endSlab = null;
|
| - |
|
148 |
if (payoutSlabs.size() - 1 > i) {
|
| - |
|
149 |
endSlab = payoutSlabs.get(i + 1);
|
| - |
|
150 |
}
|
| 126 |
.filter(x -> x.getOnwardsAmount() > amount)
|
151 |
if (beginSlab.getOnwardsAmount() > saleAmount) {
|
| 127 |
.min(Comparator.comparing(x -> x.getOnwardsAmount())).orElse(null);
|
152 |
itemCriteriaPayout.setShortValue(beginSlab.getOnwardsAmount() - saleAmount);
|
| 128 |
createOfferRequest.setNextTargetSlab(nextSlab);
|
153 |
itemCriteriaPayout.setNextSlab(beginSlab);
|
| 129 |
if (nextSlab != null) {
|
154 |
LOGGER.info("I am here");
|
| 130 |
createOfferRequest
|
155 |
break;
|
| 131 |
.setNextTarget(targets.get(createOfferRequest.getTargetSlabs().indexOf(nextSlab)));
|
- |
|
| 132 |
}
|
156 |
}
|
| - |
|
157 |
if (endSlab != null) {
|
| - |
|
158 |
if (beginSlab.getOnwardsAmount() <= saleAmount && endSlab.getOnwardsAmount() > saleAmount) {
|
| 133 |
createOfferRequest.setCurrentTargetSlab(currentSlab);
|
159 |
itemCriteriaPayout.setCurrentSlab(beginSlab);
|
| 134 |
if (currentSlab != null) {
|
160 |
beginSlab.setSelected(true);
|
| 135 |
createOfferRequest.setCurrentTarget(
|
161 |
itemCriteriaPayout.setNextSlab(endSlab);
|
| 136 |
targets.get(createOfferRequest.getTargetSlabs().indexOf(currentSlab)));
|
162 |
itemCriteriaPayout.setShortValue(endSlab.getOnwardsAmount() - saleAmount);
|
| - |
|
163 |
LOGGER.info("I am here");
|
| - |
|
164 |
break;
|
| 137 |
}
|
165 |
}
|
| - |
|
166 |
// Last loop
|
| - |
|
167 |
} else {
|
| - |
|
168 |
beginSlab.setSelected(true);
|
| 138 |
createOfferRequest.setEligibleSale((int) amount);
|
169 |
itemCriteriaPayout.setCurrentSlab(beginSlab);
|
| - |
|
170 |
LOGGER.info("I am here");
|
| 139 |
}
|
171 |
}
|
| 140 |
|
- |
|
| 141 |
}
|
172 |
}
|
| - |
|
173 |
LOGGER.info("I am here --- {}", itemCriteriaPayout);
|
| 142 |
}
|
174 |
}
|
| 143 |
return createOfferRequests;
|
- |
|
| - |
|
175 |
|
| 144 |
}
|
176 |
}
|
| 145 |
|
177 |
|
| 146 |
@Override
|
178 |
@Override
|
| - |
|
179 |
@Cacheable(value = "allOffers", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 147 |
public List<CreateOfferRequest> getAllOffers(YearMonth yearMonth) {
|
180 |
public Map<Integer, CreateOfferRequest> getAllOffers(YearMonth yearMonth) {
|
| 148 |
List<Offer> allOffers = offerRepository.selectAll(yearMonth, false);
|
181 |
List<Offer> allOffers = offerRepository.selectAll(yearMonth, false);
|
| 149 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
182 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
| 150 |
for (Offer offer : allOffers) {
|
183 |
for (Offer offer : allOffers) {
|
| 151 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
184 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
| 152 |
createOfferRequests.add(createOfferRequest);
|
185 |
createOfferRequests.add(createOfferRequest);
|
| 153 |
}
|
186 |
}
|
| 154 |
return createOfferRequests;
|
187 |
return createOfferRequests.stream().collect(Collectors.toMap(CreateOfferRequest::getId, x -> x));
|
| 155 |
}
|
188 |
}
|
| 156 |
|
189 |
|
| 157 |
@Override
|
190 |
@Override
|
| - |
|
191 |
@Cacheable(value = "partnerOffers", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 158 |
public CreateOfferRequest getOffer(int offerId) {
|
192 |
public CreateOfferRequest getOffer(int fofoId, int offerId) {
|
| 159 |
Offer offer = offerRepository.selectById(offerId);
|
193 |
Offer offer = offerRepository.selectById(offerId);
|
| 160 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
194 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
| - |
|
195 |
if (fofoId > 0) {
|
| - |
|
196 |
this.setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
| - |
|
197 |
}
|
| - |
|
198 |
|
| 161 |
return createOfferRequest;
|
199 |
return createOfferRequest;
|
| 162 |
}
|
200 |
}
|
| 163 |
|
201 |
|
| 164 |
private CreateOfferRequest getCreateOfferRequest(Offer fromOffer) {
|
202 |
private CreateOfferRequest getCreateOfferRequest(Offer fromOffer) {
|
| 165 |
CreateOfferRequest createOfferRequest = new CreateOfferRequest();
|
203 |
CreateOfferRequest createOfferRequest = new CreateOfferRequest();
|
| Line 185... |
Line 223... |
| 185 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = targetSlabRepository
|
223 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = targetSlabRepository
|
| 186 |
.getByOfferId(fromOffer.getId());
|
224 |
.getByOfferId(fromOffer.getId());
|
| 187 |
createOfferRequest.setPartnerCriteriaString(
|
225 |
createOfferRequest.setPartnerCriteriaString(
|
| 188 |
retailerService.getPartnerCriteriaString(createOfferRequest.getPartnerCriteria()));
|
226 |
retailerService.getPartnerCriteriaString(createOfferRequest.getPartnerCriteria()));
|
| 189 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
227 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
| - |
|
228 |
for (com.spice.profitmandi.dao.model.ItemCriteriaPayout itemCriteriaPayout : createOfferRequest.getTargetSlabs()
|
| - |
|
229 |
.get(0).getItemCriteriaPayouts()) {
|
| 190 |
LOGGER.info("createOfferRequest {}", createOfferRequest);
|
230 |
itemCriteriaPayout.setNextSlab(itemCriteriaPayout.getPayoutSlabs().get(0));
|
| - |
|
231 |
}
|
| 191 |
return createOfferRequest;
|
232 |
return createOfferRequest;
|
| 192 |
|
233 |
|
| 193 |
}
|
234 |
}
|
| 194 |
|
235 |
|
| 195 |
private void createTargetSlabs(CreateOfferRequest createOfferRequest) throws ProfitMandiBusinessException {
|
236 |
private void createTargetSlabs(CreateOfferRequest createOfferRequest) throws ProfitMandiBusinessException {
|
| Line 258... |
Line 299... |
| 258 |
}
|
299 |
}
|
| 259 |
}
|
300 |
}
|
| 260 |
|
301 |
|
| 261 |
return createOfferRequests;
|
302 |
return createOfferRequests;
|
| 262 |
}
|
303 |
}
|
| 263 |
|
304 |
|
| 264 |
@Override
|
305 |
@Override
|
| 265 |
public void createOffers(InputStream fileInputStream) throws Exception {
|
306 |
public void createOffers(InputStream fileInputStream) throws Exception {
|
| 266 |
Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap = this.parseFromExcel(fileInputStream);
|
307 |
Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap = this.parseFromExcel(fileInputStream);
|
| 267 |
for(Map.Entry<CreateOfferRequest, List<PartnerTargetModel>> partnerTargetEntry: offerPartnerTargetMap.entrySet()) {
|
308 |
for (Map.Entry<CreateOfferRequest, List<PartnerTargetModel>> partnerTargetEntry : offerPartnerTargetMap
|
| - |
|
309 |
.entrySet()) {
|
| 268 |
CreateOfferRequest createOfferRequest = partnerTargetEntry.getKey();
|
310 |
CreateOfferRequest createOfferRequest = partnerTargetEntry.getKey();
|
| 269 |
Map<List<Integer>, List<Integer>> targetPartnerMap = partnerTargetEntry.getValue().stream().collect(Collectors.groupingBy(PartnerTargetModel::getTargets, Collectors.mapping(PartnerTargetModel::getFofoId, Collectors.toList())));
|
311 |
Map<List<Integer>, List<Integer>> targetPartnerMap = partnerTargetEntry.getValue().stream()
|
| - |
|
312 |
.collect(Collectors.groupingBy(PartnerTargetModel::getTargets,
|
| - |
|
313 |
Collectors.mapping(PartnerTargetModel::getFofoId, Collectors.toList())));
|
| 270 |
for (Map.Entry<List<Integer>, List<Integer>> targetPartnersEntry : targetPartnerMap.entrySet()) {
|
314 |
for (Map.Entry<List<Integer>, List<Integer>> targetPartnersEntry : targetPartnerMap.entrySet()) {
|
| 271 |
List<Integer> fofoIds = createOfferRequest.getPartnerCriteria().getFofoIds();
|
315 |
List<Integer> fofoIds = createOfferRequest.getPartnerCriteria().getFofoIds();
|
| 272 |
List<Integer> filterFofoIds = targetPartnersEntry.getValue().stream().filter(x->!fofoIds.contains(x)).collect(Collectors.toList());
|
316 |
List<Integer> filterFofoIds = targetPartnersEntry.getValue().stream().filter(x -> !fofoIds.contains(x))
|
| - |
|
317 |
.collect(Collectors.toList());
|
| 273 |
List<Integer> targets = targetPartnersEntry.getKey();
|
318 |
List<Integer> targets = targetPartnersEntry.getKey();
|
| 274 |
|
319 |
|
| 275 |
createOfferRequest.getPartnerCriteria().setFofoIds(filterFofoIds);
|
320 |
createOfferRequest.getPartnerCriteria().setFofoIds(filterFofoIds);
|
| 276 |
int counter = 0;
|
321 |
int counter = 0;
|
| 277 |
for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : createOfferRequest.getTargetSlabs()) {
|
322 |
ItemCriteriaPayout itemCriteriaPayout = createOfferRequest.getTargetSlabs().get(0)
|
| - |
|
323 |
.getItemCriteriaPayouts().get(0);
|
| - |
|
324 |
for (PayoutSlab payoutSlab : itemCriteriaPayout.getPayoutSlabs()) {
|
| 278 |
targetSlab.setOnwardsAmount(targets.get(counter));
|
325 |
payoutSlab.setOnwardsAmount(targets.get(counter));
|
| 279 |
counter++;
|
326 |
counter++;
|
| 280 |
}
|
327 |
}
|
| - |
|
328 |
}
|
| 281 |
this.addOfferService(createOfferRequest);
|
329 |
this.addOfferService(createOfferRequest);
|
| 282 |
}
|
- |
|
| 283 |
}
|
330 |
}
|
| 284 |
}
|
331 |
}
|
| 285 |
|
- |
|
| 286 |
private Map<CreateOfferRequest, List<PartnerTargetModel>> parseFromExcel(InputStream inputStream) throws ProfitMandiBusinessException {
|
- |
|
| 287 |
|
332 |
|
| - |
|
333 |
private Map<CreateOfferRequest, List<PartnerTargetModel>> parseFromExcel(InputStream inputStream)
|
| - |
|
334 |
throws ProfitMandiBusinessException {
|
| - |
|
335 |
|
| 288 |
Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap = new HashMap<>();
|
336 |
Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap = new HashMap<>();
|
| 289 |
XSSFWorkbook myWorkBook = null;
|
337 |
XSSFWorkbook myWorkBook = null;
|
| 290 |
try {
|
338 |
try {
|
| 291 |
myWorkBook = new XSSFWorkbook(inputStream);
|
339 |
myWorkBook = new XSSFWorkbook(inputStream);
|
| 292 |
myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
340 |
myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
| 293 |
for(int i=0; i< myWorkBook.getNumberOfSheets();i++) {
|
341 |
for (int i = 0; i < myWorkBook.getNumberOfSheets(); i++) {
|
| 294 |
|
342 |
|
| 295 |
XSSFSheet mySheet = myWorkBook.getSheetAt(i);
|
343 |
XSSFSheet mySheet = myWorkBook.getSheetAt(i);
|
| 296 |
int offerId = Integer.parseInt(mySheet.getSheetName());
|
344 |
int offerId = Integer.parseInt(mySheet.getSheetName());
|
| 297 |
CreateOfferRequest existingOffer = this.getOffer(offerId);
|
345 |
CreateOfferRequest existingOffer = this.getOffer(0, offerId);
|
| 298 |
List<PartnerTargetModel> partnerTargetModels = new ArrayList<>();
|
346 |
List<PartnerTargetModel> partnerTargetModels = new ArrayList<>();
|
| 299 |
offerPartnerTargetMap.put(existingOffer, partnerTargetModels);
|
347 |
offerPartnerTargetMap.put(existingOffer, partnerTargetModels);
|
| 300 |
this.printIterator(mySheet);
|
348 |
this.printIterator(mySheet);
|
| 301 |
LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
|
349 |
LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
|
| 302 |
for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
|
350 |
for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
|
| Line 328... |
Line 376... |
| 328 |
partnerTargetModel.setTargets(targets);
|
376 |
partnerTargetModel.setTargets(targets);
|
| 329 |
partnerTargetModels.add(partnerTargetModel);
|
377 |
partnerTargetModels.add(partnerTargetModel);
|
| 330 |
}
|
378 |
}
|
| 331 |
}
|
379 |
}
|
| 332 |
myWorkBook.close();
|
380 |
myWorkBook.close();
|
| 333 |
} catch ( ProfitMandiBusinessException pbse) {
|
381 |
} catch (ProfitMandiBusinessException pbse) {
|
| 334 |
throw pbse;
|
382 |
throw pbse;
|
| 335 |
} catch (IOException ioException) {
|
383 |
} catch (IOException ioException) {
|
| 336 |
ioException.printStackTrace();
|
384 |
ioException.printStackTrace();
|
| 337 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(),
|
385 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(),
|
| 338 |
"EXL_VE_1000");
|
386 |
"EXL_VE_1000");
|
| Line 347... |
Line 395... |
| 347 |
}
|
395 |
}
|
| 348 |
}
|
396 |
}
|
| 349 |
LOGGER.info("offerPartnerTargetMap {}", offerPartnerTargetMap);
|
397 |
LOGGER.info("offerPartnerTargetMap {}", offerPartnerTargetMap);
|
| 350 |
return offerPartnerTargetMap;
|
398 |
return offerPartnerTargetMap;
|
| 351 |
}
|
399 |
}
|
| 352 |
|
400 |
|
| 353 |
private void printIterator (XSSFSheet sheet) {
|
401 |
private void printIterator(XSSFSheet sheet) {
|
| 354 |
Iterator<Row> rowIterator = sheet.iterator();
|
402 |
Iterator<Row> rowIterator = sheet.iterator();
|
| 355 |
while (rowIterator.hasNext())
|
403 |
while (rowIterator.hasNext()) {
|
| 356 |
{
|
- |
|
| 357 |
Row row = rowIterator.next();
|
404 |
Row row = rowIterator.next();
|
| 358 |
//For each row, iterate through all the columns
|
405 |
// For each row, iterate through all the columns
|
| 359 |
Iterator<Cell> cellIterator = row.cellIterator();
|
406 |
Iterator<Cell> cellIterator = row.cellIterator();
|
| 360 |
|
407 |
|
| 361 |
while (cellIterator.hasNext())
|
408 |
while (cellIterator.hasNext()) {
|
| 362 |
{
|
- |
|
| 363 |
Cell cell = cellIterator.next();
|
409 |
Cell cell = cellIterator.next();
|
| 364 |
//Check the cell type and format accordingly
|
410 |
// Check the cell type and format accordingly
|
| 365 |
switch (cell.getCellType())
|
411 |
switch (cell.getCellType()) {
|
| 366 |
{
|
- |
|
| 367 |
case Cell.CELL_TYPE_NUMERIC:
|
412 |
case Cell.CELL_TYPE_NUMERIC:
|
| 368 |
System.out.print(cell.getNumericCellValue() + "t");
|
413 |
System.out.print(cell.getNumericCellValue() + "t");
|
| 369 |
break;
|
414 |
break;
|
| 370 |
case Cell.CELL_TYPE_STRING:
|
415 |
case Cell.CELL_TYPE_STRING:
|
| 371 |
System.out.print(cell.getStringCellValue() + "t");
|
416 |
System.out.print(cell.getStringCellValue() + "t");
|
| 372 |
break;
|
417 |
break;
|
| 373 |
}
|
418 |
}
|
| 374 |
}
|
419 |
}
|
| 375 |
System.out.println("");
|
420 |
System.out.println("");
|
| - |
|
421 |
}
|
| - |
|
422 |
}
|
| - |
|
423 |
|
| 376 |
}
|
424 |
@Override
|
| - |
|
425 |
public Map<Integer, CreateOfferRequest> getPublishedOffers(LocalDate date, int fofoId, String brand) {
|
| - |
|
426 |
// TODO Auto-generated method stub
|
| - |
|
427 |
return null;
|
| 377 |
}
|
428 |
}
|
| 378 |
|
429 |
|
| - |
|
430 |
@Override
|
| - |
|
431 |
@Cacheable(value = "slabPayoutMap", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| - |
|
432 |
public Map<Integer, Map<Integer, Long>> getSlabPayoutMap(CreateOfferRequest createOfferRequest) {
|
| - |
|
433 |
Map<Integer, Map<Integer, Long>> itemSlabPayoutMap = new HashMap<>();
|
| - |
|
434 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = createOfferRequest.getTargetSlabs();
|
| - |
|
435 |
com.spice.profitmandi.dao.model.TargetSlab targetSlab = targetSlabs.get(0);
|
| - |
|
436 |
List<ItemCriteriaPayout> payouts = targetSlab.getItemCriteriaPayouts();
|
| - |
|
437 |
for (ItemCriteriaPayout itemCriteriaPayout : payouts) {
|
| - |
|
438 |
com.spice.profitmandi.service.offers.ItemCriteria itemCriteria = itemCriteriaPayout.getItemCriteria();
|
| - |
|
439 |
List<Integer> itemIds = itemRepository.getItems(itemCriteria);
|
| - |
|
440 |
for (PayoutSlab payoutSlab : Lists.reverse(itemCriteriaPayout.getPayoutSlabs())) {
|
| - |
|
441 |
if (itemCriteriaPayout.getAmountType().equals(AmountType.FIXED)) {
|
| - |
|
442 |
for (Integer itemId : itemIds) {
|
| - |
|
443 |
if (!itemSlabPayoutMap.containsKey(itemId)) {
|
| - |
|
444 |
itemSlabPayoutMap.put(itemId, new LinkedHashMap<>());
|
| - |
|
445 |
}
|
| - |
|
446 |
itemSlabPayoutMap.get(itemId).put(payoutSlab.getOnwardsAmount(),
|
| - |
|
447 |
(long) payoutSlab.getPayoutAmount());
|
| - |
|
448 |
}
|
| - |
|
449 |
} else if (itemCriteriaPayout.getAmountType().equals(AmountType.SLAB_FIXED)) {
|
| - |
|
450 |
for (Integer itemId : itemIds) {
|
| - |
|
451 |
if (!itemSlabPayoutMap.containsKey(itemId)) {
|
| - |
|
452 |
itemSlabPayoutMap.put(itemId, new LinkedHashMap<>());
|
| - |
|
453 |
}
|
| - |
|
454 |
itemSlabPayoutMap.get(itemId).put(payoutSlab.getOnwardsAmount(),
|
| - |
|
455 |
(long) (payoutSlab.getPayoutAmount() / payoutSlab.getOnwardsAmount()));
|
| - |
|
456 |
}
|
| - |
|
457 |
} else if (itemCriteriaPayout.getAmountType().equals(AmountType.PERCENTAGE)) {
|
| - |
|
458 |
List<TagListing> tagListings = tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(itemIds),
|
| - |
|
459 |
null);
|
| - |
|
460 |
for (TagListing tagListing : tagListings) {
|
| - |
|
461 |
float taxableSellingPrice = tagListing.getSellingPrice() / (1 + 18f / 100);
|
| - |
|
462 |
if (!itemSlabPayoutMap.containsKey(tagListing.getItemId())) {
|
| - |
|
463 |
itemSlabPayoutMap.put(tagListing.getItemId(), new LinkedHashMap<>());
|
| - |
|
464 |
}
|
| - |
|
465 |
itemSlabPayoutMap.get(tagListing.getItemId()).put(payoutSlab.getOnwardsAmount(),
|
| - |
|
466 |
(long) (taxableSellingPrice * payoutSlab.getPayoutAmount() / 100));
|
| - |
|
467 |
}
|
| - |
|
468 |
}
|
| - |
|
469 |
}
|
| - |
|
470 |
}
|
| - |
|
471 |
return itemSlabPayoutMap;
|
| - |
|
472 |
}
|
| 379 |
|
473 |
|
| 380 |
}
|
474 |
}
|