| Line 253... |
Line 253... |
| 253 |
@Autowired
|
253 |
@Autowired
|
| 254 |
private ItemRepository itemRepository;
|
254 |
private ItemRepository itemRepository;
|
| 255 |
|
255 |
|
| 256 |
@Autowired
|
256 |
@Autowired
|
| 257 |
private OrderRepository orderRepository;
|
257 |
private OrderRepository orderRepository;
|
| 258 |
|
258 |
|
| 259 |
@Autowired
|
259 |
@Autowired
|
| 260 |
private OrderService orderService;
|
260 |
private OrderService orderService;
|
| 261 |
|
261 |
|
| 262 |
@Autowired
|
262 |
@Autowired
|
| 263 |
private SchemeRepository schemeRepository;
|
263 |
private SchemeRepository schemeRepository;
|
| Line 579... |
Line 579... |
| 579 |
}
|
579 |
}
|
| 580 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
580 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 581 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
581 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
| 582 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
582 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
| 583 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
583 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 584 |
|
584 |
|
| 585 |
List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager",
|
585 |
List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager",
|
| 586 |
"Team Leader", "Wallet Amount", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
586 |
"Team Leader", "Wallet Amount", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
| 587 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty");
|
587 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty");
|
| 588 |
List<List<? extends Serializable>> rows = new ArrayList<>();
|
588 |
List<List<? extends Serializable>> rows = new ArrayList<>();
|
| 589 |
Map<String, List<? extends Serializable>> partnerRow = new HashMap<>();
|
589 |
Map<String, List<? extends Serializable>> partnerRow = new HashMap<>();
|
| Line 598... |
Line 598... |
| 598 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoStore.getId(),
|
598 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoStore.getId(),
|
| 599 |
1);
|
599 |
1);
|
| 600 |
partnerDailyInvestment.setDate(yesterDay);
|
600 |
partnerDailyInvestment.setDate(yesterDay);
|
| 601 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
601 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 602 |
|
602 |
|
| 603 |
List<? extends Serializable> row = Arrays.asList(fofoStore.getCode(),
|
603 |
List<? extends Serializable> row = Arrays.asList(fofoStore.getCode(), retailer.getBusinessName(),
|
| 604 |
retailer.getBusinessName(), "SmartDukaan-" + fofoStore.getCode().replaceAll("[a-zA-Z]+", ""),
|
604 |
"SmartDukaan-" + fofoStore.getCode().replaceAll("[a-zA-Z]+", ""),
|
| 605 |
storeManagerMap.get(retailer.getEmail()).get(2), storeManagerMap.get(retailer.getEmail()).get(1),
|
605 |
storeManagerMap.get(retailer.getEmail()).get(2), storeManagerMap.get(retailer.getEmail()).get(1),
|
| 606 |
storeManagerMap.get(retailer.getEmail()).get(0), partnerDailyInvestment.getWalletAmount(),
|
606 |
storeManagerMap.get(retailer.getEmail()).get(0), partnerDailyInvestment.getWalletAmount(),
|
| 607 |
partnerDailyInvestment.getInStockAmount(), 0,
|
607 |
partnerDailyInvestment.getInStockAmount(), 0, partnerDailyInvestment.getUnbilledAmount(),
|
| 608 |
partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
608 |
partnerDailyInvestment.getGrnPendingAmount(), partnerDailyInvestment.getMinInvestment(),
|
| 609 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
609 |
partnerDailyInvestment.getTotalInvestment(), partnerDailyInvestment.getShortInvestment(),
|
| 610 |
partnerDailyInvestment.getShortInvestment(),
|
- |
|
| 611 |
partnerDailyInvestment.getUnbilledQty());
|
610 |
partnerDailyInvestment.getUnbilledQty());
|
| 612 |
partnerRow.put(retailer.getEmail(), row);
|
611 |
partnerRow.put(retailer.getEmail(), row);
|
| 613 |
rows.add(row);
|
612 |
rows.add(row);
|
| 614 |
|
613 |
|
| 615 |
}
|
614 |
}
|
| Line 627... |
Line 626... |
| 627 |
storeGuyMap.remove("");
|
626 |
storeGuyMap.remove("");
|
| 628 |
|
627 |
|
| 629 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
628 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 630 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuyMap.entrySet()) {
|
629 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuyMap.entrySet()) {
|
| 631 |
List<List<? extends Serializable>> filteredRows = storeGuyEntry.getValue().stream()
|
630 |
List<List<? extends Serializable>> filteredRows = storeGuyEntry.getValue().stream()
|
| 632 |
.map(x -> partnerRow.get(x)).filter(x->x!=null).collect(Collectors.toList());
|
631 |
.map(x -> partnerRow.get(x)).filter(x -> x != null).collect(Collectors.toList());
|
| 633 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
632 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
| 634 |
String[] sendToArray = new String[] { nameEmail.get(storeGuyEntry.getKey()) };
|
633 |
String[] sendToArray = new String[] { nameEmail.get(storeGuyEntry.getKey()) };
|
| 635 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA",
|
634 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA",
|
| 636 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
635 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
| 637 |
}
|
636 |
}
|
| Line 691... |
Line 690... |
| 691 |
if (partnerSalesTargetRowsMap.get(retailer.getEmail()) != null) {
|
690 |
if (partnerSalesTargetRowsMap.get(retailer.getEmail()) != null) {
|
| 692 |
row.addAll(partnerSalesTargetRowsMap.get(retailer.getEmail()));
|
691 |
row.addAll(partnerSalesTargetRowsMap.get(retailer.getEmail()));
|
| 693 |
partnerRowMap.put(retailer.getEmail(), row);
|
692 |
partnerRowMap.put(retailer.getEmail(), row);
|
| 694 |
rows.add(row);
|
693 |
rows.add(row);
|
| 695 |
}
|
694 |
}
|
| 696 |
} catch(Exception e) {
|
695 |
} catch (Exception e) {
|
| 697 |
LOGGER.warn("Could not find partner with email - {}", retailer.getEmail());
|
696 |
LOGGER.warn("Could not find partner with email - {}", retailer.getEmail());
|
| 698 |
}
|
697 |
}
|
| 699 |
|
698 |
|
| 700 |
}
|
699 |
}
|
| 701 |
|
700 |
|
| Line 713... |
Line 712... |
| 713 |
storeGuyMap.remove("");
|
712 |
storeGuyMap.remove("");
|
| 714 |
|
713 |
|
| 715 |
String fileName = "TargetVsSales-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
714 |
String fileName = "TargetVsSales-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 716 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuyMap.entrySet()) {
|
715 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuyMap.entrySet()) {
|
| 717 |
List<List<? extends Serializable>> filteredRows = storeGuyEntry.getValue().stream()
|
716 |
List<List<? extends Serializable>> filteredRows = storeGuyEntry.getValue().stream()
|
| 718 |
.map(x -> partnerRowMap.get(x)).filter(x->x!=null).collect(Collectors.toList());
|
717 |
.map(x -> partnerRowMap.get(x)).filter(x -> x != null).collect(Collectors.toList());
|
| 719 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
718 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
| 720 |
String[] sendToArray = new String[] { nameEmail.get(storeGuyEntry.getKey()) };
|
719 |
String[] sendToArray = new String[] { nameEmail.get(storeGuyEntry.getKey()) };
|
| 721 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA",
|
720 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA",
|
| 722 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
721 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
| 723 |
}
|
722 |
}
|
| Line 1292... |
Line 1291... |
| 1292 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
1291 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 1293 |
helper.setFrom(senderAddress);
|
1292 |
helper.setFrom(senderAddress);
|
| 1294 |
mailSender.send(message);
|
1293 |
mailSender.send(message);
|
| 1295 |
}
|
1294 |
}
|
| 1296 |
|
1295 |
|
| 1297 |
public void sendNotification() throws IOException {
|
1296 |
public void sendNotification() throws Exception {
|
| 1298 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
|
1297 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
|
| 1299 |
if (!pushNotifications.isEmpty()) {
|
1298 |
if (!pushNotifications.isEmpty()) {
|
| 1300 |
for (PushNotifications pushNotification : pushNotifications) {
|
1299 |
for (PushNotifications pushNotification : pushNotifications) {
|
| 1301 |
Device devices = deviceRepository.selectById(pushNotification.getDeviceId());
|
1300 |
Device device = deviceRepository.selectById(pushNotification.getDeviceId());
|
| 1302 |
NotificationCampaign notificationCampaign = notificationCampaignRepository
|
1301 |
NotificationCampaign notificationCampaign = notificationCampaignRepository
|
| 1303 |
.selectById(pushNotification.getNotificationCampaignid());
|
1302 |
.selectById(pushNotification.getNotificationCampaignid());
|
| 1304 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
1303 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
| 1305 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
1304 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
| 1306 |
|
1305 |
|
| 1307 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
1306 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
| 1308 |
SimpleCampaignParams.class);
|
1307 |
SimpleCampaignParams.class);
|
| 1309 |
Campaign campaign = new SimpleCampaign(scp);
|
1308 |
Campaign campaign = new SimpleCampaign(scp);
|
| 1310 |
String result_url = campaign.getUrl() + "&user_id=" + devices.getUser_id();
|
1309 |
String result_url = campaign.getUrl() + "&user_id=" + device.getUser_id();
|
| 1311 |
JSONObject json = new JSONObject();
|
1310 |
JSONObject json = new JSONObject();
|
| 1312 |
json.put("to", devices.getFcmId());
|
1311 |
json.put("to", device.getFcmId());
|
| 1313 |
JSONObject jsonObj = new JSONObject();
|
1312 |
JSONObject jsonObj = new JSONObject();
|
| 1314 |
jsonObj.put("message", campaign.getMessage());
|
1313 |
jsonObj.put("message", campaign.getMessage());
|
| 1315 |
jsonObj.put("title", campaign.getTitle());
|
1314 |
jsonObj.put("title", campaign.getTitle());
|
| 1316 |
jsonObj.put("type", campaign.getType());
|
1315 |
jsonObj.put("type", campaign.getType());
|
| 1317 |
jsonObj.put("url", result_url);
|
1316 |
jsonObj.put("url", result_url);
|
| Line 1322... |
Line 1321... |
| 1322 |
jsonObj.put("vibrate", 1);
|
1321 |
jsonObj.put("vibrate", 1);
|
| 1323 |
jsonObj.put("pid", pushNotification.getId());
|
1322 |
jsonObj.put("pid", pushNotification.getId());
|
| 1324 |
jsonObj.put("sound", 1);
|
1323 |
jsonObj.put("sound", 1);
|
| 1325 |
jsonObj.put("priority", "high");
|
1324 |
jsonObj.put("priority", "high");
|
| 1326 |
json.put("data", jsonObj);
|
1325 |
json.put("data", jsonObj);
|
| - |
|
1326 |
try {
|
| - |
|
1327 |
CloseableHttpClient client = HttpClients.createDefault();
|
| - |
|
1328 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
| 1327 |
|
1329 |
|
| 1328 |
CloseableHttpClient client = HttpClients.createDefault();
|
- |
|
| 1329 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
- |
|
| 1330 |
|
- |
|
| 1331 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
1330 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
| 1332 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
1331 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
| 1333 |
StringEntity entity = new StringEntity(json.toString());
|
1332 |
StringEntity entity = new StringEntity(json.toString());
|
| 1334 |
httpPost.setEntity(entity);
|
1333 |
httpPost.setEntity(entity);
|
| 1335 |
CloseableHttpResponse response = client.execute(httpPost);
|
1334 |
CloseableHttpResponse response = client.execute(httpPost);
|
| 1336 |
LOGGER.info("response" + response);
|
1335 |
LOGGER.info("response" + response);
|
| 1337 |
|
- |
|
| 1338 |
if (response.getStatusLine().getStatusCode() == 200) {
|
- |
|
| 1339 |
|
- |
|
| 1340 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
- |
|
| 1341 |
}
|
- |
|
| 1342 |
|
1336 |
|
| - |
|
1337 |
if (response.getStatusLine().getStatusCode() == 200) {
|
| - |
|
1338 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
| 1343 |
else {
|
1339 |
} else {
|
| - |
|
1340 |
LOGGER.info("message" + "not sent");
|
| - |
|
1341 |
}
|
| 1344 |
|
1342 |
|
| - |
|
1343 |
} catch (Exception e) {
|
| - |
|
1344 |
e.printStackTrace();
|
| 1345 |
LOGGER.info("message" + "not sent");
|
1345 |
LOGGER.info("message" + "not sent");
|
| 1346 |
}
|
1346 |
}
|
| 1347 |
|
- |
|
| 1348 |
}
|
1347 |
}
|
| 1349 |
}
|
1348 |
}
|
| 1350 |
}
|
1349 |
}
|
| 1351 |
|
1350 |
|
| 1352 |
public static final Map<String, String> nameEmail = new HashMap<>();
|
1351 |
public static final Map<String, String> nameEmail = new HashMap<>();
|