Subversion Repositories SmartDukaan

Rev

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

Rev 24177 Rev 24184
Line 12... Line 12...
12
import java.util.HashMap;
12
import java.util.HashMap;
13
import java.util.List;
13
import java.util.List;
14
import java.util.Map;
14
import java.util.Map;
15
import java.util.stream.Collectors;
15
import java.util.stream.Collectors;
16
 
16
 
-
 
17
import javax.activation.DataSource;
17
import javax.mail.MessagingException;
18
import javax.mail.MessagingException;
18
import javax.mail.internet.InternetAddress;
19
import javax.mail.internet.InternetAddress;
19
import javax.mail.internet.MimeMessage;
20
import javax.mail.internet.MimeMessage;
20
 
21
 
21
import org.apache.commons.codec.CharEncoding;
22
import org.apache.commons.codec.CharEncoding;
22
import org.apache.commons.io.IOUtils;
23
import org.apache.commons.io.IOUtils;
23
import org.apache.commons.io.output.ByteArrayOutputStream;
24
import org.apache.commons.io.output.ByteArrayOutputStream;
24
import org.apache.logging.log4j.LogManager;
25
import org.apache.logging.log4j.LogManager;
25
import org.apache.logging.log4j.Logger;
26
import org.apache.logging.log4j.Logger;
-
 
27
import org.apache.poi.EncryptedDocumentException;
-
 
28
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-
 
29
import org.apache.poi.ss.usermodel.Workbook;
26
import org.springframework.beans.factory.annotation.Autowired;
30
import org.springframework.beans.factory.annotation.Autowired;
27
import org.springframework.beans.factory.annotation.Qualifier;
31
import org.springframework.beans.factory.annotation.Qualifier;
28
import org.springframework.beans.factory.annotation.Value;
32
import org.springframework.beans.factory.annotation.Value;
29
import org.springframework.core.io.ByteArrayResource;
33
import org.springframework.core.io.ByteArrayResource;
30
import org.springframework.mail.javamail.JavaMailSender;
34
import org.springframework.mail.javamail.JavaMailSender;
Line 373... Line 377...
373
						"kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" },
377
						"kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" },
374
				"Partner Investment Summary", "PFA", fileName, new ByteArrayResource(baos.toByteArray()));
378
				"Partner Investment Summary", "PFA", fileName, new ByteArrayResource(baos.toByteArray()));
375
	}
379
	}
376
 
380
 
377
	private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
381
	private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
378
			Map<String, InputStream> inputStreams)
382
			InputStream is)
379
			throws MessagingException, ProfitMandiBusinessException, IOException {
383
			throws MessagingException, ProfitMandiBusinessException, IOException {
380
		MimeMessage message = mailSender.createMimeMessage();
384
		MimeMessage message = mailSender.createMimeMessage();
381
		MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
385
		MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
382
		helper.setSubject(subject);
386
		helper.setSubject(subject);
383
		helper.setText(body);
387
		helper.setText(body);
384
		if (ccEmails != null) {
388
		if (ccEmails != null) {
385
			helper.setCc(ccEmails);
389
			helper.setCc(ccEmails);
386
		}
390
		}
387
		for (String attachment : inputStreams.keySet()) {
391
		helper.addAttachment("DailySaleTargetReports_"+LocalDate.now()+".xls",new ByteArrayResource(IOUtils.toByteArray(is)));
388
			helper.addAttachment(attachment + LocalDate.now() + ".xlsx",
392
		helper.setTo(email);
389
					new ByteArrayResource(IOUtils.toByteArray(inputStreams.get(attachment))));
393
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
-
 
394
		helper.setFrom(senderAddress);
-
 
395
		mailSender.send(message);
390
		}
396
	}
-
 
397
	private void sendMailWithAttachmentsForPartners(String email, String body, String subject,
-
 
398
			InputStream is)
-
 
399
			throws MessagingException, ProfitMandiBusinessException, IOException {
-
 
400
		MimeMessage message = mailSender.createMimeMessage();
-
 
401
		MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
-
 
402
		helper.setSubject(subject);
-
 
403
		helper.setText(body);
-
 
404
		helper.addAttachment("DailySaleTargetReports_"+LocalDate.now()+".xls",new ByteArrayResource(IOUtils.toByteArray(is)));
391
		helper.setTo(email);
405
		helper.setTo(email);
392
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
406
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
393
		helper.setFrom(senderAddress);
407
		helper.setFrom(senderAddress);
394
		mailSender.send(message);
408
		mailSender.send(message);
395
	}
409
	}
Line 414... Line 428...
414
		LOGGER.info("message" + message);
428
		LOGGER.info("message" + message);
415
		if (salesHeadDetail.getName().equals("Kamal")) {
429
		if (salesHeadDetail.getName().equals("Kamal")) {
416
			LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
430
			LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
417
			String[] to = { salesHeadDetail.getEmail(), "mohinder.mutreja@smartdukaan.com" };
431
			String[] to = { salesHeadDetail.getEmail(), "mohinder.mutreja@smartdukaan.com" };
418
 
432
 
419
			this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
433
			//this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
420
 
434
 
421
		} else {
435
		} else {
422
			LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
436
			LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
423
			String[] to = { salesHeadDetail.getEmail() };
437
			String[] to = { salesHeadDetail.getEmail() };
424
			this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
438
			//this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
425
		}
439
		}
426
	}
440
	}
427
 
441
 
428
	public void sendMailToPartnerAboutTargetAndSales()
442
	public void sendMailToPartnerAboutTargetAndSales()
429
			throws ProfitMandiBusinessException, MessagingException, IOException {
443
			throws ProfitMandiBusinessException, MessagingException, IOException, EncryptedDocumentException, InvalidFormatException {
430
		List<Integer> fofoIds = targetService.getfofoIdsFromfofoStore();
444
		List<Integer> fofoIds = targetService.getfofoIdsFromfofoStore();
431
		Map<String, InputStream> inputStreams = new HashMap<>();
445
		Map<String, InputStream> inputStreams = new HashMap<>();
432
		Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService
446
		Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService
433
				.getFofoRetailers(new ArrayList<>(fofoIds));
447
				.getFofoRetailers(new ArrayList<>(fofoIds));
-
 
448
		List<InputStream> input=new ArrayList<>();
434
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
449
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
435
				.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
450
				.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
436
		for (Integer fofoId : fofoIds) {
451
		for (Integer fofoId : fofoIds) {
437
			for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
-
 
438
				Map<Integer, Float> foFoIdsAndTargetValues = targetService
-
 
439
						.getAllTargetValues(partnerTargetDetail.getId());
-
 
440
				if(foFoIdsAndTargetValues.get(fofoId)==null)
-
 
441
				{
-
 
442
					continue;
-
 
443
				}
-
 
444
				InputStream is=targetService.getDailySaleReportVsTargetForPartner(fofoId, partnerTargetDetail);
452
			InputStream is=targetService.getDailySaleReportVsTargetForPartner(fofoId,partnerTargetDetails);
445
				inputStreams.put(partnerTargetDetail.getTargetName(),is);
-
 
446
			}
-
 
447
			LOGGER.info("fofoId"+fofoId);
453
			LOGGER.info("fofoId"+fofoId);
448
			String[] email= {"govind.kumar@shop2020.in"};
454
			String email= "govind.kumar@shop2020.in";
449
			LOGGER.info(fofoIdsAndCustomRetailer.get(fofoId).getEmail());
455
			LOGGER.info(fofoIdsAndCustomRetailer.get(fofoId).getEmail());
450
			String subject="Daily Sales Report";
456
			String subject="Daily Sales Report";
451
			String message = MessageFormat.format("Sale Target summary for {0}",LocalDate.now());
457
			String message = MessageFormat.format("Sale Target summary for {0}",LocalDate.now());
452
			LOGGER.info(message);
458
			LOGGER.info(message);
453
			this.sendMailWithAttachments(email, null,message, subject,inputStreams);
459
			this.sendMailWithAttachmentsForPartners(email, message, subject, is);
454
		}
460
		}
455
	}
461
	}
456
 
462
 
457
}
463
}