Subversion Repositories SmartDukaan

Rev

Rev 34415 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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