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