/**
 *
 */
package com.foc.offline;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.io.IOUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.foc.conf.Constants;
import com.foc.flightdynamics.bean.FlightDynamicsBean;
import com.foc.flightdynamics.entity.FlightDynamicsEntity;
import com.foc.flightdynamics.service.FlightDynamicsService;

/**
 * 
 * @team BBDTEK IT Team
 * @author renmb
 * @version 1.0
 * @time  2016年12月25日
 */
public class FlightCheckMain {

    /**
     * 
     * @author renmb
     * @time  2016年12月25日
     * @param args
     * @throws IOException 
     * @throws FileNotFoundException 
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO Auto-generated method stub
        args = new String[]{"2016-12-24", "2016-12-23 22:30:02", "W:\\WorkSpace\\JAVASpace\\foc-task-1.0\\target\\2016122610\\dynamics.20161226105806.json"};
        
        String flightDate = args[0];//"2016-12-23 22:30:02";
        String modified = args[1];//"2016-12-23 22:30:02";
        String filePath = args[2];//"W:\\WorkSpace\\JAVASpace\\foc-task-1.0\\target\\dynamics.2016122400\\2016122400\\dynamics.20161224000237.json";
        
        FlightDynamicsService service = new FlightDynamicsService();
        
        String text = IOUtils.toString(new FileInputStream(filePath));
        JSONObject result = JSON.parseObject(text);
        JSONObject dataJson = (JSONObject) result.get("data");
        JSONArray  jsonArray = (JSONArray) dataJson.get("apiResp");
        
        Set<String> sets = new HashSet<>();

        System.out.println(sets.size());
//        sets.clear();
        List<FlightDynamicsBean> flightDynamicsBeans = JSONObject.parseArray(jsonArray.toJSONString(),
                FlightDynamicsBean.class);
        if (flightDynamicsBeans != null) {
            int index=0;
            int size = flightDynamicsBeans.size();
            for (FlightDynamicsBean flightDynamicsBean : flightDynamicsBeans) {
                try {
//                    index++;
//                    if(flightDate.equals(flightDynamicsBean.getDatopChn())){// 如果是明天的航班则需要插入数据
//                        System.out.println(flightDynamicsBean.getFlightNo());
//                        if(sets.contains(flightDynamicsBean.getFlightNo()) ==false){
//                        index++; 
//                        System.out.print("【DYNAMIC】第【"+index+"】条【"+flightDynamicsBean.getFlightNo()+"】"
//                                + "【"+flightDynamicsBean.getDatopChn()+"】"
//                                        + "【"+flightDynamicsBean.getDepStn()+"】"
//                                                + "【"+flightDynamicsBean.getArrStn()+"】"
//                                                        + "【"+flightDynamicsBean.getStatus()+"】");
//                        System.out.println("【正常】");
//                        if("JD0362".equals(flightDynamicsBean.getFlightNo())){
//                            System.out.println("【DYNAMIC】第【"+index+"】条【"+flightDynamicsBean.getFlightNo()+"】"
//                                    + "【"+flightDynamicsBean.getDatopChn()+"】"
//                                            + "【"+flightDynamicsBean.getDepStn()+"】"
//                                                    + "【"+flightDynamicsBean.getArrStn()+"】"
//                                                            + "【"+flightDynamicsBean.getStatus()+"】");
//                        }
//                        String key = flightDynamicsBean.getFlightNo()+" "
//                                +flightDynamicsBean.getDepStn()+" "
//                                        + flightDynamicsBean.getArrStn();
//                        if(sets.contains(key)){
                            index++; 
                            System.out.print("【DYNAMIC】第【"+index+"/"+size+"】条【"+flightDynamicsBean.getFlightNo()+"】"
                                    + "【"+flightDynamicsBean.getDatopChn()+"】"
                                            + "【"+flightDynamicsBean.getDepStn()+"】"
                                                    + "【"+flightDynamicsBean.getArrStn()+"】"
                                                            + "【"+flightDynamicsBean.getStatus()+"】"
                            + "【"+flightDynamicsBean.getSta()+"】"
                            + "【"+flightDynamicsBean.getStd()+"】");
                            System.out.println("【正常】");
//                        } else {
//                            sets.add(key);
//                        }
//                            
//                            sets.add(key);
//                        }
                            
//                        }
                        
//                    }
                } catch (Exception e) {
                    // TODO: handle exception
                    
                    System.out.println("【异常】");
                }
            }
        }
    }

}
