Subversion Repositories SmartDukaan

Rev

Rev 29198 | Rev 29927 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29198 Rev 29204
Line 2... Line 2...
2
 
2
 
3
import java.time.LocalDateTime;
3
import java.time.LocalDateTime;
4
import java.util.ArrayList;
4
import java.util.ArrayList;
5
import java.util.HashSet;
5
import java.util.HashSet;
6
import java.util.List;
6
import java.util.List;
7
import java.util.Map;
7
import java.util.Set;
8
import java.util.stream.Collectors;
8
import java.util.stream.Collectors;
9
 
9
 
10
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.LogManager;
11
import org.apache.logging.log4j.Logger;
11
import org.apache.logging.log4j.Logger;
12
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.stereotype.Component;
13
import org.springframework.stereotype.Component;
14
 
14
 
15
import com.google.gson.Gson;
15
import com.google.gson.Gson;
16
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
16
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
17
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
18
import com.spice.profitmandi.common.model.SendNotificationModel;
17
import com.spice.profitmandi.common.model.SendNotificationModel;
19
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
18
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
20
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
19
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
21
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
20
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
22
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
23
import com.spice.profitmandi.dao.entity.user.Device;
21
import com.spice.profitmandi.dao.entity.user.Device;
24
import com.spice.profitmandi.dao.model.SimpleCampaign;
22
import com.spice.profitmandi.dao.model.SimpleCampaign;
25
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
23
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
26
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
24
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
27
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
25
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
Line 79... Line 77...
79
		nc.setCreatedTimestamp(LocalDateTime.now());
77
		nc.setCreatedTimestamp(LocalDateTime.now());
80
		notificationCampaignRepository.persist(nc);
78
		notificationCampaignRepository.persist(nc);
81
 
79
 
82
		UserCampaign uc = null;
80
		UserCampaign uc = null;
83
 
81
 
84
		List<Integer> fofoIds = fofoStoreRepository.selectByWarehouseIds(sendNotificationModel.getStateIds()).stream()
-
 
85
				.map(x -> x.getId()).collect(Collectors.toList());
82
		Set<Integer> userIds = new HashSet<>();
86
 
-
 
87
		Map<Integer, CustomRetailer> userIdMap = retailerService.getFofoRetailerUserId(fofoIds);
83
		if(sendNotificationModel.getUserIds() != null && sendNotificationModel.getUserIds().size() > 0) {
88
		List<Integer> users = sendNotificationModel.getUserIds();
84
			userIds.addAll(sendNotificationModel.getUserIds());
89
 
-
 
90
		if (!fofoIds.isEmpty()) {
-
 
91
			users.addAll(userIdMap.keySet().stream().map(x -> x).collect(Collectors.toList()));
-
 
92
		}
85
		}
93
 
86
 
94
		LOGGER.info("users" + users);
87
		if(sendNotificationModel.getStateIds() !=null && sendNotificationModel.getStateIds().size() > 0) {
95
		HashSet<Integer> userHashset = new HashSet<Integer>();
88
			userIds.addAll(fofoStoreRepository.selectByWarehouseIds(sendNotificationModel.getStateIds()).stream()
96
		userHashset.addAll(users);
89
					.map(x -> x.getId()).collect(Collectors.toList()));
97
 
90
		}
98
		List<Integer> userIds = new ArrayList<>(userHashset);
-
 
99
 
91
 
100
		LOGGER.info("userIds" + userIds);
92
		LOGGER.info("userIds" + userIds);
101
 
93
 
102
		for (Integer userId : userIds) {
94
		for (Integer userId : userIds) {
103
			uc = new UserCampaign();
95
			uc = new UserCampaign();
Line 105... Line 97...
105
			uc.setUserId(userId);
97
			uc.setUserId(userId);
106
			uc.setPushTimestamp(LocalDateTime.now());
98
			uc.setPushTimestamp(LocalDateTime.now());
107
			userCampaignRepository.persist(uc);
99
			userCampaignRepository.persist(uc);
108
		}
100
		}
109
 
101
 
110
		List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(userIds,
102
		List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(new ArrayList<>(userIds),
111
				LocalDateTime.now().minusMonths(3), LocalDateTime.now());
103
				LocalDateTime.now().minusMonths(3), LocalDateTime.now());
112
 
104
 
113
		LOGGER.info("devices" + devices);
105
		LOGGER.info("devices" + devices);
114
		pushNotification(nc.getId(), devices);
106
		pushNotification(nc.getId(), devices);
115
 
107