| Line 9... |
Line 9... |
| 9 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
9 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
| 10 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
10 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 11 |
import com.spice.profitmandi.dao.entity.catalog.TargetSlab;
|
11 |
import com.spice.profitmandi.dao.entity.catalog.TargetSlab;
|
| 12 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
12 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 13 |
import com.spice.profitmandi.dao.entity.fofo.OfferPayout;
|
13 |
import com.spice.profitmandi.dao.entity.fofo.OfferPayout;
|
| - |
|
14 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 14 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
15 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 15 |
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
|
16 |
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
|
| 16 |
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
|
17 |
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
|
| 17 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
18 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 18 |
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
|
19 |
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
|
| Line 44... |
Line 45... |
| 44 |
import java.util.stream.Collectors;
|
45 |
import java.util.stream.Collectors;
|
| 45 |
|
46 |
|
| 46 |
@Component
|
47 |
@Component
|
| 47 |
public class OfferServiceImpl implements OfferService {
|
48 |
public class OfferServiceImpl implements OfferService {
|
| 48 |
|
49 |
|
| 49 |
private static final List<String> targets = Arrays.asList("Target 1", "Target 2", "Target 3", "Target 4",
|
50 |
private static final List<String> targets = Arrays.asList("Target 1", "Target 2", "Target 3", "Target 4",
|
| 50 |
"Target 5");
|
51 |
"Target 5");
|
| 51 |
|
52 |
|
| 52 |
@Autowired
|
53 |
@Autowired
|
| 53 |
private Gson gson;
|
54 |
private Gson gson;
|
| 54 |
|
55 |
|
| 55 |
@Autowired
|
56 |
@Autowired
|
| 56 |
private OfferRepository offerRepository;
|
57 |
private OfferRepository offerRepository;
|
| 57 |
|
58 |
|
| 58 |
@Autowired
|
59 |
@Autowired
|
| 59 |
private RetailerService retailerService;
|
60 |
private RetailerService retailerService;
|
| 60 |
|
61 |
|
| 61 |
@Autowired
|
62 |
@Autowired
|
| 62 |
OfferPayoutRepository offerPayoutRepository;
|
63 |
OfferPayoutRepository offerPayoutRepository;
|
| 63 |
|
64 |
|
| 64 |
@Autowired
|
65 |
@Autowired
|
| 65 |
private ItemCriteriaRepository itemCriteriaRepository;
|
66 |
private ItemCriteriaRepository itemCriteriaRepository;
|
| 66 |
|
67 |
|
| 67 |
@Autowired
|
68 |
@Autowired
|
| 68 |
private ItemRepository itemRepository;
|
69 |
private ItemRepository itemRepository;
|
| 69 |
|
70 |
|
| 70 |
@Autowired
|
71 |
@Autowired
|
| 71 |
private TagListingRepository tagListingRepository;
|
72 |
private TagListingRepository tagListingRepository;
|
| 72 |
|
73 |
|
| 73 |
@Autowired
|
74 |
@Autowired
|
| 74 |
private OfferTargetSlabRepository offerTargetSlabRepository;
|
75 |
private OfferTargetSlabRepository offerTargetSlabRepository;
|
| 75 |
|
76 |
|
| 76 |
@Autowired
|
77 |
@Autowired
|
| 77 |
CacheManager thirtyMinsTimeOutCacheManager;
|
78 |
CacheManager thirtyMinsTimeOutCacheManager;
|
| 78 |
|
79 |
|
| 79 |
|
80 |
|
| 80 |
private static final Logger LOGGER = LogManager.getLogger(OfferServiceImpl.class);
|
81 |
private static final Logger LOGGER = LogManager.getLogger(OfferServiceImpl.class);
|
| 81 |
|
82 |
|
| 82 |
@Override
|
83 |
@Override
|
| 83 |
public void addOfferService(CreateOfferRequest createOfferRequest) throws ProfitMandiBusinessException {
|
84 |
public void addOfferService(CreateOfferRequest createOfferRequest) throws ProfitMandiBusinessException {
|
| 84 |
LOGGER.info("createOfferRequest -- {}", createOfferRequest);
|
85 |
LOGGER.info("createOfferRequest -- {}", createOfferRequest);
|
| 85 |
this.createOffer(createOfferRequest);
|
86 |
this.createOffer(createOfferRequest);
|
| 86 |
this.createTargetSlabs(createOfferRequest);
|
87 |
this.createTargetSlabs(createOfferRequest);
|
| 87 |
}
|
88 |
}
|
| 88 |
|
89 |
|
| 89 |
private void createOffer(CreateOfferRequest createOfferRequest) {
|
90 |
private void createOffer(CreateOfferRequest createOfferRequest) {
|
| 90 |
Offer offer = new Offer();
|
91 |
Offer offer = new Offer();
|
| 91 |
offer.setName(createOfferRequest.getName());
|
92 |
offer.setName(createOfferRequest.getName());
|
| 92 |
offer.setTargetType(createOfferRequest.getTargetType());
|
93 |
offer.setTargetType(createOfferRequest.getTargetType());
|
| 93 |
offer.setBooster(createOfferRequest.isBooster());
|
94 |
offer.setBooster(createOfferRequest.isBooster());
|
| 94 |
offer.setPayoutType(createOfferRequest.getPayoutType());
|
95 |
offer.setPayoutType(createOfferRequest.getPayoutType());
|
| 95 |
offer.setSchemeType(createOfferRequest.getSchemeType());
|
96 |
offer.setSchemeType(createOfferRequest.getSchemeType());
|
| 96 |
offer.setBaseCriteia(createOfferRequest.isBaseCriteria());
|
97 |
offer.setBaseCriteia(createOfferRequest.isBaseCriteria());
|
| 97 |
offer.setEndDate(createOfferRequest.getEndDate());
|
98 |
offer.setEndDate(createOfferRequest.getEndDate());
|
| 98 |
offer.setStartDate(createOfferRequest.getStartDate());
|
99 |
offer.setStartDate(createOfferRequest.getStartDate());
|
| 99 |
offer.setBrandSharePercentage(createOfferRequest.getBrandShareTerms());
|
100 |
offer.setBrandSharePercentage(createOfferRequest.getBrandShareTerms());
|
| 100 |
offer.setSellinPercentage(createOfferRequest.getSellinPercentage());
|
101 |
offer.setSellinPercentage(createOfferRequest.getSellinPercentage());
|
| 101 |
offer.setOfferNotes(createOfferRequest.getOfferNotes());
|
102 |
offer.setOfferNotes(createOfferRequest.getOfferNotes());
|
| 102 |
offer.setActivationBrands(createOfferRequest.getActivationBrands());
|
103 |
offer.setActivationBrands(createOfferRequest.getActivationBrands());
|
| 103 |
offer.setTerms(createOfferRequest.getTerms());
|
104 |
offer.setTerms(createOfferRequest.getTerms());
|
| 104 |
offer.setItemCriteria(gson.toJson(createOfferRequest.getItemCriteria()));
|
105 |
offer.setItemCriteria(gson.toJson(createOfferRequest.getItemCriteria()));
|
| 105 |
offer.setPartnerCriteria(gson.toJson(createOfferRequest.getPartnerCriteria()));
|
106 |
offer.setPartnerCriteria(gson.toJson(createOfferRequest.getPartnerCriteria()));
|
| 106 |
offerRepository.persist(offer);
|
107 |
offerRepository.persist(offer);
|
| 107 |
createOfferRequest.setId(offer.getId());
|
108 |
createOfferRequest.setId(offer.getId());
|
| 108 |
}
|
109 |
}
|
| 109 |
|
110 |
|
| 110 |
@Override
|
111 |
@Override
|
| 111 |
public List<CreateOfferRequest> getPublishedOffers(int fofoId, YearMonth yearMonth) {
|
112 |
public List<CreateOfferRequest> getPublishedOffers(int fofoId, YearMonth yearMonth) {
|
| 112 |
List<Offer> publishedOffers = offerRepository.selectAllPublishedMapByPartner(yearMonth).get(fofoId);
|
113 |
List<Offer> publishedOffers = offerRepository.selectAllPublishedMapByPartner(yearMonth).get(fofoId);
|
| 113 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
114 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
| 114 |
if (publishedOffers != null) {
|
115 |
if (publishedOffers != null) {
|
| 115 |
for (Offer offer : publishedOffers) {
|
116 |
for (Offer offer : publishedOffers) {
|
| 116 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
117 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
| 117 |
createOfferRequests.add(createOfferRequest);
|
118 |
createOfferRequests.add(createOfferRequest);
|
| 118 |
setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
119 |
setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
| 119 |
|
120 |
|
| 120 |
}
|
121 |
}
|
| 121 |
}
|
122 |
}
|
| 122 |
return createOfferRequests;
|
123 |
return createOfferRequests;
|
| 123 |
}
|
124 |
}
|
| 124 |
|
125 |
|
| 125 |
private void setCriteriaPayoutAchieved(int fofoId, CreateOfferRequest createOfferRequest) {
|
126 |
private void setCriteriaPayoutAchieved(int fofoId, CreateOfferRequest createOfferRequest) {
|
| 126 |
Map<Integer, Long> criteriaTransactionMap = null;
|
127 |
Map<Integer, Long> criteriaTransactionMap = null;
|
| 127 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.SELLIN)) {
|
128 |
if (createOfferRequest.getSchemeType().equals(OfferSchemeType.SELLIN)) {
|
| 128 |
criteriaTransactionMap = offerRepository.getPartnerWisePurchaseSum(createOfferRequest).get(fofoId);
|
129 |
criteriaTransactionMap = offerRepository.getPartnerWisePurchaseSum(createOfferRequest).get(fofoId);
|
| 129 |
} else {
|
130 |
} else {
|
| 130 |
criteriaTransactionMap = offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId);
|
131 |
criteriaTransactionMap = offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId);
|
| 131 |
}
|
132 |
}
|
| 132 |
LOGGER.info("I am here ------- {}", createOfferRequest.getId());
|
133 |
LOGGER.info("I am here ------- {}", createOfferRequest.getId());
|
| 133 |
List<com.spice.profitmandi.dao.model.ItemCriteriaPayout> itemCriteriaPayouts = createOfferRequest
|
134 |
List<com.spice.profitmandi.dao.model.ItemCriteriaPayout> itemCriteriaPayouts = createOfferRequest
|
| 134 |
.getTargetSlabs().get(0).getItemCriteriaPayouts();
|
135 |
.getTargetSlabs().get(0).getItemCriteriaPayouts();
|
| 135 |
|
136 |
|
| 136 |
for (com.spice.profitmandi.dao.model.ItemCriteriaPayout itemCriteriaPayout : itemCriteriaPayouts) {
|
137 |
for (com.spice.profitmandi.dao.model.ItemCriteriaPayout itemCriteriaPayout : itemCriteriaPayouts) {
|
| 137 |
itemCriteriaPayout.setNextSlab(null);
|
138 |
itemCriteriaPayout.setNextSlab(null);
|
| 138 |
LOGGER.info("I am here --- {}", itemCriteriaPayout.getPayoutSlabs());
|
139 |
LOGGER.info("I am here --- {}", itemCriteriaPayout.getPayoutSlabs());
|
| 139 |
long saleAmount = 0;
|
140 |
long saleAmount = 0;
|
| 140 |
if (criteriaTransactionMap != null
|
141 |
if (criteriaTransactionMap != null
|
| 141 |
&& criteriaTransactionMap.containsKey(itemCriteriaPayout.getItemCriteria().getId())) {
|
142 |
&& criteriaTransactionMap.containsKey(itemCriteriaPayout.getItemCriteria().getId())) {
|
| 142 |
saleAmount = criteriaTransactionMap.get(itemCriteriaPayout.getItemCriteria().getId());
|
143 |
saleAmount = criteriaTransactionMap.get(itemCriteriaPayout.getItemCriteria().getId());
|
| 143 |
}
|
144 |
}
|
| 144 |
itemCriteriaPayout.setAchievedValue(saleAmount);
|
145 |
itemCriteriaPayout.setAchievedValue(saleAmount);
|
| 145 |
List<com.spice.profitmandi.service.offers.PayoutSlab> payoutSlabs = itemCriteriaPayout.getPayoutSlabs();
|
146 |
List<com.spice.profitmandi.service.offers.PayoutSlab> payoutSlabs = itemCriteriaPayout.getPayoutSlabs();
|
| 146 |
for (int i = 0; i < payoutSlabs.size(); i++) {
|
147 |
for (int i = 0; i < payoutSlabs.size(); i++) {
|
| 147 |
com.spice.profitmandi.service.offers.PayoutSlab beginSlab = payoutSlabs.get(i);
|
148 |
com.spice.profitmandi.service.offers.PayoutSlab beginSlab = payoutSlabs.get(i);
|
| 148 |
com.spice.profitmandi.service.offers.PayoutSlab endSlab = null;
|
149 |
com.spice.profitmandi.service.offers.PayoutSlab endSlab = null;
|
| 149 |
if (payoutSlabs.size() - 1 > i) {
|
150 |
if (payoutSlabs.size() - 1 > i) {
|
| 150 |
endSlab = payoutSlabs.get(i + 1);
|
151 |
endSlab = payoutSlabs.get(i + 1);
|
| 151 |
}
|
152 |
}
|
| 152 |
if (beginSlab.getOnwardsAmount() > saleAmount) {
|
153 |
if (beginSlab.getOnwardsAmount() > saleAmount) {
|
| 153 |
itemCriteriaPayout.setShortValue(beginSlab.getOnwardsAmount() - saleAmount);
|
154 |
itemCriteriaPayout.setShortValue(beginSlab.getOnwardsAmount() - saleAmount);
|
| 154 |
itemCriteriaPayout.setNextSlab(beginSlab);
|
155 |
itemCriteriaPayout.setNextSlab(beginSlab);
|
| 155 |
LOGGER.info("I am here");
|
156 |
LOGGER.info("I am here");
|
| 156 |
break;
|
157 |
break;
|
| 157 |
}
|
158 |
}
|
| 158 |
if (endSlab != null) {
|
159 |
if (endSlab != null) {
|
| 159 |
if (beginSlab.getOnwardsAmount() <= saleAmount && endSlab.getOnwardsAmount() > saleAmount) {
|
160 |
if (beginSlab.getOnwardsAmount() <= saleAmount && endSlab.getOnwardsAmount() > saleAmount) {
|
| 160 |
itemCriteriaPayout.setCurrentSlab(beginSlab);
|
161 |
itemCriteriaPayout.setCurrentSlab(beginSlab);
|
| 161 |
beginSlab.setSelected(true);
|
162 |
beginSlab.setSelected(true);
|
| 162 |
itemCriteriaPayout.setNextSlab(endSlab);
|
163 |
itemCriteriaPayout.setNextSlab(endSlab);
|
| 163 |
itemCriteriaPayout.setShortValue(endSlab.getOnwardsAmount() - saleAmount);
|
164 |
itemCriteriaPayout.setShortValue(endSlab.getOnwardsAmount() - saleAmount);
|
| 164 |
LOGGER.info("I am here");
|
165 |
LOGGER.info("I am here");
|
| 165 |
break;
|
166 |
break;
|
| 166 |
}
|
167 |
}
|
| 167 |
// Last loop
|
168 |
// Last loop
|
| 168 |
} else {
|
169 |
} else {
|
| 169 |
beginSlab.setSelected(true);
|
170 |
beginSlab.setSelected(true);
|
| 170 |
itemCriteriaPayout.setCurrentSlab(beginSlab);
|
171 |
itemCriteriaPayout.setCurrentSlab(beginSlab);
|
| 171 |
LOGGER.info("I am here");
|
172 |
LOGGER.info("I am here");
|
| 172 |
}
|
173 |
}
|
| 173 |
}
|
174 |
}
|
| 174 |
LOGGER.info("I am here --- {}", itemCriteriaPayout);
|
175 |
LOGGER.info("I am here --- {}", itemCriteriaPayout);
|
| 175 |
}
|
176 |
}
|
| 176 |
|
177 |
|
| 177 |
}
|
178 |
}
|
| 178 |
|
179 |
|
| 179 |
@Override
|
180 |
@Override
|
| 180 |
@Cacheable(value = "allOffers", cacheManager = "thirtyMinsTimeOutCacheManager")
|
181 |
@Cacheable(value = "allOffers", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 181 |
public Map<Integer, CreateOfferRequest> getAllOffers(YearMonth yearMonth) {
|
182 |
public Map<Integer, CreateOfferRequest> getAllOffers(YearMonth yearMonth) {
|
| 182 |
List<Offer> allOffers = offerRepository.selectAll(yearMonth, false);
|
183 |
List<Offer> allOffers = offerRepository.selectAll(yearMonth, false);
|
| 183 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
184 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
| 184 |
for (Offer offer : allOffers) {
|
185 |
for (Offer offer : allOffers) {
|
| 185 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
186 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
| 186 |
createOfferRequests.add(createOfferRequest);
|
187 |
createOfferRequests.add(createOfferRequest);
|
| 187 |
}
|
188 |
}
|
| 188 |
return createOfferRequests.stream().collect(Collectors.toMap(CreateOfferRequest::getId, x -> x));
|
189 |
return createOfferRequests.stream().collect(Collectors.toMap(CreateOfferRequest::getId, x -> x));
|
| 189 |
}
|
190 |
}
|
| 190 |
|
191 |
|
| 191 |
@Override
|
192 |
@Override
|
| 192 |
@Cacheable(value = "partnerOffers", cacheManager = "thirtyMinsTimeOutCacheManager")
|
193 |
@Cacheable(value = "partnerOffers", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 193 |
public CreateOfferRequest getOffer(int fofoId, int offerId) {
|
194 |
public CreateOfferRequest getOffer(int fofoId, int offerId) {
|
| 194 |
Offer offer = offerRepository.selectById(offerId);
|
195 |
Offer offer = offerRepository.selectById(offerId);
|
| 195 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
196 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
| 196 |
if (fofoId > 0) {
|
197 |
if (fofoId > 0) {
|
| 197 |
this.setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
198 |
this.setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
| 198 |
}
|
199 |
}
|
| 199 |
|
200 |
|
| 200 |
return createOfferRequest;
|
201 |
return createOfferRequest;
|
| 201 |
}
|
202 |
}
|
| 202 |
|
203 |
|
| 203 |
@Override
|
204 |
@Override
|
| 204 |
public CreateOfferRequest getCreateOfferRequest(Offer fromOffer) {
|
205 |
public CreateOfferRequest getCreateOfferRequest(Offer fromOffer) {
|
| 205 |
CreateOfferRequest createOfferRequest = new CreateOfferRequest();
|
206 |
CreateOfferRequest createOfferRequest = new CreateOfferRequest();
|
| 206 |
createOfferRequest.setName(fromOffer.getName());
|
207 |
createOfferRequest.setName(fromOffer.getName());
|
| 207 |
createOfferRequest.setTargetType(fromOffer.getTargetType());
|
208 |
createOfferRequest.setTargetType(fromOffer.getTargetType());
|
| 208 |
createOfferRequest.setPayoutType(fromOffer.getPayoutType());
|
209 |
createOfferRequest.setPayoutType(fromOffer.getPayoutType());
|
| 209 |
createOfferRequest.setSchemeType(fromOffer.getSchemeType());
|
210 |
createOfferRequest.setSchemeType(fromOffer.getSchemeType());
|
| 210 |
createOfferRequest.setActivationBrands(fromOffer.getActivationBrands());
|
211 |
createOfferRequest.setActivationBrands(fromOffer.getActivationBrands());
|
| 211 |
createOfferRequest.setEndDate(fromOffer.getEndDate());
|
212 |
createOfferRequest.setEndDate(fromOffer.getEndDate());
|
| 212 |
createOfferRequest.setProcessTimestamp(fromOffer.getProcessedTimestamp());
|
213 |
createOfferRequest.setProcessTimestamp(fromOffer.getProcessedTimestamp());
|
| 213 |
createOfferRequest.setStartDate(fromOffer.getStartDate());
|
214 |
createOfferRequest.setStartDate(fromOffer.getStartDate());
|
| 214 |
createOfferRequest.setBooster(fromOffer.isBooster());
|
215 |
createOfferRequest.setBooster(fromOffer.isBooster());
|
| 215 |
createOfferRequest.setActive(fromOffer.isActive());
|
216 |
createOfferRequest.setActive(fromOffer.isActive());
|
| 216 |
createOfferRequest.setSellinPercentage(fromOffer.getSellinPercentage());
|
217 |
createOfferRequest.setSellinPercentage(fromOffer.getSellinPercentage());
|
| 217 |
createOfferRequest.setBrandShareTerms(fromOffer.getBrandSharePercentage());
|
218 |
createOfferRequest.setBrandShareTerms(fromOffer.getBrandSharePercentage());
|
| 218 |
createOfferRequest.setOfferNotes(fromOffer.getOfferNotes());
|
219 |
createOfferRequest.setOfferNotes(fromOffer.getOfferNotes());
|
| 219 |
createOfferRequest.setTerms(fromOffer.getTerms());
|
220 |
createOfferRequest.setTerms(fromOffer.getTerms());
|
| 220 |
createOfferRequest.setBaseCriteria(fromOffer.isBaseCriteia());
|
221 |
createOfferRequest.setBaseCriteria(fromOffer.isBaseCriteia());
|
| 221 |
createOfferRequest.setItemCriteria(
|
222 |
createOfferRequest.setItemCriteria(
|
| 222 |
gson.fromJson(fromOffer.getItemCriteria(), com.spice.profitmandi.service.offers.ItemCriteria.class));
|
223 |
gson.fromJson(fromOffer.getItemCriteria(), com.spice.profitmandi.service.offers.ItemCriteria.class));
|
| 223 |
createOfferRequest.setPartnerCriteria(gson.fromJson(fromOffer.getPartnerCriteria(), PartnerCriteria.class));
|
224 |
createOfferRequest.setPartnerCriteria(gson.fromJson(fromOffer.getPartnerCriteria(), PartnerCriteria.class));
|
| 224 |
createOfferRequest.setId(fromOffer.getId());
|
225 |
createOfferRequest.setId(fromOffer.getId());
|
| 225 |
createOfferRequest.setCreatedOn(fromOffer.getCreatedTimestamp());
|
226 |
createOfferRequest.setCreatedOn(fromOffer.getCreatedTimestamp());
|
| 226 |
createOfferRequest.setItemCriteriaString(
|
227 |
createOfferRequest.setItemCriteriaString(
|
| 227 |
itemCriteriaRepository.getItemCriteriaDescription(createOfferRequest.getItemCriteria()));
|
228 |
itemCriteriaRepository.getItemCriteriaDescription(createOfferRequest.getItemCriteria()));
|
| 228 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = offerTargetSlabRepository
|
229 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = offerTargetSlabRepository
|
| 229 |
.getByOfferId(fromOffer.getId());
|
230 |
.getByOfferId(fromOffer.getId());
|
| 230 |
createOfferRequest.setPartnerCriteriaString(
|
231 |
createOfferRequest.setPartnerCriteriaString(
|
| 231 |
retailerService.getPartnerCriteriaString(createOfferRequest.getPartnerCriteria()));
|
232 |
retailerService.getPartnerCriteriaString(createOfferRequest.getPartnerCriteria()));
|
| 232 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
233 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
| 233 |
for (com.spice.profitmandi.dao.model.ItemCriteriaPayout itemCriteriaPayout : createOfferRequest.getTargetSlabs()
|
234 |
for (com.spice.profitmandi.dao.model.ItemCriteriaPayout itemCriteriaPayout : createOfferRequest.getTargetSlabs()
|
| 234 |
.get(0).getItemCriteriaPayouts()) {
|
235 |
.get(0).getItemCriteriaPayouts()) {
|
| 235 |
itemCriteriaPayout.setNextSlab(itemCriteriaPayout.getPayoutSlabs().get(0));
|
236 |
itemCriteriaPayout.setNextSlab(itemCriteriaPayout.getPayoutSlabs().get(0));
|
| 236 |
}
|
237 |
}
|
| 237 |
return createOfferRequest;
|
238 |
return createOfferRequest;
|
| 238 |
|
239 |
|
| 239 |
}
|
240 |
}
|
| 240 |
|
241 |
|
| 241 |
@Autowired
|
242 |
@Autowired
|
| 242 |
private WalletService walletService;
|
243 |
private WalletService walletService;
|
| 243 |
|
244 |
|
| 244 |
@Override
|
245 |
@Override
|
| 245 |
public void reverseAdditionalSelloutSchemes(int fofoId, List<InventoryItem> inventoryItems) throws ProfitMandiBusinessException {
|
246 |
public void reverseAdditionalSelloutSchemes(int fofoId, List<InventoryItem> inventoryItems) throws ProfitMandiBusinessException {
|
| 246 |
List<OfferPayout> offerPayouts = new ArrayList<>();
|
247 |
List<OfferPayout> offerPayouts = new ArrayList<>();
|
| 247 |
//As of now we are not handling non-serialised items
|
248 |
//As of now we are not handling non-serialised items
|
| 248 |
inventoryItems = inventoryItems.stream().filter(x -> x.getSerialNumber() != null).collect(Collectors.toList());
|
249 |
inventoryItems = inventoryItems.stream().filter(x -> x.getSerialNumber() != null).collect(Collectors.toList());
|
| 249 |
for (InventoryItem inventoryItem : inventoryItems) {
|
250 |
for (InventoryItem inventoryItem : inventoryItems) {
|
| 250 |
offerPayouts.addAll(offerPayoutRepository.selectAllBySerialNumber(inventoryItem.getFofoId(), inventoryItem.getSerialNumber())
|
251 |
offerPayouts.addAll(offerPayoutRepository.selectAllBySerialNumber(inventoryItem.getFofoId(), inventoryItem.getSerialNumber())
|
| 251 |
.stream()
|
252 |
.stream()
|
| 252 |
.filter(x -> x.getRejectTimestamp() == null)
|
253 |
.filter(x -> x.getRejectTimestamp() == null)
|
| 253 |
.collect(Collectors.toList()));
|
254 |
.collect(Collectors.toList()));
|
| 254 |
}
|
255 |
}
|
| 255 |
for (OfferPayout offerPayout : offerPayouts) {
|
256 |
for (OfferPayout offerPayout : offerPayouts) {
|
| 256 |
offerPayout.setStatus(SchemePayoutStatus.REJECTED);
|
257 |
offerPayout.setStatus(SchemePayoutStatus.REJECTED);
|
| 257 |
offerPayout.setRejectTimestamp(LocalDateTime.now());
|
258 |
offerPayout.setRejectTimestamp(LocalDateTime.now());
|
| 258 |
}
|
259 |
}
|
| 259 |
Map<Long, Double> offerPayoutAmountMap = offerPayouts.stream().collect(Collectors.groupingBy(x -> x.getOfferId(), Collectors.summingDouble(x -> x.getAmount())));
|
260 |
Map<Long, Double> offerPayoutAmountMap = offerPayouts.stream().collect(Collectors.groupingBy(x -> x.getOfferId(), Collectors.summingDouble(x -> x.getAmount())));
|
| 260 |
for (Map.Entry<Long, Double> offerPayoutEntry : offerPayoutAmountMap.entrySet()) {
|
261 |
for (Map.Entry<Long, Double> offerPayoutEntry : offerPayoutAmountMap.entrySet()) {
|
| 261 |
walletService.rollbackAmountFromWallet(fofoId, offerPayoutEntry.getValue().floatValue(), offerPayoutEntry.getKey().intValue(),
|
262 |
List<UserWalletHistory> histories = walletService.getAllByReference(fofoId, offerPayoutEntry.getKey().intValue(), WalletReferenceType.ADDITIONAL_SCHEME);
|
| 262 |
WalletReferenceType.ADDITIONAL_SCHEME, "Imeis for corresponding schemes are returned", LocalDateTime.now());
|
263 |
if (histories.size() > 0) {
|
| 263 |
}
|
264 |
|
| 264 |
}
|
265 |
walletService.rollbackAmountFromWallet(fofoId, offerPayoutEntry.getValue().floatValue(), offerPayoutEntry.getKey().intValue(),
|
| 265 |
|
266 |
WalletReferenceType.ADDITIONAL_SCHEME, "Imeis for corresponding schemes are returned", LocalDateTime.now());
|
| 266 |
private void createTargetSlabs(CreateOfferRequest createOfferRequest) throws ProfitMandiBusinessException {
|
267 |
}
|
| 267 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = createOfferRequest.getTargetSlabs().stream()
|
268 |
}
|
| 268 |
.filter(x -> x.validate()).collect(Collectors.toList());
|
269 |
}
|
| 269 |
if (targetSlabs.size() >= 0) {
|
270 |
|
| 270 |
Collections.sort(targetSlabs);
|
271 |
private void createTargetSlabs(CreateOfferRequest createOfferRequest) throws ProfitMandiBusinessException {
|
| 271 |
for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : targetSlabs) {
|
272 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = createOfferRequest.getTargetSlabs().stream()
|
| 272 |
if (targetSlab.validate()) {
|
273 |
.filter(x -> x.validate()).collect(Collectors.toList());
|
| 273 |
List<ItemCriteriaPayout> itemCriteriaPayouts = targetSlab.getItemCriteriaPayouts();
|
274 |
if (targetSlabs.size() >= 0) {
|
| 274 |
for (ItemCriteriaPayout itemCriteriaPayout : itemCriteriaPayouts) {
|
275 |
Collections.sort(targetSlabs);
|
| 275 |
ItemCriteria itemCriteria = itemCriteriaRepository.selectById(itemCriteriaPayout.getItemCriteria().getId());
|
276 |
for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : targetSlabs) {
|
| 276 |
if (itemCriteriaPayout.getItemCriteria().getId() > 0) {
|
277 |
if (targetSlab.validate()) {
|
| 277 |
itemCriteriaPayout.getItemCriteria().setId(0);
|
278 |
List<ItemCriteriaPayout> itemCriteriaPayouts = targetSlab.getItemCriteriaPayouts();
|
| 278 |
} else {
|
279 |
for (ItemCriteriaPayout itemCriteriaPayout : itemCriteriaPayouts) {
|
| 279 |
|
280 |
ItemCriteria itemCriteria = itemCriteriaRepository.selectById(itemCriteriaPayout.getItemCriteria().getId());
|
| 280 |
String itemCriteriaJson = gson.toJson(itemCriteriaPayout.getItemCriteria());
|
281 |
if (itemCriteriaPayout.getItemCriteria().getId() > 0) {
|
| 281 |
itemCriteria = itemCriteriaRepository.selectByCriteria(itemCriteriaJson);
|
282 |
itemCriteriaPayout.getItemCriteria().setId(0);
|
| 282 |
// ItemCriteria Only once
|
283 |
} else {
|
| 283 |
if (itemCriteria == null) {
|
284 |
|
| 284 |
itemCriteria = new ItemCriteria();
|
285 |
String itemCriteriaJson = gson.toJson(itemCriteriaPayout.getItemCriteria());
|
| 285 |
itemCriteria.setCriteria(gson.toJson(itemCriteriaPayout.getItemCriteria()));
|
286 |
itemCriteria = itemCriteriaRepository.selectByCriteria(itemCriteriaJson);
|
| 286 |
itemCriteriaRepository.persist(itemCriteria);
|
287 |
// ItemCriteria Only once
|
| 287 |
}
|
288 |
if (itemCriteria == null) {
|
| 288 |
}
|
289 |
itemCriteria = new ItemCriteria();
|
| 289 |
for (PayoutSlab payoutSlab : itemCriteriaPayout.getPayoutSlabs()) {
|
290 |
itemCriteria.setCriteria(gson.toJson(itemCriteriaPayout.getItemCriteria()));
|
| 290 |
TargetSlab targetSlab1 = new TargetSlab();
|
291 |
itemCriteriaRepository.persist(itemCriteria);
|
| 291 |
targetSlab1.setOfferId(createOfferRequest.getId());
|
292 |
}
|
| 292 |
targetSlab1.setOnwardsTarget(targetSlab.getOnwardsAmount());
|
293 |
}
|
| 293 |
targetSlab1.setTargetDescription(targetSlab.getTargetDescription());
|
294 |
for (PayoutSlab payoutSlab : itemCriteriaPayout.getPayoutSlabs()) {
|
| 294 |
targetSlab1.setPayoutTarget(payoutSlab.getOnwardsAmount());
|
295 |
TargetSlab targetSlab1 = new TargetSlab();
|
| 295 |
targetSlab1.setPayoutValue(payoutSlab.getPayoutAmount());
|
296 |
targetSlab1.setOfferId(createOfferRequest.getId());
|
| 296 |
targetSlab1.setItemCriteriaId(itemCriteria.getId());
|
297 |
targetSlab1.setOnwardsTarget(targetSlab.getOnwardsAmount());
|
| 297 |
targetSlab1.setAmountType(itemCriteriaPayout.getAmountType());
|
298 |
targetSlab1.setTargetDescription(targetSlab.getTargetDescription());
|
| 298 |
offerTargetSlabRepository.persist(targetSlab1);
|
299 |
targetSlab1.setPayoutTarget(payoutSlab.getOnwardsAmount());
|
| 299 |
}
|
300 |
targetSlab1.setPayoutValue(payoutSlab.getPayoutAmount());
|
| 300 |
}
|
301 |
targetSlab1.setItemCriteriaId(itemCriteria.getId());
|
| 301 |
}
|
302 |
targetSlab1.setAmountType(itemCriteriaPayout.getAmountType());
|
| 302 |
}
|
303 |
offerTargetSlabRepository.persist(targetSlab1);
|
| 303 |
|
304 |
}
|
| 304 |
} else {
|
305 |
}
|
| 305 |
throw new ProfitMandiBusinessException("Invalid Target Slabs", "Invalid Target", "");
|
306 |
}
|
| 306 |
}
|
307 |
}
|
| 307 |
|
308 |
|
| 308 |
}
|
309 |
} else {
|
| 309 |
|
310 |
throw new ProfitMandiBusinessException("Invalid Target Slabs", "Invalid Target", "");
|
| 310 |
@Override
|
311 |
}
|
| 311 |
public List<CreateOfferRequest> getPublishedOffers(LocalDate date, int fofoId, int catalogId) {
|
312 |
|
| 312 |
List<Offer> publishedOffers = offerRepository.selectAllPublishedMapByPartner(YearMonth.from(date)).get(fofoId);
|
313 |
}
|
| 313 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
314 |
|
| 314 |
if (publishedOffers != null) {
|
315 |
@Override
|
| 315 |
for (Offer offer : publishedOffers) {
|
316 |
public List<CreateOfferRequest> getPublishedOffers(LocalDate date, int fofoId, int catalogId) {
|
| 316 |
boolean found = false;
|
317 |
List<Offer> publishedOffers = offerRepository.selectAllPublishedMapByPartner(YearMonth.from(date)).get(fofoId);
|
| 317 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = offerTargetSlabRepository
|
318 |
List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
|
| 318 |
.getByOfferId(offer.getId());
|
319 |
if (publishedOffers != null) {
|
| 319 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
320 |
for (Offer offer : publishedOffers) {
|
| 320 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
321 |
boolean found = false;
|
| 321 |
this.setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
322 |
List<com.spice.profitmandi.dao.model.TargetSlab> targetSlabs = offerTargetSlabRepository
|
| 322 |
Set<com.spice.profitmandi.service.offers.ItemCriteria> itemCriteriaSet = targetSlabs.stream()
|
323 |
.getByOfferId(offer.getId());
|
| 323 |
.flatMap(x -> x.getItemCriteriaPayouts().stream()).map(x -> x.getItemCriteria()).distinct()
|
324 |
CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
|
| 324 |
.filter(x -> itemRepository.containsModel(x, catalogId)).collect(Collectors.toSet());
|
325 |
createOfferRequest.setTargetSlabs(targetSlabs);
|
| 325 |
|
326 |
this.setCriteriaPayoutAchieved(fofoId, createOfferRequest);
|
| 326 |
for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : targetSlabs) {
|
327 |
Set<com.spice.profitmandi.service.offers.ItemCriteria> itemCriteriaSet = targetSlabs.stream()
|
| 327 |
targetSlab.setItemCriteriaPayouts(targetSlab.getItemCriteriaPayouts().stream()
|
328 |
.flatMap(x -> x.getItemCriteriaPayouts().stream()).map(x -> x.getItemCriteria()).distinct()
|
| 328 |
.filter(x -> itemCriteriaSet.contains(x.getItemCriteria())).collect(Collectors.toList()));
|
329 |
.filter(x -> itemRepository.containsModel(x, catalogId)).collect(Collectors.toSet());
|
| 329 |
if (targetSlab.getItemCriteriaPayouts().size() > 0) {
|
330 |
|
| 330 |
found = true;
|
331 |
for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : targetSlabs) {
|
| 331 |
}
|
332 |
targetSlab.setItemCriteriaPayouts(targetSlab.getItemCriteriaPayouts().stream()
|
| 332 |
}
|
333 |
.filter(x -> itemCriteriaSet.contains(x.getItemCriteria())).collect(Collectors.toList()));
|
| 333 |
if (found) {
|
334 |
if (targetSlab.getItemCriteriaPayouts().size() > 0) {
|
| 334 |
createOfferRequests.add(createOfferRequest);
|
335 |
found = true;
|
| 335 |
}
|
336 |
}
|
| 336 |
}
|
337 |
}
|
| 337 |
}
|
338 |
if (found) {
|
| 338 |
|
339 |
createOfferRequests.add(createOfferRequest);
|
| 339 |
return createOfferRequests;
|
340 |
}
|
| 340 |
}
|
341 |
}
|
| 341 |
|
342 |
}
|
| 342 |
@Override
|
343 |
|
| 343 |
public void createOffers(InputStream fileInputStream) throws Exception {
|
344 |
return createOfferRequests;
|
| 344 |
Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap = this.parseFromExcel(fileInputStream);
|
345 |
}
|
| 345 |
for (Map.Entry<CreateOfferRequest, List<PartnerTargetModel>> partnerTargetEntry : offerPartnerTargetMap
|
346 |
|
| 346 |
.entrySet()) {
|
347 |
@Override
|
| 347 |
CreateOfferRequest createOfferRequest = partnerTargetEntry.getKey();
|
348 |
public void createOffers(InputStream fileInputStream) throws Exception {
|
| 348 |
Map<List<Integer>, List<Integer>> targetPartnerMap = partnerTargetEntry.getValue().stream()
|
349 |
Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap = this.parseFromExcel(fileInputStream);
|
| 349 |
.collect(Collectors.groupingBy(PartnerTargetModel::getTargets,
|
350 |
for (Map.Entry<CreateOfferRequest, List<PartnerTargetModel>> partnerTargetEntry : offerPartnerTargetMap
|
| 350 |
Collectors.mapping(PartnerTargetModel::getFofoId, Collectors.toList())));
|
351 |
.entrySet()) {
|
| 351 |
for (Map.Entry<List<Integer>, List<Integer>> targetPartnersEntry : targetPartnerMap.entrySet()) {
|
352 |
CreateOfferRequest createOfferRequest = partnerTargetEntry.getKey();
|
| 352 |
List<Integer> fofoIds = createOfferRequest.getPartnerCriteria().getFofoIds();
|
353 |
Map<List<Integer>, List<Integer>> targetPartnerMap = partnerTargetEntry.getValue().stream()
|
| 353 |
List<Integer> filterFofoIds = targetPartnersEntry.getValue().stream().filter(x -> !fofoIds.contains(x))
|
354 |
.collect(Collectors.groupingBy(PartnerTargetModel::getTargets,
|
| 354 |
.collect(Collectors.toList());
|
355 |
Collectors.mapping(PartnerTargetModel::getFofoId, Collectors.toList())));
|
| 355 |
LOGGER.info("FofoIds {}", filterFofoIds);
|
356 |
for (Map.Entry<List<Integer>, List<Integer>> targetPartnersEntry : targetPartnerMap.entrySet()) {
|
| 356 |
List<Integer> targets = targetPartnersEntry.getKey();
|
357 |
List<Integer> fofoIds = createOfferRequest.getPartnerCriteria().getFofoIds();
|
| 357 |
LOGGER.info("Targets {}", targets);
|
358 |
List<Integer> filterFofoIds = targetPartnersEntry.getValue().stream().filter(x -> !fofoIds.contains(x))
|
| 358 |
|
359 |
.collect(Collectors.toList());
|
| 359 |
createOfferRequest.getPartnerCriteria().setFofoIds(filterFofoIds);
|
360 |
LOGGER.info("FofoIds {}", filterFofoIds);
|
| 360 |
int counter = 0;
|
361 |
List<Integer> targets = targetPartnersEntry.getKey();
|
| 361 |
List<ItemCriteriaPayout> itemCriteriaPayouts = createOfferRequest.getTargetSlabs().get(0)
|
362 |
LOGGER.info("Targets {}", targets);
|
| 362 |
.getItemCriteriaPayouts();
|
363 |
|
| 363 |
List<PayoutSlab> payoutSlabs = itemCriteriaPayouts.stream().flatMap(x -> x.getPayoutSlabs().stream()).collect(Collectors.toList());
|
364 |
createOfferRequest.getPartnerCriteria().setFofoIds(filterFofoIds);
|
| 364 |
for (PayoutSlab payoutSlab : payoutSlabs) {
|
365 |
int counter = 0;
|
| 365 |
payoutSlab.setOnwardsAmount(targets.get(counter));
|
366 |
List<ItemCriteriaPayout> itemCriteriaPayouts = createOfferRequest.getTargetSlabs().get(0)
|
| 366 |
counter++;
|
367 |
.getItemCriteriaPayouts();
|
| 367 |
}
|
368 |
List<PayoutSlab> payoutSlabs = itemCriteriaPayouts.stream().flatMap(x -> x.getPayoutSlabs().stream()).collect(Collectors.toList());
|
| 368 |
this.addOfferService(createOfferRequest);
|
369 |
for (PayoutSlab payoutSlab : payoutSlabs) {
|
| 369 |
}
|
370 |
payoutSlab.setOnwardsAmount(targets.get(counter));
|
| 370 |
}
|
371 |
counter++;
|
| 371 |
thirtyMinsTimeOutCacheManager.getCache("allOffers").evict(YearMonth.now());
|
372 |
}
|
| 372 |
|
373 |
this.addOfferService(createOfferRequest);
|
| 373 |
}
|
374 |
}
|
| 374 |
|
375 |
}
|
| 375 |
private Map<CreateOfferRequest, List<PartnerTargetModel>> parseFromExcel(InputStream inputStream)
|
376 |
thirtyMinsTimeOutCacheManager.getCache("allOffers").evict(YearMonth.now());
|
| 376 |
throws ProfitMandiBusinessException {
|
377 |
|
| 377 |
|
378 |
}
|
| 378 |
Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap = new HashMap<>();
|
379 |
|
| 379 |
XSSFWorkbook myWorkBook = null;
|
380 |
private Map<CreateOfferRequest, List<PartnerTargetModel>> parseFromExcel(InputStream inputStream)
|
| 380 |
try {
|
381 |
throws ProfitMandiBusinessException {
|
| 381 |
myWorkBook = new XSSFWorkbook(inputStream);
|
382 |
|
| 382 |
myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
383 |
Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap = new HashMap<>();
|
| 383 |
for (int i = 0; i < myWorkBook.getNumberOfSheets(); i++) {
|
384 |
XSSFWorkbook myWorkBook = null;
|
| 384 |
|
385 |
try {
|
| 385 |
XSSFSheet mySheet = myWorkBook.getSheetAt(i);
|
386 |
myWorkBook = new XSSFWorkbook(inputStream);
|
| 386 |
int offerId = Integer.parseInt(mySheet.getSheetName());
|
387 |
myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
| 387 |
CreateOfferRequest existingOffer = this.getOffer(0, offerId);
|
388 |
for (int i = 0; i < myWorkBook.getNumberOfSheets(); i++) {
|
| 388 |
List<PartnerTargetModel> partnerTargetModels = new ArrayList<>();
|
389 |
|
| 389 |
offerPartnerTargetMap.put(existingOffer, partnerTargetModels);
|
390 |
XSSFSheet mySheet = myWorkBook.getSheetAt(i);
|
| 390 |
this.printIterator(mySheet);
|
391 |
int offerId = Integer.parseInt(mySheet.getSheetName());
|
| 391 |
LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
|
392 |
CreateOfferRequest existingOffer = this.getOffer(0, offerId);
|
| 392 |
for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
|
393 |
List<PartnerTargetModel> partnerTargetModels = new ArrayList<>();
|
| 393 |
XSSFRow row = mySheet.getRow(rowNumber);
|
394 |
offerPartnerTargetMap.put(existingOffer, partnerTargetModels);
|
| 394 |
LOGGER.info("row {}", row);
|
395 |
this.printIterator(mySheet);
|
| 395 |
PartnerTargetModel partnerTargetModel = new PartnerTargetModel();
|
396 |
LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
|
| 396 |
|
397 |
for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
|
| 397 |
if (row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC) {
|
398 |
XSSFRow row = mySheet.getRow(rowNumber);
|
| 398 |
partnerTargetModel.setFofoId((int) row.getCell(0).getNumericCellValue());
|
399 |
LOGGER.info("row {}", row);
|
| 399 |
} else {
|
400 |
PartnerTargetModel partnerTargetModel = new PartnerTargetModel();
|
| 400 |
ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
|
401 |
|
| 401 |
"FOFO ID", row.getCell(0).toString(), "TGLSTNG_VE_1010");
|
402 |
if (row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC) {
|
| 402 |
LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
|
403 |
partnerTargetModel.setFofoId((int) row.getCell(0).getNumericCellValue());
|
| 403 |
throw profitMandiBusinessException;
|
404 |
} else {
|
| 404 |
}
|
405 |
ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
|
| 405 |
List<Integer> targets = new ArrayList<>();
|
406 |
"FOFO ID", row.getCell(0).toString(), "TGLSTNG_VE_1010");
|
| 406 |
long targetsSize = existingOffer.getTargetSlabs().get(0).getItemCriteriaPayouts().stream().flatMap(x -> x.getPayoutSlabs().stream()).collect(Collectors.counting());
|
407 |
LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
|
| 407 |
for (int cellNumber = 1; cellNumber <= targetsSize; cellNumber++) {
|
408 |
throw profitMandiBusinessException;
|
| 408 |
if (row.getCell(cellNumber) != null
|
409 |
}
|
| 409 |
&& row.getCell(cellNumber).getCellTypeEnum() == CellType.NUMERIC) {
|
410 |
List<Integer> targets = new ArrayList<>();
|
| 410 |
targets.add((int) row.getCell(cellNumber).getNumericCellValue());
|
411 |
long targetsSize = existingOffer.getTargetSlabs().get(0).getItemCriteriaPayouts().stream().flatMap(x -> x.getPayoutSlabs().stream()).collect(Collectors.counting());
|
| 411 |
} else {
|
412 |
for (int cellNumber = 1; cellNumber <= targetsSize; cellNumber++) {
|
| 412 |
ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
|
413 |
if (row.getCell(cellNumber) != null
|
| 413 |
"Target Column issue at " + rowNumber + ", " + cellNumber, row.getCell(cellNumber),
|
414 |
&& row.getCell(cellNumber).getCellTypeEnum() == CellType.NUMERIC) {
|
| 414 |
"Invalid target");
|
415 |
targets.add((int) row.getCell(cellNumber).getNumericCellValue());
|
| 415 |
LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
|
416 |
} else {
|
| 416 |
throw profitMandiBusinessException;
|
417 |
ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
|
| 417 |
}
|
418 |
"Target Column issue at " + rowNumber + ", " + cellNumber, row.getCell(cellNumber),
|
| 418 |
}
|
419 |
"Invalid target");
|
| 419 |
partnerTargetModel.setTargets(targets);
|
420 |
LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
|
| 420 |
partnerTargetModels.add(partnerTargetModel);
|
421 |
throw profitMandiBusinessException;
|
| 421 |
}
|
422 |
}
|
| 422 |
}
|
423 |
}
|
| 423 |
myWorkBook.close();
|
424 |
partnerTargetModel.setTargets(targets);
|
| 424 |
} catch (ProfitMandiBusinessException pbse) {
|
425 |
partnerTargetModels.add(partnerTargetModel);
|
| 425 |
throw pbse;
|
426 |
}
|
| 426 |
} catch (IOException ioException) {
|
427 |
}
|
| 427 |
ioException.printStackTrace();
|
428 |
myWorkBook.close();
|
| 428 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(),
|
429 |
} catch (ProfitMandiBusinessException pbse) {
|
| 429 |
"EXL_VE_1000");
|
430 |
throw pbse;
|
| 430 |
} finally {
|
431 |
} catch (IOException ioException) {
|
| 431 |
if (myWorkBook != null) {
|
432 |
ioException.printStackTrace();
|
| 432 |
try {
|
433 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(),
|
| 433 |
myWorkBook.close();
|
434 |
"EXL_VE_1000");
|
| 434 |
} catch (IOException e) {
|
435 |
} finally {
|
| 435 |
// TODO Auto-generated catch block
|
436 |
if (myWorkBook != null) {
|
| 436 |
e.printStackTrace();
|
437 |
try {
|
| 437 |
}
|
438 |
myWorkBook.close();
|
| 438 |
}
|
439 |
} catch (IOException e) {
|
| 439 |
}
|
440 |
// TODO Auto-generated catch block
|
| 440 |
LOGGER.info("offerPartnerTargetMap {}", offerPartnerTargetMap);
|
441 |
e.printStackTrace();
|
| 441 |
return offerPartnerTargetMap;
|
442 |
}
|
| 442 |
}
|
443 |
}
|
| 443 |
|
444 |
}
|
| 444 |
private void printIterator(XSSFSheet sheet) {
|
445 |
LOGGER.info("offerPartnerTargetMap {}", offerPartnerTargetMap);
|
| 445 |
Iterator<Row> rowIterator = sheet.iterator();
|
446 |
return offerPartnerTargetMap;
|
| 446 |
while (rowIterator.hasNext()) {
|
447 |
}
|
| 447 |
Row row = rowIterator.next();
|
448 |
|
| 448 |
// For each row, iterate through all the columns
|
449 |
private void printIterator(XSSFSheet sheet) {
|
| 449 |
Iterator<Cell> cellIterator = row.cellIterator();
|
450 |
Iterator<Row> rowIterator = sheet.iterator();
|
| 450 |
|
451 |
while (rowIterator.hasNext()) {
|
| 451 |
while (cellIterator.hasNext()) {
|
452 |
Row row = rowIterator.next();
|
| 452 |
Cell cell = cellIterator.next();
|
453 |
// For each row, iterate through all the columns
|
| 453 |
// Check the cell type and format accordingly
|
454 |
Iterator<Cell> cellIterator = row.cellIterator();
|
| 454 |
switch (cell.getCellType()) {
|
455 |
|
| 455 |
case Cell.CELL_TYPE_NUMERIC:
|
456 |
while (cellIterator.hasNext()) {
|
| 456 |
System.out.print(cell.getNumericCellValue() + "t");
|
457 |
Cell cell = cellIterator.next();
|
| 457 |
break;
|
458 |
// Check the cell type and format accordingly
|
| 458 |
case Cell.CELL_TYPE_STRING:
|
459 |
switch (cell.getCellType()) {
|
| 459 |
System.out.print(cell.getStringCellValue() + "t");
|
460 |
case Cell.CELL_TYPE_NUMERIC:
|
| 460 |
break;
|
461 |
System.out.print(cell.getNumericCellValue() + "t");
|
| 461 |
}
|
462 |
break;
|
| 462 |
}
|
463 |
case Cell.CELL_TYPE_STRING:
|
| 463 |
System.out.println("");
|
464 |
System.out.print(cell.getStringCellValue() + "t");
|
| 464 |
}
|
465 |
break;
|
| 465 |
}
|
466 |
}
|
| 466 |
|
467 |
}
|
| 467 |
@Override
|
468 |
System.out.println("");
|
| 468 |
public Map<Integer, CreateOfferRequest> getPublishedOffers(LocalDate date, int fofoId, String brand) {
|
469 |
}
|
| 469 |
// TODO Auto-generated method stub
|
470 |
}
|
| 470 |
return null;
|
471 |
|
| 471 |
}
|
472 |
@Override
|
| 472 |
|
473 |
public Map<Integer, CreateOfferRequest> getPublishedOffers(LocalDate date, int fofoId, String brand) {
|
| 473 |
@Override
|
474 |
// TODO Auto-generated method stub
|
| 474 |
@Cacheable(value = "slabPayoutMap", cacheManager = "oneDayCacheManager")
|
475 |
return null;
|
| 475 |
public Map<Integer, Map<Integer, Long>> getSlabPayoutMap(CreateOfferRequest createOfferRequest) {
|
476 |
}
|
| 476 |
Map<Integer, Map<Integer, Long>> catalogSlabPayoutMap = new HashMap<>();
|
477 |
|
| 477 |
com.spice.profitmandi.dao.model.TargetSlab targetSlab = createOfferRequest.getTargetSlabs().get(0);
|
478 |
@Override
|
| 478 |
List<ItemCriteriaPayout> payouts = targetSlab.getItemCriteriaPayouts();
|
479 |
@Cacheable(value = "slabPayoutMap", cacheManager = "oneDayCacheManager")
|
| 479 |
|
480 |
public Map<Integer, Map<Integer, Long>> getSlabPayoutMap(CreateOfferRequest createOfferRequest) {
|
| 480 |
for (ItemCriteriaPayout itemCriteriaPayout : payouts) {
|
481 |
Map<Integer, Map<Integer, Long>> catalogSlabPayoutMap = new HashMap<>();
|
| 481 |
com.spice.profitmandi.service.offers.ItemCriteria itemCriteria = itemCriteriaPayout.getItemCriteria();
|
482 |
com.spice.profitmandi.dao.model.TargetSlab targetSlab = createOfferRequest.getTargetSlabs().get(0);
|
| 482 |
List<Integer> catalogIds = itemRepository.getCatalogIds(itemCriteria);
|
483 |
List<ItemCriteriaPayout> payouts = targetSlab.getItemCriteriaPayouts();
|
| 483 |
for (PayoutSlab payoutSlab : Lists.reverse(itemCriteriaPayout.getPayoutSlabs())) {
|
484 |
|
| 484 |
if (itemCriteriaPayout.getAmountType().equals(AmountType.FIXED)) {
|
485 |
for (ItemCriteriaPayout itemCriteriaPayout : payouts) {
|
| 485 |
for (Integer catalogId : catalogIds) {
|
486 |
com.spice.profitmandi.service.offers.ItemCriteria itemCriteria = itemCriteriaPayout.getItemCriteria();
|
| 486 |
if (!catalogSlabPayoutMap.containsKey(catalogId)) {
|
487 |
List<Integer> catalogIds = itemRepository.getCatalogIds(itemCriteria);
|
| 487 |
catalogSlabPayoutMap.put(catalogId, new LinkedHashMap<>());
|
488 |
for (PayoutSlab payoutSlab : Lists.reverse(itemCriteriaPayout.getPayoutSlabs())) {
|
| 488 |
}
|
489 |
if (itemCriteriaPayout.getAmountType().equals(AmountType.FIXED)) {
|
| 489 |
catalogSlabPayoutMap.get(catalogId).put(payoutSlab.getOnwardsAmount(),
|
490 |
for (Integer catalogId : catalogIds) {
|
| 490 |
(long) payoutSlab.getPayoutAmount());
|
491 |
if (!catalogSlabPayoutMap.containsKey(catalogId)) {
|
| 491 |
}
|
492 |
catalogSlabPayoutMap.put(catalogId, new LinkedHashMap<>());
|
| 492 |
} else if (itemCriteriaPayout.getAmountType().equals(AmountType.SLAB_FIXED)) {
|
493 |
}
|
| 493 |
for (Integer catalogId : catalogIds) {
|
494 |
catalogSlabPayoutMap.get(catalogId).put(payoutSlab.getOnwardsAmount(),
|
| 494 |
if (!catalogSlabPayoutMap.containsKey(catalogId)) {
|
495 |
(long) payoutSlab.getPayoutAmount());
|
| 495 |
catalogSlabPayoutMap.put(catalogId, new LinkedHashMap<>());
|
496 |
}
|
| 496 |
}
|
497 |
} else if (itemCriteriaPayout.getAmountType().equals(AmountType.SLAB_FIXED)) {
|
| 497 |
catalogSlabPayoutMap.get(catalogId).put(payoutSlab.getOnwardsAmount(),
|
498 |
for (Integer catalogId : catalogIds) {
|
| 498 |
(long) (payoutSlab.getPayoutAmount() / payoutSlab.getOnwardsAmount()));
|
499 |
if (!catalogSlabPayoutMap.containsKey(catalogId)) {
|
| 499 |
}
|
500 |
catalogSlabPayoutMap.put(catalogId, new LinkedHashMap<>());
|
| 500 |
} else if (itemCriteriaPayout.getAmountType().equals(AmountType.PERCENTAGE)) {
|
501 |
}
|
| 501 |
Map<Integer, TagListing> tagListingsMap = tagListingRepository.selectAllByCatalogIds(catalogIds);
|
502 |
catalogSlabPayoutMap.get(catalogId).put(payoutSlab.getOnwardsAmount(),
|
| 502 |
for (Map.Entry<Integer, TagListing> tagListingEntry : tagListingsMap.entrySet()) {
|
503 |
(long) (payoutSlab.getPayoutAmount() / payoutSlab.getOnwardsAmount()));
|
| 503 |
TagListing tagListing = tagListingEntry.getValue();
|
504 |
}
|
| 504 |
if (!catalogSlabPayoutMap.containsKey(tagListingEntry.getKey())) {
|
505 |
} else if (itemCriteriaPayout.getAmountType().equals(AmountType.PERCENTAGE)) {
|
| 505 |
catalogSlabPayoutMap.put(tagListingEntry.getKey(), new LinkedHashMap<>());
|
506 |
Map<Integer, TagListing> tagListingsMap = tagListingRepository.selectAllByCatalogIds(catalogIds);
|
| 506 |
}
|
507 |
for (Map.Entry<Integer, TagListing> tagListingEntry : tagListingsMap.entrySet()) {
|
| 507 |
catalogSlabPayoutMap.get(tagListingEntry.getKey()).put(payoutSlab.getOnwardsAmount(),
|
508 |
TagListing tagListing = tagListingEntry.getValue();
|
| 508 |
(long) (tagListing.getSellingPrice() * payoutSlab.getPayoutAmount() / 100));
|
509 |
if (!catalogSlabPayoutMap.containsKey(tagListingEntry.getKey())) {
|
| 509 |
}
|
510 |
catalogSlabPayoutMap.put(tagListingEntry.getKey(), new LinkedHashMap<>());
|
| 510 |
}
|
511 |
}
|
| 511 |
}
|
512 |
catalogSlabPayoutMap.get(tagListingEntry.getKey()).put(payoutSlab.getOnwardsAmount(),
|
| 512 |
}
|
513 |
(long) (tagListing.getSellingPrice() * payoutSlab.getPayoutAmount() / 100));
|
| 513 |
return catalogSlabPayoutMap;
|
514 |
}
|
| 514 |
}
|
515 |
}
|
| - |
|
516 |
}
|
| - |
|
517 |
}
|
| - |
|
518 |
return catalogSlabPayoutMap;
|
| - |
|
519 |
}
|
| 515 |
|
520 |
|
| 516 |
}
|
521 |
}
|