| 34468 |
vikas.jang |
1 |
package com.spice.profitmandi.dao.service;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 34492 |
vikas.jang |
4 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 34468 |
vikas.jang |
5 |
import com.spice.profitmandi.common.util.Utils;
|
|
|
6 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
7 |
import com.spice.profitmandi.dao.entity.catalog.Bid;
|
|
|
8 |
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
|
| 34492 |
vikas.jang |
9 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 34468 |
vikas.jang |
10 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
|
|
11 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
12 |
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
|
|
|
13 |
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 34492 |
vikas.jang |
15 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 34468 |
vikas.jang |
16 |
import com.spice.profitmandi.service.AuthService;
|
|
|
17 |
import com.spice.profitmandi.service.NotificationService;
|
|
|
18 |
import org.apache.logging.log4j.LogManager;
|
|
|
19 |
import org.apache.logging.log4j.Logger;
|
|
|
20 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
21 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
22 |
import org.springframework.stereotype.Component;
|
|
|
23 |
|
|
|
24 |
import java.util.ArrayList;
|
|
|
25 |
import java.util.List;
|
|
|
26 |
|
|
|
27 |
@Component
|
|
|
28 |
public class BidServiceImpl implements BidService {
|
|
|
29 |
private static final Logger LOGGER = LogManager.getLogger(BidServiceImpl.class);
|
|
|
30 |
@Autowired
|
|
|
31 |
AuthRepository authRepository;
|
|
|
32 |
@Autowired
|
|
|
33 |
AuthService authService;
|
|
|
34 |
@Autowired
|
|
|
35 |
JavaMailSender mailSender;
|
|
|
36 |
@Autowired
|
|
|
37 |
UserRepository userRepository;
|
|
|
38 |
@Autowired
|
|
|
39 |
CsService csService;
|
|
|
40 |
@Autowired
|
|
|
41 |
BidRepository bidRepository;
|
|
|
42 |
@Autowired
|
|
|
43 |
LiquidationRepository liquidationRepository;
|
|
|
44 |
@Autowired
|
|
|
45 |
NotificationService notificationService;
|
|
|
46 |
|
|
|
47 |
@Override
|
|
|
48 |
public void sendMailToRBM(double netAmountInHand, double totalPayableAmount, int fofoId) throws Exception {
|
|
|
49 |
User user = userRepository.selectById(fofoId);
|
|
|
50 |
int rbmId = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
|
|
|
51 |
AuthUser authUser = authRepository.selectById(rbmId);
|
|
|
52 |
|
|
|
53 |
String[] emailTo = new String[] { authUser.getEmailId() };
|
|
|
54 |
//String[] emailTo = new String[] { "vjangra856@gmail.com" };
|
|
|
55 |
|
|
|
56 |
String[] ccTo = {user.getEmailId()};
|
|
|
57 |
String subject = "Dispatch On Hold(Bidding)";
|
|
|
58 |
String message = String.format(
|
|
|
59 |
"Dear Team,\n\n"
|
|
|
60 |
+ "This is to inform you that the material for %s, valued at Rs.%s, "
|
|
|
61 |
+ "is on hold until the payment against the stock is received. Kindly "
|
|
|
62 |
+ "top up your wallet with an amount of Rs.%s to proceed with the dispatch.",
|
| 34492 |
vikas.jang |
63 |
user.getName(), totalPayableAmount, (totalPayableAmount - netAmountInHand)
|
| 34468 |
vikas.jang |
64 |
);
|
|
|
65 |
|
|
|
66 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
@Override
|
|
|
70 |
public void sendSummaryMailToUserAndManagers(int userId, List<Bid> bids, Liquidation liquidation) throws Exception {
|
|
|
71 |
String content = this.generateContent(bids, liquidation, ProfitMandiConstants.BID_ENUM.CLOSED);
|
|
|
72 |
AuthUser authUser = authRepository.selectById(userId);
|
| 34492 |
vikas.jang |
73 |
//String[] emailTo = {"vikas.jangra@smartdukaan.com"};
|
|
|
74 |
String[] emailTo = {authUser.getEmailId(), "vikas.jangra@smartdukaan.com"};
|
| 34468 |
vikas.jang |
75 |
|
|
|
76 |
String[] ccTo = authService.getAllManagers(userId).stream().map(AuthUser::getEmailId).toArray(String[]::new);
|
|
|
77 |
String subject = "Liquidation Report";
|
|
|
78 |
String message = "Dear Team,\n\n"
|
|
|
79 |
+ "Liquidation has been completed. Here is the summary:\n\n"
|
|
|
80 |
+ content;
|
|
|
81 |
|
|
|
82 |
LOGGER.info("mailMessage: {}",message);
|
|
|
83 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
@Override
|
| 34492 |
vikas.jang |
87 |
public void notifyPartner(int userId, Bid bid, ProfitMandiConstants.BID_ENUM status) throws Exception {
|
| 34468 |
vikas.jang |
88 |
User user = userRepository.selectById(userId);
|
| 34492 |
vikas.jang |
89 |
List<Bid> topBid = bidRepository.selectBidByLiquidationId(bid.getLiquidationId());
|
|
|
90 |
String message = this.generateWhatsAppBidMessage(user.getName(), bid, topBid.get(0).getBiddingAmount(), status);
|
|
|
91 |
String mobile = user.getMobileNumber();
|
|
|
92 |
notificationService.sendWhatsappMessage(message, "Bid Update!", mobile);
|
| 34468 |
vikas.jang |
93 |
}
|
|
|
94 |
|
|
|
95 |
private String generateContent(List<Bid> bids, Liquidation liquidation, ProfitMandiConstants.BID_ENUM status){
|
|
|
96 |
StringBuilder sb = new StringBuilder();
|
|
|
97 |
sb.append("<h4>Bidding Summary</h3>");
|
|
|
98 |
sb.append("<p><strong>Liquidation ID:</strong> ").append(liquidation.getId()).append("</p>");
|
|
|
99 |
sb.append("<p><strong>Catalog ID:</strong> ").append(liquidation.getCatalogId()).append("</p>");
|
|
|
100 |
sb.append("<p><strong>Total Quantity Available:</strong> ").append(liquidation.getQuantity()).append("</p>");
|
|
|
101 |
sb.append("<p><strong>End Date:</strong> ").append(liquidation.getEndDate()).append("</p>");
|
|
|
102 |
|
|
|
103 |
sb.append("<table border='1' cellpadding='5' cellspacing='0' style='border-collapse: collapse;'>");
|
|
|
104 |
sb.append("<thead>");
|
|
|
105 |
sb.append("<tr>")
|
|
|
106 |
.append("<th>Bidder ID (Fofo)</th>")
|
|
|
107 |
.append("<th>Item Name</th>")
|
|
|
108 |
.append("<th>Bid Amount</th>")
|
|
|
109 |
.append("<th>Quantity</th>")
|
|
|
110 |
.append("<th>Status</th>")
|
|
|
111 |
.append("<th>Bid Time</th>")
|
|
|
112 |
.append("</tr>");
|
|
|
113 |
sb.append("</thead>");
|
|
|
114 |
sb.append("<tbody>");
|
|
|
115 |
|
|
|
116 |
for (Bid bid : bids) {
|
|
|
117 |
sb.append("<tr>")
|
|
|
118 |
.append("<td>").append(bid.getFofoId()).append("</td>")
|
|
|
119 |
.append("<td>").append(bid.getItemName() != null ? bid.getItemName() : "-").append("</td>")
|
|
|
120 |
.append("<td>").append(bid.getBiddingAmount()).append("</td>")
|
|
|
121 |
.append("<td>").append(bid.getQuantity()).append("</td>")
|
|
|
122 |
.append("<td>").append(bid.getStatus().name()).append("</td>")
|
|
|
123 |
.append("<td>").append(bid.getCreatedAt()).append("</td>")
|
|
|
124 |
.append("</tr>");
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
sb.append("</tbody>");
|
|
|
128 |
sb.append("</table>");
|
|
|
129 |
|
|
|
130 |
return sb.toString();
|
|
|
131 |
}
|
|
|
132 |
|
| 34492 |
vikas.jang |
133 |
public void cancelYesterdayProcessBid(Bid bid) throws Exception {
|
| 34468 |
vikas.jang |
134 |
bid.setStatus(ProfitMandiConstants.BID_ENUM.CANCELLED);
|
|
|
135 |
Liquidation liquidation = liquidationRepository.selectLiquidationById(bid.getLiquidationId());
|
|
|
136 |
List<Bid> bids = bidRepository.selectBidByLiquidationId(bid.getLiquidationId());
|
|
|
137 |
this.sendSummaryMailToUserAndManagers(liquidation.getCreatedBy(), bids, liquidation);
|
| 34492 |
vikas.jang |
138 |
this.notifyPartner(bid.getFofoId(), bid, ProfitMandiConstants.BID_ENUM.CANCELLED);
|
| 34468 |
vikas.jang |
139 |
}
|
|
|
140 |
|
| 34492 |
vikas.jang |
141 |
private String generateWhatsAppBidMessage(String fofoName, Bid bidData, double topBidAmount, ProfitMandiConstants.BID_ENUM status) {
|
|
|
142 |
String bidTime = StringUtils.toLocalDateTime(String.valueOf(bidData.getCreatedAt()));
|
|
|
143 |
String bidAmount = String.format("%.2f", bidData.getBiddingAmount());
|
| 34468 |
vikas.jang |
144 |
|
| 34492 |
vikas.jang |
145 |
String message = "";
|
| 34468 |
vikas.jang |
146 |
|
| 34492 |
vikas.jang |
147 |
if (status.equals(ProfitMandiConstants.BID_ENUM.CLOSED)) {
|
|
|
148 |
message = "Congratulations! %s,"+ "\n"+
|
|
|
149 |
"\n"+
|
|
|
150 |
"Your bid for %s has been confirmed!\n" +
|
|
|
151 |
"\n"+
|
|
|
152 |
"Bid Details:\n" +
|
|
|
153 |
"* Bid Amount: ₹%s\n" +
|
|
|
154 |
"* Quantity: %s\n" +
|
|
|
155 |
"* Bid Time: %s\n" +
|
|
|
156 |
"\n"+
|
|
|
157 |
"Thank you for participating. We'll dispatch your order soon.";
|
|
|
158 |
message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime);
|
| 34468 |
vikas.jang |
159 |
}
|
| 34492 |
vikas.jang |
160 |
else if (status.equals(ProfitMandiConstants.BID_ENUM.CANCELLED)) {
|
|
|
161 |
message = "Hi %s,"+ "\n"+
|
|
|
162 |
"\n"+
|
|
|
163 |
"We regret to inform you that your bid for %s was not selected this time.\n" +
|
|
|
164 |
"\n"+
|
|
|
165 |
"Bid Details:\n" +
|
|
|
166 |
"* Bid Amount: ₹%s\n" +
|
|
|
167 |
"* Quantity: %s\n" +
|
|
|
168 |
"* Bid Time: %s\n" +
|
|
|
169 |
"* Qualified Bid Amount: ₹%s\n" +
|
|
|
170 |
"\n"+
|
|
|
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)) {
|
|
|
175 |
message = "Hi %s,"+ "\n"+
|
|
|
176 |
"\n"+
|
|
|
177 |
"Your bid for %s has been placed successfully!\n" +
|
|
|
178 |
"\n"+
|
|
|
179 |
"Bid Details:\n" +
|
|
|
180 |
"* Bid Amount: ₹%s\n" +
|
|
|
181 |
"* Quantity: %s\n" +
|
|
|
182 |
"* Bid Time: %s\n" +
|
|
|
183 |
"\n"+
|
|
|
184 |
"We'll keep you updated. You'll be notified once the bidding period ends.";
|
|
|
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"+
|
|
|
190 |
"A higher bid has been placed for %s. Don't miss your chance!\n" +
|
|
|
191 |
"\n"+
|
|
|
192 |
"Your Bid Details:\n" +
|
|
|
193 |
"* Bid Amount: ₹%s\n" +
|
|
|
194 |
"* Quantity: %s\n" +
|
|
|
195 |
"* Bid Time: %s\n" +
|
|
|
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));
|
|
|
200 |
}
|
| 34468 |
vikas.jang |
201 |
|
| 34492 |
vikas.jang |
202 |
return message;
|
| 34468 |
vikas.jang |
203 |
}
|
| 34492 |
vikas.jang |
204 |
|
| 34468 |
vikas.jang |
205 |
}
|