| 23755 |
amit.gupta |
1 |
package com.smartdukaan.cron;
|
| 23723 |
amit.gupta |
2 |
|
| 24174 |
govind |
3 |
import java.util.List;
|
| 23906 |
amit.gupta |
4 |
import java.util.Properties;
|
|
|
5 |
|
| 23723 |
amit.gupta |
6 |
import org.apache.logging.log4j.LogManager;
|
|
|
7 |
import org.apache.logging.log4j.Logger;
|
| 23898 |
amit.gupta |
8 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
9 |
import org.springframework.boot.ApplicationArguments;
|
|
|
10 |
import org.springframework.boot.ApplicationRunner;
|
| 23723 |
amit.gupta |
11 |
import org.springframework.boot.WebApplicationType;
|
|
|
12 |
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
13 |
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
|
14 |
import org.springframework.cache.annotation.EnableCaching;
|
|
|
15 |
import org.springframework.context.annotation.Bean;
|
|
|
16 |
import org.springframework.context.annotation.ComponentScan;
|
| 23935 |
amit.gupta |
17 |
import org.springframework.context.annotation.Primary;
|
| 23723 |
amit.gupta |
18 |
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
|
|
19 |
import org.springframework.core.io.ClassPathResource;
|
| 23906 |
amit.gupta |
20 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
21 |
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
| 23723 |
amit.gupta |
22 |
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
23 |
|
| 23898 |
amit.gupta |
24 |
import com.smartdukaan.cron.migrations.RunOnceTasks;
|
| 23929 |
amit.gupta |
25 |
import com.smartdukaan.cron.scheduled.ScheduledTasks;
|
| 24174 |
govind |
26 |
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
|
|
|
27 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23724 |
amit.gupta |
28 |
|
| 23723 |
amit.gupta |
29 |
@SpringBootApplication
|
|
|
30 |
@EnableCaching
|
|
|
31 |
@EnableScheduling
|
| 23755 |
amit.gupta |
32 |
@ComponentScan("com.smartdukaan.cron.*, com.spice.profitmandi.common.*")
|
| 24122 |
govind |
33 |
public class Application implements ApplicationRunner {
|
|
|
34 |
|
|
|
35 |
private static final Logger LOGGER = LogManager.getLogger(Application.class);
|
|
|
36 |
|
| 24174 |
govind |
37 |
@Autowired
|
|
|
38 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
39 |
|
| 23723 |
amit.gupta |
40 |
public static void main(String[] args) throws Throwable {
|
| 23738 |
amit.gupta |
41 |
new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(args);
|
| 23723 |
amit.gupta |
42 |
}
|
| 24122 |
govind |
43 |
|
| 23723 |
amit.gupta |
44 |
@Bean
|
| 23738 |
amit.gupta |
45 |
public static PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
|
| 23755 |
amit.gupta |
46 |
LOGGER.info("Called Configuration");
|
| 24122 |
govind |
47 |
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
|
| 23723 |
amit.gupta |
48 |
propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("/META-INF/env.properties"));
|
|
|
49 |
return propertySourcesPlaceholderConfigurer;
|
|
|
50 |
}
|
| 24122 |
govind |
51 |
|
|
|
52 |
@Bean(name = "mailSender")
|
| 23935 |
amit.gupta |
53 |
@Primary
|
| 24122 |
govind |
54 |
public JavaMailSender sendGridMailSender() {
|
|
|
55 |
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
| 23723 |
amit.gupta |
56 |
|
| 24122 |
govind |
57 |
// Using gmail
|
|
|
58 |
mailSender.setHost("smtp.sendgrid.net");
|
|
|
59 |
mailSender.setPort(587);
|
|
|
60 |
mailSender.setUsername("shop2020");
|
|
|
61 |
mailSender.setPassword("U2/=fP,t");
|
|
|
62 |
|
|
|
63 |
Properties javaMailProperties = new Properties();
|
|
|
64 |
javaMailProperties.put("mail.smtp.starttls.enable", "false");
|
|
|
65 |
javaMailProperties.put("mail.smtp.auth", "true");
|
|
|
66 |
javaMailProperties.put("mail.transport.protocol", "smtp");
|
| 24226 |
amit.gupta |
67 |
//javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
|
| 24122 |
govind |
68 |
|
|
|
69 |
mailSender.setJavaMailProperties(javaMailProperties);
|
|
|
70 |
return mailSender;
|
|
|
71 |
}
|
|
|
72 |
|
| 23935 |
amit.gupta |
73 |
@Bean
|
| 24122 |
govind |
74 |
public JavaMailSender googleMailSender() {
|
| 23935 |
amit.gupta |
75 |
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
| 24122 |
govind |
76 |
// Using gmail
|
| 23935 |
amit.gupta |
77 |
mailSender.setHost("smtp.gmail.com");
|
|
|
78 |
mailSender.setPort(587);
|
|
|
79 |
mailSender.setUsername("build@shop2020.in");
|
|
|
80 |
mailSender.setPassword("cafe@nes");
|
| 24122 |
govind |
81 |
|
| 23935 |
amit.gupta |
82 |
Properties javaMailProperties = new Properties();
|
|
|
83 |
javaMailProperties.put("mail.smtp.starttls.enable", "true");
|
|
|
84 |
javaMailProperties.put("mail.smtp.auth", "true");
|
|
|
85 |
javaMailProperties.put("mail.transport.protocol", "smtp");
|
| 24122 |
govind |
86 |
javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
|
| 23935 |
amit.gupta |
87 |
mailSender.setJavaMailProperties(javaMailProperties);
|
|
|
88 |
return mailSender;
|
|
|
89 |
}
|
|
|
90 |
|
| 24122 |
govind |
91 |
@Autowired
|
| 23898 |
amit.gupta |
92 |
private RunOnceTasks runOnceTasks;
|
| 24122 |
govind |
93 |
|
|
|
94 |
@Autowired
|
| 23929 |
amit.gupta |
95 |
private ScheduledTasks scheduledTasks;
|
| 24122 |
govind |
96 |
|
| 23898 |
amit.gupta |
97 |
@Override
|
|
|
98 |
public void run(ApplicationArguments args) throws Exception {
|
|
|
99 |
LOGGER.info("Called run method");
|
| 24122 |
govind |
100 |
if (args.containsOption("once")) {
|
|
|
101 |
if (args.containsOption("1")) {
|
|
|
102 |
scheduledTasks.sendPartnerInvestmentDetails();
|
|
|
103 |
System.exit(0);
|
|
|
104 |
}
|
| 24174 |
govind |
105 |
if (args.containsOption("saleHeads")) {
|
|
|
106 |
List<SaleHeadDetails> saleHeadDetails=fofoStoreRepository.selectAllSalesHeadDetails();
|
|
|
107 |
for(SaleHeadDetails saleHeadDetail:saleHeadDetails)
|
|
|
108 |
{
|
|
|
109 |
scheduledTasks.sendMailToSalesHeadAboutTargetAndSales(saleHeadDetail);
|
|
|
110 |
}
|
| 24122 |
govind |
111 |
System.exit(0);
|
| 24174 |
govind |
112 |
|
| 24122 |
govind |
113 |
}
|
| 24174 |
govind |
114 |
if (args.containsOption("partners")) {
|
|
|
115 |
scheduledTasks.sendMailToPartnerAboutTargetAndSales();
|
|
|
116 |
System.exit(0);
|
|
|
117 |
|
|
|
118 |
}
|
| 24151 |
amit.gupta |
119 |
if (args.containsOption("3")) {
|
|
|
120 |
scheduledTasks.processScheme();
|
|
|
121 |
System.exit(0);
|
|
|
122 |
}
|
| 24238 |
amit.gupta |
123 |
if (args.containsOption("4")) {
|
| 24241 |
amit.gupta |
124 |
scheduledTasks.evaluateExcessSchemeOut();
|
| 24238 |
amit.gupta |
125 |
System.exit(0);
|
|
|
126 |
}
|
| 24122 |
govind |
127 |
|
| 23898 |
amit.gupta |
128 |
}
|
| 24122 |
govind |
129 |
|
| 23898 |
amit.gupta |
130 |
}
|
|
|
131 |
|
| 23723 |
amit.gupta |
132 |
}
|