| 23755 |
amit.gupta |
1 |
package com.smartdukaan.cron;
|
| 23723 |
amit.gupta |
2 |
|
| 24693 |
amit.gupta |
3 |
import java.util.ArrayList;
|
| 24337 |
amit.gupta |
4 |
import java.util.Formatter;
|
| 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;
|
| 24693 |
amit.gupta |
22 |
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
|
|
23 |
import org.springframework.http.converter.HttpMessageConverter;
|
| 23906 |
amit.gupta |
24 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
25 |
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
| 23723 |
amit.gupta |
26 |
import org.springframework.scheduling.annotation.EnableScheduling;
|
| 24693 |
amit.gupta |
27 |
import org.springframework.web.client.RestTemplate;
|
| 23723 |
amit.gupta |
28 |
|
| 23898 |
amit.gupta |
29 |
import com.smartdukaan.cron.migrations.RunOnceTasks;
|
| 23929 |
amit.gupta |
30 |
import com.smartdukaan.cron.scheduled.ScheduledTasks;
|
| 24174 |
govind |
31 |
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
|
|
|
32 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23724 |
amit.gupta |
33 |
|
| 23723 |
amit.gupta |
34 |
@SpringBootApplication
|
|
|
35 |
@EnableCaching
|
|
|
36 |
@EnableScheduling
|
| 23755 |
amit.gupta |
37 |
@ComponentScan("com.smartdukaan.cron.*, com.spice.profitmandi.common.*")
|
| 24122 |
govind |
38 |
public class Application implements ApplicationRunner {
|
|
|
39 |
|
|
|
40 |
private static final Logger LOGGER = LogManager.getLogger(Application.class);
|
|
|
41 |
|
| 24174 |
govind |
42 |
@Autowired
|
|
|
43 |
private FofoStoreRepository fofoStoreRepository;
|
| 24603 |
amit.gupta |
44 |
|
| 23723 |
amit.gupta |
45 |
public static void main(String[] args) throws Throwable {
|
| 23738 |
amit.gupta |
46 |
new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(args);
|
| 23723 |
amit.gupta |
47 |
}
|
| 24122 |
govind |
48 |
|
| 23723 |
amit.gupta |
49 |
@Bean
|
| 23738 |
amit.gupta |
50 |
public static PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
|
| 23755 |
amit.gupta |
51 |
LOGGER.info("Called Configuration");
|
| 24122 |
govind |
52 |
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
|
| 23723 |
amit.gupta |
53 |
propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("/META-INF/env.properties"));
|
|
|
54 |
return propertySourcesPlaceholderConfigurer;
|
|
|
55 |
}
|
| 24122 |
govind |
56 |
|
|
|
57 |
@Bean(name = "mailSender")
|
| 23935 |
amit.gupta |
58 |
@Primary
|
| 24122 |
govind |
59 |
public JavaMailSender sendGridMailSender() {
|
|
|
60 |
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
| 23723 |
amit.gupta |
61 |
|
| 24122 |
govind |
62 |
// Using gmail
|
|
|
63 |
mailSender.setHost("smtp.sendgrid.net");
|
|
|
64 |
mailSender.setPort(587);
|
|
|
65 |
mailSender.setUsername("shop2020");
|
|
|
66 |
mailSender.setPassword("U2/=fP,t");
|
|
|
67 |
|
|
|
68 |
Properties javaMailProperties = new Properties();
|
|
|
69 |
javaMailProperties.put("mail.smtp.starttls.enable", "false");
|
|
|
70 |
javaMailProperties.put("mail.smtp.auth", "true");
|
|
|
71 |
javaMailProperties.put("mail.transport.protocol", "smtp");
|
| 24603 |
amit.gupta |
72 |
// javaMailProperties.put("mail.debug", "true");// Prints out everything on
|
|
|
73 |
// screen
|
| 24122 |
govind |
74 |
|
|
|
75 |
mailSender.setJavaMailProperties(javaMailProperties);
|
|
|
76 |
return mailSender;
|
|
|
77 |
}
|
|
|
78 |
|
| 23935 |
amit.gupta |
79 |
@Bean
|
| 24122 |
govind |
80 |
public JavaMailSender googleMailSender() {
|
| 23935 |
amit.gupta |
81 |
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
| 24122 |
govind |
82 |
// Using gmail
|
| 23935 |
amit.gupta |
83 |
mailSender.setHost("smtp.gmail.com");
|
|
|
84 |
mailSender.setPort(587);
|
|
|
85 |
mailSender.setUsername("build@shop2020.in");
|
|
|
86 |
mailSender.setPassword("cafe@nes");
|
| 24122 |
govind |
87 |
|
| 23935 |
amit.gupta |
88 |
Properties javaMailProperties = new Properties();
|
|
|
89 |
javaMailProperties.put("mail.smtp.starttls.enable", "true");
|
|
|
90 |
javaMailProperties.put("mail.smtp.auth", "true");
|
|
|
91 |
javaMailProperties.put("mail.transport.protocol", "smtp");
|
| 24122 |
govind |
92 |
javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
|
| 23935 |
amit.gupta |
93 |
mailSender.setJavaMailProperties(javaMailProperties);
|
|
|
94 |
return mailSender;
|
|
|
95 |
}
|
| 24693 |
amit.gupta |
96 |
|
|
|
97 |
@Bean
|
|
|
98 |
public RestTemplate restTemplate() {
|
| 24695 |
amit.gupta |
99 |
RestTemplate restTemplate = new RestTemplate();
|
|
|
100 |
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
|
|
|
101 |
return restTemplate;
|
| 24693 |
amit.gupta |
102 |
}
|
| 23935 |
amit.gupta |
103 |
|
| 24122 |
govind |
104 |
@Autowired
|
| 23898 |
amit.gupta |
105 |
private RunOnceTasks runOnceTasks;
|
| 24122 |
govind |
106 |
|
|
|
107 |
@Autowired
|
| 23929 |
amit.gupta |
108 |
private ScheduledTasks scheduledTasks;
|
| 24122 |
govind |
109 |
|
| 23898 |
amit.gupta |
110 |
@Override
|
|
|
111 |
public void run(ApplicationArguments args) throws Exception {
|
| 24603 |
amit.gupta |
112 |
|
| 23898 |
amit.gupta |
113 |
LOGGER.info("Called run method");
|
| 24674 |
amit.gupta |
114 |
if (args.containsOption("reco1")) {
|
| 24629 |
amit.gupta |
115 |
scheduledTasks.dryRunSchemeReco();
|
| 24603 |
amit.gupta |
116 |
System.exit(0);
|
| 24592 |
amit.gupta |
117 |
}
|
| 24674 |
amit.gupta |
118 |
if (args.containsOption("reco2")) {
|
|
|
119 |
scheduledTasks.dryRunOutSchemeReco();
|
|
|
120 |
System.exit(0);
|
|
|
121 |
}
|
| 24122 |
govind |
122 |
if (args.containsOption("once")) {
|
|
|
123 |
if (args.containsOption("1")) {
|
| 24603 |
amit.gupta |
124 |
if (args.containsOption("test")) {
|
| 24271 |
amit.gupta |
125 |
scheduledTasks.sendPartnerInvestmentDetails(args.getOptionValues("email"));
|
| 24272 |
amit.gupta |
126 |
} else {
|
|
|
127 |
scheduledTasks.sendPartnerInvestmentDetails();
|
| 24271 |
amit.gupta |
128 |
}
|
| 24122 |
govind |
129 |
System.exit(0);
|
|
|
130 |
}
|
| 24682 |
amit.gupta |
131 |
if (args.containsOption("2")) {
|
| 24696 |
amit.gupta |
132 |
if (args.containsOption("test")) {
|
|
|
133 |
String [] emails = new String [args.getOptionValues("email").size()];
|
|
|
134 |
scheduledTasks.sendAgeingReport(args.getOptionValues("email").toArray(emails));
|
|
|
135 |
} else {
|
|
|
136 |
scheduledTasks.sendAgeingReport();
|
|
|
137 |
}
|
| 24682 |
amit.gupta |
138 |
System.exit(0);
|
|
|
139 |
}
|
| 24174 |
govind |
140 |
if (args.containsOption("saleHeads")) {
|
| 24603 |
amit.gupta |
141 |
List<SaleHeadDetails> saleHeadDetails = fofoStoreRepository.selectAllSalesHeadDetails();
|
|
|
142 |
for (SaleHeadDetails saleHeadDetail : saleHeadDetails) {
|
| 24174 |
govind |
143 |
scheduledTasks.sendMailToSalesHeadAboutTargetAndSales(saleHeadDetail);
|
|
|
144 |
}
|
| 24122 |
govind |
145 |
System.exit(0);
|
| 24603 |
amit.gupta |
146 |
|
| 24122 |
govind |
147 |
}
|
| 24174 |
govind |
148 |
if (args.containsOption("partners")) {
|
| 24603 |
amit.gupta |
149 |
scheduledTasks.sendMailToPartnerAboutTargetAndSales();
|
| 24174 |
govind |
150 |
System.exit(0);
|
| 24603 |
amit.gupta |
151 |
|
| 24174 |
govind |
152 |
}
|
| 24151 |
amit.gupta |
153 |
if (args.containsOption("3")) {
|
| 24603 |
amit.gupta |
154 |
if (args.getOptionNames().contains("offset")) {
|
| 24461 |
amit.gupta |
155 |
int offset = Integer.parseInt(args.getOptionValues("offset").get(0));
|
| 24603 |
amit.gupta |
156 |
if (args.getOptionNames().contains("days")) {
|
| 24461 |
amit.gupta |
157 |
int durationDays = Integer.parseInt(args.getOptionValues("days").get(0));
|
|
|
158 |
scheduledTasks.processScheme(offset, durationDays);
|
|
|
159 |
} else {
|
|
|
160 |
scheduledTasks.processScheme(offset);
|
|
|
161 |
}
|
| 24560 |
amit.gupta |
162 |
} else if (args.containsOption("catalogid")) {
|
| 24603 |
amit.gupta |
163 |
// scheduledTasks.processSchemeForModel(args.getOptionValues("catalogid").get(0));
|
| 24461 |
amit.gupta |
164 |
} else {
|
|
|
165 |
scheduledTasks.processScheme();
|
|
|
166 |
}
|
| 24151 |
amit.gupta |
167 |
System.exit(0);
|
|
|
168 |
}
|
| 24238 |
amit.gupta |
169 |
if (args.containsOption("4")) {
|
| 24241 |
amit.gupta |
170 |
scheduledTasks.evaluateExcessSchemeOut();
|
| 24256 |
amit.gupta |
171 |
}
|
|
|
172 |
if (args.containsOption("5")) {
|
|
|
173 |
int offset = Integer.parseInt(args.getOptionValues("offset").get(0));
|
|
|
174 |
scheduledTasks.processScheme(offset);
|
| 24238 |
amit.gupta |
175 |
System.exit(0);
|
|
|
176 |
}
|
| 24603 |
amit.gupta |
177 |
if (args.containsOption("cancelOrder")) {
|
| 24265 |
amit.gupta |
178 |
List<String> invoiceNumbers = args.getOptionValues("invoiceNumber");
|
|
|
179 |
runOnceTasks.cancelOrder(invoiceNumbers);
|
|
|
180 |
}
|
| 24641 |
amit.gupta |
181 |
if (args.containsOption("migratePurchase")) {
|
|
|
182 |
runOnceTasks.migratePurchase();
|
|
|
183 |
}
|
| 24603 |
amit.gupta |
184 |
if (args.containsOption("scrapejd")) {
|
| 24337 |
amit.gupta |
185 |
this.scrapeJD();
|
|
|
186 |
}
|
| 24603 |
amit.gupta |
187 |
if (args.containsOption("migratepd")) {
|
| 24431 |
amit.gupta |
188 |
scheduledTasks.moveImeisToPriceDropImeis();
|
|
|
189 |
}
|
| 24603 |
amit.gupta |
190 |
if (args.containsOption("walletmismatch")) {
|
| 24542 |
amit.gupta |
191 |
scheduledTasks.walletmismatch();
|
|
|
192 |
}
|
| 24603 |
amit.gupta |
193 |
if (args.containsOption("schemewalletmismatch")) {
|
| 24580 |
amit.gupta |
194 |
scheduledTasks.schemewalletmismatch();
|
|
|
195 |
}
|
| 24603 |
amit.gupta |
196 |
if (args.containsOption("gst")) {
|
| 24542 |
amit.gupta |
197 |
scheduledTasks.gst();
|
|
|
198 |
}
|
| 24265 |
amit.gupta |
199 |
System.exit(0);
|
| 23898 |
amit.gupta |
200 |
}
|
|
|
201 |
}
|
| 24603 |
amit.gupta |
202 |
|
| 24337 |
amit.gupta |
203 |
private void scrapeJD() {
|
|
|
204 |
String jdUrlTemplate = "https://www.justdial.com/Delhi/Mobile-Phone-Dealers/nct-11216691/page-{0}";
|
|
|
205 |
Formatter formatter = new Formatter();
|
| 24603 |
amit.gupta |
206 |
|
| 24337 |
amit.gupta |
207 |
}
|
| 23723 |
amit.gupta |
208 |
}
|