| 30209 |
amit.gupta |
1 |
package com.smartdukaan.cron.scheduled;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.dao.entity.fofo.ActivatedImei;
|
|
|
4 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
|
|
5 |
import org.apache.logging.log4j.LogManager;
|
|
|
6 |
import org.apache.logging.log4j.Logger;
|
|
|
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
8 |
import org.springframework.stereotype.Service;
|
|
|
9 |
|
|
|
10 |
import java.time.LocalDate;
|
|
|
11 |
import java.time.LocalDateTime;
|
|
|
12 |
import java.util.ArrayList;
|
|
|
13 |
import java.util.List;
|
|
|
14 |
import java.util.Map;
|
|
|
15 |
|
|
|
16 |
@Service
|
| 30372 |
amit.gupta |
17 |
//Also contains realme
|
| 30209 |
amit.gupta |
18 |
public class OppoImeiActivationService {
|
|
|
19 |
|
|
|
20 |
private static final Logger LOGGER = LogManager.getLogger(OppoImeiActivationService.class);
|
|
|
21 |
@Autowired
|
|
|
22 |
ActivatedImeiRepository activatedImeiRepository;
|
| 30372 |
amit.gupta |
23 |
@Autowired
|
|
|
24 |
CheckOppoWarrantyTask checkOppoWarrantyTask;
|
| 30209 |
amit.gupta |
25 |
|
|
|
26 |
public void updateActivationDate(List<String> imeis) throws Exception {
|
| 34413 |
amit.gupta |
27 |
//System.setProperty("os.arch", "arm");
|
| 30372 |
amit.gupta |
28 |
Map<String, LocalDate> imeisDateMap = checkOppoWarrantyTask.checkWarranty(imeis);
|
|
|
29 |
List<String> foundImeis = new ArrayList<>();
|
|
|
30 |
imeisDateMap.entrySet().forEach(y -> {
|
|
|
31 |
foundImeis.add(y.getKey());
|
|
|
32 |
System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
|
|
|
33 |
ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(y.getKey());
|
|
|
34 |
if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
|
|
|
35 |
activatedImei = new ActivatedImei();
|
|
|
36 |
activatedImei.setSerialNumber(y.getKey());
|
|
|
37 |
activatedImei.setCreateTimestamp(LocalDateTime.now());
|
|
|
38 |
activatedImeiRepository.persist(activatedImei);
|
|
|
39 |
}
|
| 30377 |
amit.gupta |
40 |
activatedImei.setCreateTimestamp(LocalDateTime.now());
|
| 30372 |
amit.gupta |
41 |
if (y.getValue() != null) {
|
|
|
42 |
activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
|
|
|
43 |
}
|
|
|
44 |
});
|
| 34415 |
amit.gupta |
45 |
/*if(foundImeis.size() > 0) {
|
|
|
46 |
imeis.removeAll(foundImeis);
|
|
|
47 |
}
|
|
|
48 |
LOGGER.info("Could not break captcha for imeis - " + imeis);*/
|
| 30372 |
amit.gupta |
49 |
}
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
/*public void updateRealmeActivationDate(List<String> imeis) throws Exception {
|
| 30352 |
amit.gupta |
53 |
//TODO:Change bucket size
|
| 30372 |
amit.gupta |
54 |
int bucketSize = 10;
|
| 30352 |
amit.gupta |
55 |
int chromeThreads = imeis.size() / bucketSize;
|
| 30209 |
amit.gupta |
56 |
ExecutorService excecutorService = Executors.newFixedThreadPool(chromeThreads);
|
| 30372 |
amit.gupta |
57 |
List<CheckRealmeWarrantyTask> tasks = new ArrayList<>();
|
| 30315 |
amit.gupta |
58 |
for (int i = 0; i < imeis.size() / bucketSize; i++) {
|
| 30372 |
amit.gupta |
59 |
CheckRealmeWarrantyTask task = new CheckRealmeWarrantyTask(imeis);
|
| 30209 |
amit.gupta |
60 |
tasks.add(task);
|
|
|
61 |
}
|
| 30355 |
amit.gupta |
62 |
LOGGER.info("Total tasks {}", tasks.size());
|
| 30209 |
amit.gupta |
63 |
List<Future<Map<String, LocalDate>>> futures = excecutorService.invokeAll(tasks);
|
|
|
64 |
List<String> foundImeis = new ArrayList<>();
|
|
|
65 |
futures.stream().forEach(x -> {
|
|
|
66 |
try {
|
|
|
67 |
x.get().entrySet().forEach(y -> {
|
|
|
68 |
foundImeis.add(y.getKey());
|
|
|
69 |
System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
|
| 30352 |
amit.gupta |
70 |
ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(y.getKey());
|
| 30209 |
amit.gupta |
71 |
if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
|
| 30352 |
amit.gupta |
72 |
activatedImei = new ActivatedImei();
|
| 30209 |
amit.gupta |
73 |
activatedImei.setSerialNumber(y.getKey());
|
|
|
74 |
activatedImei.setCreateTimestamp(LocalDateTime.now());
|
|
|
75 |
activatedImeiRepository.persist(activatedImei);
|
|
|
76 |
}
|
| 30352 |
amit.gupta |
77 |
if (y.getValue() != null) {
|
|
|
78 |
activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
|
|
|
79 |
}
|
| 30209 |
amit.gupta |
80 |
});
|
|
|
81 |
} catch (InterruptedException e) {
|
|
|
82 |
e.printStackTrace();
|
|
|
83 |
} catch (ExecutionException e) {
|
|
|
84 |
e.printStackTrace();
|
|
|
85 |
}
|
|
|
86 |
});
|
|
|
87 |
imeis.removeAll(foundImeis);
|
|
|
88 |
LOGGER.info("Could not break captcha for imeis - " + foundImeis);
|
| 30372 |
amit.gupta |
89 |
}*/
|
| 30209 |
amit.gupta |
90 |
}
|