| Line 38... |
Line 38... |
| 38 |
import com.spice.profitmandi.service.order.OrderService;
|
38 |
import com.spice.profitmandi.service.order.OrderService;
|
| 39 |
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModelNew;
|
39 |
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModelNew;
|
| 40 |
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
|
40 |
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
|
| 41 |
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
|
41 |
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
|
| 42 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
42 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| - |
|
43 |
import com.spice.profitmandi.service.pricing.PriceHikeService;
|
| 43 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
44 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 44 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
45 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 45 |
import com.spice.profitmandi.service.user.RetailerService;
|
46 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 46 |
import com.spice.profitmandi.service.wallet.WalletService;
|
47 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 47 |
import com.spice.profitmandi.web.model.LoginDetails;
|
48 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| Line 98... |
Line 99... |
| 98 |
@Autowired
|
99 |
@Autowired
|
| 99 |
private MVCResponseSender mvcResponseSender;
|
100 |
private MVCResponseSender mvcResponseSender;
|
| 100 |
@Autowired
|
101 |
@Autowired
|
| 101 |
private PriceDropService priceDropService;
|
102 |
private PriceDropService priceDropService;
|
| 102 |
@Autowired
|
103 |
@Autowired
|
| - |
|
104 |
private PriceHikeService priceHikeService;
|
| - |
|
105 |
@Autowired
|
| 103 |
private ItemPricingHistoryRepository itemPricingHistoryRepository;
|
106 |
private ItemPricingHistoryRepository itemPricingHistoryRepository;
|
| 104 |
@Autowired
|
107 |
@Autowired
|
| 105 |
private WalletService walletService;
|
108 |
private WalletService walletService;
|
| 106 |
@Autowired
|
109 |
@Autowired
|
| 107 |
private TagListingRepository tagListingRepository;
|
110 |
private TagListingRepository tagListingRepository;
|
| Line 346... |
Line 349... |
| 346 |
boolean response = false;
|
349 |
boolean response = false;
|
| 347 |
if (priceDrop.getPartnerPayout() == 0) {
|
350 |
if (priceDrop.getPartnerPayout() == 0) {
|
| 348 |
priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
|
351 |
priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
|
| 349 |
}
|
352 |
}
|
| 350 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
353 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
| 351 |
// Generate IMEI rows if missing — a manually-flagged hike has none yet (its priceDropStatus
|
- |
|
| 352 |
// ran at creation while deduct_on_hike was false). Idempotent: no-op once rows exist (drops).
|
- |
|
| 353 |
priceDropService.priceDropStatus(priceDrop.getId());
|
- |
|
| 354 |
priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
|
354 |
priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
|
| 355 |
response = true;
|
355 |
response = true;
|
| 356 |
model.addAttribute("response1", mvcResponseSender.createResponseString(response));
|
356 |
model.addAttribute("response1", mvcResponseSender.createResponseString(response));
|
| 357 |
return "response";
|
357 |
return "response";
|
| 358 |
}
|
358 |
}
|
| 359 |
|
359 |
|
| 360 |
// Generate (only) the IMEI rows for a flagged price hike so they can be reviewed before
|
360 |
// On-demand price-hike deduction for a whole hike: figures out billed partners/IMEIs, then
|
| - |
|
361 |
// debits each partner in the background (one transaction per retailer). Idempotent — re-calling
|
| 361 |
// processing. Does NOT debit. Idempotent: priceDropStatus creates rows only when none exist.
|
362 |
// skips units already recovered (incl. those already handled by the GRN hook).
|
| 362 |
@RequestMapping(value = "/priceHike/generateImeis/{priceDropId}", method = RequestMethod.GET)
|
363 |
@RequestMapping(value = "/priceHike/process/{priceDropId}", method = RequestMethod.GET)
|
| 363 |
public String generateHikeImeis(HttpServletRequest request, @PathVariable int priceDropId, Model model)
|
364 |
public String processPriceHike(HttpServletRequest request, @PathVariable int priceDropId, Model model)
|
| 364 |
throws Exception {
|
365 |
throws Exception {
|
| 365 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
|
- |
|
| 366 |
if (priceDrop.getAmount() >= 0 || !priceDrop.isDeductOnHike()) {
|
- |
|
| 367 |
throw new ProfitMandiBusinessException("Generate hike IMEIs", String.valueOf(priceDropId),
|
- |
|
| 368 |
"Not a price hike flagged for deduction (amount must be < 0 and deduct_on_hike = 1)");
|
- |
|
| 369 |
}
|
- |
|
| 370 |
priceDropService.priceDropStatus(priceDropId);
|
366 |
priceHikeService.triggerHikeDeduction(priceDropId);
|
| 371 |
List<PriceDropIMEI> rows = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
|
- |
|
| 372 |
Map<String, Object> result = new HashMap<>();
|
- |
|
| 373 |
result.put("priceDropId", priceDropId);
|
367 |
model.addAttribute("response1",
|
| 374 |
result.put("generatedCount", rows.size());
|
- |
|
| 375 |
result.put("statusBreakdown", rows.stream()
|
- |
|
| 376 |
.collect(Collectors.groupingBy(x -> x.getStatus().name(), Collectors.counting())));
|
368 |
mvcResponseSender.createResponseString("Price hike deduction started for priceDropId " + priceDropId));
|
| 377 |
model.addAttribute("response1", mvcResponseSender.createResponseString(result));
|
- |
|
| 378 |
return "response";
|
369 |
return "response";
|
| 379 |
}
|
370 |
}
|
| 380 |
|
371 |
|
| 381 |
@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
|
372 |
@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
|
| 382 |
public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
|
373 |
public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
|