| Line 15... |
Line 15... |
| 15 |
import org.apache.logging.log4j.Logger;
|
15 |
import org.apache.logging.log4j.Logger;
|
| 16 |
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 17 |
import org.springframework.stereotype.Component;
|
17 |
import org.springframework.stereotype.Component;
|
| 18 |
|
18 |
|
| 19 |
import com.google.gson.Gson;
|
19 |
import com.google.gson.Gson;
|
| - |
|
20 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 20 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
21 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21 |
import com.spice.profitmandi.dao.entity.catalog.ItemCriteria;
|
22 |
import com.spice.profitmandi.dao.entity.catalog.ItemCriteria;
|
| 22 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
23 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
| 23 |
import com.spice.profitmandi.dao.entity.catalog.TargetSlab;
|
24 |
import com.spice.profitmandi.dao.entity.catalog.TargetSlab;
|
| - |
|
25 |
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
|
| 24 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
26 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 25 |
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
|
27 |
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
|
| 26 |
import com.spice.profitmandi.dao.repository.catalog.ItemCriteriaRepository;
|
28 |
import com.spice.profitmandi.dao.repository.catalog.ItemCriteriaRepository;
|
| 27 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
29 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 28 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
30 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
| 29 |
import com.spice.profitmandi.dao.repository.catalog.OfferTargetSlabRepository;
|
31 |
import com.spice.profitmandi.dao.repository.catalog.OfferTargetSlabRepository;
|
| 30 |
import com.spice.profitmandi.service.user.RetailerService;
|
32 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 31 |
|
33 |
|
| 32 |
@Component
|
34 |
@Component
|
| 33 |
public class OfferServiceImpl implements OfferService {
|
35 |
public class OfferServiceImpl implements OfferService {
|
| 34 |
|
36 |
|
| 35 |
private static final List<String> targets = Arrays.asList("Target 1", "Target 2", "Target 3", "Target 4", "Target 5" );
|
37 |
private static final List<String> targets = Arrays.asList("Target 1", "Target 2", "Target 3", "Target 4",
|
| - |
|
38 |
"Target 5");
|
| 36 |
|
39 |
|
| 37 |
@Autowired
|
40 |
@Autowired
|
| 38 |
private Gson gson;
|
41 |
private Gson gson;
|
| 39 |
|
42 |
|
| 40 |
@Autowired
|
43 |
@Autowired
|
| Line 94... |
Line 97... |
| 94 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
97 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
| 95 |
createOfferRequests.add(createOfferRequest);
|
98 |
createOfferRequests.add(createOfferRequest);
|
| 96 |
|
99 |
|
| 97 |
}
|
100 |
}
|
| 98 |
for (CreateOfferRequest createOfferRequest : createOfferRequests) {
|
101 |
for (CreateOfferRequest createOfferRequest : createOfferRequests) {
|
| - |
|
102 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.SELLIN)) {
|
| - |
|
103 |
} else {
|
| 99 |
long amount = offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId) == null ? 0
|
104 |
long amount = offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId) == null ? 0
|
| 100 |
: offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId);
|
105 |
: offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId);
|
| 101 |
|
106 |
|
| 102 |
com.spice.profitmandi.dao.model.TargetSlab currentSlab = createOfferRequest.getTargetSlabs().stream()
|
107 |
com.spice.profitmandi.dao.model.TargetSlab currentSlab = createOfferRequest.getTargetSlabs()
|
| 103 |
.filter(x -> x.getOnwardsAmount() <= amount)
|
108 |
.stream().filter(x -> x.getOnwardsAmount() <= amount)
|
| 104 |
.max(Comparator.comparing(x -> x.getOnwardsAmount())).orElse(null);
|
109 |
.max(Comparator.comparing(x -> x.getOnwardsAmount())).orElse(null);
|
| 105 |
|
110 |
|
| 106 |
com.spice.profitmandi.dao.model.TargetSlab nextSlab = createOfferRequest.getTargetSlabs().stream()
|
111 |
com.spice.profitmandi.dao.model.TargetSlab nextSlab = createOfferRequest.getTargetSlabs().stream()
|
| 107 |
.filter(x -> x.getOnwardsAmount() > amount).min(Comparator.comparing(x -> x.getOnwardsAmount()))
|
112 |
.filter(x -> x.getOnwardsAmount() > amount)
|
| 108 |
.orElse(null);
|
113 |
.min(Comparator.comparing(x -> x.getOnwardsAmount())).orElse(null);
|
| 109 |
createOfferRequest.setNextTargetSlab(nextSlab);
|
114 |
createOfferRequest.setNextTargetSlab(nextSlab);
|
| 110 |
if(nextSlab!=null) {
|
115 |
if (nextSlab != null) {
|
| - |
|
116 |
createOfferRequest
|
| 111 |
createOfferRequest.setNextTarget(targets.get(createOfferRequest.getTargetSlabs().indexOf(nextSlab)));
|
117 |
.setNextTarget(targets.get(createOfferRequest.getTargetSlabs().indexOf(nextSlab)));
|
| 112 |
}
|
118 |
}
|
| 113 |
createOfferRequest.setCurrentTargetSlab(currentSlab);
|
119 |
createOfferRequest.setCurrentTargetSlab(currentSlab);
|
| 114 |
if(currentSlab!=null) {
|
120 |
if (currentSlab != null) {
|
| - |
|
121 |
createOfferRequest.setCurrentTarget(
|
| 115 |
createOfferRequest.setCurrentTarget(targets.get(createOfferRequest.getTargetSlabs().indexOf(currentSlab)));
|
122 |
targets.get(createOfferRequest.getTargetSlabs().indexOf(currentSlab)));
|
| - |
|
123 |
}
|
| - |
|
124 |
createOfferRequest.setEligibleSale((int) amount);
|
| 116 |
}
|
125 |
}
|
| 117 |
createOfferRequest.setEligibleSale((int) amount);
|
- |
|
| 118 |
|
126 |
|
| 119 |
}
|
127 |
}
|
| 120 |
}
|
128 |
}
|
| 121 |
return createOfferRequests;
|
129 |
return createOfferRequests;
|
| 122 |
}
|
130 |
}
|
| Line 224... |
Line 232... |
| 224 |
.filter(x -> itemRepository.containsItem(x, itemId)).collect(Collectors.toSet());
|
232 |
.filter(x -> itemRepository.containsItem(x, itemId)).collect(Collectors.toSet());
|
| 225 |
|
233 |
|
| 226 |
for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : targetSlabs) {
|
234 |
for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : targetSlabs) {
|
| 227 |
targetSlab.setItemCriteriaPayouts(targetSlab.getItemCriteriaPayouts().stream()
|
235 |
targetSlab.setItemCriteriaPayouts(targetSlab.getItemCriteriaPayouts().stream()
|
| 228 |
.filter(x -> itemCriteriaSet.contains(x.getItemCriteria())).collect(Collectors.toList()));
|
236 |
.filter(x -> itemCriteriaSet.contains(x.getItemCriteria())).collect(Collectors.toList()));
|
| 229 |
if(targetSlab.getItemCriteriaPayouts().size() >0) {
|
237 |
if (targetSlab.getItemCriteriaPayouts().size() > 0) {
|
| 230 |
found = true;
|
238 |
found = true;
|
| 231 |
}
|
239 |
}
|
| 232 |
}
|
240 |
}
|
| 233 |
if(found) {
|
241 |
if (found) {
|
| 234 |
createOfferRequests.add(createOfferRequest);
|
242 |
createOfferRequests.add(createOfferRequest);
|
| 235 |
}
|
243 |
}
|
| 236 |
}
|
244 |
}
|
| 237 |
}
|
245 |
}
|
| 238 |
|
246 |
|
| 239 |
return createOfferRequests;
|
247 |
return createOfferRequests;
|
| 240 |
}
|
248 |
}
|
| 241 |
|
249 |
|
| 242 |
}
|
250 |
}
|