| 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 |
import java.util.concurrent.ExecutionException;
|
|
|
16 |
import java.util.concurrent.ExecutorService;
|
|
|
17 |
import java.util.concurrent.Executors;
|
|
|
18 |
import java.util.concurrent.Future;
|
|
|
19 |
|
|
|
20 |
@Service
|
|
|
21 |
public class OppoImeiActivationService {
|
|
|
22 |
|
|
|
23 |
private static final Logger LOGGER = LogManager.getLogger(OppoImeiActivationService.class);
|
|
|
24 |
@Autowired
|
|
|
25 |
ActivatedImeiRepository activatedImeiRepository;
|
|
|
26 |
|
|
|
27 |
public void updateActivationDate(List<String> imeis) throws Exception {
|
| 30352 |
amit.gupta |
28 |
//TODO:Change bucket size
|
|
|
29 |
int bucketSize = 25;
|
|
|
30 |
int chromeThreads = imeis.size() / bucketSize;
|
| 30209 |
amit.gupta |
31 |
ExecutorService excecutorService = Executors.newFixedThreadPool(chromeThreads);
|
|
|
32 |
List<CheckOppoWarrantyTask> tasks = new ArrayList<>();
|
| 30315 |
amit.gupta |
33 |
for (int i = 0; i < imeis.size() / bucketSize; i++) {
|
| 30352 |
amit.gupta |
34 |
CheckOppoWarrantyTask task = new CheckOppoWarrantyTask(imeis);
|
| 30209 |
amit.gupta |
35 |
tasks.add(task);
|
|
|
36 |
}
|
|
|
37 |
List<Future<Map<String, LocalDate>>> futures = excecutorService.invokeAll(tasks);
|
|
|
38 |
List<String> foundImeis = new ArrayList<>();
|
|
|
39 |
futures.stream().forEach(x -> {
|
|
|
40 |
try {
|
|
|
41 |
x.get().entrySet().forEach(y -> {
|
|
|
42 |
foundImeis.add(y.getKey());
|
|
|
43 |
System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
|
| 30352 |
amit.gupta |
44 |
ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(y.getKey());
|
| 30209 |
amit.gupta |
45 |
if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
|
| 30352 |
amit.gupta |
46 |
activatedImei = new ActivatedImei();
|
| 30209 |
amit.gupta |
47 |
activatedImei.setSerialNumber(y.getKey());
|
|
|
48 |
activatedImei.setCreateTimestamp(LocalDateTime.now());
|
|
|
49 |
activatedImeiRepository.persist(activatedImei);
|
|
|
50 |
}
|
| 30352 |
amit.gupta |
51 |
if (y.getValue() != null) {
|
|
|
52 |
activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
|
|
|
53 |
}
|
| 30209 |
amit.gupta |
54 |
});
|
|
|
55 |
} catch (InterruptedException e) {
|
|
|
56 |
e.printStackTrace();
|
|
|
57 |
} catch (ExecutionException e) {
|
|
|
58 |
e.printStackTrace();
|
|
|
59 |
}
|
|
|
60 |
});
|
|
|
61 |
imeis.removeAll(foundImeis);
|
|
|
62 |
LOGGER.info("Could not break captcha for imeis - " + foundImeis);
|
|
|
63 |
}
|
|
|
64 |
}
|