Subversion Repositories SmartDukaan

Rev

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

Rev 34492 Rev 34545
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.model.ProfitMandiConstants;
4
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
5
import com.spice.profitmandi.common.model.SendNotificationModel;
4
import com.spice.profitmandi.common.util.StringUtils;
6
import com.spice.profitmandi.common.util.StringUtils;
5
import com.spice.profitmandi.common.util.Utils;
7
import com.spice.profitmandi.common.util.Utils;
6
import com.spice.profitmandi.dao.entity.auth.AuthUser;
8
import com.spice.profitmandi.dao.entity.auth.AuthUser;
7
import com.spice.profitmandi.dao.entity.catalog.Bid;
9
import com.spice.profitmandi.dao.entity.catalog.Bid;
8
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
10
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
Line 10... Line 12...
10
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
12
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
11
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
13
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
12
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
14
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
13
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
15
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
14
import com.spice.profitmandi.dao.repository.cs.CsService;
16
import com.spice.profitmandi.dao.repository.cs.CsService;
-
 
17
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
18
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
15
import com.spice.profitmandi.dao.repository.user.UserRepository;
19
import com.spice.profitmandi.dao.repository.user.UserRepository;
16
import com.spice.profitmandi.service.AuthService;
20
import com.spice.profitmandi.service.AuthService;
17
import com.spice.profitmandi.service.NotificationService;
21
import com.spice.profitmandi.service.NotificationService;
-
 
22
import com.spice.profitmandi.service.whatsapp.WhatsappMessageType;
18
import org.apache.logging.log4j.LogManager;
23
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.Logger;
24
import org.apache.logging.log4j.Logger;
20
import org.springframework.beans.factory.annotation.Autowired;
25
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.mail.javamail.JavaMailSender;
26
import org.springframework.mail.javamail.JavaMailSender;
22
import org.springframework.stereotype.Component;
27
import org.springframework.stereotype.Component;
23
 
28
 
-
 
29
import java.time.LocalDateTime;
24
import java.util.ArrayList;
30
import java.util.Arrays;
-
 
31
import java.util.Collections;
25
import java.util.List;
32
import java.util.List;
-
 
33
import java.util.Map;
-
 
34
 
-
 
35
import static java.util.stream.Collectors.toList;
26
 
36
 
27
@Component
37
@Component
28
public class BidServiceImpl implements BidService {
38
public class BidServiceImpl implements BidService {
29
    private static final Logger LOGGER = LogManager.getLogger(BidServiceImpl.class);
39
    private static final Logger LOGGER = LogManager.getLogger(BidServiceImpl.class);
30
    @Autowired
40
    @Autowired
Line 41... Line 51...
41
    BidRepository bidRepository;
51
    BidRepository bidRepository;
42
    @Autowired
52
    @Autowired
43
    LiquidationRepository liquidationRepository;
53
    LiquidationRepository liquidationRepository;
44
    @Autowired
54
    @Autowired
45
    NotificationService notificationService;
55
    NotificationService notificationService;
-
 
56
    @Autowired
-
 
57
    private UserAccountRepository userAccountRepository;
-
 
58
    @Autowired
-
 
59
    private FofoStoreRepository fofoStoreRepository;
46
 
60
 
47
    @Override
61
    @Override
48
    public void sendMailToRBM(double netAmountInHand, double totalPayableAmount, int fofoId) throws Exception {
62
    public void sendMailToRBM(double netAmountInHand, double totalPayableAmount, int fofoId) throws Exception {
49
        User user = userRepository.selectById(fofoId);
63
        User user = userRepository.selectById(fofoId);
50
        int rbmId = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
64
        int rbmId = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
Line 68... Line 82...
68
 
82
 
69
    @Override
83
    @Override
70
    public void sendSummaryMailToUserAndManagers(int userId, List<Bid> bids, Liquidation liquidation) throws Exception {
84
    public void sendSummaryMailToUserAndManagers(int userId, List<Bid> bids, Liquidation liquidation) throws Exception {
71
        String content = this.generateContent(bids, liquidation, ProfitMandiConstants.BID_ENUM.CLOSED);
85
        String content = this.generateContent(bids, liquidation, ProfitMandiConstants.BID_ENUM.CLOSED);
72
        AuthUser authUser = authRepository.selectById(userId);
86
        AuthUser authUser = authRepository.selectById(userId);
73
        //String[] emailTo = {"vikas.jangra@smartdukaan.com"};
-
 
74
        String[] emailTo = {authUser.getEmailId(), "vikas.jangra@smartdukaan.com"};
87
        String[] emailTo = {authUser.getEmailId(), "vikas.jangra@smartdukaan.com"};
75
 
88
 
76
        String[] ccTo = authService.getAllManagers(userId).stream().map(AuthUser::getEmailId).toArray(String[]::new);
89
        String[] ccTo = authService.getAllManagers(userId).stream().map(AuthUser::getEmailId).toArray(String[]::new);
77
        String subject = "Liquidation Report";
90
        String subject = "Liquidation Report";
78
        String message = "Dear Team,\n\n"
91
        String message = "Dear Team,\n\n"
Line 82... Line 95...
82
        LOGGER.info("mailMessage: {}",message);
95
        LOGGER.info("mailMessage: {}",message);
83
        Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
96
        Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
84
    }
97
    }
85
 
98
 
86
    @Override
99
    @Override
87
    public void notifyPartner(int userId, Bid bid, ProfitMandiConstants.BID_ENUM status) throws Exception {
100
    public void notifyPartner(int fofoId, Bid bid, ProfitMandiConstants.BID_ENUM status) throws Exception {
88
        User user = userRepository.selectById(userId);
101
        User user = userRepository.selectById(fofoId);
89
        List<Bid> topBid = bidRepository.selectBidByLiquidationId(bid.getLiquidationId());
102
        List<Bid> topBid = bidRepository.selectBidByLiquidationId(bid.getLiquidationId());
90
        String message = this.generateWhatsAppBidMessage(user.getName(), bid, topBid.get(0).getBiddingAmount(), status);
103
        String message = this.generateWhatsAppBidMessage(user.getName(), bid, topBid.get(0).getBiddingAmount(), status);
-
 
104
        this.sendPushNotification(message, "Bid Update!", Arrays.asList(fofoId));
91
        String mobile = user.getMobileNumber();
105
        //String mobile = user.getMobileNumber();
92
        notificationService.sendWhatsappMessage(message, "Bid Update!", mobile);
106
        //notificationService.sendWhatsappMessage(message, "Bid Update!", mobile);
-
 
107
    }
-
 
108
 
-
 
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);
93
    }
140
    }
94
 
141
 
95
    private String generateContent(List<Bid> bids, Liquidation liquidation, ProfitMandiConstants.BID_ENUM status){
142
    private String generateContent(List<Bid> bids, Liquidation liquidation, ProfitMandiConstants.BID_ENUM status){
96
        StringBuilder sb = new StringBuilder();
143
        StringBuilder sb = new StringBuilder();
97
        sb.append("<h4>Bidding Summary</h3>");
144
        sb.append("<h4>Bidding Summary</h3>");
Line 143... Line 190...
143
        String bidAmount = String.format("%.2f", bidData.getBiddingAmount());
190
        String bidAmount = String.format("%.2f", bidData.getBiddingAmount());
144
 
191
 
145
        String message = "";
192
        String message = "";
146
 
193
 
147
        if (status.equals(ProfitMandiConstants.BID_ENUM.CLOSED)) {
194
        if (status.equals(ProfitMandiConstants.BID_ENUM.CLOSED)) {
148
            message = "Congratulations! %s,"+ "\n"+
195
            message = "Congratulations! %s,\n"+
149
                    "\n"+
196
                    "\n"+
150
                    "Your bid for %s has been confirmed!\n" +
197
                    "Your bid for %s has been confirmed!\n"+
151
                    "\n"+
198
                    "\n"+
152
                    "Bid Details:\n" +
199
                    "Bid Details:\n"+
153
                    "* Bid Amount: ₹%s\n" +
200
                    "Bid Amount: Rs. %s\n"+
154
                    "* Quantity: %s\n" +
201
                    "Quantity: %s\n"+
155
                    "* Bid Time: %s\n" +
202
                    "Bid Time: %s\n"+
156
                    "\n"+
203
                    "\n"+
157
                    "Thank you for participating. We'll dispatch your order soon.";
204
                    "Thank you for participating. We'll dispatch your order soon.";
158
            message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime);
205
            message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime);
159
        }
206
        }
160
        else if (status.equals(ProfitMandiConstants.BID_ENUM.CANCELLED)) {
207
        else if (status.equals(ProfitMandiConstants.BID_ENUM.CANCELLED)) {
161
            message = "Hi %s,"+ "\n"+
208
            message = "Hi %s,\n"+
162
                    "\n"+
209
                    "\n"+
163
                    "We regret to inform you that your bid for %s was not selected this time.\n" +
210
                    "We regret to inform you that your bid for %s was not selected this time.\n"+
164
                    "\n"+
211
                    "\n"+
165
                    "Bid Details:\n" +
212
                    "Bid Details:\n"+
166
                    "* Bid Amount: ₹%s\n" +
213
                    "Bid Amount: Rs. %s\n"+
167
                    "* Quantity: %s\n" +
214
                    "Quantity: %s\n"+
168
                    "* Bid Time: %s\n" +
215
                    "Bid Time: %s\n"+
169
                    "* Qualified Bid Amount: ₹%s\n" +
-
 
170
                    "\n"+
216
                    "\n"+
-
 
217
                    "Qualified Bid Amount: ₹%s\n"+
171
                    "Thank you for your participation. Stay tuned for more opportunities!";
218
                    "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));
219
            message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime, String.format("%.2f", topBidAmount));
173
        }
220
        }
174
        else if (status.equals(ProfitMandiConstants.BID_ENUM.PENDING)) {
221
        else if (status.equals(ProfitMandiConstants.BID_ENUM.PENDING)) {
175
            message = "Hi %s,"+ "\n"+
222
            message = "Hi %s,\n"+
176
                    "\n"+
223
                    "\n"+
177
                    "Your bid for %s has been placed successfully!\n" +
224
                    "Your bid for %s has been placed successfully.\n"+
178
                    "\n"+
225
                    "\n"+
179
                    "Bid Details:\n" +
226
                    "Bid Details:\n"+
180
                    "* Bid Amount: ₹%s\n" +
227
                    "Bid Amount: Rs. %s\n"+
181
                    "* Quantity: %s\n" +
228
                    "Quantity: %s\n"+
182
                    "* Bid Time: %s\n" +
229
                    "Time: %s\n"+
183
                    "\n"+
230
                    "\n"+
184
                    "We'll keep you updated. You'll be notified once the bidding period ends.";
231
                    "We will keep you updated. You will be notified once the bidding period ends.";
185
            message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime);
232
            message = String.format(message, fofoName.trim(), bidData.getItemName().trim(), bidAmount, bidData.getQuantity(), bidTime);
186
        }
233
        }
187
        else if (status.equals(ProfitMandiConstants.BID_ENUM.UPDATE)) {
234
        else if (status.equals(ProfitMandiConstants.BID_ENUM.UPDATE)) {
188
            message = "Hi %s,"+ "\n"+
235
            message = "Hi %s,\n"+
189
                    "\n"+
-
 
190
                    "A higher bid has been placed for %s. Don't miss your chance!\n" +
236
                    "A higher bid has been placed for %s. Don't miss your chance!\n"+
191
                    "\n"+
237
                    "\n"+
192
                    "Your Bid Details:\n" +
238
                    "Your Bid Details:\n"+
193
                    "* Bid Amount: ₹%s\n" +
239
                    "Bid Amount: Rs. %s\n"+
194
                    "* Quantity: %s\n" +
240
                    "Quantity: %s\n"+
195
                    "* Bid Time: %s\n" +
241
                    "Bid Time: %s\n"+
196
                    "\n"+
242
                    "\n"+
197
                    "Another user has placed a higher bid of ₹%s.\n" +
243
                    "Another user has placed a higher bid of %s.\n"+
198
                    "Update your bid before the bidding ends to stay ahead in the race!";
244
                    "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));
245
            message = String.format(message, fofoName, bidData.getItemName(), bidAmount, bidData.getQuantity(), bidTime, String.format("%.2f", topBidAmount));
200
        }
246
        }
201
 
247
 
202
        return message;
248
        return message;