 import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;

 public class AnprStatusJob
   implements Job {

   private String jobSays;
   private float myFloatValue;
   private ArrayList<Date> state;
   private String g_strTenel = "";
   private List<String> g_listN1 = new ArrayList<>();
   private List<String> g_listN3 = new ArrayList<>();

   private final Logger logger = Logger.getLogger(AnprStatusJob.class);

   public AnprStatusJob() {
     PropertyConfigurator.configure("./log4j.properties");

     try {
       String propFile = "./config.properties";
       Properties props = new Properties();
       FileInputStream fis = new FileInputStream(propFile);
       props.load(new BufferedInputStream(fis));
       this.g_strTenel = props.getProperty("tennel_no");

       props.clear();
       props = null;
       System.out.println("===================== A");

       this.g_listN1.add("01");
       this.g_listN1.add("02");
       this.g_listN1.add("03");
       this.g_listN1.add("04");
       this.g_listN1.add("05");
       this.g_listN1.add("06");
       this.g_listN1.add("07");
       this.g_listN1.add("08");

       this.g_listN3.add("01");
       this.g_listN3.add("02");
       this.g_listN3.add("03");
       this.g_listN3.add("04");


       this.g_listN3.add("07");
       this.g_listN3.add("08");
       this.g_listN3.add("09");
       this.g_listN3.add("10");
       System.out.println("===================== B");
     } catch (Exception e) {
       this.logger.debug("Exception : " + e);
     }
   }


   @Override
   public void execute(JobExecutionContext context) throws JobExecutionException {
     JobKey key = context.getJobDetail().getKey();
     this.state.add(new Date());

     this.logger.info("Instance " + key + " of DmbJob says: " + this.jobSays + ", and val is: " + this.myFloatValue +
         ", state size:" + this.state.size() + "," + this.state.get(this.state.size() - 1));

     this.logger.debug("======== 차로개수 : " + this.g_listN3.size());
     List<String> list = new ArrayList<>();
     if (this.g_strTenel.equals("3")) {
       list.addAll(this.g_listN3); //8개항목
     } else if (this.g_strTenel.equals("1")) {
       list.addAll(this.g_listN1); //8개항목
     } else {
       return;
     }

     AnprStateSend obj = null;
     for (int i = 0; i < list.size(); i++) { //8번반복
       this.logger.debug(String.format("%s차로 시작", new Object[] { list.get(i) }));

       obj = new AnprStateSend(list.get(i));
       obj.runCarNoImageSend();

       this.logger.debug(String.format("%s차로 끝", new Object[] { list.get(i) }));
     }
   }


   public void setJobSays(String jobSays) {
     this.jobSays = jobSays;
   }

   public void setMyFloatValue(float myFloatValue) {
     this.myFloatValue = myFloatValue;
   }

   public void setState(ArrayList<Date> state) {
     this.state = state;
   }
 }
