Subversion Repositories SmartDukaan

Rev

Rev 36503 | Rev 36561 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36503 Rev 36556
Line 3973... Line 3973...
3973
        }
3973
        }
3974
 
3974
 
3975
 
3975
 
3976
    }
3976
    }
3977
 
3977
 
-
 
3978
    public void convertExpiredFlagshipCredits() {
-
 
3979
        synchronized (SD_CREDIT_LOCK) {
-
 
3980
            try {
-
 
3981
                sdCreditService.convertExpiredFlagshipCredits();
-
 
3982
            } catch (Exception e) {
-
 
3983
                LOGGER.error("Error converting expired flagship credits", e);
-
 
3984
            }
-
 
3985
        }
-
 
3986
    }
-
 
3987
 
-
 
3988
    public void notifyFlagshipExpiryIn2Days() {
-
 
3989
        try {
-
 
3990
            java.time.LocalDate expiryDate = java.time.LocalDate.now().plusDays(2);
-
 
3991
            List<Loan> expiringLoans = loanRepository.selectFlagshipLoansExpiringOn(expiryDate);
-
 
3992
            LOGGER.info("Found {} flagship credits expiring on {}", expiringLoans.size(), expiryDate);
-
 
3993
 
-
 
3994
            Map<Integer, List<Loan>> byPartner = expiringLoans.stream()
-
 
3995
                    .collect(java.util.stream.Collectors.groupingBy(Loan::getFofoId));
-
 
3996
 
-
 
3997
            for (Map.Entry<Integer, List<Loan>> entry : byPartner.entrySet()) {
-
 
3998
                int fofoId = entry.getKey();
-
 
3999
                List<Loan> loans = entry.getValue();
-
 
4000
                double totalAmount = loans.stream().mapToDouble(l -> l.getPendingAmount().doubleValue()).sum();
-
 
4001
 
-
 
4002
                String title = "Flagship Credit Expiring Soon";
-
 
4003
                String message = String.format(
-
 
4004
                        "Your flagship credit of Rs.%.0f will convert to a regular loan on %s. " +
-
 
4005
                        "Sell the items before then to avoid interest charges.",
-
 
4006
                        totalAmount, expiryDate.format(java.time.format.DateTimeFormatter.ofPattern("dd-MMM-yyyy")));
-
 
4007
 
-
 
4008
                try {
-
 
4009
                    int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
-
 
4010
                    SendNotificationModel model = new SendNotificationModel();
-
 
4011
                    model.setCampaignName("Flagship credit expiry reminder");
-
 
4012
                    model.setTitle(title);
-
 
4013
                    model.setMessage(message);
-
 
4014
                    model.setType("url");
-
 
4015
                    model.setUrl("https://app.smartdukaan.com/pages/home/credit");
-
 
4016
                    model.setExpiresat(java.time.LocalDateTime.now().plusDays(2));
-
 
4017
                    model.setMessageType(MessageType.reminder);
-
 
4018
                    model.setUserIds(java.util.Arrays.asList(userId));
-
 
4019
                    notificationService.sendNotification(model);
-
 
4020
                } catch (Exception e) {
-
 
4021
                    LOGGER.error("Failed to send flagship expiry notification to fofoId {}", fofoId, e);
-
 
4022
                }
-
 
4023
            }
-
 
4024
        } catch (Exception e) {
-
 
4025
            LOGGER.error("Error sending flagship expiry notifications", e);
-
 
4026
        }
-
 
4027
    }
-
 
4028
 
3978
    public void dailyLoanAlert() throws Exception {
4029
    public void dailyLoanAlert() throws Exception {
3979
        List<Loan> loans = loanRepository.selectAllActiveLoan();
4030
        List<Loan> loans = loanRepository.selectAllActiveLoan();
3980
 
4031
 
3981
        Map<Integer, Double> partnerLoanAmount = new HashMap<>();
4032
        Map<Integer, Double> partnerLoanAmount = new HashMap<>();
3982
 
4033