| 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 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
10 |
|
|
|
11 |
import java.time.LocalDate;
|
|
|
12 |
import java.time.LocalDateTime;
|
|
|
13 |
import java.util.ArrayList;
|
|
|
14 |
import java.util.List;
|
|
|
15 |
import java.util.Map;
|
|
|
16 |
import java.util.concurrent.ExecutionException;
|
|
|
17 |
import java.util.concurrent.ExecutorService;
|
|
|
18 |
import java.util.concurrent.Executors;
|
|
|
19 |
import java.util.concurrent.Future;
|
|
|
20 |
|
|
|
21 |
@Service
|
|
|
22 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
23 |
public class OppoImeiActivationService {
|
|
|
24 |
|
|
|
25 |
private static final Logger LOGGER = LogManager.getLogger(OppoImeiActivationService.class);
|
|
|
26 |
@Autowired
|
|
|
27 |
ActivatedImeiRepository activatedImeiRepository;
|
|
|
28 |
|
|
|
29 |
public void updateActivationDate(List<String> imeis) throws Exception {
|
|
|
30 |
int chromeThreads = 5;
|
|
|
31 |
int bucketSize = imeis.size() / chromeThreads;
|
|
|
32 |
/*List<ImeiActivationTimestampModel> imeisActivationList = activatedImeiRepository
|
|
|
33 |
.selectImeiActivationByBrand("Oppo");*/
|
|
|
34 |
//List<String> imeisSubList = imeis.subList(0, chromeThreads*bucketSize).stream().map(x -> x.getSerialNumber()).collect(Collectors.toList());
|
|
|
35 |
ExecutorService excecutorService = Executors.newFixedThreadPool(chromeThreads);
|
|
|
36 |
List<String> imeisSubList = imeis.subList(0, chromeThreads * bucketSize);
|
|
|
37 |
List<CheckOppoWarrantyTask> tasks = new ArrayList<>();
|
|
|
38 |
for (int i = 0; i < chromeThreads; i++) {
|
|
|
39 |
CheckOppoWarrantyTask task = new CheckOppoWarrantyTask(imeisSubList.subList(i * bucketSize, (i + 1) * bucketSize));
|
|
|
40 |
tasks.add(task);
|
|
|
41 |
}
|
|
|
42 |
List<Future<Map<String, LocalDate>>> futures = excecutorService.invokeAll(tasks);
|
|
|
43 |
List<String> foundImeis = new ArrayList<>();
|
|
|
44 |
futures.stream().forEach(x -> {
|
|
|
45 |
try {
|
|
|
46 |
x.get().entrySet().forEach(y -> {
|
|
|
47 |
foundImeis.add(y.getKey());
|
|
|
48 |
System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
|
|
|
49 |
if (y.getValue() == null) return;
|
|
|
50 |
if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
|
|
|
51 |
ActivatedImei activatedImei = new ActivatedImei();
|
|
|
52 |
activatedImei.setSerialNumber(y.getKey());
|
|
|
53 |
activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
|
|
|
54 |
activatedImei.setCreateTimestamp(LocalDateTime.now());
|
|
|
55 |
activatedImeiRepository.persist(activatedImei);
|
|
|
56 |
}
|
|
|
57 |
});
|
|
|
58 |
} catch (InterruptedException e) {
|
|
|
59 |
e.printStackTrace();
|
|
|
60 |
} catch (ExecutionException e) {
|
|
|
61 |
e.printStackTrace();
|
|
|
62 |
}
|
|
|
63 |
});
|
|
|
64 |
imeis.removeAll(foundImeis);
|
|
|
65 |
LOGGER.info("Could not break captcha for imeis - " + foundImeis);
|
|
|
66 |
}
|
|
|
67 |
}
|