| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.math.BigDecimal;
|
- |
|
| 4 |
import java.math.RoundingMode;
|
- |
|
| 5 |
import java.time.Duration;
|
- |
|
| 6 |
import java.time.LocalDate;
|
- |
|
| 7 |
import java.time.LocalDateTime;
|
- |
|
| 8 |
import java.time.LocalTime;
|
- |
|
| 9 |
import java.time.temporal.ChronoUnit;
|
- |
|
| 10 |
import java.util.ArrayList;
|
- |
|
| 11 |
import java.util.Arrays;
|
- |
|
| 12 |
import java.util.HashMap;
|
- |
|
| 13 |
import java.util.HashSet;
|
- |
|
| 14 |
import java.util.List;
|
- |
|
| 15 |
import java.util.Map;
|
- |
|
| 16 |
import java.util.Map.Entry;
|
- |
|
| 17 |
import java.util.Set;
|
- |
|
| 18 |
import java.util.stream.Collectors;
|
- |
|
| 19 |
|
- |
|
| 20 |
import javax.servlet.http.HttpServletRequest;
|
- |
|
| 21 |
import javax.transaction.Transactional;
|
- |
|
| 22 |
|
- |
|
| 23 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 24 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 25 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 26 |
import org.springframework.mail.javamail.JavaMailSender;
|
- |
|
| 27 |
import org.springframework.stereotype.Controller;
|
- |
|
| 28 |
import org.springframework.ui.Model;
|
- |
|
| 29 |
import org.springframework.web.bind.annotation.RequestBody;
|
- |
|
| 30 |
import org.springframework.web.bind.annotation.RequestMapping;
|
- |
|
| 31 |
import org.springframework.web.bind.annotation.RequestMethod;
|
- |
|
| 32 |
import org.springframework.web.bind.annotation.RequestParam;
|
- |
|
| 33 |
|
- |
|
| 34 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
3 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 36 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
5 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 37 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
6 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 38 |
import com.spice.profitmandi.common.util.Utils;
|
7 |
import com.spice.profitmandi.common.util.Utils;
|
| Line 40... |
Line 9... |
| 40 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
9 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
| 41 |
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
|
10 |
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
|
| 42 |
import com.spice.profitmandi.dao.entity.fofo.CurrentPartnerDailyInvestment;
|
11 |
import com.spice.profitmandi.dao.entity.fofo.CurrentPartnerDailyInvestment;
|
| 43 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
12 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 44 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
13 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 45 |
import com.spice.profitmandi.dao.entity.transaction.Loan;
|
14 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
| 46 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
- |
|
| 47 |
import com.spice.profitmandi.dao.entity.transaction.SDCreditRequirement;
|
- |
|
| 48 |
import com.spice.profitmandi.dao.entity.transaction.SanctionRequest;
|
- |
|
| 49 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
- |
|
| 50 |
import com.spice.profitmandi.dao.entity.user.Address;
|
15 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 51 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
16 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
| 52 |
import com.spice.profitmandi.dao.enumuration.transaction.LoanSummaryType;
|
17 |
import com.spice.profitmandi.dao.enumuration.transaction.LoanSummaryType;
|
| 53 |
import com.spice.profitmandi.dao.enumuration.transaction.SanctionStatus;
|
18 |
import com.spice.profitmandi.dao.enumuration.transaction.SanctionStatus;
|
| 54 |
import com.spice.profitmandi.dao.model.FofoReportingModel;
|
19 |
import com.spice.profitmandi.dao.model.*;
|
| 55 |
import com.spice.profitmandi.dao.model.SDCreditResponseOut;
|
- |
|
| 56 |
import com.spice.profitmandi.dao.model.SanctionRequestModel;
|
- |
|
| 57 |
import com.spice.profitmandi.dao.model.SdCreditRequirementModel;
|
- |
|
| 58 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
20 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 59 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
21 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 60 |
import com.spice.profitmandi.dao.repository.cs.CsService1;
|
22 |
import com.spice.profitmandi.dao.repository.cs.CsService1;
|
| 61 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
23 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
| 62 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
24 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 63 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
25 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 64 |
import com.spice.profitmandi.dao.repository.fofo.CurrentPartnerDailyInvestmentRepository;
|
26 |
import com.spice.profitmandi.dao.repository.fofo.CurrentPartnerDailyInvestmentRepository;
|
| 65 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
27 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 66 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
28 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 67 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
29 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
| 68 |
import com.spice.profitmandi.dao.repository.transaction.LoanStatementRepository;
|
- |
|
| 69 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
- |
|
| 70 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
- |
|
| 71 |
import com.spice.profitmandi.dao.repository.transaction.SanctionRequestRepository;
|
- |
|
| 72 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
- |
|
| 73 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
30 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 74 |
import com.spice.profitmandi.service.NotificationService;
|
31 |
import com.spice.profitmandi.service.NotificationService;
|
| 75 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
32 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
| 76 |
import com.spice.profitmandi.service.user.RetailerService;
|
33 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 77 |
import com.spice.profitmandi.service.user.UserService;
|
34 |
import com.spice.profitmandi.service.user.UserService;
|
| 78 |
import com.spice.profitmandi.web.model.LoginDetails;
|
35 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 79 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
36 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 80 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
37 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| - |
|
38 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
39 |
import org.apache.logging.log4j.Logger;
|
| - |
|
40 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
41 |
import org.springframework.mail.javamail.JavaMailSender;
|
| - |
|
42 |
import org.springframework.stereotype.Controller;
|
| - |
|
43 |
import org.springframework.ui.Model;
|
| - |
|
44 |
import org.springframework.web.bind.annotation.RequestBody;
|
| - |
|
45 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| - |
|
46 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| - |
|
47 |
import org.springframework.web.bind.annotation.RequestParam;
|
| - |
|
48 |
|
| - |
|
49 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
50 |
import javax.transaction.Transactional;
|
| - |
|
51 |
import java.math.BigDecimal;
|
| - |
|
52 |
import java.math.RoundingMode;
|
| - |
|
53 |
import java.time.Duration;
|
| - |
|
54 |
import java.time.LocalDate;
|
| - |
|
55 |
import java.time.LocalDateTime;
|
| - |
|
56 |
import java.time.LocalTime;
|
| - |
|
57 |
import java.time.temporal.ChronoUnit;
|
| - |
|
58 |
import java.util.*;
|
| - |
|
59 |
import java.util.Map.Entry;
|
| - |
|
60 |
import java.util.stream.Collectors;
|
| 81 |
|
61 |
|
| 82 |
@Controller
|
62 |
@Controller
|
| 83 |
@Transactional(rollbackOn = Throwable.class)
|
63 |
@Transactional(rollbackOn = Throwable.class)
|
| 84 |
public class SDCreditController {
|
64 |
public class SDCreditController {
|
| 85 |
|
65 |
|
| Line 272... |
Line 252... |
| 272 |
List<Integer> fofoIds = sanctionRequests.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
252 |
List<Integer> fofoIds = sanctionRequests.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 273 |
|
253 |
|
| 274 |
Map<Integer, Long> partnerCreditDaysMap = new HashMap<>();
|
254 |
Map<Integer, Long> partnerCreditDaysMap = new HashMap<>();
|
| 275 |
|
255 |
|
| 276 |
Map<Integer, Integer> partnerActiveLoanMap = new HashMap<>();
|
256 |
Map<Integer, Integer> partnerActiveLoanMap = new HashMap<>();
|
| - |
|
257 |
Map<Integer, Integer> partnerAverageCreditDaysMap = new HashMap<>();
|
| 277 |
|
258 |
|
| 278 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
259 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 279 |
|
260 |
|
| 280 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
261 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
| 281 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
262 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
| Line 283... |
Line 264... |
| 283 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), 0, false);
|
264 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), 0, false);
|
| 284 |
|
265 |
|
| 285 |
Map<Integer, Double> lmsSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
266 |
Map<Integer, Double> lmsSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
| 286 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), 0, false);
|
267 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), 0, false);
|
| 287 |
|
268 |
|
| - |
|
269 |
List<Loan> loans = loanRepository.selectAllLoans(fofoIds, DateRangeModel.withStartDate(curDate.minusYears(2)));
|
| - |
|
270 |
Map<Integer, List<Loan>> partnerClosedLoansMap = loans.stream().filter(x -> x.getPendingAmount().equals(BigDecimal.ZERO)).collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 288 |
|
271 |
|
| 289 |
for (Integer fofoId : fofoIds) {
|
- |
|
| 290 |
List<Loan> loans = loanRepository.selectActiveLoan(fofoId);
|
- |
|
| 291 |
|
272 |
|
| - |
|
273 |
Map<Integer, List<Loan>> activeLoansMap = loans.stream().filter(x -> !x.getPendingAmount().equals(BigDecimal.ZERO)).collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 292 |
|
274 |
|
| - |
|
275 |
for (Integer fofoId : fofoIds) {
|
| - |
|
276 |
List<Loan> activeLoans = activeLoansMap.get(fofoId);
|
| 293 |
if (!loans.isEmpty()) {
|
277 |
if (activeLoans != null) {
|
| 294 |
|
- |
|
| 295 |
partnerActiveLoanMap.put(fofoId, loans.size());
|
278 |
partnerActiveLoanMap.put(fofoId, activeLoans.size());
|
| 296 |
Loan loan = loans.get(loans.size() - 1);
|
279 |
Loan loan = activeLoans.get(0);
|
| 297 |
|
- |
|
| 298 |
long daysBetween = Duration.between(loan.getCreatedOn(), LocalDateTime.now()).toDays();
|
280 |
long daysBetween = Duration.between(loan.getCreatedOn(), LocalDateTime.now()).toDays();
|
| 299 |
|
- |
|
| 300 |
partnerCreditDaysMap.put(fofoId, daysBetween);
|
281 |
partnerCreditDaysMap.put(fofoId, daysBetween);
|
| 301 |
|
- |
|
| 302 |
}
|
282 |
}
|
| 303 |
model.addAttribute("partnerCreditDaysMap", partnerCreditDaysMap);
|
283 |
List<Loan> closedLoans = partnerClosedLoansMap.get(fofoId);
|
| - |
|
284 |
if (closedLoans != null) {
|
| - |
|
285 |
long averageCreditDays = Math.round(closedLoans.stream().mapToLong(x -> Duration.between(x.getCreatedOn(),
|
| - |
|
286 |
x.getSettledOn() == null ? x.getCreatedOn().plusDays(10) : x.getSettledOn()).toDays()).average().orElse(0.0));
|
| 304 |
model.addAttribute("partnerActiveLoanMap", partnerActiveLoanMap);
|
287 |
partnerAverageCreditDaysMap.put(fofoId, (int) averageCreditDays);
|
| - |
|
288 |
}
|
| 305 |
|
289 |
|
| 306 |
}
|
290 |
}
|
| - |
|
291 |
model.addAttribute("partnerActiveLoanMap", partnerActiveLoanMap);
|
| - |
|
292 |
model.addAttribute("partnerCreditDaysMap", partnerCreditDaysMap);
|
| - |
|
293 |
model.addAttribute("partnerAverageCreditDaysMap", partnerAverageCreditDaysMap);
|
| 307 |
|
294 |
|
| 308 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
295 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 309 |
|
296 |
|
| 310 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds)).stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
297 |
Map<Integer, UserWallet> userWalletMap = userWalletRepository.selectByRetailerIds(new HashSet<>(fofoIds)).stream().collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
| 311 |
|
298 |
|