Subversion Repositories SmartDukaan

Rev

Rev 34413 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.smartdukaan.cron.scheduled;

import com.spice.profitmandi.dao.entity.fofo.ActivatedImei;
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
//Also contains realme
public class OppoImeiActivationService {

        private static final Logger LOGGER = LogManager.getLogger(OppoImeiActivationService.class);
        @Autowired
        ActivatedImeiRepository activatedImeiRepository;
        @Autowired
        CheckOppoWarrantyTask checkOppoWarrantyTask;

        public void updateActivationDate(List<String> imeis) throws Exception {
                //System.setProperty("os.arch", "arm");
                Map<String, LocalDate> imeisDateMap = checkOppoWarrantyTask.checkWarranty(imeis);
                List<String> foundImeis = new ArrayList<>();
                imeisDateMap.entrySet().forEach(y -> {
                        foundImeis.add(y.getKey());
                        System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
                        ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(y.getKey());
                        if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
                                activatedImei = new ActivatedImei();
                                activatedImei.setSerialNumber(y.getKey());
                                activatedImei.setCreateTimestamp(LocalDateTime.now());
                                activatedImeiRepository.persist(activatedImei);
                        }
                        activatedImei.setCreateTimestamp(LocalDateTime.now());
                        if (y.getValue() != null) {
                                activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
                        }
                });
                /*if(foundImeis.size() > 0) {
                        imeis.removeAll(foundImeis);
                }
                LOGGER.info("Could not break captcha for imeis - " + imeis);*/
        }


        /*public void updateRealmeActivationDate(List<String> imeis) throws Exception {
                //TODO:Change bucket size
                int bucketSize = 10;
                int chromeThreads = imeis.size() / bucketSize;
                ExecutorService excecutorService = Executors.newFixedThreadPool(chromeThreads);
                List<CheckRealmeWarrantyTask> tasks = new ArrayList<>();
                for (int i = 0; i < imeis.size() / bucketSize; i++) {
                        CheckRealmeWarrantyTask task = new CheckRealmeWarrantyTask(imeis);
                        tasks.add(task);
                }
                LOGGER.info("Total tasks {}", tasks.size());
                List<Future<Map<String, LocalDate>>> futures = excecutorService.invokeAll(tasks);
                List<String> foundImeis = new ArrayList<>();
                futures.stream().forEach(x -> {
                        try {
                                x.get().entrySet().forEach(y -> {
                                        foundImeis.add(y.getKey());
                                        System.out.println("Serial Number " + y.getKey() + "Date " + y.getValue());
                                        ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(y.getKey());
                                        if (activatedImeiRepository.selectBySerialNumber(y.getKey()) == null) {
                                                activatedImei = new ActivatedImei();
                                                activatedImei.setSerialNumber(y.getKey());
                                                activatedImei.setCreateTimestamp(LocalDateTime.now());
                                                activatedImeiRepository.persist(activatedImei);
                                        }
                                        if (y.getValue() != null) {
                                                activatedImei.setActivationTimestamp(y.getValue().atStartOfDay());
                                        }
                                });
                        } catch (InterruptedException e) {
                                e.printStackTrace();
                        } catch (ExecutionException e) {
                                e.printStackTrace();
                        }
                });
                imeis.removeAll(foundImeis);
                LOGGER.info("Could not break captcha for imeis - " + foundImeis);
        }*/
}