| Line 23... |
Line 23... |
| 23 |
import java.util.stream.Collectors;
|
23 |
import java.util.stream.Collectors;
|
| 24 |
|
24 |
|
| 25 |
import javax.mail.MessagingException;
|
25 |
import javax.mail.MessagingException;
|
| 26 |
import javax.mail.internet.InternetAddress;
|
26 |
import javax.mail.internet.InternetAddress;
|
| 27 |
import javax.mail.internet.MimeMessage;
|
27 |
import javax.mail.internet.MimeMessage;
|
| - |
|
28 |
import javax.servlet.http.HttpServletRequest;
|
| 28 |
|
29 |
|
| 29 |
import org.apache.commons.codec.CharEncoding;
|
30 |
import org.apache.commons.codec.CharEncoding;
|
| 30 |
import org.apache.commons.io.IOUtils;
|
31 |
import org.apache.commons.io.IOUtils;
|
| 31 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
32 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| - |
|
33 |
import org.apache.http.client.methods.CloseableHttpResponse;
|
| - |
|
34 |
import org.apache.http.client.methods.HttpPost;
|
| - |
|
35 |
import org.apache.http.entity.StringEntity;
|
| - |
|
36 |
import org.apache.http.impl.client.CloseableHttpClient;
|
| - |
|
37 |
import org.apache.http.impl.client.HttpClients;
|
| 32 |
import org.apache.logging.log4j.LogManager;
|
38 |
import org.apache.logging.log4j.LogManager;
|
| 33 |
import org.apache.logging.log4j.Logger;
|
39 |
import org.apache.logging.log4j.Logger;
|
| 34 |
import org.apache.poi.EncryptedDocumentException;
|
40 |
import org.apache.poi.EncryptedDocumentException;
|
| 35 |
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
41 |
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
| - |
|
42 |
import org.json.JSONObject;
|
| 36 |
import org.springframework.beans.factory.annotation.Autowired;
|
43 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 37 |
import org.springframework.beans.factory.annotation.Qualifier;
|
44 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 38 |
import org.springframework.beans.factory.annotation.Value;
|
45 |
import org.springframework.beans.factory.annotation.Value;
|
| 39 |
import org.springframework.core.io.ByteArrayResource;
|
46 |
import org.springframework.core.io.ByteArrayResource;
|
| 40 |
import org.springframework.core.io.InputStreamSource;
|
47 |
import org.springframework.core.io.InputStreamSource;
|
| 41 |
import org.springframework.mail.javamail.JavaMailSender;
|
48 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 42 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
49 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 43 |
import org.springframework.stereotype.Component;
|
50 |
import org.springframework.stereotype.Component;
|
| 44 |
import org.springframework.transaction.annotation.Transactional;
|
51 |
import org.springframework.transaction.annotation.Transactional;
|
| - |
|
52 |
import org.springframework.ui.Model;
|
| - |
|
53 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| - |
|
54 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 45 |
|
55 |
|
| 46 |
import com.google.common.collect.Lists;
|
56 |
import com.google.common.collect.Lists;
|
| - |
|
57 |
import com.google.gson.Gson;
|
| - |
|
58 |
import com.google.gson.GsonBuilder;
|
| 47 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
59 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 48 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
60 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 49 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
61 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 50 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
62 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 51 |
import com.spice.profitmandi.common.model.GstRate;
|
63 |
import com.spice.profitmandi.common.model.GstRate;
|
| Line 53... |
Line 65... |
| 53 |
import com.spice.profitmandi.common.services.ReporticoService;
|
65 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 54 |
import com.spice.profitmandi.common.util.FileUtil;
|
66 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 55 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
67 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 56 |
import com.spice.profitmandi.common.util.Utils;
|
68 |
import com.spice.profitmandi.common.util.Utils;
|
| 57 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
69 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
| - |
|
70 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
| - |
|
71 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
| 58 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
72 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 59 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
73 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
| - |
|
74 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
| 60 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
75 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
| - |
|
76 |
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
|
| 61 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
77 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
| 62 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
78 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
| 63 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
79 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 64 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
80 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 65 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
81 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| Line 75... |
Line 91... |
| 75 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
91 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 76 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
92 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 77 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
93 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 78 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
94 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 79 |
import com.spice.profitmandi.dao.entity.user.Address;
|
95 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| - |
|
96 |
import com.spice.profitmandi.dao.entity.user.Device;
|
| 80 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
97 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 81 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
98 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| - |
|
99 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
| - |
|
100 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| - |
|
101 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| 82 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
102 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 83 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
103 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 84 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
104 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 85 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
105 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 86 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
106 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| - |
|
107 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
| - |
|
108 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
| 87 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
109 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
| 88 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
110 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
| 89 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
111 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 90 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
112 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 91 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
113 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| Line 271... |
Line 293... |
| 271 |
|
293 |
|
| 272 |
@Autowired
|
294 |
@Autowired
|
| 273 |
private Mongo mongoClient;
|
295 |
private Mongo mongoClient;
|
| 274 |
|
296 |
|
| 275 |
@Autowired
|
297 |
@Autowired
|
| - |
|
298 |
private DeviceRepository deviceRepository;
|
| - |
|
299 |
|
| - |
|
300 |
@Autowired
|
| - |
|
301 |
private PushNotificationRepository pushNotificationRepository;
|
| - |
|
302 |
|
| - |
|
303 |
@Autowired
|
| - |
|
304 |
private NotificationCampaignRepository notificationCampaignRepository;
|
| - |
|
305 |
|
| - |
|
306 |
@Autowired
|
| 276 |
private UserAccountRepository userAccountRepository;
|
307 |
private UserAccountRepository userAccountRepository;
|
| 277 |
|
308 |
|
| 278 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
309 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 279 |
|
310 |
|
| - |
|
311 |
private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
|
| - |
|
312 |
private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
|
| - |
|
313 |
|
| 280 |
public void generateDailyRecharge() {
|
314 |
public void generateDailyRecharge() {
|
| 281 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
315 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
| 282 |
.selectAll(0, 2000);
|
316 |
.selectAll(0, 2000);
|
| 283 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
317 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
| 284 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
318 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
| Line 1244... |
Line 1278... |
| 1244 |
}
|
1278 |
}
|
| 1245 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
1279 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 1246 |
helper.setFrom(senderAddress);
|
1280 |
helper.setFrom(senderAddress);
|
| 1247 |
mailSender.send(message);
|
1281 |
mailSender.send(message);
|
| 1248 |
}
|
1282 |
}
|
| - |
|
1283 |
|
| - |
|
1284 |
public void sendNotification() throws IOException {
|
| - |
|
1285 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
|
| - |
|
1286 |
if (!pushNotifications.isEmpty()) {
|
| - |
|
1287 |
for (PushNotifications pushNotification : pushNotifications) {
|
| - |
|
1288 |
Device devices = deviceRepository.selectById(pushNotification.getDeviceId());
|
| - |
|
1289 |
NotificationCampaign notificationCampaign = notificationCampaignRepository
|
| - |
|
1290 |
.selectById(pushNotification.getNotificationCampaignid());
|
| - |
|
1291 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
| - |
|
1292 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
| - |
|
1293 |
|
| - |
|
1294 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
| - |
|
1295 |
SimpleCampaignParams.class);
|
| - |
|
1296 |
Campaign campaign = new SimpleCampaign(scp);
|
| - |
|
1297 |
String result_url = campaign.getUrl() + "&user_id=" + devices.getUser_id();
|
| - |
|
1298 |
JSONObject json = new JSONObject();
|
| - |
|
1299 |
json.put("to", devices.getFcmId());
|
| - |
|
1300 |
JSONObject jsonObj = new JSONObject();
|
| - |
|
1301 |
jsonObj.put("message", campaign.getMessage());
|
| - |
|
1302 |
jsonObj.put("title", campaign.getTitle());
|
| - |
|
1303 |
jsonObj.put("type", campaign.getType());
|
| - |
|
1304 |
jsonObj.put("url", result_url);
|
| - |
|
1305 |
jsonObj.put("time_to_live", campaign.getExpireTimestamp());
|
| - |
|
1306 |
jsonObj.put("image", campaign.getImageUrl());
|
| - |
|
1307 |
jsonObj.put("largeIcon", "large_icon");
|
| - |
|
1308 |
jsonObj.put("smallIcon", "small_icon");
|
| - |
|
1309 |
jsonObj.put("vibrate", 1);
|
| - |
|
1310 |
jsonObj.put("pid", pushNotification.getId());
|
| - |
|
1311 |
jsonObj.put("sound", 1);
|
| - |
|
1312 |
jsonObj.put("priority", "high");
|
| - |
|
1313 |
json.put("data", jsonObj);
|
| - |
|
1314 |
|
| - |
|
1315 |
CloseableHttpClient client = HttpClients.createDefault();
|
| - |
|
1316 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
| - |
|
1317 |
|
| - |
|
1318 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
| - |
|
1319 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
| - |
|
1320 |
StringEntity entity = new StringEntity(json.toString());
|
| - |
|
1321 |
httpPost.setEntity(entity);
|
| - |
|
1322 |
CloseableHttpResponse response = client.execute(httpPost);
|
| - |
|
1323 |
LOGGER.info("response" + response);
|
| - |
|
1324 |
|
| - |
|
1325 |
if (response.getStatusLine().getStatusCode() == 200) {
|
| - |
|
1326 |
|
| - |
|
1327 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
| - |
|
1328 |
}
|
| - |
|
1329 |
|
| - |
|
1330 |
else {
|
| - |
|
1331 |
|
| - |
|
1332 |
LOGGER.info("message" + "not sent");
|
| - |
|
1333 |
}
|
| - |
|
1334 |
|
| - |
|
1335 |
}
|
| - |
|
1336 |
}
|
| - |
|
1337 |
}
|
| - |
|
1338 |
|
| 1249 |
}
|
1339 |
}
|