Subversion Repositories SmartDukaan

Rev

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

Rev 34470 Rev 34492
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.model.ProfitMandiConstants;
3
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
4
import com.spice.profitmandi.common.util.StringUtils;
4
import com.spice.profitmandi.common.util.Utils;
5
import com.spice.profitmandi.common.util.Utils;
5
import com.spice.profitmandi.dao.entity.auth.AuthUser;
6
import com.spice.profitmandi.dao.entity.auth.AuthUser;
6
import com.spice.profitmandi.dao.entity.catalog.Bid;
7
import com.spice.profitmandi.dao.entity.catalog.Bid;
7
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
8
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
8
import com.spice.profitmandi.dao.entity.dtr.User;
9
import com.spice.profitmandi.dao.entity.user.User;
9
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
10
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
10
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
11
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
11
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
12
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
12
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
13
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
13
import com.spice.profitmandi.dao.repository.cs.CsService;
14
import com.spice.profitmandi.dao.repository.cs.CsService;
14
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
15
import com.spice.profitmandi.dao.repository.user.UserRepository;
15
import com.spice.profitmandi.service.AuthService;
16
import com.spice.profitmandi.service.AuthService;
16
import com.spice.profitmandi.service.NotificationService;
17
import com.spice.profitmandi.service.NotificationService;
17
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.Logger;
19
import org.apache.logging.log4j.Logger;
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.beans.factory.annotation.Autowired;
Line 57... Line 58...
57
        String message = String.format(
58
        String message = String.format(
58
                "Dear Team,\n\n"
59
                "Dear Team,\n\n"
59
                        + "This is to inform you that the material for %s, valued at Rs.%s, "
60
                        + "This is to inform you that the material for %s, valued at Rs.%s, "
60
                        + "is on hold until the payment against the stock is received. Kindly "
61
                        + "is on hold until the payment against the stock is received. Kindly "
61
                        + "top up your wallet with an amount of Rs.%s to proceed with the dispatch.",
62
                        + "top up your wallet with an amount of Rs.%s to proceed with the dispatch.",
62
                user.getFirstName() + " " + user.getLastName(), totalPayableAmount, (totalPayableAmount - netAmountInHand)
63
                user.getName(), totalPayableAmount, (totalPayableAmount - netAmountInHand)
63
        );
64
        );
64
 
65
 
65
        Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
66
        Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
66
    }
67
    }
67
 
68
 
68
    @Override
69
    @Override
69
    public void sendSummaryMailToUserAndManagers(int userId, List<Bid> bids, Liquidation liquidation) throws Exception {
70
    public void sendSummaryMailToUserAndManagers(int userId, List<Bid> bids, Liquidation liquidation) throws Exception {
70
        String content = this.generateContent(bids, liquidation, ProfitMandiConstants.BID_ENUM.CLOSED);
71
        String content = this.generateContent(bids, liquidation, ProfitMandiConstants.BID_ENUM.CLOSED);
71
        AuthUser authUser = authRepository.selectById(userId);
72
        AuthUser authUser = authRepository.selectById(userId);
-
 
73
        //String[] emailTo = {"vikas.jangra@smartdukaan.com"};
72
        String[] emailTo = {authUser.getEmailId()};
74
        String[] emailTo = {authUser.getEmailId(), "vikas.jangra@smartdukaan.com"};
73
 
75
 
74
        String[] ccTo = authService.getAllManagers(userId).stream().map(AuthUser::getEmailId).toArray(String[]::new);
76
        String[] ccTo = authService.getAllManagers(userId).stream().map(AuthUser::getEmailId).toArray(String[]::new);
75
        String subject = "Liquidation Report";
77
        String subject = "Liquidation Report";
76
        String message = "Dear Team,\n\n"
78
        String message = "Dear Team,\n\n"
77
                + "Liquidation has been completed. Here is the summary:\n\n"
79
                + "Liquidation has been completed. Here is the summary:\n\n"
Line 80... Line 82...
80
        LOGGER.info("mailMessage: {}",message);
82
        LOGGER.info("mailMessage: {}",message);
81
        Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
83
        Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
82
    }
84
    }
83
 
85
 
84
    @Override
86
    @Override
85
    public void notifyPartner(int userId, List<Bid> bids, Liquidation liquidation, ProfitMandiConstants.BID_ENUM status) throws Exception {
87
    public void notifyPartner(int userId, Bid bid, ProfitMandiConstants.BID_ENUM status) throws Exception {
86
        User user = userRepository.selectById(userId);
88
        User user = userRepository.selectById(userId);
87
        List<Bid> topBid = bidRepository.selectBidByLiquidationId(bids.get(0).getLiquidationId());
89
        List<Bid> topBid = bidRepository.selectBidByLiquidationId(bid.getLiquidationId());
88
        String message = this.generateBidStatusMessage(user.getFirstName()+" "+user.getLastName(), bids.get(0), topBid.get(0).getBiddingAmount());
90
        String message = this.generateWhatsAppBidMessage(user.getName(), bid, topBid.get(0).getBiddingAmount(), status);
-
 
91
        String mobile = user.getMobileNumber();
89
        notificationService.sendWhatsappMessage(message, "Bid Update!", user.getMobileNumber());
92
        notificationService.sendWhatsappMessage(message, "Bid Update!", mobile);
90
    }
93
    }
91
 
94
 
92
    private String generateContent(List<Bid> bids, Liquidation liquidation, ProfitMandiConstants.BID_ENUM status){
95
    private String generateContent(List<Bid> bids, Liquidation liquidation, ProfitMandiConstants.BID_ENUM status){
93
        StringBuilder sb = new StringBuilder();
96
        StringBuilder sb = new StringBuilder();
94
        if (status.equals(ProfitMandiConstants.BID_ENUM.CLOSED)){
-
 
95
            sb.append("<h3>Congratulations your BID has ").append(status).append("</h3>");
-
 
96
        } else {
-
 
97
            sb.append("<h3>Sorry your BID has ").append(status).append("</h3>");
-
 
98
        }
-
 
99
        sb.append("<h4>Bidding Summary</h3>");
97
        sb.append("<h4>Bidding Summary</h3>");
100
        sb.append("<p><strong>Liquidation ID:</strong> ").append(liquidation.getId()).append("</p>");
98
        sb.append("<p><strong>Liquidation ID:</strong> ").append(liquidation.getId()).append("</p>");
101
        sb.append("<p><strong>Catalog ID:</strong> ").append(liquidation.getCatalogId()).append("</p>");
99
        sb.append("<p><strong>Catalog ID:</strong> ").append(liquidation.getCatalogId()).append("</p>");
102
        sb.append("<p><strong>Total Quantity Available:</strong> ").append(liquidation.getQuantity()).append("</p>");
100
        sb.append("<p><strong>Total Quantity Available:</strong> ").append(liquidation.getQuantity()).append("</p>");
103
        sb.append("<p><strong>End Date:</strong> ").append(liquidation.getEndDate()).append("</p>");
101
        sb.append("<p><strong>End Date:</strong> ").append(liquidation.getEndDate()).append("</p>");
Line 130... Line 128...
130
        sb.append("</table>");
128
        sb.append("</table>");
131
 
129
 
132
        return sb.toString();
130
        return sb.toString();
133
    }
131
    }
134
 
132
 
135
    public void cancelYesterdayProcessBid(int id) throws Exception {
133
    public void cancelYesterdayProcessBid(Bid bid) throws Exception {
136
        Bid bid = bidRepository.selectById(id);
-
 
137
        bid.setStatus(ProfitMandiConstants.BID_ENUM.CANCELLED);
134
        bid.setStatus(ProfitMandiConstants.BID_ENUM.CANCELLED);
138
        Liquidation liquidation = liquidationRepository.selectLiquidationById(bid.getLiquidationId());
135
        Liquidation liquidation = liquidationRepository.selectLiquidationById(bid.getLiquidationId());
139
        List<Bid> bids = bidRepository.selectBidByLiquidationId(bid.getLiquidationId());
136
        List<Bid> bids = bidRepository.selectBidByLiquidationId(bid.getLiquidationId());
140
        this.sendSummaryMailToUserAndManagers(liquidation.getCreatedBy(), bids, liquidation);
137
        this.sendSummaryMailToUserAndManagers(liquidation.getCreatedBy(), bids, liquidation);
141
        List<Bid> partnerBid = new ArrayList<>();
-
 
142
        partnerBid.add(bid);
-
 
143
        this.notifyPartner(bid.getFofoId(), partnerBid, liquidation, ProfitMandiConstants.BID_ENUM.CANCELLED);
138
        this.notifyPartner(bid.getFofoId(), bid, ProfitMandiConstants.BID_ENUM.CANCELLED);
144
    }
139
    }
145
 
140
 
146
    private String generateBidStatusMessage(String fofoName, Bid bidData, double topBidAmount) {
141
    private String generateWhatsAppBidMessage(String fofoName, Bid bidData, double topBidAmount, ProfitMandiConstants.BID_ENUM status) {
147
        StringBuilder message = new StringBuilder();
142
        String bidTime = StringUtils.toLocalDateTime(String.valueOf(bidData.getCreatedAt()));
148
        message.append("Hi ").append(fofoName).append(",👋\n\n");
143
        String bidAmount = String.format("%.2f", bidData.getBiddingAmount());
149
 
144
 
150
        switch (bidData.getStatus()) {
145
        String message = "";
-
 
146
 
-
 
147
        if (status.equals(ProfitMandiConstants.BID_ENUM.CLOSED)) {
-
 
148
            message = "Congratulations! %s,"+ "\n"+
151
            case CLOSED:
149
                    "\n"+
152
                message.append("Your bid for ").append(bidData.getItemName()).append(" has been confirmed!🎉\n\n")
150
                    "Your bid for %s has been confirmed!\n" +
-
 
151
                    "\n"+
153
                    .append("🧾Bid Details:\n")
152
                    "Bid Details:\n" +
154
                    .append("* Bid Amount: ₹").append(String.format("%.2f", bidData.getBiddingAmount())).append("\n")
153
                    "* Bid Amount: ₹%s\n" +
155
                    .append("* Quantity: ").append(bidData.getQuantity()).append("\n")
154
                    "* Quantity: %s\n" +
156
                    .append("* Confirmation Date: ").append(bidData.getCreatedAt()).append("\n\n")
155
                    "* Bid Time: %s\n" +
-
 
156
                    "\n"+
157
                    .append("Thank you for participating. We'll dispatch your order soon.");
157
                    "Thank you for participating. We'll dispatch your order soon.";
-
 
158
            message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime);
-
 
159
        }
-
 
160
        else if (status.equals(ProfitMandiConstants.BID_ENUM.CANCELLED)) {
158
                break;
161
            message = "Hi %s,"+ "\n"+
159
 
-
 
160
            case CANCELLED:
162
                    "\n"+
161
                message.append("We regret to inform you that your bid for ").append(bidData.getItemName()).append(" was not selected this time.\n\n")
163
                    "We regret to inform you that your bid for %s was not selected this time.\n" +
-
 
164
                    "\n"+
162
                    .append("🧾Bid Details:\n")
165
                    "Bid Details:\n" +
163
                    .append("* Bid Amount: ₹").append(String.format("%.2f", bidData.getBiddingAmount())).append("\n")
166
                    "* Bid Amount: ₹%s\n" +
164
                    .append("* Quantity: ").append(bidData.getQuantity()).append("\n")
167
                    "* Quantity: %s\n" +
165
                    .append("* Bid Date: ").append(bidData.getCreatedAt()).append("\n")
168
                    "* Bid Time: %s\n" +
166
                        .append("Qualified Bid Amount: ").append(topBidAmount).append("\n\n")
169
                    "* Qualified Bid Amount: ₹%s\n" +
-
 
170
                    "\n"+
167
                    .append("Thank you for your participation. Stay tuned for more opportunities!");
171
                    "Thank you for your participation. Stay tuned for more opportunities!";
-
 
172
            message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime, String.format("%.2f", topBidAmount));
-
 
173
        }
-
 
174
        else if (status.equals(ProfitMandiConstants.BID_ENUM.PENDING)) {
168
                break;
175
            message = "Hi %s,"+ "\n"+
169
 
-
 
170
            case PENDING:
176
                    "\n"+
171
                message.append("Your bid for ").append(bidData.getItemName()).append(" is currently pending.⏳\n\n")
177
                    "Your bid for %s has been placed successfully!\n" +
-
 
178
                    "\n"+
172
                    .append("Bid Details:\n")
179
                    "Bid Details:\n" +
-
 
180
                    "* Bid Amount: ₹%s\n" +
-
 
181
                    "* Quantity: %s\n" +
-
 
182
                    "* Bid Time: %s\n" +
-
 
183
                    "\n"+
173
                    .append("* Bid Amount: ₹").append(String.format("%.2f", bidData.getBiddingAmount())).append("\n")
184
                    "We'll keep you updated. You'll be notified once the bidding period ends.";
174
                    .append("* Quantity: ").append(bidData.getQuantity()).append("\n")
185
            message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime);
-
 
186
        }
-
 
187
        else if (status.equals(ProfitMandiConstants.BID_ENUM.UPDATE)) {
-
 
188
            message = "Hi %s,"+ "\n"+
-
 
189
                    "\n"+
175
                    .append("* Bid Date: ").append(bidData.getCreatedAt()).append("\n\n")
190
                    "A higher bid has been placed for %s. Don't miss your chance!\n" +
-
 
191
                    "\n"+
-
 
192
                    "Your Bid Details:\n" +
176
                    .append("We'll notify you once the bidding period ends.");
193
                    "* Bid Amount: ₹%s\n" +
-
 
194
                    "* Quantity: %s\n" +
-
 
195
                    "* Bid Time: %s\n" +
177
                break;
196
                    "\n"+
-
 
197
                    "Another user has placed a higher bid of ₹%s.\n" +
-
 
198
                    "Update your bid before the bidding ends to stay ahead in the race!";
-
 
199
            message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime, String.format("%.2f", topBidAmount));
178
        }
200
        }
179
 
201
 
180
        return message.toString();
202
        return message;
181
    }
203
    }
-
 
204
 
182
}
205
}