Subversion Repositories SmartDukaan

Rev

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