| 24026 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 33247 |
ranu |
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 31238 |
amit.gupta |
4 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
|
|
5 |
import com.spice.profitmandi.common.model.SendMessageModel;
|
|
|
6 |
import com.spice.profitmandi.common.util.Utils;
|
|
|
7 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
8 |
import com.spice.profitmandi.service.user.RetailerService;
|
|
|
9 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 24026 |
tejbeer |
10 |
import org.apache.logging.log4j.LogManager;
|
|
|
11 |
import org.apache.logging.log4j.Logger;
|
|
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
13 |
import org.springframework.stereotype.Controller;
|
|
|
14 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
15 |
import org.springframework.ui.Model;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
19 |
|
| 31238 |
amit.gupta |
20 |
import javax.servlet.http.HttpServletRequest;
|
|
|
21 |
import java.util.List;
|
|
|
22 |
import java.util.Map;
|
|
|
23 |
import java.util.stream.Collectors;
|
| 24026 |
tejbeer |
24 |
|
|
|
25 |
@Controller
|
|
|
26 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
27 |
public class MessageController {
|
|
|
28 |
|
|
|
29 |
@Autowired
|
|
|
30 |
FofoStoreRepository fofoStoreRepository;
|
|
|
31 |
|
|
|
32 |
@Autowired
|
|
|
33 |
private RetailerService retailerService;
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
private MVCResponseSender mvcResponseSender;
|
|
|
37 |
|
|
|
38 |
private static final Logger Logger = LogManager.getLogger(NotificationController.class);
|
|
|
39 |
|
|
|
40 |
@RequestMapping(value = "/sendMessagingPanel", method = RequestMethod.GET)
|
| 33247 |
ranu |
41 |
public String sendMessagingPanel(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 24026 |
tejbeer |
42 |
|
|
|
43 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
44 |
.collect(Collectors.toList());
|
| 30426 |
tejbeer |
45 |
|
|
|
46 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
47 |
|
|
|
48 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
49 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
50 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 24026 |
tejbeer |
51 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
52 |
return "send-message";
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
@RequestMapping(value = "/sendMessage", method = RequestMethod.POST)
|
|
|
56 |
public String sendMessage(HttpServletRequest request, @RequestBody SendMessageModel sendMessageModel, Model model)
|
|
|
57 |
throws Exception {
|
|
|
58 |
|
|
|
59 |
List<Integer> retailerIds = sendMessageModel.getUserIds();
|
| 30426 |
tejbeer |
60 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 24026 |
tejbeer |
61 |
|
| 30426 |
tejbeer |
62 |
Map<Integer, CustomRetailer> customRetailersMap = retailerIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
63 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
64 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
65 |
|
| 24026 |
tejbeer |
66 |
for (Integer retailerId : retailerIds) {
|
|
|
67 |
|
|
|
68 |
CustomRetailer customRetailer = customRetailersMap.get(retailerId);
|
|
|
69 |
String phone = customRetailer.getMobileNumber();
|
|
|
70 |
String msg = java.text.MessageFormat.format("{0}", sendMessageModel.getMessageText());
|
|
|
71 |
Utils.sendSms(msg, phone);
|
|
|
72 |
}
|
| 31238 |
amit.gupta |
73 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 24026 |
tejbeer |
74 |
return "response";
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
}
|