| 34468 |
vikas.jang |
1 |
package com.spice.profitmandi.dao.service;
|
|
|
2 |
|
| 34545 |
vikas.jang |
3 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 34468 |
vikas.jang |
4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 34545 |
vikas.jang |
5 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 34492 |
vikas.jang |
6 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 34468 |
vikas.jang |
7 |
import com.spice.profitmandi.common.util.Utils;
|
|
|
8 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
9 |
import com.spice.profitmandi.dao.entity.catalog.Bid;
|
|
|
10 |
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
|
| 34492 |
vikas.jang |
11 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 34468 |
vikas.jang |
12 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
|
|
13 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
|
|
|
15 |
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
|
|
|
16 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 34545 |
vikas.jang |
17 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
18 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 34492 |
vikas.jang |
19 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 34468 |
vikas.jang |
20 |
import com.spice.profitmandi.service.AuthService;
|
|
|
21 |
import com.spice.profitmandi.service.NotificationService;
|
| 34545 |
vikas.jang |
22 |
import com.spice.profitmandi.service.whatsapp.WhatsappMessageType;
|
| 34468 |
vikas.jang |
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.Component;
|
|
|
28 |
|
| 34545 |
vikas.jang |
29 |
import java.time.LocalDateTime;
|
|
|
30 |
import java.util.Arrays;
|
|
|
31 |
import java.util.Collections;
|
| 34468 |
vikas.jang |
32 |
import java.util.List;
|
| 34545 |
vikas.jang |
33 |
import java.util.Map;
|
| 34468 |
vikas.jang |
34 |
|
| 34545 |
vikas.jang |
35 |
import static java.util.stream.Collectors.toList;
|
|
|
36 |
|
| 34468 |
vikas.jang |
37 |
@Component
|
|
|
38 |
public class BidServiceImpl implements BidService {
|
|
|
39 |
private static final Logger LOGGER = LogManager.getLogger(BidServiceImpl.class);
|
|
|
40 |
@Autowired
|
|
|
41 |
AuthRepository authRepository;
|
|
|
42 |
@Autowired
|
|
|
43 |
AuthService authService;
|
|
|
44 |
@Autowired
|
|
|
45 |
JavaMailSender mailSender;
|
|
|
46 |
@Autowired
|
|
|
47 |
UserRepository userRepository;
|
|
|
48 |
@Autowired
|
|
|
49 |
CsService csService;
|
|
|
50 |
@Autowired
|
|
|
51 |
BidRepository bidRepository;
|
|
|
52 |
@Autowired
|
|
|
53 |
LiquidationRepository liquidationRepository;
|
|
|
54 |
@Autowired
|
|
|
55 |
NotificationService notificationService;
|
| 34545 |
vikas.jang |
56 |
@Autowired
|
|
|
57 |
private UserAccountRepository userAccountRepository;
|
|
|
58 |
@Autowired
|
|
|
59 |
private FofoStoreRepository fofoStoreRepository;
|
| 34468 |
vikas.jang |
60 |
|
|
|
61 |
@Override
|
|
|
62 |
public void sendMailToRBM(double netAmountInHand, double totalPayableAmount, int fofoId) throws Exception {
|
|
|
63 |
User user = userRepository.selectById(fofoId);
|
|
|
64 |
int rbmId = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
|
|
|
65 |
AuthUser authUser = authRepository.selectById(rbmId);
|
|
|
66 |
|
|
|
67 |
String[] emailTo = new String[] { authUser.getEmailId() };
|
|
|
68 |
//String[] emailTo = new String[] { "vjangra856@gmail.com" };
|
|
|
69 |
|
|
|
70 |
String[] ccTo = {user.getEmailId()};
|
|
|
71 |
String subject = "Dispatch On Hold(Bidding)";
|
|
|
72 |
String message = String.format(
|
|
|
73 |
"Dear Team,\n\n"
|
|
|
74 |
+ "This is to inform you that the material for %s, valued at Rs.%s, "
|
|
|
75 |
+ "is on hold until the payment against the stock is received. Kindly "
|
|
|
76 |
+ "top up your wallet with an amount of Rs.%s to proceed with the dispatch.",
|
| 34492 |
vikas.jang |
77 |
user.getName(), totalPayableAmount, (totalPayableAmount - netAmountInHand)
|
| 34468 |
vikas.jang |
78 |
);
|
|
|
79 |
|
|
|
80 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
@Override
|
|
|
84 |
public void sendSummaryMailToUserAndManagers(int userId, List<Bid> bids, Liquidation liquidation) throws Exception {
|
|
|
85 |
String content = this.generateContent(bids, liquidation, ProfitMandiConstants.BID_ENUM.CLOSED);
|
|
|
86 |
AuthUser authUser = authRepository.selectById(userId);
|
| 34492 |
vikas.jang |
87 |
String[] emailTo = {authUser.getEmailId(), "vikas.jangra@smartdukaan.com"};
|
| 34468 |
vikas.jang |
88 |
|
|
|
89 |
String[] ccTo = authService.getAllManagers(userId).stream().map(AuthUser::getEmailId).toArray(String[]::new);
|
|
|
90 |
String subject = "Liquidation Report";
|
|
|
91 |
String message = "Dear Team,\n\n"
|
|
|
92 |
+ "Liquidation has been completed. Here is the summary:\n\n"
|
|
|
93 |
+ content;
|
|
|
94 |
|
|
|
95 |
LOGGER.info("mailMessage: {}",message);
|
|
|
96 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
@Override
|
| 34545 |
vikas.jang |
100 |
public void notifyPartner(int fofoId, Bid bid, ProfitMandiConstants.BID_ENUM status) throws Exception {
|
|
|
101 |
User user = userRepository.selectById(fofoId);
|
| 34492 |
vikas.jang |
102 |
List<Bid> topBid = bidRepository.selectBidByLiquidationId(bid.getLiquidationId());
|
|
|
103 |
String message = this.generateWhatsAppBidMessage(user.getName(), bid, topBid.get(0).getBiddingAmount(), status);
|
| 34545 |
vikas.jang |
104 |
this.sendPushNotification(message, "Bid Update!", Arrays.asList(fofoId));
|
|
|
105 |
//String mobile = user.getMobileNumber();
|
|
|
106 |
//notificationService.sendWhatsappMessage(message, "Bid Update!", mobile);
|
| 34468 |
vikas.jang |
107 |
}
|
|
|
108 |
|
| 34545 |
vikas.jang |
109 |
@Override
|
|
|
110 |
public void biddingLiveNotification(String message, String mediaURL) throws Exception {
|
|
|
111 |
this.sendPushNotification(message, "Bidding Live Now!", Collections.emptyList());
|
|
|
112 |
//List<String> mobiles = Arrays.asList("7619985051","8529003611","7082253510","7903840919","9667014826");
|
|
|
113 |
if (mediaURL == null){
|
|
|
114 |
notificationService.sendWhatsappMessage(message,null, "8529003611");
|
|
|
115 |
} else {
|
|
|
116 |
notificationService.sendWhatsappMediaMessage(message,"8529003611", mediaURL,"whatsapp.jpeg", WhatsappMessageType.IMAGE);
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
@Override
|
|
|
121 |
public void sendPushNotification(String message, String title, List<Integer> fofoIds) throws Exception {
|
|
|
122 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
123 |
sendNotificationModel.setCampaignName(title);
|
|
|
124 |
sendNotificationModel.setMessage(message);
|
|
|
125 |
sendNotificationModel.setType("url");
|
|
|
126 |
sendNotificationModel.setTitle(title);
|
|
|
127 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/clearance");
|
|
|
128 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusHours(6));
|
|
|
129 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
130 |
List<Integer> userIds;
|
|
|
131 |
if (fofoIds.size() > 0) {
|
|
|
132 |
userIds = userAccountRepository.selectUserIdsByRetailerIds(fofoIds); //Arrays.asList(171912487)
|
|
|
133 |
} else {
|
|
|
134 |
fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x->x.getId()).collect(toList());
|
|
|
135 |
userIds = userAccountRepository.selectUserIdsByRetailerIds(fofoIds);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
sendNotificationModel.setUserIds(userIds);
|
|
|
139 |
notificationService.sendNotification(sendNotificationModel);
|
| 34550 |
vikas.jang |
140 |
notificationService.sendNotificationToSystemUsers(sendNotificationModel);
|
| 34545 |
vikas.jang |
141 |
}
|
|
|
142 |
|
| 34468 |
vikas.jang |
143 |
private String generateContent(List<Bid> bids, Liquidation liquidation, ProfitMandiConstants.BID_ENUM status){
|
|
|
144 |
StringBuilder sb = new StringBuilder();
|
|
|
145 |
sb.append("<h4>Bidding Summary</h3>");
|
|
|
146 |
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>");
|
|
|
148 |
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>");
|
|
|
150 |
|
|
|
151 |
sb.append("<table border='1' cellpadding='5' cellspacing='0' style='border-collapse: collapse;'>");
|
|
|
152 |
sb.append("<thead>");
|
|
|
153 |
sb.append("<tr>")
|
|
|
154 |
.append("<th>Bidder ID (Fofo)</th>")
|
|
|
155 |
.append("<th>Item Name</th>")
|
|
|
156 |
.append("<th>Bid Amount</th>")
|
|
|
157 |
.append("<th>Quantity</th>")
|
|
|
158 |
.append("<th>Status</th>")
|
|
|
159 |
.append("<th>Bid Time</th>")
|
|
|
160 |
.append("</tr>");
|
|
|
161 |
sb.append("</thead>");
|
|
|
162 |
sb.append("<tbody>");
|
|
|
163 |
|
|
|
164 |
for (Bid bid : bids) {
|
|
|
165 |
sb.append("<tr>")
|
|
|
166 |
.append("<td>").append(bid.getFofoId()).append("</td>")
|
|
|
167 |
.append("<td>").append(bid.getItemName() != null ? bid.getItemName() : "-").append("</td>")
|
|
|
168 |
.append("<td>").append(bid.getBiddingAmount()).append("</td>")
|
|
|
169 |
.append("<td>").append(bid.getQuantity()).append("</td>")
|
|
|
170 |
.append("<td>").append(bid.getStatus().name()).append("</td>")
|
|
|
171 |
.append("<td>").append(bid.getCreatedAt()).append("</td>")
|
|
|
172 |
.append("</tr>");
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
sb.append("</tbody>");
|
|
|
176 |
sb.append("</table>");
|
|
|
177 |
|
|
|
178 |
return sb.toString();
|
|
|
179 |
}
|
|
|
180 |
|
| 34492 |
vikas.jang |
181 |
public void cancelYesterdayProcessBid(Bid bid) throws Exception {
|
| 34468 |
vikas.jang |
182 |
bid.setStatus(ProfitMandiConstants.BID_ENUM.CANCELLED);
|
|
|
183 |
Liquidation liquidation = liquidationRepository.selectLiquidationById(bid.getLiquidationId());
|
|
|
184 |
List<Bid> bids = bidRepository.selectBidByLiquidationId(bid.getLiquidationId());
|
|
|
185 |
this.sendSummaryMailToUserAndManagers(liquidation.getCreatedBy(), bids, liquidation);
|
| 34492 |
vikas.jang |
186 |
this.notifyPartner(bid.getFofoId(), bid, ProfitMandiConstants.BID_ENUM.CANCELLED);
|
| 34468 |
vikas.jang |
187 |
}
|
|
|
188 |
|
| 34492 |
vikas.jang |
189 |
private String generateWhatsAppBidMessage(String fofoName, Bid bidData, double topBidAmount, ProfitMandiConstants.BID_ENUM status) {
|
|
|
190 |
String bidTime = StringUtils.toLocalDateTime(String.valueOf(bidData.getCreatedAt()));
|
|
|
191 |
String bidAmount = String.format("%.2f", bidData.getBiddingAmount());
|
| 34468 |
vikas.jang |
192 |
|
| 34492 |
vikas.jang |
193 |
String message = "";
|
| 34468 |
vikas.jang |
194 |
|
| 34492 |
vikas.jang |
195 |
if (status.equals(ProfitMandiConstants.BID_ENUM.CLOSED)) {
|
| 34545 |
vikas.jang |
196 |
message = "Congratulations! %s,\n"+
|
| 34492 |
vikas.jang |
197 |
"\n"+
|
| 34545 |
vikas.jang |
198 |
"Your bid for %s has been confirmed!\n"+
|
| 34492 |
vikas.jang |
199 |
"\n"+
|
| 34545 |
vikas.jang |
200 |
"Bid Details:\n"+
|
|
|
201 |
"Bid Amount: Rs. %s\n"+
|
|
|
202 |
"Quantity: %s\n"+
|
|
|
203 |
"Bid Time: %s\n"+
|
| 34492 |
vikas.jang |
204 |
"\n"+
|
|
|
205 |
"Thank you for participating. We'll dispatch your order soon.";
|
|
|
206 |
message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime);
|
| 34468 |
vikas.jang |
207 |
}
|
| 34492 |
vikas.jang |
208 |
else if (status.equals(ProfitMandiConstants.BID_ENUM.CANCELLED)) {
|
| 34545 |
vikas.jang |
209 |
message = "Hi %s,\n"+
|
| 34492 |
vikas.jang |
210 |
"\n"+
|
| 34545 |
vikas.jang |
211 |
"We regret to inform you that your bid for %s was not selected this time.\n"+
|
| 34492 |
vikas.jang |
212 |
"\n"+
|
| 34545 |
vikas.jang |
213 |
"Bid Details:\n"+
|
|
|
214 |
"Bid Amount: Rs. %s\n"+
|
|
|
215 |
"Quantity: %s\n"+
|
|
|
216 |
"Bid Time: %s\n"+
|
| 34492 |
vikas.jang |
217 |
"\n"+
|
| 34545 |
vikas.jang |
218 |
"Qualified Bid Amount: ₹%s\n"+
|
| 34492 |
vikas.jang |
219 |
"Thank you for your participation. Stay tuned for more opportunities!";
|
|
|
220 |
message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime, String.format("%.2f", topBidAmount));
|
|
|
221 |
}
|
|
|
222 |
else if (status.equals(ProfitMandiConstants.BID_ENUM.PENDING)) {
|
| 34545 |
vikas.jang |
223 |
message = "Hi %s,\n"+
|
| 34492 |
vikas.jang |
224 |
"\n"+
|
| 34545 |
vikas.jang |
225 |
"Your bid for %s has been placed successfully.\n"+
|
| 34492 |
vikas.jang |
226 |
"\n"+
|
| 34545 |
vikas.jang |
227 |
"Bid Details:\n"+
|
|
|
228 |
"Bid Amount: Rs. %s\n"+
|
|
|
229 |
"Quantity: %s\n"+
|
|
|
230 |
"Time: %s\n"+
|
| 34492 |
vikas.jang |
231 |
"\n"+
|
| 34545 |
vikas.jang |
232 |
"We will keep you updated. You will be notified once the bidding period ends.";
|
|
|
233 |
message = String.format(message, fofoName.trim(), bidData.getItemName().trim(), bidAmount, bidData.getQuantity(), bidTime);
|
| 34492 |
vikas.jang |
234 |
}
|
|
|
235 |
else if (status.equals(ProfitMandiConstants.BID_ENUM.UPDATE)) {
|
| 34545 |
vikas.jang |
236 |
message = "Hi %s,\n"+
|
|
|
237 |
"A higher bid has been placed for %s. Don't miss your chance!\n"+
|
| 34492 |
vikas.jang |
238 |
"\n"+
|
| 34545 |
vikas.jang |
239 |
"Your Bid Details:\n"+
|
|
|
240 |
"Bid Amount: Rs. %s\n"+
|
|
|
241 |
"Quantity: %s\n"+
|
|
|
242 |
"Bid Time: %s\n"+
|
| 34492 |
vikas.jang |
243 |
"\n"+
|
| 34545 |
vikas.jang |
244 |
"Another user has placed a higher bid of %s.\n"+
|
| 34492 |
vikas.jang |
245 |
"Update your bid before the bidding ends to stay ahead in the race!";
|
|
|
246 |
message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime, String.format("%.2f", topBidAmount));
|
|
|
247 |
}
|
| 34468 |
vikas.jang |
248 |
|
| 34492 |
vikas.jang |
249 |
return message;
|
| 34468 |
vikas.jang |
250 |
}
|
| 34492 |
vikas.jang |
251 |
|
| 34468 |
vikas.jang |
252 |
}
|