Subversion Repositories SmartDukaan

Rev

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

Rev 30315 Rev 30352
Line 4... Line 4...
4
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
4
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
5
import org.apache.logging.log4j.LogManager;
5
import org.apache.logging.log4j.LogManager;
6
import org.apache.logging.log4j.Logger;
6
import org.apache.logging.log4j.Logger;
7
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.stereotype.Service;
8
import org.springframework.stereotype.Service;
9
import org.springframework.transaction.annotation.Transactional;
-
 
10
 
9
 
11
import java.time.LocalDate;
10
import java.time.LocalDate;
12
import java.time.LocalDateTime;
11
import java.time.LocalDateTime;
13
import java.util.ArrayList;
12
import java.util.ArrayList;
14
import java.util.List;
13
import java.util.List;
Line 17... Line 16...
17
import java.util.concurrent.ExecutorService;
16
import java.util.concurrent.ExecutorService;
18
import java.util.concurrent.Executors;
17
import java.util.concurrent.Executors;
19
import java.util.concurrent.Future;
18
import java.util.concurrent.Future;
20
 
19
 
21
@Service
20
@Service
22
@Transactional(rollbackFor = Throwable.class)
-
 
23
public class OppoImeiActivationService {
21
public class OppoImeiActivationService {
24
 
22
 
25
	private static final Logger LOGGER = LogManager.getLogger(OppoImeiActivationService.class);
23
	private static final Logger LOGGER = LogManager.getLogger(OppoImeiActivationService.class);
26
	@Autowired
24
	@Autowired
27
	ActivatedImeiRepository activatedImeiRepository;
25
	ActivatedImeiRepository activatedImeiRepository;
28
 
26
 
29
	public void updateActivationDate(List<String> imeis) throws Exception {
27
	public void updateActivationDate(List<String> imeis) throws Exception {
30
		int chromeThreads = 7;
28
		//TODO:Change bucket size
31
		int bucketSize = 4;
29
		int bucketSize = 25;
-
 
30
		int chromeThreads = imeis.size() / bucketSize;
32
		ExecutorService excecutorService = Executors.newFixedThreadPool(chromeThreads);
31
		ExecutorService excecutorService = Executors.newFixedThreadPool(chromeThreads);
33
		List<CheckOppoWarrantyTask> tasks = new ArrayList<>();
32
		List<CheckOppoWarrantyTask> tasks = new ArrayList<>();
34
		for (int i = 0; i < imeis.size() / bucketSize; i++) {
33
		for (int i = 0; i < imeis.size() / bucketSize; i++) {
35
			CheckOppoWarrantyTask task = new CheckOppoWarrantyTask(imeis.subList(i * bucketSize, (i + 1) * bucketSize));
34
			CheckOppoWarrantyTask task = new CheckOppoWarrantyTask(imeis);
36
			tasks.add(task);
35
			tasks.add(task);
37
		}
36
		}
38
		List<Future<Map<String, LocalDate>>> futures = excecutorService.invokeAll(tasks);
37
		List<Future<Map<String, LocalDate>>> futures = excecutorService.invokeAll(tasks);
39
		List<String> foundImeis = new ArrayList<>();
38
		List<String> foundImeis = new ArrayList<>();
40
		futures.stream().forEach(x -> {
39
		futures.stream().forEach(x -> {
41
			try {
40
			try {
42
				x.get().entrySet().forEach(y -> {
41
				x.get().entrySet().forEach(y -> {
43
					foundImeis.add(y.getKey());
42
					foundImeis.add(y.getKey());
44
					System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
43
					System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
45
					if (y.getValue() == null) return;
44
					ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(y.getKey());
46
					if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
45
					if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
47
						ActivatedImei activatedImei = new ActivatedImei();
46
						activatedImei = new ActivatedImei();
48
						activatedImei.setSerialNumber(y.getKey());
47
						activatedImei.setSerialNumber(y.getKey());
49
						activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
-
 
50
						activatedImei.setCreateTimestamp(LocalDateTime.now());
48
						activatedImei.setCreateTimestamp(LocalDateTime.now());
51
						activatedImeiRepository.persist(activatedImei);
49
						activatedImeiRepository.persist(activatedImei);
52
					}
50
					}
-
 
51
					if (y.getValue() != null) {
-
 
52
						activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
-
 
53
					}
53
				});
54
				});
54
			} catch (InterruptedException e) {
55
			} catch (InterruptedException e) {
55
				e.printStackTrace();
56
				e.printStackTrace();
56
			} catch (ExecutionException e) {
57
			} catch (ExecutionException e) {
57
				e.printStackTrace();
58
				e.printStackTrace();