| Line 338... |
Line 338... |
| 338 |
@RequestMapping(value = "/updatePriceDropImeis", method = RequestMethod.POST)
|
338 |
@RequestMapping(value = "/updatePriceDropImeis", method = RequestMethod.POST)
|
| 339 |
public String updatePriceDropImeis(HttpServletRequest request,
|
339 |
public String updatePriceDropImeis(HttpServletRequest request,
|
| 340 |
@RequestBody PriceDropImeisModel priceDropImeisModel, Model model)
|
340 |
@RequestBody PriceDropImeisModel priceDropImeisModel, Model model)
|
| 341 |
throws ProfitMandiBusinessException, Exception {
|
341 |
throws ProfitMandiBusinessException, Exception {
|
| 342 |
PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
|
342 |
PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
|
| 343 |
;
|
- |
|
| 344 |
|
343 |
|
| 345 |
switch (priceDropImeisModel.getUpdatedStatus()) {
|
344 |
switch (priceDropImeisModel.getUpdatedStatus()) {
|
| 346 |
case "pending": {
|
345 |
case "approved": {
|
| 347 |
status = PriceDropImeiStatus.PENDING;
|
346 |
status = PriceDropImeiStatus.APPROVED;
|
| 348 |
break;
|
347 |
break;
|
| 349 |
}
|
348 |
}
|
| 350 |
case "approved": {
|
349 |
case "rejected": {
|
| 351 |
status = PriceDropImeiStatus.APPROVED;
|
350 |
status = PriceDropImeiStatus.REJECTED;
|
| 352 |
break;
|
351 |
break;
|
| 353 |
}
|
352 |
}
|
| 354 |
case "rejected": {
|
- |
|
| 355 |
status = PriceDropImeiStatus.REJECTED;
|
- |
|
| 356 |
break;
|
- |
|
| 357 |
}
|
353 |
}
|
| 358 |
|
354 |
|
| - |
|
355 |
if(PriceDropImeiStatus.PENDING.equals(status)) {
|
| - |
|
356 |
throw new ProfitMandiBusinessException("INVALID STATUS", "PENDING", "only approved and rejected is allowed");
|
| 359 |
}
|
357 |
}
|
| - |
|
358 |
|
| - |
|
359 |
//TODO:PD
|
| 360 |
List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
|
360 |
List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
|
| 361 |
.selectByPriceDropId(priceDropImeisModel.getPriceDropId());
|
361 |
.selectByPriceDropId(priceDropImeisModel.getPriceDropId());
|
| 362 |
|
362 |
|
| 363 |
List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
|
363 |
List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
|
| 364 |
for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
|
364 |
for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
|
| 365 |
if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
|
365 |
if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
|
| 366 |
|| priceDropIMEI.getStatus().equals(PriceDropImeiStatus.APPROVED)
|
- |
|
| 367 |
|| priceDropIMEI.getStatus().equals(status)) {
|
366 |
|| priceDropIMEI.getStatus().equals(status)) {
|
| 368 |
continue;
|
367 |
continue;
|
| 369 |
} else {
|
368 |
} else {
|
| 370 |
if (status.equals(PriceDropImeiStatus.APPROVED)) {
|
- |
|
| 371 |
priceDropIMEIsToProcess.add(priceDropIMEI);
|
369 |
priceDropIMEIsToProcess.add(priceDropIMEI);
|
| 372 |
}
|
- |
|
| 373 |
priceDropIMEI.setStatus(status);
|
370 |
priceDropIMEI.setStatus(status);
|
| - |
|
371 |
if(status.equals(PriceDropImeiStatus.REJECTED)) {
|
| - |
|
372 |
priceDropIMEI.setRejectionReason(priceDropImeisModel.getRejectionReason());
|
| - |
|
373 |
}
|
| 374 |
priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
|
374 |
priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
|
| 375 |
priceDropIMEIRepository.persist(priceDropIMEI);
|
375 |
priceDropIMEIRepository.persist(priceDropIMEI);
|
| 376 |
}
|
376 |
}
|
| 377 |
}
|
377 |
}
|
| 378 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropImeisModel.getPriceDropId());
|
- |
|
| 379 |
Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
|
- |
|
| 380 |
String description = item.getItemDescriptionNoColor();
|
- |
|
| 381 |
if (priceDropIMEIsToProcess.size() > 0) {
|
378 |
if (priceDropIMEIsToProcess.size() > 0) {
|
| 382 |
|
- |
|
| 383 |
Map<Integer, List<InventoryItem>> pendingPartnerInventoryMap = priceDropService
|
- |
|
| 384 |
.getInventoryForPriceDrop(priceDropIMEIsToProcess, priceDrop).stream()
|
379 |
priceDropService.processManualPriceDrop(priceDropImeisModel.getPriceDropId(), priceDropIMEIsToProcess, status);
|
| 385 |
.collect(Collectors.groupingBy(InventoryItem::getFofoId));
|
- |
|
| 386 |
|
- |
|
| 387 |
for (Map.Entry<Integer, List<InventoryItem>> pendingPartnerInventory : pendingPartnerInventoryMap
|
- |
|
| 388 |
.entrySet()) {
|
- |
|
| 389 |
List<InventoryItem> fofoInventoryList = pendingPartnerInventory.getValue();
|
- |
|
| 390 |
int fofoId = pendingPartnerInventory.getKey();
|
- |
|
| 391 |
|
- |
|
| 392 |
String reversalReason = MessageFormat.format(
|
- |
|
| 393 |
"Scheme differential for Price Drop of Rs.{0} on {1}, on {3}. Total {2} item(s)",
|
- |
|
| 394 |
priceDrop.getAmount(), description, fofoInventoryList.size(),
|
- |
|
| 395 |
FormattingUtils.formatDate(priceDrop.getAffectedOn()));
|
- |
|
| 396 |
String aReason = MessageFormat.format(
|
- |
|
| 397 |
"Payout of Rs.{4} per unit for Price Drop of Rs.{0} on {1}, on {3}. Total {2} item(s)",
|
- |
|
| 398 |
priceDrop.getAmount(), description, fofoInventoryList.size(),
|
- |
|
| 399 |
FormattingUtils.formatDate(priceDrop.getAffectedOn()), priceDrop.getPartnerPayout());
|
- |
|
| 400 |
inventoryService.updatePriceDrop(fofoInventoryList, priceDrop.getAmount());
|
- |
|
| 401 |
if (item.getBrand().equals("Samsung")) {
|
- |
|
| 402 |
schemeService.reverseSchemes(fofoInventoryList, priceDrop.getId(), reversalReason);
|
- |
|
| 403 |
}
|
- |
|
| 404 |
walletService.addAmountToWallet(fofoId, priceDrop.getId(), WalletReferenceType.PRICE_DROP, aReason,
|
- |
|
| 405 |
priceDrop.getPartnerPayout() * fofoInventoryList.size());
|
- |
|
| 406 |
}
|
- |
|
| 407 |
|
- |
|
| 408 |
}
|
380 |
}
|
| 409 |
|
381 |
|
| 410 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
382 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 411 |
return "response";
|
383 |
return "response";
|
| 412 |
|
384 |
|