| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service;
|
1 |
package com.spice.profitmandi.service;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDateTime;
|
3 |
import java.time.LocalDateTime;
|
| - |
|
4 |
import java.util.ArrayList;
|
| - |
|
5 |
import java.util.HashSet;
|
| 4 |
import java.util.List;
|
6 |
import java.util.List;
|
| - |
|
7 |
import java.util.Map;
|
| - |
|
8 |
import java.util.stream.Collectors;
|
| 5 |
|
9 |
|
| 6 |
import org.apache.logging.log4j.LogManager;
|
10 |
import org.apache.logging.log4j.LogManager;
|
| 7 |
import org.apache.logging.log4j.Logger;
|
11 |
import org.apache.logging.log4j.Logger;
|
| 8 |
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 9 |
import org.springframework.stereotype.Component;
|
13 |
import org.springframework.stereotype.Component;
|
| 10 |
|
14 |
|
| 11 |
import com.google.gson.Gson;
|
15 |
import com.google.gson.Gson;
|
| - |
|
16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
17 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 12 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
18 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 13 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
19 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
| 14 |
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
|
20 |
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
|
| 15 |
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
|
21 |
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
|
| - |
|
22 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 16 |
import com.spice.profitmandi.dao.entity.user.Device;
|
23 |
import com.spice.profitmandi.dao.entity.user.Device;
|
| 17 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
24 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
| 18 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
25 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 19 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
26 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| - |
|
27 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 20 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
28 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
| 21 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
29 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
| 22 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
30 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
| - |
|
31 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23 |
|
32 |
|
| 24 |
@Component
|
33 |
@Component
|
| 25 |
public class NotificationServiceImpl implements NotificationService {
|
34 |
public class NotificationServiceImpl implements NotificationService {
|
| 26 |
|
35 |
|
| 27 |
@Autowired
|
36 |
@Autowired
|
| Line 32... |
Line 41... |
| 32 |
|
41 |
|
| 33 |
@Autowired
|
42 |
@Autowired
|
| 34 |
DeviceRepository deviceRepository;
|
43 |
DeviceRepository deviceRepository;
|
| 35 |
|
44 |
|
| 36 |
@Autowired
|
45 |
@Autowired
|
| - |
|
46 |
FofoStoreRepository fofoStoreRepository;
|
| - |
|
47 |
|
| - |
|
48 |
@Autowired
|
| - |
|
49 |
RetailerService retailerService;
|
| - |
|
50 |
|
| - |
|
51 |
@Autowired
|
| 37 |
PushNotificationRepository pushNotificationRepository;
|
52 |
PushNotificationRepository pushNotificationRepository;
|
| 38 |
|
53 |
|
| 39 |
@Autowired
|
54 |
@Autowired
|
| 40 |
private Gson gson;
|
55 |
private Gson gson;
|
| 41 |
|
56 |
|
| 42 |
private static final Logger LOGGER = LogManager.getLogger(NotificationService.class);
|
57 |
private static final Logger LOGGER = LogManager.getLogger(NotificationService.class);
|
| 43 |
|
58 |
|
| 44 |
@Override
|
59 |
@Override
|
| 45 |
public void sendNotification(SendNotificationModel sendNotificationModel) {
|
60 |
public void sendNotification(SendNotificationModel sendNotificationModel) throws ProfitMandiBusinessException {
|
| 46 |
|
61 |
|
| 47 |
SimpleCampaignParams scp = new SimpleCampaignParams();
|
62 |
SimpleCampaignParams scp = new SimpleCampaignParams();
|
| 48 |
scp.setMessage(sendNotificationModel.getMessage());
|
63 |
scp.setMessage(sendNotificationModel.getMessage());
|
| 49 |
scp.setTitle(sendNotificationModel.getTitle());
|
64 |
scp.setTitle(sendNotificationModel.getTitle());
|
| 50 |
scp.setImageUrl(sendNotificationModel.getImageUrl());
|
65 |
scp.setImageUrl(sendNotificationModel.getImageUrl());
|
| Line 63... |
Line 78... |
| 63 |
nc.setDocumentId(sendNotificationModel.getDocumentId());
|
78 |
nc.setDocumentId(sendNotificationModel.getDocumentId());
|
| 64 |
nc.setCreatedTimestamp(LocalDateTime.now());
|
79 |
nc.setCreatedTimestamp(LocalDateTime.now());
|
| 65 |
notificationCampaignRepository.persist(nc);
|
80 |
notificationCampaignRepository.persist(nc);
|
| 66 |
|
81 |
|
| 67 |
UserCampaign uc = null;
|
82 |
UserCampaign uc = null;
|
| - |
|
83 |
|
| - |
|
84 |
List<Integer> fofoIds = fofoStoreRepository.selectByWarehouseIds(sendNotificationModel.getStateIds()).stream()
|
| - |
|
85 |
.map(x -> x.getId()).collect(Collectors.toList());
|
| - |
|
86 |
|
| - |
|
87 |
Map<Integer, CustomRetailer> userIdMap = retailerService.getFofoRetailerUserId(fofoIds);
|
| 68 |
List<Integer> userIds = sendNotificationModel.getUserIds();
|
88 |
List<Integer> users = sendNotificationModel.getUserIds();
|
| - |
|
89 |
|
| - |
|
90 |
if (!fofoIds.isEmpty()) {
|
| - |
|
91 |
users.addAll(userIdMap.keySet().stream().map(x -> x).collect(Collectors.toList()));
|
| - |
|
92 |
}
|
| - |
|
93 |
|
| - |
|
94 |
LOGGER.info("users" + users);
|
| - |
|
95 |
HashSet<Integer> userHashset = new HashSet<Integer>();
|
| - |
|
96 |
userHashset.addAll(users);
|
| - |
|
97 |
|
| - |
|
98 |
List<Integer> userIds = new ArrayList<>(userHashset);
|
| - |
|
99 |
|
| - |
|
100 |
LOGGER.info("userIds" + userIds);
|
| - |
|
101 |
|
| 69 |
for (Integer userId : userIds) {
|
102 |
for (Integer userId : userIds) {
|
| 70 |
uc = new UserCampaign();
|
103 |
uc = new UserCampaign();
|
| 71 |
uc.setCampaignId(nc.getId());
|
104 |
uc.setCampaignId(nc.getId());
|
| 72 |
uc.setUserId(userId);
|
105 |
uc.setUserId(userId);
|
| 73 |
uc.setPushTimestamp(LocalDateTime.now());
|
106 |
uc.setPushTimestamp(LocalDateTime.now());
|
| 74 |
userCampaignRepository.persist(uc);
|
107 |
userCampaignRepository.persist(uc);
|
| 75 |
}
|
108 |
}
|
| 76 |
LOGGER.info("userIds" + userIds);
|
- |
|
| 77 |
|
109 |
|
| 78 |
List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(userIds,
|
110 |
List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(userIds,
|
| 79 |
LocalDateTime.now().minusMonths(3), LocalDateTime.now());
|
111 |
LocalDateTime.now().minusMonths(3), LocalDateTime.now());
|
| 80 |
|
112 |
|
| 81 |
LOGGER.info("devices" + devices);
|
113 |
LOGGER.info("devices" + devices);
|