Subversion Repositories SmartDukaan

Rev

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

Rev 34550 Rev 34568
Line 1... Line 1...
1
package com.spice.profitmandi.dao.service;
1
package com.spice.profitmandi.dao.service;
2
 
2
 
3
import com.spice.profitmandi.common.enumuration.MessageType;
3
import com.spice.profitmandi.common.enumuration.MessageType;
-
 
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
5
import com.spice.profitmandi.common.model.CustomRetailer;
4
import com.spice.profitmandi.common.model.ProfitMandiConstants;
6
import com.spice.profitmandi.common.model.ProfitMandiConstants;
5
import com.spice.profitmandi.common.model.SendNotificationModel;
7
import com.spice.profitmandi.common.model.SendNotificationModel;
6
import com.spice.profitmandi.common.util.StringUtils;
8
import com.spice.profitmandi.common.util.StringUtils;
7
import com.spice.profitmandi.common.util.Utils;
9
import com.spice.profitmandi.common.util.Utils;
8
import com.spice.profitmandi.dao.entity.auth.AuthUser;
10
import com.spice.profitmandi.dao.entity.auth.AuthUser;
Line 17... Line 19...
17
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
19
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
18
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
20
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
19
import com.spice.profitmandi.dao.repository.user.UserRepository;
21
import com.spice.profitmandi.dao.repository.user.UserRepository;
20
import com.spice.profitmandi.service.AuthService;
22
import com.spice.profitmandi.service.AuthService;
21
import com.spice.profitmandi.service.NotificationService;
23
import com.spice.profitmandi.service.NotificationService;
-
 
24
import com.spice.profitmandi.service.user.RetailerService;
22
import com.spice.profitmandi.service.whatsapp.WhatsappMessageType;
25
import com.spice.profitmandi.service.whatsapp.WhatsappMessageType;
23
import org.apache.logging.log4j.LogManager;
26
import org.apache.logging.log4j.LogManager;
24
import org.apache.logging.log4j.Logger;
27
import org.apache.logging.log4j.Logger;
25
import org.springframework.beans.factory.annotation.Autowired;
28
import org.springframework.beans.factory.annotation.Autowired;
26
import org.springframework.mail.javamail.JavaMailSender;
29
import org.springframework.mail.javamail.JavaMailSender;
Line 55... Line 58...
55
    NotificationService notificationService;
58
    NotificationService notificationService;
56
    @Autowired
59
    @Autowired
57
    private UserAccountRepository userAccountRepository;
60
    private UserAccountRepository userAccountRepository;
58
    @Autowired
61
    @Autowired
59
    private FofoStoreRepository fofoStoreRepository;
62
    private FofoStoreRepository fofoStoreRepository;
-
 
63
    @Autowired
-
 
64
    private RetailerService retailerService;
60
 
65
 
61
    @Override
66
    @Override
62
    public void sendMailToRBM(double netAmountInHand, double totalPayableAmount, int fofoId) throws Exception {
67
    public void sendMailToRBM(double netAmountInHand, double totalPayableAmount, int fofoId) throws Exception {
63
        User user = userRepository.selectById(fofoId);
68
        User user = userRepository.selectById(fofoId);
64
        int rbmId = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
69
        int rbmId = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
Line 82... Line 87...
82
 
87
 
83
    @Override
88
    @Override
84
    public void sendSummaryMailToUserAndManagers(int userId, List<Bid> bids, Liquidation liquidation) throws Exception {
89
    public void sendSummaryMailToUserAndManagers(int userId, List<Bid> bids, Liquidation liquidation) throws Exception {
85
        String content = this.generateContent(bids, liquidation, ProfitMandiConstants.BID_ENUM.CLOSED);
90
        String content = this.generateContent(bids, liquidation, ProfitMandiConstants.BID_ENUM.CLOSED);
86
        AuthUser authUser = authRepository.selectById(userId);
91
        AuthUser authUser = authRepository.selectById(userId);
87
        String[] emailTo = {authUser.getEmailId(), "vikas.jangra@smartdukaan.com"};
92
        String[] emailTo = {authUser.getEmailId(), "sourcing@smartdukaan.com", "vikas.jangra@smartdukaan.com"};
88
 
93
 
89
        String[] ccTo = authService.getAllManagers(userId).stream().map(AuthUser::getEmailId).toArray(String[]::new);
94
        String[] ccTo = authService.getAllManagers(userId).stream().map(AuthUser::getEmailId).toArray(String[]::new);
90
        String subject = "Liquidation Report";
95
        String subject = "Liquidation Report";
91
        String message = "Dear Team,\n\n"
96
        String message = "Dear Team,\n\n"
92
                + "Liquidation has been completed. Here is the summary:\n\n"
97
                + "Liquidation has been completed. Here is the summary:\n\n"
Line 138... Line 143...
138
        sendNotificationModel.setUserIds(userIds);
143
        sendNotificationModel.setUserIds(userIds);
139
        notificationService.sendNotification(sendNotificationModel);
144
        notificationService.sendNotification(sendNotificationModel);
140
        notificationService.sendNotificationToSystemUsers(sendNotificationModel);
145
        notificationService.sendNotificationToSystemUsers(sendNotificationModel);
141
    }
146
    }
142
 
147
 
143
    private String generateContent(List<Bid> bids, Liquidation liquidation, ProfitMandiConstants.BID_ENUM status){
148
    private String generateContent(List<Bid> bids, Liquidation liquidation, ProfitMandiConstants.BID_ENUM status) throws ProfitMandiBusinessException {
-
 
149
        Map<Integer, CustomRetailer> retailers = retailerService.getAllFofoRetailers();
144
        StringBuilder sb = new StringBuilder();
150
        StringBuilder sb = new StringBuilder();
145
        sb.append("<h4>Bidding Summary</h3>");
151
        sb.append("<h4>Bidding Summary</h3>");
146
        sb.append("<p><strong>Liquidation ID:</strong> ").append(liquidation.getId()).append("</p>");
152
        sb.append("<p><strong>Liquidation ID:</strong> ").append(liquidation.getId()).append("</p>");
147
        sb.append("<p><strong>Catalog ID:</strong> ").append(liquidation.getCatalogId()).append("</p>");
153
        sb.append("<p><strong>Catalog ID:</strong> ").append(liquidation.getCatalogId()).append("</p>");
148
        sb.append("<p><strong>Total Quantity Available:</strong> ").append(liquidation.getQuantity()).append("</p>");
154
        sb.append("<p><strong>Total Quantity Available:</strong> ").append(liquidation.getQuantity()).append("</p>");
149
        sb.append("<p><strong>End Date:</strong> ").append(liquidation.getEndDate()).append("</p>");
155
        sb.append("<p><strong>End Date:</strong> ").append(liquidation.getEndDate()).append("</p>");
150
 
156
 
151
        sb.append("<table border='1' cellpadding='5' cellspacing='0' style='border-collapse: collapse;'>");
157
        sb.append("<table border='1' cellpadding='5' cellspacing='0' style='border-collapse: collapse;'>");
152
        sb.append("<thead>");
158
        sb.append("<thead>");
153
        sb.append("<tr>")
159
        sb.append("<tr>")
154
                .append("<th>Bidder ID (Fofo)</th>")
160
                .append("<th>Bidder</th>")
155
                .append("<th>Item Name</th>")
161
                .append("<th>Item Name</th>")
156
                .append("<th>Bid Amount</th>")
162
                .append("<th>Bid Amount</th>")
157
                .append("<th>Quantity</th>")
163
                .append("<th>Quantity</th>")
158
                .append("<th>Status</th>")
164
                .append("<th>Status</th>")
159
                .append("<th>Bid Time</th>")
165
                .append("<th>Bid Time</th>")
Line 161... Line 167...
161
        sb.append("</thead>");
167
        sb.append("</thead>");
162
        sb.append("<tbody>");
168
        sb.append("<tbody>");
163
 
169
 
164
        for (Bid bid : bids) {
170
        for (Bid bid : bids) {
165
            sb.append("<tr>")
171
            sb.append("<tr>")
166
                    .append("<td>").append(bid.getFofoId()).append("</td>")
172
                    .append("<td>").append(retailers.get(bid.getFofoId()).getDisplayName()).append("</td>")
167
                    .append("<td>").append(bid.getItemName() != null ? bid.getItemName() : "-").append("</td>")
173
                    .append("<td>").append(bid.getItemName() != null ? bid.getItemName() : "-").append("</td>")
168
                    .append("<td>").append(bid.getBiddingAmount()).append("</td>")
174
                    .append("<td>").append(bid.getBiddingAmount()).append("</td>")
169
                    .append("<td>").append(bid.getQuantity()).append("</td>")
175
                    .append("<td>").append(bid.getQuantity()).append("</td>")
170
                    .append("<td>").append(bid.getStatus().name()).append("</td>")
176
                    .append("<td>").append(bid.getStatus().name()).append("</td>")
171
                    .append("<td>").append(bid.getCreatedAt()).append("</td>")
177
                    .append("<td>").append(bid.getCreatedAt()).append("</td>")