Subversion Repositories SmartDukaan

Rev

Rev 30355 | Rev 30377 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30355 Rev 30372
Line 10... Line 10...
10
import java.time.LocalDate;
10
import java.time.LocalDate;
11
import java.time.LocalDateTime;
11
import java.time.LocalDateTime;
12
import java.util.ArrayList;
12
import java.util.ArrayList;
13
import java.util.List;
13
import java.util.List;
14
import java.util.Map;
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
 
15
 
20
@Service
16
@Service
-
 
17
//Also contains realme
21
public class OppoImeiActivationService {
18
public class OppoImeiActivationService {
22
 
19
 
23
	private static final Logger LOGGER = LogManager.getLogger(OppoImeiActivationService.class);
20
	private static final Logger LOGGER = LogManager.getLogger(OppoImeiActivationService.class);
24
	@Autowired
21
	@Autowired
25
	ActivatedImeiRepository activatedImeiRepository;
22
	ActivatedImeiRepository activatedImeiRepository;
-
 
23
	@Autowired
-
 
24
	CheckOppoWarrantyTask checkOppoWarrantyTask;
26
 
25
 
27
	public void updateActivationDate(List<String> imeis) throws Exception {
26
	public void updateActivationDate(List<String> imeis) throws Exception {
-
 
27
		Map<String, LocalDate> imeisDateMap = checkOppoWarrantyTask.checkWarranty(imeis);
-
 
28
		List<String> foundImeis = new ArrayList<>();
-
 
29
		imeisDateMap.entrySet().forEach(y -> {
-
 
30
			foundImeis.add(y.getKey());
-
 
31
			System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
-
 
32
			ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(y.getKey());
-
 
33
			if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
-
 
34
				activatedImei = new ActivatedImei();
-
 
35
				activatedImei.setSerialNumber(y.getKey());
-
 
36
				activatedImei.setCreateTimestamp(LocalDateTime.now());
-
 
37
				activatedImeiRepository.persist(activatedImei);
-
 
38
			}
-
 
39
			if (y.getValue() != null) {
-
 
40
				activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
-
 
41
			}
-
 
42
		});
-
 
43
		imeis.removeAll(foundImeis);
-
 
44
		LOGGER.info("Could not break captcha for imeis - " + foundImeis);
-
 
45
	}
-
 
46
 
-
 
47
 
-
 
48
	/*public void updateRealmeActivationDate(List<String> imeis) throws Exception {
28
		//TODO:Change bucket size
49
		//TODO:Change bucket size
29
		int bucketSize = 25;
50
		int bucketSize = 10;
30
		int chromeThreads = imeis.size() / bucketSize;
51
		int chromeThreads = imeis.size() / bucketSize;
31
		ExecutorService excecutorService = Executors.newFixedThreadPool(chromeThreads);
52
		ExecutorService excecutorService = Executors.newFixedThreadPool(chromeThreads);
32
		List<CheckOppoWarrantyTask> tasks = new ArrayList<>();
53
		List<CheckRealmeWarrantyTask> tasks = new ArrayList<>();
33
		for (int i = 0; i < imeis.size() / bucketSize; i++) {
54
		for (int i = 0; i < imeis.size() / bucketSize; i++) {
34
			CheckOppoWarrantyTask task = new CheckOppoWarrantyTask(imeis);
55
			CheckRealmeWarrantyTask task = new CheckRealmeWarrantyTask(imeis);
35
			tasks.add(task);
56
			tasks.add(task);
36
		}
57
		}
37
		LOGGER.info("Total tasks {}", tasks.size());
58
		LOGGER.info("Total tasks {}", tasks.size());
38
		List<Future<Map<String, LocalDate>>> futures = excecutorService.invokeAll(tasks);
59
		List<Future<Map<String, LocalDate>>> futures = excecutorService.invokeAll(tasks);
39
		List<String> foundImeis = new ArrayList<>();
60
		List<String> foundImeis = new ArrayList<>();
Line 59... Line 80...
59
				e.printStackTrace();
80
				e.printStackTrace();
60
			}
81
			}
61
		});
82
		});
62
		imeis.removeAll(foundImeis);
83
		imeis.removeAll(foundImeis);
63
		LOGGER.info("Could not break captcha for imeis - " + foundImeis);
84
		LOGGER.info("Could not break captcha for imeis - " + foundImeis);
64
	}
85
	}*/
65
}
86
}
66
87