Subversion Repositories SmartDukaan

Rev

Rev 30377 | Rev 34415 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
		});
45
		imeis.removeAll(foundImeis);
46
		LOGGER.info("Could not break captcha for imeis - " + foundImeis);
47
	}
48
 
49
 
50
	/*public void updateRealmeActivationDate(List<String> imeis) throws Exception {
30352 amit.gupta 51
		//TODO:Change bucket size
30372 amit.gupta 52
		int bucketSize = 10;
30352 amit.gupta 53
		int chromeThreads = imeis.size() / bucketSize;
30209 amit.gupta 54
		ExecutorService excecutorService = Executors.newFixedThreadPool(chromeThreads);
30372 amit.gupta 55
		List<CheckRealmeWarrantyTask> tasks = new ArrayList<>();
30315 amit.gupta 56
		for (int i = 0; i < imeis.size() / bucketSize; i++) {
30372 amit.gupta 57
			CheckRealmeWarrantyTask task = new CheckRealmeWarrantyTask(imeis);
30209 amit.gupta 58
			tasks.add(task);
59
		}
30355 amit.gupta 60
		LOGGER.info("Total tasks {}", tasks.size());
30209 amit.gupta 61
		List<Future<Map<String, LocalDate>>> futures = excecutorService.invokeAll(tasks);
62
		List<String> foundImeis = new ArrayList<>();
63
		futures.stream().forEach(x -> {
64
			try {
65
				x.get().entrySet().forEach(y -> {
66
					foundImeis.add(y.getKey());
67
					System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
30352 amit.gupta 68
					ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(y.getKey());
30209 amit.gupta 69
					if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
30352 amit.gupta 70
						activatedImei = new ActivatedImei();
30209 amit.gupta 71
						activatedImei.setSerialNumber(y.getKey());
72
						activatedImei.setCreateTimestamp(LocalDateTime.now());
73
						activatedImeiRepository.persist(activatedImei);
74
					}
30352 amit.gupta 75
					if (y.getValue() != null) {
76
						activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
77
					}
30209 amit.gupta 78
				});
79
			} catch (InterruptedException e) {
80
				e.printStackTrace();
81
			} catch (ExecutionException e) {
82
				e.printStackTrace();
83
			}
84
		});
85
		imeis.removeAll(foundImeis);
86
		LOGGER.info("Could not break captcha for imeis - " + foundImeis);
30372 amit.gupta 87
	}*/
30209 amit.gupta 88
}