| Line 1... |
Line 1... |
| 1 |
package com.smartdukaan.cron.scheduled;
|
1 |
package com.smartdukaan.cron.scheduled;
|
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| 4 |
import java.io.InputStream;
|
4 |
import java.io.InputStream;
|
| 5 |
import java.sql.Timestamp;
|
5 |
import java.sql.Timestamp;
|
| - |
|
6 |
import java.text.MessageFormat;
|
| 6 |
import java.time.LocalDate;
|
7 |
import java.time.LocalDate;
|
| 7 |
import java.time.LocalDateTime;
|
8 |
import java.time.LocalDateTime;
|
| 8 |
import java.time.temporal.ChronoUnit;
|
9 |
import java.time.temporal.ChronoUnit;
|
| 9 |
import java.util.ArrayList;
|
10 |
import java.util.ArrayList;
|
| 10 |
import java.util.Arrays;
|
11 |
import java.util.Arrays;
|
| Line 42... |
Line 43... |
| 42 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
43 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
| 43 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
44 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
| 44 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
45 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 45 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
46 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 46 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
47 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| - |
|
48 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 47 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
49 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| - |
|
50 |
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
|
| 48 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
51 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 49 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
52 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 50 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
53 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 51 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
54 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
| 52 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
55 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
| 53 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
56 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
57 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| - |
|
58 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 55 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
59 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 56 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
60 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 57 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
61 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 58 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
62 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
| 59 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
63 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
| Line 156... |
Line 160... |
| 156 |
private OrderRepository orderRepository;
|
160 |
private OrderRepository orderRepository;
|
| 157 |
|
161 |
|
| 158 |
@Autowired
|
162 |
@Autowired
|
| 159 |
private JavaMailSender mailSender;
|
163 |
private JavaMailSender mailSender;
|
| 160 |
|
164 |
|
| 161 |
|
165 |
@Autowired
|
| - |
|
166 |
private PartnerTargetRepository partnerTargetRepository;
|
| 162 |
|
167 |
|
| 163 |
@Autowired
|
168 |
@Autowired
|
| 164 |
@Qualifier(value = "googleMailSender")
|
169 |
@Qualifier(value = "googleMailSender")
|
| 165 |
private JavaMailSender googleMailSender;
|
170 |
private JavaMailSender googleMailSender;
|
| 166 |
|
171 |
|
| Line 370... |
Line 375... |
| 370 |
new String[] { "amandeep.singh@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
375 |
new String[] { "amandeep.singh@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 371 |
"kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" },
|
376 |
"kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" },
|
| 372 |
"Partner Investment Summary", "PFA", fileName, new ByteArrayResource(baos.toByteArray()));
|
377 |
"Partner Investment Summary", "PFA", fileName, new ByteArrayResource(baos.toByteArray()));
|
| 373 |
}
|
378 |
}
|
| 374 |
|
379 |
|
| 375 |
public void sendMailWithAttachmentsForSalesHead(String[] email,String subject,String body,String saleHead) throws MessagingException, ProfitMandiBusinessException, IOException
|
380 |
private void sendMailWithAttachments(String[] email,String[] ccEmails,String body,String subject,String attachment,InputStream is) throws MessagingException, ProfitMandiBusinessException, IOException
|
| 376 |
{
|
381 |
{
|
| 377 |
MimeMessage message = mailSender.createMimeMessage();
|
382 |
MimeMessage message = mailSender.createMimeMessage();
|
| 378 |
MimeMessageHelper helper = new MimeMessageHelper(message,true,CharEncoding.UTF_8);
|
383 |
MimeMessageHelper helper = new MimeMessageHelper(message,true,CharEncoding.UTF_8);
|
| 379 |
InputStream is=targetService.getDailySaleReportVsTargetForSaleHead(saleHead);
|
- |
|
| 380 |
helper.setSubject(subject);
|
384 |
helper.setSubject(subject);
|
| 381 |
helper.setText(body);
|
385 |
helper.setText(body);
|
| 382 |
String ccEmails[]= {"Tarun.verma@smartdukaan.com","Kamini.sharma@smartdukaan.com","chaitnaya.vats@smartdukaan.com","dhruv.kathpal@smartdukaan.com"};
|
386 |
if(ccEmails !=null)
|
| - |
|
387 |
{
|
| 383 |
helper.setCc(ccEmails);
|
388 |
helper.setCc(ccEmails);
|
| - |
|
389 |
}
|
| 384 |
helper.addAttachment("saleReport"+LocalDate.now()+".xlsx",new ByteArrayResource(IOUtils.toByteArray(is)));
|
390 |
helper.addAttachment(attachment+LocalDate.now()+".xlsx",new ByteArrayResource(IOUtils.toByteArray(is)));
|
| 385 |
helper.setTo(email);
|
391 |
helper.setTo(email);
|
| 386 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
392 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
| 387 |
helper.setFrom(senderAddress);
|
393 |
helper.setFrom(senderAddress);
|
| 388 |
mailSender.send(message);
|
394 |
mailSender.send(message);
|
| 389 |
}
|
395 |
}
|
| 390 |
|
- |
|
| 391 |
public void sendMailWithAttachments(String[] email,String subject,String body) throws MessagingException, ProfitMandiBusinessException, IOException
|
396 |
public void sendMailToSalesHeadAboutTargetAndSales(SaleHeadDetails salesHeadDetail) throws MessagingException, ProfitMandiBusinessException, IOException
|
| 392 |
{
|
397 |
{
|
| - |
|
398 |
List<PartnerTargetDetails> partnerTargetDetails=partnerTargetRepository.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
| 393 |
MimeMessage message = mailSender.createMimeMessage();
|
399 |
for(PartnerTargetDetails partnerTargetDetail:partnerTargetDetails)
|
| - |
|
400 |
{
|
| 394 |
MimeMessageHelper helper = new MimeMessageHelper(message,true,CharEncoding.UTF_8);
|
401 |
InputStream is=targetService.getDailySaleReportVsTargetForSaleHead(partnerTargetDetail,salesHeadDetail.getName());
|
| - |
|
402 |
//String[] ccEmails={"Tarun.verma@smartdukaan.com","Kamini.sharma@smartdukaan.com","chaitnaya.vats@smartdukaan.com","dhruv.kathpal@smartdukaan.com"};
|
| - |
|
403 |
String[] ccEmails= null;
|
| 395 |
InputStream is=targetService.getDailySaleReportVsTarget();
|
404 |
String subject="Daily Sales Report "+partnerTargetDetail.getTargetName();
|
| - |
|
405 |
String message = MessageFormat.format("{0} Sale Target summary for {1}",partnerTargetDetail.getTargetName(),LocalDate.now());
|
| 396 |
helper.setSubject(subject);
|
406 |
LOGGER.info("message"+message);
|
| 397 |
helper.setText(body);
|
407 |
if(salesHeadDetail.getName().equals("Kamal"))
|
| - |
|
408 |
{
|
| - |
|
409 |
LOGGER.info("salesHeadDetail.getName()"+salesHeadDetail.getName());
|
| 398 |
String ccEmails[]= {"Tarun.verma@smartdukaan.com","Kamini.sharma@smartdukaan.com","chaitnaya.vats@smartdukaan.com","dhruv.kathpal@smartdukaan.com","care@smartdukaan.com"};
|
410 |
String[] to= {salesHeadDetail.getEmail(),"mohinder.mutreja@smartdukaan.com"};
|
| - |
|
411 |
|
| - |
|
412 |
this.sendMailWithAttachments(to, ccEmails,message, subject,partnerTargetDetail.getTargetName(),is);
|
| - |
|
413 |
|
| - |
|
414 |
}
|
| - |
|
415 |
else
|
| - |
|
416 |
{
|
| - |
|
417 |
LOGGER.info("salesHeadDetail.getName()"+salesHeadDetail.getName());
|
| 399 |
helper.setCc(ccEmails);
|
418 |
String[] to= {salesHeadDetail.getEmail()};
|
| 400 |
helper.addAttachment("saleReport"+LocalDate.now()+".xlsx",new ByteArrayResource(IOUtils.toByteArray(is)));
|
419 |
this.sendMailWithAttachments(to, ccEmails,message,subject,partnerTargetDetail.getTargetName(),is);
|
| - |
|
420 |
}
|
| - |
|
421 |
}
|
| - |
|
422 |
}
|
| - |
|
423 |
public void sendMailToPartnerAboutTargetAndSales() throws ProfitMandiBusinessException, MessagingException, IOException
|
| - |
|
424 |
{
|
| - |
|
425 |
List<PartnerTargetDetails> partnerTargetDetails=partnerTargetRepository.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
| - |
|
426 |
for(PartnerTargetDetails partnerTargetDetail:partnerTargetDetails)
|
| - |
|
427 |
{
|
| - |
|
428 |
Map<Integer, Float> foFoIdsAndTargetValues=targetService.getAllTargetValues(partnerTargetDetail.getId());
|
| - |
|
429 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService.getFofoRetailers(new ArrayList<>(foFoIdsAndTargetValues.keySet()));
|
| 401 |
helper.setTo(email);
|
430 |
for(Integer fofoId:foFoIdsAndTargetValues.keySet())
|
| - |
|
431 |
{
|
| 402 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
432 |
InputStream is=targetService.getDailySaleReportVsTargetForPartner(fofoId, partnerTargetDetail);
|
| 403 |
helper.setFrom(senderAddress);
|
433 |
LOGGER.info("fofoId"+fofoId);
|
| - |
|
434 |
String[] email= {"govind.kumar@shop2020.in"};
|
| - |
|
435 |
LOGGER.info(fofoIdsAndCustomRetailer.get(fofoId).getEmail());
|
| - |
|
436 |
String subject="Daily Sales Report "+" "+partnerTargetDetail.getTargetName();
|
| - |
|
437 |
String message = MessageFormat.format("{0} Sale Target summary for {1}",partnerTargetDetail.getTargetName(),LocalDate.now());
|
| 404 |
mailSender.send(message);
|
438 |
LOGGER.info(message);
|
| - |
|
439 |
this.sendMailWithAttachments(email, null,message, subject, partnerTargetDetail.getTargetName(),is);
|
| - |
|
440 |
|
| - |
|
441 |
}
|
| - |
|
442 |
}
|
| 405 |
}
|
443 |
}
|
| 406 |
|
444 |
|
| 407 |
}
|
445 |
}
|