| Line 5... |
Line 5... |
| 5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 7 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
7 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 8 |
import com.spice.profitmandi.common.web.client.RestClient;
|
8 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 9 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
9 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 10 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
- |
|
| 11 |
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
|
- |
|
| 12 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
10 |
import com.spice.profitmandi.dao.entity.dtr.*;
|
| 13 |
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
|
- |
|
| 14 |
import com.spice.profitmandi.dao.entity.user.Device;
|
11 |
import com.spice.profitmandi.dao.entity.user.Device;
|
| 15 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
12 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
| 16 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
13 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 17 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
14 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| 18 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
15 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 19 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
16 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 20 |
import com.spice.profitmandi.service.user.RetailerService;
|
17 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 21 |
|
- |
|
| 22 |
import org.apache.http.conn.HttpHostConnectException;
|
- |
|
| 23 |
import org.apache.logging.log4j.LogManager;
|
18 |
import org.apache.logging.log4j.LogManager;
|
| 24 |
import org.apache.logging.log4j.Logger;
|
19 |
import org.apache.logging.log4j.Logger;
|
| 25 |
import org.springframework.beans.factory.annotation.Autowired;
|
20 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
21 |
import org.springframework.beans.factory.annotation.Value;
|
| 26 |
import org.springframework.stereotype.Component;
|
22 |
import org.springframework.stereotype.Component;
|
| 27 |
|
23 |
|
| 28 |
import java.time.LocalDateTime;
|
24 |
import java.time.LocalDateTime;
|
| 29 |
import java.util.*;
|
25 |
import java.util.*;
|
| 30 |
import java.util.stream.Collectors;
|
26 |
import java.util.stream.Collectors;
|
| 31 |
|
27 |
|
| 32 |
@Component
|
28 |
@Component
|
| 33 |
public class NotificationServiceImpl implements NotificationService {
|
29 |
public class NotificationServiceImpl implements NotificationService {
|
| 34 |
|
30 |
|
| - |
|
31 |
private static final Logger LOGGER = LogManager.getLogger(NotificationService.class);
|
| 35 |
@Autowired
|
32 |
@Autowired
|
| 36 |
UserCampaignRepository userCampaignRepository;
|
33 |
UserCampaignRepository userCampaignRepository;
|
| - |
|
34 |
@Autowired
|
| - |
|
35 |
UserRepository dtrUserRepository;
|
| - |
|
36 |
@Autowired
|
| - |
|
37 |
UserAccountRepository userAccountRepository;
|
| - |
|
38 |
@Autowired
|
| - |
|
39 |
NotificationCampaignRepository notificationCampaignRepository;
|
| - |
|
40 |
@Autowired
|
| - |
|
41 |
DeviceRepository deviceRepository;
|
| - |
|
42 |
@Autowired
|
| - |
|
43 |
FofoStoreRepository fofoStoreRepository;
|
| - |
|
44 |
@Autowired
|
| - |
|
45 |
CsService csService;
|
| - |
|
46 |
@Autowired
|
| - |
|
47 |
OptinRepository optinRepository;
|
| - |
|
48 |
@Autowired
|
| - |
|
49 |
RetailerService retailerService;
|
| - |
|
50 |
@Autowired
|
| - |
|
51 |
PushNotificationRepository pushNotificationRepository;
|
| - |
|
52 |
@Autowired
|
| - |
|
53 |
private Gson gson;
|
| - |
|
54 |
@Autowired
|
| - |
|
55 |
private RestClient restClient;
|
| - |
|
56 |
@Value("${prod}")
|
| - |
|
57 |
private boolean isProd;
|
| 37 |
|
58 |
|
| 38 |
@Autowired
|
59 |
@Override
|
| - |
|
60 |
public void sendNotification(SendNotificationModel sendNotificationModel) throws ProfitMandiBusinessException {
|
| - |
|
61 |
|
| - |
|
62 |
SimpleCampaignParams scp = new SimpleCampaignParams();
|
| - |
|
63 |
scp.setMessage(sendNotificationModel.getMessage());
|
| - |
|
64 |
scp.setTitle(sendNotificationModel.getTitle());
|
| - |
|
65 |
scp.setImageUrl(sendNotificationModel.getImageUrl());
|
| - |
|
66 |
scp.setType(sendNotificationModel.getType());
|
| - |
|
67 |
scp.setUrl(sendNotificationModel.getUrl());
|
| - |
|
68 |
scp.setShowImage(sendNotificationModel.getShowImage());
|
| - |
|
69 |
scp.setExpireTimestamp(sendNotificationModel.getExpiresat());
|
| - |
|
70 |
SimpleCampaign sc = new SimpleCampaign(scp);
|
| - |
|
71 |
sc.setSimpleCampaignParams(scp);
|
| - |
|
72 |
|
| - |
|
73 |
NotificationCampaign nc = new NotificationCampaign();
|
| - |
|
74 |
nc.setName(sendNotificationModel.getCampaignName());
|
| - |
|
75 |
nc.setImplementationType("SimpleCampaign");
|
| - |
|
76 |
nc.setImplementationParams(gson.toJson(scp));
|
| - |
|
77 |
nc.setMessageType(sendNotificationModel.getMessageType());
|
| - |
|
78 |
nc.setDocumentId(sendNotificationModel.getDocumentId());
|
| - |
|
79 |
nc.setCreatedTimestamp(LocalDateTime.now());
|
| - |
|
80 |
notificationCampaignRepository.persist(nc);
|
| - |
|
81 |
|
| - |
|
82 |
UserCampaign uc = null;
|
| - |
|
83 |
|
| - |
|
84 |
Set<Integer> userIds = new HashSet<>();
|
| - |
|
85 |
if (sendNotificationModel.getUserIds() != null && sendNotificationModel.getUserIds().size() > 0) {
|
| - |
|
86 |
userIds.addAll(sendNotificationModel.getUserIds());
|
| - |
|
87 |
}
|
| - |
|
88 |
|
| - |
|
89 |
if (sendNotificationModel.getStateIds() != null && sendNotificationModel.getStateIds().size() > 0) {
|
| - |
|
90 |
userIds.addAll(fofoStoreRepository.selectByWarehouseIds(sendNotificationModel.getStateIds()).stream()
|
| - |
|
91 |
.map(x -> x.getId()).collect(Collectors.toList()));
|
| - |
|
92 |
}
|
| - |
|
93 |
|
| - |
|
94 |
LOGGER.info("userIds" + userIds);
|
| - |
|
95 |
|
| - |
|
96 |
for (Integer userId : userIds) {
|
| - |
|
97 |
uc = new UserCampaign();
|
| - |
|
98 |
uc.setCampaignId(nc.getId());
|
| 39 |
UserRepository dtrUserRepository;
|
99 |
uc.setUserId(userId);
|
| - |
|
100 |
uc.setPushTimestamp(LocalDateTime.now());
|
| - |
|
101 |
userCampaignRepository.persist(uc);
|
| - |
|
102 |
}
|
| - |
|
103 |
|
| - |
|
104 |
List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(new ArrayList<>(userIds),
|
| - |
|
105 |
LocalDateTime.now().minusMonths(3), LocalDateTime.now());
|
| - |
|
106 |
|
| - |
|
107 |
LOGGER.info("devices" + devices);
|
| - |
|
108 |
pushNotification(nc.getId(), devices);
|
| - |
|
109 |
|
| - |
|
110 |
}
|
| - |
|
111 |
|
| - |
|
112 |
@Override
|
| - |
|
113 |
public void sendNotificationToAll(SendNotificationModel sendNotificationModel) throws ProfitMandiBusinessException {
|
| - |
|
114 |
sendNotificationModel.setUserIds(fofoStoreRepository.selectAllDtrUserIds());
|
| - |
|
115 |
Set<AuthUser> authUsers = new HashSet<>(
|
| - |
|
116 |
csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
|
| - |
|
117 |
authUsers.addAll(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY));
|
| - |
|
118 |
authUsers.addAll(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES));
|
| - |
|
119 |
List<String> emailIds = authUsers.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
| - |
|
120 |
emailIds.add("devkinandan.lal@smartdukaan.com");
|
| - |
|
121 |
List<User> systemUsers = dtrUserRepository.selectAllByEmailIds(emailIds);
|
| - |
|
122 |
sendNotificationModel.getUserIds()
|
| - |
|
123 |
.addAll(systemUsers.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| - |
|
124 |
this.sendNotification(sendNotificationModel);
|
| - |
|
125 |
}
|
| 40 |
|
126 |
|
| 41 |
@Autowired
|
127 |
@Override
|
| - |
|
128 |
public void sendNotification(int fofoId, String campaignName, MessageType messageType, String title, String message)
|
| - |
|
129 |
throws ProfitMandiBusinessException {
|
| - |
|
130 |
SendNotificationModel sendNotificationModel = this.getDefaultNotificationModel();
|
| - |
|
131 |
sendNotificationModel.setCampaignName(campaignName);
|
| - |
|
132 |
sendNotificationModel.setMessageType(messageType);
|
| - |
|
133 |
sendNotificationModel.setTitle(title);
|
| - |
|
134 |
sendNotificationModel.setMessage(message);
|
| - |
|
135 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
| - |
|
136 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| - |
|
137 |
sendNotificationModel.setMessageType(MessageType.wallet);
|
| - |
|
138 |
this.sendNotification(sendNotificationModel);
|
| - |
|
139 |
}
|
| - |
|
140 |
|
| - |
|
141 |
public SendNotificationModel getDefaultNotificationModel() {
|
| - |
|
142 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| - |
|
143 |
sendNotificationModel.setType("url");
|
| - |
|
144 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| - |
|
145 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| - |
|
146 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| - |
|
147 |
return sendNotificationModel;
|
| - |
|
148 |
}
|
| - |
|
149 |
|
| - |
|
150 |
public void pushNotification(int cid, List<Device> devices) {
|
| - |
|
151 |
|
| - |
|
152 |
for (Device device : devices) {
|
| - |
|
153 |
PushNotifications pn = new PushNotifications();
|
| - |
|
154 |
pn.setNotificationCampaignid(cid);
|
| - |
|
155 |
pn.setDeviceId(device.getId());
|
| - |
|
156 |
pn.setUserId(device.getUser_id());
|
| - |
|
157 |
pushNotificationRepository.persist(pn);
|
| - |
|
158 |
}
|
| - |
|
159 |
|
| - |
|
160 |
}
|
| - |
|
161 |
|
| - |
|
162 |
@Override
|
| - |
|
163 |
public void sendNotification(int fofoId, String campaignName, MessageType messageType, String title, String message,
|
| - |
|
164 |
String url) throws ProfitMandiBusinessException {
|
| - |
|
165 |
SendNotificationModel sendNotificationModel = this.getDefaultNotificationModel();
|
| - |
|
166 |
sendNotificationModel.setCampaignName(campaignName);
|
| - |
|
167 |
sendNotificationModel.setMessageType(messageType);
|
| - |
|
168 |
sendNotificationModel.setTitle(title);
|
| - |
|
169 |
sendNotificationModel.setMessage(message);
|
| - |
|
170 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
| - |
|
171 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| - |
|
172 |
sendNotificationModel.setMessageType(messageType);
|
| - |
|
173 |
sendNotificationModel.setUrl(url);
|
| - |
|
174 |
this.sendNotification(sendNotificationModel);
|
| - |
|
175 |
}
|
| - |
|
176 |
|
| - |
|
177 |
@Override
|
| - |
|
178 |
public void sendWhatsappMessage(String message, String title, String mobile)
|
| - |
|
179 |
throws Exception {
|
| - |
|
180 |
this.sendWhatsappMessage(message, title, mobile, null, null);
|
| - |
|
181 |
}
|
| - |
|
182 |
|
| - |
|
183 |
@Override
|
| - |
|
184 |
public void sendWhatsappMediaMessage(String message, String mobile, String mediaUrl, String fileName)
|
| - |
|
185 |
throws Exception {
|
| - |
|
186 |
this.sendWhatsappMessage(message, null, mobile, mediaUrl, fileName);
|
| - |
|
187 |
}
|
| - |
|
188 |
|
| - |
|
189 |
@Override
|
| - |
|
190 |
public void optIn(String phoneNumber) throws Exception {
|
| - |
|
191 |
Map<String, String> requestheaders = new HashMap<>();
|
| - |
|
192 |
requestheaders.put("Content-Type", "application/x-www-form-urlencoded");
|
| - |
|
193 |
Map<String, String> requestParams = new HashMap<>();
|
| - |
|
194 |
requestParams.put("userid", String.valueOf(2000215976));
|
| - |
|
195 |
requestParams.put("password", "MFRd!BBL");
|
| - |
|
196 |
requestParams.put("phone_number", phoneNumber);
|
| - |
|
197 |
requestParams.put("auth_scheme", "plain");
|
| - |
|
198 |
requestParams.put("v", "1.1");
|
| - |
|
199 |
requestParams.put("format", "json");
|
| - |
|
200 |
|
| - |
|
201 |
requestParams.put("method", "OPT_IN");
|
| - |
|
202 |
|
| - |
|
203 |
requestParams.put("channel", "WHATSAPP");
|
| - |
|
204 |
String response = restClient.get("https://media.smsgupshup.com/GatewayAPI/rest", requestParams, requestheaders);
|
| - |
|
205 |
LOGGER.info("response" + response);
|
| - |
|
206 |
}
|
| - |
|
207 |
|
| - |
|
208 |
private void sendWhatsappMessage(String message, String title, String mobile, String mediaUrl, String fileName)
|
| - |
|
209 |
throws Exception {
|
| - |
|
210 |
Map<String, String> requestheaders = new HashMap<>();
|
| - |
|
211 |
requestheaders.put("Content-Type", "application/x-www-form-urlencoded");
|
| - |
|
212 |
Map<String, String> requestParams = new HashMap<>();
|
| - |
|
213 |
requestParams.put("userid", String.valueOf(2000215976));
|
| - |
|
214 |
requestParams.put("password", "MFRd!BBL");
|
| - |
|
215 |
requestParams.put("send_to", mobile);
|
| - |
|
216 |
requestParams.put("v", "1.1");
|
| - |
|
217 |
requestParams.put("format", "json");
|
| - |
|
218 |
requestParams.put("method", "SENDMESSAGE");
|
| - |
|
219 |
requestParams.put("auth_scheme", "plain");
|
| - |
|
220 |
if (mediaUrl == null) {
|
| - |
|
221 |
/*requestParams.put("msg_type", "HSM");
|
| - |
|
222 |
requestParams.put("msg", message);
|
| - |
|
223 |
requestParams.put("isTemplate", "true");
|
| - |
|
224 |
requestParams.put("header", title);*/
|
| - |
|
225 |
//} else if(isProd && mediaUrl !=null) {
|
| - |
|
226 |
} else if (mediaUrl != null) {
|
| - |
|
227 |
Optin optin = optinRepository.selectByMobile(mobile);
|
| - |
|
228 |
if (optin == null) {
|
| - |
|
229 |
this.optIn(mobile);
|
| - |
|
230 |
optin = new Optin();
|
| - |
|
231 |
optin.setCreated(LocalDateTime.now());
|
| - |
|
232 |
optin.setMobile(mobile);
|
| 42 |
UserAccountRepository userAccountRepository;
|
233 |
optinRepository.persist(optin);
|
| - |
|
234 |
}
|
| - |
|
235 |
//requestParams.put("isHSM", "true");
|
| - |
|
236 |
requestParams.put("msg_type", "DOCUMENT");
|
| - |
|
237 |
requestParams.put("caption", message);
|
| - |
|
238 |
requestParams.put("msg", message);
|
| - |
|
239 |
requestParams.put("media_url", mediaUrl);
|
| - |
|
240 |
requestParams.put("filename", fileName);
|
| - |
|
241 |
}
|
| - |
|
242 |
|
| - |
|
243 |
String response =
|
| - |
|
244 |
restClient.post("https://media.smsgupshup.com/GatewayAPI/rest",
|
| - |
|
245 |
requestParams,
|
| - |
|
246 |
requestheaders);
|
| - |
|
247 |
LOGGER.info("response" + response);
|
| - |
|
248 |
}
|
| 43 |
|
249 |
|
| 44 |
@Autowired
|
- |
|
| 45 |
NotificationCampaignRepository notificationCampaignRepository;
|
- |
|
| 46 |
|
- |
|
| 47 |
@Autowired
|
- |
|
| 48 |
DeviceRepository deviceRepository;
|
- |
|
| 49 |
|
- |
|
| 50 |
@Autowired
|
- |
|
| 51 |
FofoStoreRepository fofoStoreRepository;
|
- |
|
| 52 |
|
- |
|
| 53 |
@Autowired
|
- |
|
| 54 |
CsService csService;
|
- |
|
| 55 |
|
- |
|
| 56 |
@Autowired
|
- |
|
| 57 |
RetailerService retailerService;
|
- |
|
| 58 |
|
- |
|
| 59 |
@Autowired
|
- |
|
| 60 |
PushNotificationRepository pushNotificationRepository;
|
- |
|
| 61 |
|
- |
|
| 62 |
@Autowired
|
- |
|
| 63 |
private Gson gson;
|
- |
|
| 64 |
|
- |
|
| 65 |
@Autowired
|
- |
|
| 66 |
private RestClient restClient;
|
- |
|
| 67 |
|
- |
|
| 68 |
private static final Logger LOGGER = LogManager.getLogger(NotificationService.class);
|
- |
|
| 69 |
|
- |
|
| 70 |
@Override
|
- |
|
| 71 |
public void sendNotification(SendNotificationModel sendNotificationModel) throws ProfitMandiBusinessException {
|
- |
|
| 72 |
|
- |
|
| 73 |
SimpleCampaignParams scp = new SimpleCampaignParams();
|
- |
|
| 74 |
scp.setMessage(sendNotificationModel.getMessage());
|
- |
|
| 75 |
scp.setTitle(sendNotificationModel.getTitle());
|
- |
|
| 76 |
scp.setImageUrl(sendNotificationModel.getImageUrl());
|
- |
|
| 77 |
scp.setType(sendNotificationModel.getType());
|
- |
|
| 78 |
scp.setUrl(sendNotificationModel.getUrl());
|
- |
|
| 79 |
scp.setShowImage(sendNotificationModel.getShowImage());
|
- |
|
| 80 |
scp.setExpireTimestamp(sendNotificationModel.getExpiresat());
|
- |
|
| 81 |
SimpleCampaign sc = new SimpleCampaign(scp);
|
- |
|
| 82 |
sc.setSimpleCampaignParams(scp);
|
- |
|
| 83 |
|
- |
|
| 84 |
NotificationCampaign nc = new NotificationCampaign();
|
- |
|
| 85 |
nc.setName(sendNotificationModel.getCampaignName());
|
- |
|
| 86 |
nc.setImplementationType("SimpleCampaign");
|
- |
|
| 87 |
nc.setImplementationParams(gson.toJson(scp));
|
- |
|
| 88 |
nc.setMessageType(sendNotificationModel.getMessageType());
|
- |
|
| 89 |
nc.setDocumentId(sendNotificationModel.getDocumentId());
|
- |
|
| 90 |
nc.setCreatedTimestamp(LocalDateTime.now());
|
- |
|
| 91 |
notificationCampaignRepository.persist(nc);
|
- |
|
| 92 |
|
- |
|
| 93 |
UserCampaign uc = null;
|
- |
|
| 94 |
|
- |
|
| 95 |
Set<Integer> userIds = new HashSet<>();
|
- |
|
| 96 |
if (sendNotificationModel.getUserIds() != null && sendNotificationModel.getUserIds().size() > 0) {
|
- |
|
| 97 |
userIds.addAll(sendNotificationModel.getUserIds());
|
- |
|
| 98 |
}
|
- |
|
| 99 |
|
- |
|
| 100 |
if (sendNotificationModel.getStateIds() != null && sendNotificationModel.getStateIds().size() > 0) {
|
- |
|
| 101 |
userIds.addAll(fofoStoreRepository.selectByWarehouseIds(sendNotificationModel.getStateIds()).stream()
|
- |
|
| 102 |
.map(x -> x.getId()).collect(Collectors.toList()));
|
- |
|
| 103 |
}
|
- |
|
| 104 |
|
- |
|
| 105 |
LOGGER.info("userIds" + userIds);
|
- |
|
| 106 |
|
- |
|
| 107 |
for (Integer userId : userIds) {
|
- |
|
| 108 |
uc = new UserCampaign();
|
- |
|
| 109 |
uc.setCampaignId(nc.getId());
|
- |
|
| 110 |
uc.setUserId(userId);
|
- |
|
| 111 |
uc.setPushTimestamp(LocalDateTime.now());
|
- |
|
| 112 |
userCampaignRepository.persist(uc);
|
- |
|
| 113 |
}
|
- |
|
| 114 |
|
- |
|
| 115 |
List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(new ArrayList<>(userIds),
|
- |
|
| 116 |
LocalDateTime.now().minusMonths(3), LocalDateTime.now());
|
- |
|
| 117 |
|
- |
|
| 118 |
LOGGER.info("devices" + devices);
|
- |
|
| 119 |
pushNotification(nc.getId(), devices);
|
- |
|
| 120 |
|
- |
|
| 121 |
}
|
- |
|
| 122 |
|
- |
|
| 123 |
@Override
|
- |
|
| 124 |
public void sendNotificationToAll(SendNotificationModel sendNotificationModel) throws ProfitMandiBusinessException {
|
- |
|
| 125 |
sendNotificationModel.setUserIds(fofoStoreRepository.selectAllDtrUserIds());
|
- |
|
| 126 |
Set<AuthUser> authUsers = new HashSet<>(
|
- |
|
| 127 |
csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
|
- |
|
| 128 |
authUsers.addAll(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY));
|
- |
|
| 129 |
authUsers.addAll(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES));
|
- |
|
| 130 |
List<String> emailIds = authUsers.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
- |
|
| 131 |
emailIds.add("devkinandan.lal@smartdukaan.com");
|
- |
|
| 132 |
List<User> systemUsers = dtrUserRepository.selectAllByEmailIds(emailIds);
|
- |
|
| 133 |
sendNotificationModel.getUserIds()
|
- |
|
| 134 |
.addAll(systemUsers.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
- |
|
| 135 |
this.sendNotification(sendNotificationModel);
|
- |
|
| 136 |
}
|
- |
|
| 137 |
|
- |
|
| 138 |
@Override
|
- |
|
| 139 |
public void sendNotification(int fofoId, String campaignName, MessageType messageType, String title, String message)
|
- |
|
| 140 |
throws ProfitMandiBusinessException {
|
- |
|
| 141 |
SendNotificationModel sendNotificationModel = this.getDefaultNotificationModel();
|
- |
|
| 142 |
sendNotificationModel.setCampaignName(campaignName);
|
- |
|
| 143 |
sendNotificationModel.setMessageType(messageType);
|
- |
|
| 144 |
sendNotificationModel.setTitle(title);
|
- |
|
| 145 |
sendNotificationModel.setMessage(message);
|
- |
|
| 146 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
- |
|
| 147 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
- |
|
| 148 |
sendNotificationModel.setMessageType(MessageType.wallet);
|
- |
|
| 149 |
this.sendNotification(sendNotificationModel);
|
- |
|
| 150 |
}
|
- |
|
| 151 |
|
- |
|
| 152 |
public SendNotificationModel getDefaultNotificationModel() {
|
- |
|
| 153 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
- |
|
| 154 |
sendNotificationModel.setType("url");
|
- |
|
| 155 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
- |
|
| 156 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
- |
|
| 157 |
sendNotificationModel.setMessageType(MessageType.notification);
|
- |
|
| 158 |
return sendNotificationModel;
|
- |
|
| 159 |
}
|
- |
|
| 160 |
|
- |
|
| 161 |
public void pushNotification(int cid, List<Device> devices) {
|
- |
|
| 162 |
|
- |
|
| 163 |
for (Device device : devices) {
|
- |
|
| 164 |
PushNotifications pn = new PushNotifications();
|
- |
|
| 165 |
pn.setNotificationCampaignid(cid);
|
- |
|
| 166 |
pn.setDeviceId(device.getId());
|
- |
|
| 167 |
pn.setUserId(device.getUser_id());
|
- |
|
| 168 |
pushNotificationRepository.persist(pn);
|
- |
|
| 169 |
}
|
- |
|
| 170 |
|
- |
|
| 171 |
}
|
- |
|
| 172 |
|
- |
|
| 173 |
@Override
|
- |
|
| 174 |
public void sendNotification(int fofoId, String campaignName, MessageType messageType, String title, String message,
|
- |
|
| 175 |
String url) throws ProfitMandiBusinessException {
|
- |
|
| 176 |
SendNotificationModel sendNotificationModel = this.getDefaultNotificationModel();
|
- |
|
| 177 |
sendNotificationModel.setCampaignName(campaignName);
|
- |
|
| 178 |
sendNotificationModel.setMessageType(messageType);
|
- |
|
| 179 |
sendNotificationModel.setTitle(title);
|
- |
|
| 180 |
sendNotificationModel.setMessage(message);
|
- |
|
| 181 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
- |
|
| 182 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
- |
|
| 183 |
sendNotificationModel.setMessageType(messageType);
|
- |
|
| 184 |
sendNotificationModel.setUrl(url);
|
- |
|
| 185 |
this.sendNotification(sendNotificationModel);
|
- |
|
| 186 |
}
|
- |
|
| 187 |
|
- |
|
| 188 |
@Override
|
- |
|
| 189 |
public void sendWhatsappMessage(String message, String title, String mobile)
|
- |
|
| 190 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
- |
|
| 191 |
Map<String, String> requestheaders = new HashMap<>();
|
- |
|
| 192 |
requestheaders.put("Content-Type", "application/x-www-form-urlencoded");
|
- |
|
| 193 |
Map<String, String> requestParams = new HashMap<>();
|
- |
|
| 194 |
requestParams.put("userid", String.valueOf(2000215976));
|
- |
|
| 195 |
requestParams.put("password", "MFRd!BBL");
|
- |
|
| 196 |
requestParams.put("send_to", mobile);
|
- |
|
| 197 |
requestParams.put("auth_scheme", "plain");
|
- |
|
| 198 |
requestParams.put("v", "1.1");
|
- |
|
| 199 |
|
- |
|
| 200 |
requestParams.put("format", "json");
|
- |
|
| 201 |
|
- |
|
| 202 |
requestParams.put("msg_type", "HSM");
|
- |
|
| 203 |
|
- |
|
| 204 |
requestParams.put("method", "SENDMESSAGE");
|
- |
|
| 205 |
|
- |
|
| 206 |
requestParams.put("msg", message);
|
- |
|
| 207 |
|
- |
|
| 208 |
requestParams.put("isTemplate", "true");
|
- |
|
| 209 |
requestParams.put("header", title);
|
- |
|
| 210 |
// String response =
|
- |
|
| 211 |
// restClient.post("https://media.smsgupshup.com/GatewayAPI/rest",
|
- |
|
| 212 |
// requestParams,
|
- |
|
| 213 |
// requestheaders);
|
- |
|
| 214 |
// LOGGER.info("response" + response);
|
- |
|
| 215 |
}
|
- |
|
| 216 |
|
250 |
|
| 217 |
}
|
251 |
}
|