| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service;
|
1 |
package com.spice.profitmandi.service;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDateTime;
|
- |
|
| 4 |
import java.util.ArrayList;
|
- |
|
| 5 |
import java.util.HashSet;
|
- |
|
| 6 |
import java.util.List;
|
- |
|
| 7 |
import java.util.Set;
|
- |
|
| 8 |
import java.util.stream.Collectors;
|
- |
|
| 9 |
|
- |
|
| 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.Component;
|
- |
|
| 14 |
|
- |
|
| 15 |
import com.google.gson.Gson;
|
3 |
import com.google.gson.Gson;
|
| 16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
5 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 17 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
6 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| - |
|
7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 18 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
8 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
| 19 |
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
|
9 |
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
|
| - |
|
10 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 20 |
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
|
11 |
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
|
| 21 |
import com.spice.profitmandi.dao.entity.user.Device;
|
12 |
import com.spice.profitmandi.dao.entity.user.Device;
|
| 22 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
13 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
| 23 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
14 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 24 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
15 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| 25 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
16 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 26 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
- |
|
| 27 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
- |
|
| 28 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
17 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 29 |
import com.spice.profitmandi.service.user.RetailerService;
|
18 |
import com.spice.profitmandi.service.user.RetailerService;
|
| - |
|
19 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
20 |
import org.apache.logging.log4j.Logger;
|
| - |
|
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
22 |
import org.springframework.stereotype.Component;
|
| - |
|
23 |
|
| - |
|
24 |
import java.time.LocalDateTime;
|
| - |
|
25 |
import java.util.ArrayList;
|
| - |
|
26 |
import java.util.HashSet;
|
| - |
|
27 |
import java.util.List;
|
| - |
|
28 |
import java.util.Set;
|
| - |
|
29 |
import java.util.stream.Collectors;
|
| 30 |
|
30 |
|
| 31 |
@Component
|
31 |
@Component
|
| 32 |
public class NotificationServiceImpl implements NotificationService {
|
32 |
public class NotificationServiceImpl implements NotificationService {
|
| 33 |
|
33 |
|
| 34 |
@Autowired
|
34 |
@Autowired
|
| 35 |
UserCampaignRepository userCampaignRepository;
|
35 |
UserCampaignRepository userCampaignRepository;
|
| 36 |
|
36 |
|
| 37 |
@Autowired
|
37 |
@Autowired
|
| - |
|
38 |
UserRepository dtrUserRepository;
|
| - |
|
39 |
|
| - |
|
40 |
@Autowired
|
| 38 |
NotificationCampaignRepository notificationCampaignRepository;
|
41 |
NotificationCampaignRepository notificationCampaignRepository;
|
| 39 |
|
42 |
|
| 40 |
@Autowired
|
43 |
@Autowired
|
| 41 |
DeviceRepository deviceRepository;
|
44 |
DeviceRepository deviceRepository;
|
| 42 |
|
45 |
|
| 43 |
@Autowired
|
46 |
@Autowired
|
| 44 |
FofoStoreRepository fofoStoreRepository;
|
47 |
FofoStoreRepository fofoStoreRepository;
|
| 45 |
|
48 |
|
| 46 |
@Autowired
|
49 |
@Autowired
|
| - |
|
50 |
CsService csService;
|
| - |
|
51 |
|
| - |
|
52 |
@Autowired
|
| 47 |
RetailerService retailerService;
|
53 |
RetailerService retailerService;
|
| 48 |
|
54 |
|
| 49 |
@Autowired
|
55 |
@Autowired
|
| 50 |
PushNotificationRepository pushNotificationRepository;
|
56 |
PushNotificationRepository pushNotificationRepository;
|
| 51 |
|
57 |
|
| Line 105... |
Line 111... |
| 105 |
LOGGER.info("devices" + devices);
|
111 |
LOGGER.info("devices" + devices);
|
| 106 |
pushNotification(nc.getId(), devices);
|
112 |
pushNotification(nc.getId(), devices);
|
| 107 |
|
113 |
|
| 108 |
}
|
114 |
}
|
| 109 |
|
115 |
|
| - |
|
116 |
@Override
|
| - |
|
117 |
public void sendNotificationToAll(SendNotificationModel sendNotificationModel) throws ProfitMandiBusinessException {
|
| - |
|
118 |
sendNotificationModel.setUserIds(fofoStoreRepository.selectAllDtrUserIds());
|
| - |
|
119 |
Set<AuthUser> authUsers = new HashSet<>(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
|
| - |
|
120 |
authUsers.addAll(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY));
|
| - |
|
121 |
authUsers.addAll(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES));
|
| - |
|
122 |
List<String> emailIds = authUsers.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
| - |
|
123 |
List<User> user = dtrUserRepository.selectAllByEmailIds(emailIds);
|
| - |
|
124 |
sendNotificationModel.getUserIds().addAll(user.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| - |
|
125 |
this.sendNotification(sendNotificationModel);
|
| - |
|
126 |
}
|
| - |
|
127 |
|
| 110 |
public void pushNotification(int cid, List<Device> devices) {
|
128 |
public void pushNotification(int cid, List<Device> devices) {
|
| 111 |
|
129 |
|
| 112 |
for (Device device : devices) {
|
130 |
for (Device device : devices) {
|
| 113 |
PushNotifications pn = new PushNotifications();
|
131 |
PushNotifications pn = new PushNotifications();
|
| 114 |
pn.setNotificationCampaignid(cid);
|
132 |
pn.setNotificationCampaignid(cid);
|