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