| Line 4257... |
Line 4257... |
| 4257 |
public void processSidbiDeductions() throws ProfitMandiBusinessException {
|
4257 |
public void processSidbiDeductions() throws ProfitMandiBusinessException {
|
| 4258 |
//sidbiService.migrateSanctions();
|
4258 |
//sidbiService.migrateSanctions();
|
| 4259 |
sidbiService.processDeductions();
|
4259 |
sidbiService.processDeductions();
|
| 4260 |
}
|
4260 |
}
|
| 4261 |
|
4261 |
|
| 4262 |
public void updatePartnerLimit(int fofoId) throws ProfitMandiBusinessException {
|
- |
|
| 4263 |
LocalDateTime firstBillingDate = transactionRepository.getFirstBillingDate(fofoId);
|
- |
|
| 4264 |
|
- |
|
| 4265 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(fofoId, Gateway.SDDIRECT);
|
- |
|
| 4266 |
BigDecimal utilizationAmount = sdCreditService.getUtilizationAmount(fofoId);
|
- |
|
| 4267 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId, 0);
|
- |
|
| 4268 |
BigDecimal suggestedAmount = this.getSuggestedAmount(creditAccount, partnerDailyInvestment, utilizationAmount, null);
|
- |
|
| 4269 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(fofoId);
|
- |
|
| 4270 |
|
- |
|
| 4271 |
LOGGER.info("suggestedAmount {} ", suggestedAmount);
|
- |
|
| 4272 |
|
- |
|
| 4273 |
if (sdCreditRequirement == null) {
|
- |
|
| 4274 |
sdCreditRequirement = new SDCreditRequirement();
|
- |
|
| 4275 |
sdCreditRequirement.setFofoId(fofoId);
|
- |
|
| 4276 |
sdCreditRequirement.setCreditDays(15);
|
- |
|
| 4277 |
sdCreditRequirement.setInterestRate(ProfitMandiConstants.NEW_INTEREST_RATE);
|
- |
|
| 4278 |
sdCreditRequirement.setRisk(CreditRisk.HIGH_RISK);
|
- |
|
| 4279 |
sdCreditRequirement.setUtilizedAmount(BigDecimal.ZERO);
|
- |
|
| 4280 |
sdCreditRequirement.setCreateTimestamp(LocalDateTime.now());
|
- |
|
| 4281 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
- |
|
| 4282 |
sdCreditRequirementRepository.persist(sdCreditRequirement);
|
- |
|
| 4283 |
}
|
- |
|
| 4284 |
|
- |
|
| 4285 |
CreditRisk creditRisk = sdCreditService.getCurrentRisk(sdCreditRequirement, firstBillingDate);
|
- |
|
| 4286 |
|
- |
|
| 4287 |
sdCreditRequirement.setRisk(creditRisk);
|
- |
|
| 4288 |
LOGGER.info("Suggested Amount - {}", suggestedAmount);
|
- |
|
| 4289 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
- |
|
| 4290 |
if (!sdCreditRequirement.isHardLimit()) {
|
- |
|
| 4291 |
sdCreditRequirement.setLimit(suggestedAmount);
|
- |
|
| 4292 |
}
|
- |
|
| 4293 |
BigDecimal availableLimit = sdCreditRequirement.getLimit().subtract(utilizationAmount);
|
- |
|
| 4294 |
|
- |
|
| 4295 |
LOGGER.info("utilizedLimit {} ", utilizationAmount);
|
- |
|
| 4296 |
|
- |
|
| 4297 |
LOGGER.info("availableLimit {} ", availableLimit);
|
- |
|
| 4298 |
|
- |
|
| 4299 |
sdCreditRequirement.setUtilizedAmount(utilizationAmount);
|
- |
|
| 4300 |
|
- |
|
| 4301 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
- |
|
| 4302 |
|
- |
|
| 4303 |
if (creditAccount != null) {
|
- |
|
| 4304 |
|
- |
|
| 4305 |
creditAccount.setInterestRate(sdCreditRequirement.getInterestRate().floatValue());
|
- |
|
| 4306 |
creditAccount.setSanctionedAmount(sdCreditRequirement.getLimit().floatValue());
|
- |
|
| 4307 |
creditAccount.setAvailableAmount(availableLimit.floatValue());
|
- |
|
| 4308 |
creditAccount.setFreeDays(sdCreditRequirement.getFreeDays());
|
- |
|
| 4309 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
- |
|
| 4310 |
}
|
- |
|
| 4311 |
|
- |
|
| 4312 |
}
|
- |
|
| 4313 |
|
- |
|
| 4314 |
public void updatePartnerLimit() throws ProfitMandiBusinessException {
|
- |
|
| 4315 |
synchronized (SD_CREDIT_LOCK) {
|
- |
|
| 4316 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
- |
|
| 4317 |
Map<Integer, BigDecimal> fofoSidbiLimitMap = sidbiService.getSuggestedLimitMap();
|
- |
|
| 4318 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
- |
|
| 4319 |
Map<Integer, CreditAccount> creditAccountMap = creditAccountRepository.selectAllByGateways(Arrays.asList(Gateway.SIDBI, Gateway.SDDIRECT))
|
- |
|
| 4320 |
.stream().filter(x -> x.isActive()).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
- |
|
| 4321 |
Map<Integer, BulkCreditSummary> bulkSummaryMap = sdCreditService.getCreditSummaryBulk();
|
- |
|
| 4322 |
|
- |
|
| 4323 |
// Sort by fofoId to ensure deterministic row-locking order and prevent deadlocks
|
- |
|
| 4324 |
List<Integer> sortedFofoIds = customRetailerMap.keySet().stream().sorted().collect(Collectors.toList());
|
- |
|
| 4325 |
|
- |
|
| 4326 |
for (int fofoId : sortedFofoIds) {
|
- |
|
| 4327 |
CustomRetailer customRetailer = customRetailerMap.get(fofoId);
|
- |
|
| 4328 |
LocalDateTime firstBillingDate = transactionRepository.getFirstBillingDate(fofoId);
|
- |
|
| 4329 |
|
- |
|
| 4330 |
CreditAccount creditAccount = creditAccountMap.get(fofoId);
|
- |
|
| 4331 |
BulkCreditSummary bulkSummary = bulkSummaryMap.get(fofoId);
|
- |
|
| 4332 |
BigDecimal utilizationAmount = bulkSummary != null ? bulkSummary.getUtilization() : BigDecimal.ZERO;
|
- |
|
| 4333 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId, 0);
|
- |
|
| 4334 |
BigDecimal suggestedAmount = this.getSuggestedAmount(creditAccount, partnerDailyInvestment, utilizationAmount, fofoSidbiLimitMap.get(fofoId));
|
- |
|
| 4335 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementMap.get(fofoId);
|
- |
|
| 4336 |
|
- |
|
| 4337 |
LOGGER.info("suggestedAmount {} ", suggestedAmount);
|
- |
|
| 4338 |
|
- |
|
| 4339 |
if (sdCreditRequirement == null) {
|
- |
|
| 4340 |
sdCreditRequirement = new SDCreditRequirement();
|
- |
|
| 4341 |
sdCreditRequirement.setFofoId(fofoId);
|
- |
|
| 4342 |
sdCreditRequirement.setCreditDays(15);
|
- |
|
| 4343 |
sdCreditRequirement.setInterestRate(ProfitMandiConstants.NEW_INTEREST_RATE);
|
- |
|
| 4344 |
sdCreditRequirement.setRisk(CreditRisk.HIGH_RISK);
|
- |
|
| 4345 |
sdCreditRequirement.setUtilizedAmount(BigDecimal.ZERO);
|
- |
|
| 4346 |
sdCreditRequirement.setCreateTimestamp(LocalDateTime.now());
|
- |
|
| 4347 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
- |
|
| 4348 |
sdCreditRequirementRepository.persist(sdCreditRequirement);
|
- |
|
| 4349 |
}
|
- |
|
| 4350 |
|
- |
|
| 4351 |
CreditRisk creditRisk = sdCreditService.getCurrentRisk(sdCreditRequirement, firstBillingDate);
|
- |
|
| 4352 |
|
- |
|
| 4353 |
sdCreditRequirement.setRisk(creditRisk);
|
- |
|
| 4354 |
|
- |
|
| 4355 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
- |
|
| 4356 |
if (!sdCreditRequirement.isHardLimit()) {
|
- |
|
| 4357 |
sdCreditRequirement.setLimit(suggestedAmount);
|
- |
|
| 4358 |
}
|
- |
|
| 4359 |
|
- |
|
| 4360 |
BigDecimal availableLimit = sdCreditRequirement.getLimit().subtract(utilizationAmount);
|
- |
|
| 4361 |
|
- |
|
| 4362 |
LOGGER.info("utilizedLimit {} ", utilizationAmount);
|
- |
|
| 4363 |
|
- |
|
| 4364 |
LOGGER.info("availableLimit {} ", availableLimit);
|
- |
|
| 4365 |
|
- |
|
| 4366 |
sdCreditRequirement.setUtilizedAmount(utilizationAmount);
|
- |
|
| 4367 |
|
- |
|
| 4368 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
- |
|
| 4369 |
|
- |
|
| 4370 |
if (creditAccount != null) {
|
- |
|
| 4371 |
|
- |
|
| 4372 |
creditAccount.setInterestRate(sdCreditRequirement.getInterestRate().floatValue());
|
- |
|
| 4373 |
creditAccount.setSanctionedAmount(sdCreditRequirement.getLimit().floatValue());
|
- |
|
| 4374 |
creditAccount.setAvailableAmount(availableLimit.floatValue());
|
- |
|
| 4375 |
creditAccount.setFreeDays(sdCreditRequirement.getFreeDays());
|
- |
|
| 4376 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
- |
|
| 4377 |
}
|
- |
|
| 4378 |
|
- |
|
| 4379 |
}
|
- |
|
| 4380 |
}
|
- |
|
| 4381 |
|
- |
|
| 4382 |
}
|
- |
|
| 4383 |
|
- |
|
| 4384 |
private static final NavigableMap<Double, Double> discountMap = new TreeMap<>();
|
- |
|
| 4385 |
|
- |
|
| 4386 |
static {
|
- |
|
| 4387 |
discountMap.put(4 * ProfitMandiConstants.ONE_LAC - 1, 0.2); // Up to 3,99,999 -> 20%
|
- |
|
| 4388 |
discountMap.put(10 * ProfitMandiConstants.ONE_LAC - 1, 0.25); // 4,00,000 to 9,99,999 -> 25%
|
- |
|
| 4389 |
discountMap.put(20 * ProfitMandiConstants.ONE_LAC - 1, 0.3); // 10,00,000 to 19,99,999 -> 30%
|
- |
|
| 4390 |
discountMap.put(Double.MAX_VALUE, 0.4); // 20,00,000 and above -> 40%
|
- |
|
| 4391 |
}
|
- |
|
| 4392 |
|
- |
|
| 4393 |
public BigDecimal getSuggestedLimit(double investmentValue) {
|
- |
|
| 4394 |
double percentageValue = discountMap.ceilingEntry(investmentValue).getValue();
|
- |
|
| 4395 |
return this.getSuggestedAmount(investmentValue, percentageValue);
|
- |
|
| 4396 |
|
- |
|
| 4397 |
}
|
- |
|
| 4398 |
private static final BigDecimal FIFTEEN_LAC = BigDecimal.valueOf(1500000);
|
- |
|
| 4399 |
|
- |
|
| 4400 |
private BigDecimal getSuggestedAmount(double investmentValue, double percentageValue) {
|
- |
|
| 4401 |
return BigDecimal.valueOf(investmentValue * percentageValue).min(FIFTEEN_LAC);
|
- |
|
| 4402 |
}
|
- |
|
| 4403 |
/*private static List<Integer> hundredPercentLimitPartnerIds = Arrays.asList(175139630,
|
4262 |
/*private static List<Integer> hundredPercentLimitPartnerIds = Arrays.asList(175139630,
|
| 4404 |
175139815,
|
4263 |
175139815,
|
| 4405 |
175139844,
|
4264 |
175139844,
|
| 4406 |
175140101
|
4265 |
175140101
|
| 4407 |
);*/
|
4266 |
);*/
|
| 4408 |
|
4267 |
|
| 4409 |
private static List<Integer> hundredPercentLimitPartnerIds = Arrays.asList();
|
4268 |
private static List<Integer> hundredPercentLimitPartnerIds = Arrays.asList();
|
| 4410 |
|
4269 |
|
| 4411 |
private BigDecimal getSuggestedAmount(CreditAccount creditAccount, PartnerDailyInvestment
|
- |
|
| 4412 |
partnerDailyInvestment, BigDecimal utilizationAmount, BigDecimal sidbiLimit) {
|
- |
|
| 4413 |
BigDecimal suggestedAmount = BigDecimal.ZERO;
|
- |
|
| 4414 |
double utilization = utilizationAmount != null ? utilizationAmount.doubleValue() : 0;
|
- |
|
| 4415 |
//1 LAC
|
- |
|
| 4416 |
if (creditAccount == null || creditAccount.getGateway().equals(Gateway.SDDIRECT)) {
|
- |
|
| 4417 |
|
- |
|
| 4418 |
if (partnerDailyInvestment != null) {
|
- |
|
| 4419 |
if (hundredPercentLimitPartnerIds.contains(partnerDailyInvestment.getFofoId())) {
|
- |
|
| 4420 |
suggestedAmount = getSuggestedAmount(partnerDailyInvestment.getTotalInvestment() - utilization, 1);
|
- |
|
| 4421 |
suggestedAmount = suggestedAmount.min(FIFTEEN_LAC);
|
- |
|
| 4422 |
} else {
|
- |
|
| 4423 |
suggestedAmount = getSuggestedLimit(partnerDailyInvestment.getTotalInvestment() - utilization);
|
- |
|
| 4424 |
}
|
- |
|
| 4425 |
}
|
- |
|
| 4426 |
if (suggestedAmount.doubleValue() < 0) {
|
- |
|
| 4427 |
suggestedAmount = BigDecimal.ZERO;
|
- |
|
| 4428 |
}
|
- |
|
| 4429 |
} else if (creditAccount.getGateway().equals(Gateway.SIDBI) && sidbiLimit != null) {
|
- |
|
| 4430 |
suggestedAmount = getSuggestedLimit(partnerDailyInvestment.getTotalInvestment() - utilization);
|
- |
|
| 4431 |
suggestedAmount = suggestedAmount.max(sidbiLimit);
|
- |
|
| 4432 |
|
4270 |
|
| 4433 |
|
4271 |
|
| 4434 |
}
|
- |
|
| 4435 |
return suggestedAmount;
|
- |
|
| 4436 |
}
|
- |
|
| 4437 |
|
- |
|
| 4438 |
public void notifyDefaultLoans() throws ProfitMandiBusinessException, MessagingException, IOException {
|
4272 |
public void notifyDefaultLoans() throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 4439 |
synchronized (SD_CREDIT_LOCK) {
|
4273 |
synchronized (SD_CREDIT_LOCK) {
|
| 4440 |
sdCreditService.updateRisk();
|
4274 |
sdCreditService.updateRisk();
|
| 4441 |
List<Loan> defaultLoans = sdCreditService.getDefaultLoans();
|
4275 |
List<Loan> defaultLoans = sdCreditService.getDefaultLoans();
|
| 4442 |
if (!defaultLoans.isEmpty()) {
|
4276 |
if (!defaultLoans.isEmpty()) {
|