| Line 253... |
Line 253... |
| 253 |
}
|
253 |
}
|
| 254 |
|
254 |
|
| 255 |
@RequestMapping(value = "/getSanctionRequest", method = RequestMethod.GET)
|
255 |
@RequestMapping(value = "/getSanctionRequest", method = RequestMethod.GET)
|
| 256 |
public String getSanctionRequest(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
256 |
public String getSanctionRequest(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 257 |
|
257 |
|
| 258 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectByDate(LocalDate.now());
|
258 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository.getL2ApprovedByDate(LocalDate.now(), SanctionStatus.APPROVED);
|
| 259 |
|
259 |
|
| 260 |
|
260 |
|
| 261 |
if (!sanctionRequests.isEmpty()) {
|
261 |
if (!sanctionRequests.isEmpty()) {
|
| 262 |
|
262 |
|
| 263 |
List<Integer> authIds = sanctionRequests.stream().map(x -> x.getAuthId()).collect(Collectors.toList());
|
263 |
List<Integer> authIds = sanctionRequests.stream().map(x -> x.getAuthId()).collect(Collectors.toList());
|
| Line 344... |
Line 344... |
| 344 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
344 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
| 345 |
return "sanction-request";
|
345 |
return "sanction-request";
|
| 346 |
|
346 |
|
| 347 |
}
|
347 |
}
|
| 348 |
|
348 |
|
| - |
|
349 |
|
| - |
|
350 |
@RequestMapping(value = "/getRbmL2SanctionRequest", method = RequestMethod.GET)
|
| - |
|
351 |
public String getRbmL2SanctionRequest(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| - |
|
352 |
|
| - |
|
353 |
List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectByDate(LocalDate.now());
|
| - |
|
354 |
|
| - |
|
355 |
|
| - |
|
356 |
if (!sanctionRequests.isEmpty()) {
|
| - |
|
357 |
|
| - |
|
358 |
List<Integer> authIds = sanctionRequests.stream().map(x -> x.getAuthId()).collect(Collectors.toList());
|
| - |
|
359 |
|
| - |
|
360 |
Map<Integer, String> authMap = authRepository.selectAllAuthUserByIds(authIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getFullName()));
|
| - |
|
361 |
|
| - |
|
362 |
|
| - |
|
363 |
List<Integer> fofoIds = sanctionRequests.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| - |
|
364 |
|
| - |
|
365 |
Map<Integer, Long> partnerCreditDaysMap = new HashMap<>();
|
| - |
|
366 |
|
| - |
|
367 |
Map<Integer, Integer> partnerActiveLoanMap = new HashMap<>();
|
| - |
|
368 |
Map<Integer, Integer> partnerAverageCreditDaysMap = new HashMap<>();
|
| - |
|
369 |
|
| - |
|
370 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| - |
|
371 |
|
| - |
|
372 |
Map<Integer, Double> secondaryMtd = orderRepository
|
| - |
|
373 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
| - |
|
374 |
Map<Integer, Double> secondaryLmtd = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
| - |
|
375 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1));
|
| - |
|
376 |
Map<Integer, Double> secondaryLms = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
| - |
|
377 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1));
|
| - |
|
378 |
|
| - |
|
379 |
List<Loan> loans = loanRepository.selectAllLoans(fofoIds, DateRangeModel.withStartDate(curDate.minusYears(2)));
|
| - |
|
380 |
Map<Integer, List<Loan>> partnerClosedLoansMap = loans.stream().filter(x -> x.getPendingAmount().compareTo(BigDecimal.ZERO) == 0)
|
| - |
|
381 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| - |
|
382 |
|
| - |
|
383 |
|
| - |
|
384 |
Map<Integer, List<Loan>> activeLoansMap = loans.stream().filter(x -> x.getPendingAmount().compareTo(BigDecimal.ZERO) == 1).collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| - |
|
385 |
|
| - |
|
386 |
for (Integer fofoId : fofoIds) {
|
| - |
|
387 |
LOGGER.info("Fofo Id - {}", fofoId);
|
| - |
|
388 |
List<Loan> activeLoans = activeLoansMap.get(fofoId);
|
| - |
|
389 |
if (activeLoans != null) {
|
| - |
|
390 |
partnerActiveLoanMap.put(fofoId, activeLoans.size());
|
| - |
|
391 |
Loan loan = activeLoans.stream().sorted(Comparator.comparing(Loan::getCreatedOn)).findFirst().get();
|
| - |
|
392 |
long daysBetween = Duration.between(loan.getCreatedOn(), LocalDateTime.now()).toDays();
|
| - |
|
393 |
partnerCreditDaysMap.put(fofoId, daysBetween);
|
| - |
|
394 |
}
|
| - |
|
395 |
List<Loan> closedLoans = partnerClosedLoansMap.get(fofoId);
|
| - |
|
396 |
if (closedLoans != null) {
|
| - |
|
397 |
long averageCreditDays = Math.round(closedLoans.stream().mapToLong(x -> Duration.between(x.getCreatedOn(),
|
| - |
|
398 |
x.getSettledOn() == null ? x.getCreatedOn().plusDays(10) : x.getSettledOn()).toDays() + 1).average().orElse(0.0));
|
| - |
|
399 |
partnerAverageCreditDaysMap.put(fofoId, (int) averageCreditDays);
|
| - |
|
400 |
}
|
| - |
|
401 |
|
| - |
|
402 |
}
|
| - |
|
403 |
model.addAttribute("partnerActiveLoanMap", partnerActiveLoanMap);
|
| - |
|
404 |
model.addAttribute("partnerCreditDaysMap", partnerCreditDaysMap);
|
| - |
|
405 |
model.addAttribute("partnerAverageCreditDaysMap", partnerAverageCreditDaysMap);
|
| - |
|
406 |
|
| - |
|
407 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| - |
|
408 |
|
| - |
|
409 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds)).stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
| - |
|
410 |
|
| - |
|
411 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
| - |
|
412 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| - |
|
413 |
|
| - |
|
414 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
| - |
|
415 |
|
| - |
|
416 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
| - |
|
417 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
| - |
|
418 |
|
| - |
|
419 |
model.addAttribute("userWalletMap", userWalletMap);
|
| - |
|
420 |
model.addAttribute("authMap", authMap);
|
| - |
|
421 |
model.addAttribute("secondaryMtd", secondaryMtd);
|
| - |
|
422 |
model.addAttribute("secondarylmtd", secondaryLmtd);
|
| - |
|
423 |
model.addAttribute("secondarylms", secondaryLms);
|
| - |
|
424 |
|
| - |
|
425 |
List<CreditAccount> creditAccounts = creditAccountRepository.selectByFofoIds(fofoIds);
|
| - |
|
426 |
model.addAttribute("creditAccounts", creditAccounts.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x.getGateway())));
|
| - |
|
427 |
}
|
| - |
|
428 |
|
| - |
|
429 |
model.addAttribute("sanctionRequests", sanctionRequests);
|
| - |
|
430 |
|
| - |
|
431 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
| - |
|
432 |
return "sanction-request-l2";
|
| - |
|
433 |
|
| - |
|
434 |
}
|
| - |
|
435 |
|
| 349 |
@RequestMapping(value = "/sanctionRequest", method = RequestMethod.POST)
|
436 |
@RequestMapping(value = "/sanctionRequest", method = RequestMethod.POST)
|
| 350 |
public String sanctionRequest(HttpServletRequest request, @RequestBody SanctionRequestModel sanctionRequestModel, Model model) throws Exception {
|
437 |
public String sanctionRequest(HttpServletRequest request, @RequestBody SanctionRequestModel sanctionRequestModel, Model model) throws Exception {
|
| 351 |
|
438 |
|
| 352 |
LOGGER.info("sanctionRequestModel {} ", sanctionRequestModel);
|
439 |
LOGGER.info("sanctionRequestModel {} ", sanctionRequestModel);
|
| 353 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
440 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| Line 401... |
Line 488... |
| 401 |
sanctionRequest.setFreeDays(sanctionRequestModel.getFreeDays());
|
488 |
sanctionRequest.setFreeDays(sanctionRequestModel.getFreeDays());
|
| 402 |
|
489 |
|
| 403 |
sanctionRequest.setApprovalAmount(sanctionRequestModel.getApprovalAmount());
|
490 |
sanctionRequest.setApprovalAmount(sanctionRequestModel.getApprovalAmount());
|
| 404 |
if (sanctionRequestModel.getApprovalAmount() == null) {
|
491 |
if (sanctionRequestModel.getApprovalAmount() == null) {
|
| 405 |
sanctionRequest.setStatus(SanctionStatus.REJECTED);
|
492 |
sanctionRequest.setStatus(SanctionStatus.REJECTED);
|
| - |
|
493 |
sanctionRequest.setRbmL2ApprovalStatus(SanctionStatus.REJECTED);
|
| 406 |
} else {
|
494 |
} else {
|
| 407 |
sanctionRequest.setStatus(sanctionRequestModel.getStatus());
|
495 |
sanctionRequest.setStatus(sanctionRequestModel.getStatus());
|
| 408 |
}
|
496 |
}
|
| 409 |
|
497 |
|
| 410 |
sanctionRequest.setStockHold(sanctionRequestModel.isStockHold());
|
498 |
sanctionRequest.setStockHold(sanctionRequestModel.isStockHold());
|
| Line 447... |
Line 535... |
| 447 |
model.addAttribute("creditAccounts", creditAccounts.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x.getGateway())));
|
535 |
model.addAttribute("creditAccounts", creditAccounts.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x.getGateway())));
|
| 448 |
return "sanction-request-row";
|
536 |
return "sanction-request-row";
|
| 449 |
|
537 |
|
| 450 |
}
|
538 |
}
|
| 451 |
|
539 |
|
| - |
|
540 |
@RequestMapping(value = "/rbmL2ApprovalSanctionRequest", method = RequestMethod.POST)
|
| - |
|
541 |
public String rbmL2ApprovalSanctionRequest(HttpServletRequest request, @RequestBody SanctionRequestModel sanctionRequestModel, Model model) throws Exception {
|
| - |
|
542 |
|
| - |
|
543 |
LOGGER.info("sanctionRequestModel {} ", sanctionRequestModel);
|
| - |
|
544 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| - |
|
545 |
|
| - |
|
546 |
SanctionRequest sanctionRequest = sanctionRequestRepository.selectById(sanctionRequestModel.getId());
|
| - |
|
547 |
|
| - |
|
548 |
Map<Integer, String> authMap = new HashMap<>();
|
| - |
|
549 |
AuthUser authUser = authRepository.selectById(sanctionRequest.getAuthId());
|
| - |
|
550 |
|
| - |
|
551 |
authMap.put(authUser.getId(), authUser.getFullName());
|
| - |
|
552 |
|
| - |
|
553 |
model.addAttribute("authMap", authMap);
|
| - |
|
554 |
List<Integer> fofoIds = sanctionRequestRepository.selectByDate(LocalDate.now()).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| - |
|
555 |
|
| - |
|
556 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(fofoIds);
|
| - |
|
557 |
|
| - |
|
558 |
LOGGER.info("freeDays {} ", sdCreditRequirementMap.get(sanctionRequest.getFofoId()).getFreeDays());
|
| - |
|
559 |
|
| - |
|
560 |
if (sanctionRequestModel.getStatus().equals(SanctionStatus.APPROVED)) {
|
| - |
|
561 |
sanctionRequest.setRbmL2ApprovalTimestamp(LocalDateTime.now());
|
| - |
|
562 |
sanctionRequest.setRbmL2ApproverEmail(authUser.getEmailId());
|
| - |
|
563 |
}
|
| - |
|
564 |
|
| - |
|
565 |
sanctionRequest.setFreeDays(sanctionRequestModel.getFreeDays());
|
| - |
|
566 |
|
| - |
|
567 |
sanctionRequest.setApprovalAmount(sanctionRequestModel.getApprovalAmount());
|
| - |
|
568 |
if (sanctionRequestModel.getApprovalAmount() == null) {
|
| - |
|
569 |
|
| - |
|
570 |
sanctionRequest.setStatus(SanctionStatus.REJECTED);
|
| - |
|
571 |
|
| - |
|
572 |
sanctionRequest.setRbmL2ApprovalStatus(SanctionStatus.REJECTED);
|
| - |
|
573 |
sanctionRequest.setRbmL2ApprovalTimestamp(LocalDateTime.now());
|
| - |
|
574 |
sanctionRequest.setRbmL2ApproverEmail(authUser.getEmailId());
|
| - |
|
575 |
} else {
|
| - |
|
576 |
sanctionRequest.setRbmL2ApprovalStatus(sanctionRequestModel.getStatus());
|
| - |
|
577 |
}
|
| - |
|
578 |
|
| - |
|
579 |
sanctionRequest.setStockHold(sanctionRequestModel.isStockHold());
|
| - |
|
580 |
|
| - |
|
581 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| - |
|
582 |
|
| - |
|
583 |
|
| - |
|
584 |
Map<Integer, Double> secondaryMtd = orderRepository
|
| - |
|
585 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
| - |
|
586 |
Map<Integer, Double> secondarylmtd = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
| - |
|
587 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1));
|
| - |
|
588 |
Map<Integer, Double> secondarylms = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(
|
| - |
|
589 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1));
|
| - |
|
590 |
|
| - |
|
591 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = partnerDailyInvestmentRepository.selectAll(fofoIds, LocalDate.now().minusDays(1)).stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| - |
|
592 |
|
| - |
|
593 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds)).stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
| - |
|
594 |
|
| - |
|
595 |
sanctionRequest = sanctionRequestRepository.selectById(sanctionRequestModel.getId());
|
| - |
|
596 |
model.addAttribute("customRetailerMap", customRetailerMap);
|
| - |
|
597 |
model.addAttribute("sanctionRequest", sanctionRequest);
|
| - |
|
598 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
| - |
|
599 |
model.addAttribute("sdCreditRequirementMap", sdCreditRequirementMap);
|
| - |
|
600 |
model.addAttribute("userWalletMap", userWalletMap);
|
| - |
|
601 |
|
| - |
|
602 |
model.addAttribute("sanctionStatus", SanctionStatus.values());
|
| - |
|
603 |
|
| - |
|
604 |
model.addAttribute("secondarylmtd", secondarylmtd);
|
| - |
|
605 |
model.addAttribute("secondaryMtd", secondaryMtd);
|
| - |
|
606 |
model.addAttribute("secondarylms", secondarylms);
|
| - |
|
607 |
|
| - |
|
608 |
List<CreditAccount> creditAccounts = creditAccountRepository.selectByFofoIds(Arrays.asList(sanctionRequest.getFofoId()));
|
| - |
|
609 |
model.addAttribute("creditAccounts", creditAccounts.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x.getGateway())));
|
| - |
|
610 |
return "rbm-l2-pending-sanction-request";
|
| - |
|
611 |
|
| - |
|
612 |
}
|
| - |
|
613 |
|
| 452 |
List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com", "amit.gupta@smartdukaan.com");
|
614 |
List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com", "amit.gupta@smartdukaan.com");
|
| 453 |
|
615 |
|
| 454 |
@RequestMapping(value = "/getLoans", method = RequestMethod.GET)
|
616 |
@RequestMapping(value = "/getLoans", method = RequestMethod.GET)
|
| 455 |
public String getLoans(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
617 |
public String getLoans(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 456 |
|
618 |
|