| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service;
|
1 |
package com.spice.profitmandi.service;
|
| 2 |
|
2 |
|
| 3 |
import com.google.gson.Gson;
|
3 |
import com.google.gson.Gson;
|
| - |
|
4 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 5 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 6 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
7 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
8 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 8 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
9 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
| Line 20... |
Line 21... |
| 20 |
import org.apache.logging.log4j.Logger;
|
21 |
import org.apache.logging.log4j.Logger;
|
| 21 |
import org.springframework.beans.factory.annotation.Autowired;
|
22 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 22 |
import org.springframework.stereotype.Component;
|
23 |
import org.springframework.stereotype.Component;
|
| 23 |
|
24 |
|
| 24 |
import java.time.LocalDateTime;
|
25 |
import java.time.LocalDateTime;
|
| 25 |
import java.util.ArrayList;
|
- |
|
| 26 |
import java.util.HashSet;
|
- |
|
| 27 |
import java.util.List;
|
- |
|
| 28 |
import java.util.Set;
|
26 |
import java.util.*;
|
| 29 |
import java.util.stream.Collectors;
|
27 |
import java.util.stream.Collectors;
|
| 30 |
|
28 |
|
| 31 |
@Component
|
29 |
@Component
|
| 32 |
public class NotificationServiceImpl implements NotificationService {
|
30 |
public class NotificationServiceImpl implements NotificationService {
|
| 33 |
|
31 |
|
| Line 36... |
Line 34... |
| 36 |
|
34 |
|
| 37 |
@Autowired
|
35 |
@Autowired
|
| 38 |
UserRepository dtrUserRepository;
|
36 |
UserRepository dtrUserRepository;
|
| 39 |
|
37 |
|
| 40 |
@Autowired
|
38 |
@Autowired
|
| - |
|
39 |
UserAccountRepository userAccountRepository;
|
| - |
|
40 |
|
| - |
|
41 |
@Autowired
|
| 41 |
NotificationCampaignRepository notificationCampaignRepository;
|
42 |
NotificationCampaignRepository notificationCampaignRepository;
|
| 42 |
|
43 |
|
| 43 |
@Autowired
|
44 |
@Autowired
|
| 44 |
DeviceRepository deviceRepository;
|
45 |
DeviceRepository deviceRepository;
|
| 45 |
|
46 |
|
| Line 123... |
Line 124... |
| 123 |
List<User> systemUsers = dtrUserRepository.selectAllByEmailIds(emailIds);
|
124 |
List<User> systemUsers = dtrUserRepository.selectAllByEmailIds(emailIds);
|
| 124 |
sendNotificationModel.getUserIds().addAll(systemUsers.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
125 |
sendNotificationModel.getUserIds().addAll(systemUsers.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 125 |
this.sendNotification(sendNotificationModel);
|
126 |
this.sendNotification(sendNotificationModel);
|
| 126 |
}
|
127 |
}
|
| 127 |
|
128 |
|
| - |
|
129 |
@Override
|
| - |
|
130 |
public void sendNotification(int fofoId, String campaignName, String title, String message) throws ProfitMandiBusinessException {
|
| - |
|
131 |
SendNotificationModel sendNotificationModel = this.getDefaultNotificationModel();
|
| - |
|
132 |
sendNotificationModel.setCampaignName(campaignName);
|
| - |
|
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 |
}
|
| - |
|
139 |
|
| - |
|
140 |
public SendNotificationModel getDefaultNotificationModel() {
|
| - |
|
141 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| - |
|
142 |
sendNotificationModel.setType("url");
|
| - |
|
143 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| - |
|
144 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| - |
|
145 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| - |
|
146 |
return sendNotificationModel;
|
| - |
|
147 |
}
|
| - |
|
148 |
|
| 128 |
public void pushNotification(int cid, List<Device> devices) {
|
149 |
public void pushNotification(int cid, List<Device> devices) {
|
| 129 |
|
150 |
|
| 130 |
for (Device device : devices) {
|
151 |
for (Device device : devices) {
|
| 131 |
PushNotifications pn = new PushNotifications();
|
152 |
PushNotifications pn = new PushNotifications();
|
| 132 |
pn.setNotificationCampaignid(cid);
|
153 |
pn.setNotificationCampaignid(cid);
|