Subversion Repositories SmartDukaan

Rev

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