package com.offcn.process;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.offcn.TestUnti.Log;
import com.offcn.TestUnti.MapUtil;
import com.offcn.TestUnti.ReadProperties;
import com.offcn.TestUnti.cmdUtil;
import com.offcn.system.system;


public class NWN extends BasicsGM{
	
	public static boolean isClearMysql =false;
	
	public static boolean isProduct=Boolean.valueOf(((system)map.get("nwn")).getIsProduct());
	
	public static String nwn_sign = "";//mis口令
	public static String admin_login_ssid = "";//nwn登录得到的口令
	public static String nwn_url = "";//后台登录得到的nwn登录地址
	public static String PHPSESSID = "";//后台登录nwn，最终得到的PHPSESSID
	public static String admin_31_encode = "";//后台登录nwn，最终得到的PHPSESSID
	
	public static List<String> n_package_idList = new ArrayList<String>();//n_package的id
	
	public static List<String> n_admin_card_no_List = new ArrayList<String>();//n_admin的card_no
	public static List<String> n_admin_id_List = new ArrayList<String>();//n_admin的id
	public static List<String> n_admin_phone_List = new ArrayList<String>();//n_admin的phone
	public static List<String> n_admin_username_List = new ArrayList<String>();//n_admin的username
	public static List<String> getcode_id_List = new ArrayList<String>();//getcode的id 
	public static List<String> n_getcode_id_List = new ArrayList<String>();//getcode的id 
	
	public static String level_id_List = "";//层级的id
	public static List<String> user_id_List = new ArrayList<String>();//user_id
	
//	public static String phone_code = "";//手机号验证码
//	
//	
//	public static List<String> t_exam_area = new ArrayList<String>();//t_exam_area_id
//	
//	public static String union_id_str = "" ;//t_user表union_id
//	public static String open_id_str = "";//t_user表open_id
//	
//	public static String tk_token="";//登录token
	
	static{
		String mysql_local_Online=ReadProperties.GetTestPropertyByKey("mysql_local_Online");
		//本地数据库连接
		if(mysql_local_Online.equals("local")){
			try {
				Class.forName("com.mysql.jdbc.Driver");
				conn = DriverManager.getConnection(((system)map.get("nwn")).getSqlurl(),
						((system)map.get("nwn")).getSqlname(),
						((system)map.get("nwn")).getSqlpwd());
				stmt = conn.createStatement();
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if(mysql_local_Online.equals("Online")){
			//线上数据库连接
			try {
				Class.forName("com.mysql.jdbc.Driver");
				conn = DriverManager.getConnection(((system)map.get("nwnxs")).getSqlurl(),
						((system)map.get("nwnxs")).getSqlname(),
						((system)map.get("nwnxs")).getSqlpwd());
				stmt = conn.createStatement();
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	
	
	//清除注册数据根据n_admin_card_no_List
	public void cleann_n_admin_card_no_List_FromDB() {
		List<String> user_List = new ArrayList<String>();
		for(int i=0;i<n_admin_card_no_List.size();i++){
			try {
				deleteFromDB("n_admin", "card_no", n_admin_card_no_List.get(i));
				user_List.add(n_admin_card_no_List.get(i));
			} catch (Exception e) {
				e.printStackTrace();
				Log.logInfo("清除数据失败n_admin_card_no_List");
			}
			
		}
		n_admin_card_no_List.removeAll(user_List);
//		System.out.println(user_idList.toString());
	}
	
	
	//清除注册数据根据
//	public void cleann_n_admin_card_id_List_FromDB() {
//		List<String> user_List = new ArrayList<String>();
//		for(int i=0;i<n_admin_card_no_List.size();i++){
//			try {
//				deleteFromDB("n_admin", "card_no", n_admin_card_no_List.get(i));
//				user_List.add(n_admin_card_no_List.get(i));
//			} catch (Exception e) {
//				e.printStackTrace();
//				Log.logInfo("清除数据失败n_admin_card_no_List");
//			}
//			
//		}
//		n_admin_card_no_List.removeAll(user_List);
////			System.out.println(user_idList.toString());
//	}
	
	//清除注册数据根据n_package_idList
	public void cleann_n_package_List_FromDB() {
		List<String> user_List = new ArrayList<String>();
		for(int i=0;i<n_package_idList.size();i++){
			try {
				deleteFromDB("n_package", "id", n_package_idList.get(i));
				//deleteFromDB("n_packcode", "package_id", n_package_idList.get(i));
				//deleteFromDB("n_packcode_record", "package_id", n_package_idList.get(i));
				user_List.add(n_package_idList.get(i));
			} catch (Exception e) {
				e.printStackTrace();
				Log.logInfo("清除数据失败n_package_idList");
			}
			
		}
		n_package_idList.removeAll(user_List);
//			System.out.println(user_idList.toString());
	}
	
	//清除注册数据根据n_package_idList
	public void cleann_user_id_List_FromDB() {
		List<String> user_List = new ArrayList<String>();
		for(int i=0;i<user_id_List.size();i++){
			try {
				deleteFromDB("n_user", "id", user_id_List.get(i));
				user_List.add(user_id_List.get(i));
			} catch (Exception e) {
				e.printStackTrace();
				Log.logInfo("清除数据失败user_id_List");
			}
			
		}
		user_id_List.removeAll(user_List);
//		System.out.println(user_idList.toString());
	}
	//清除getcode_id_List
	public void cleann_getcode_id_List_FromDB() {
		List<String> user_List = new ArrayList<String>();
		for(int i=0;i<getcode_id_List.size();i++){
			try {
				deleteFromDB("n_packcode", "package_id", getcode_id_List.get(i));
				deleteFromDB("n_packcode_record", "package_id", getcode_id_List.get(i));
				user_List.add(getcode_id_List.get(i));
			} catch (Exception e) {
				e.printStackTrace();
				Log.logInfo("清除数据失败getcode_id_List");
			}
			
		}
		getcode_id_List.removeAll(user_List);
//		System.out.println(user_idList.toString());
	}
	
//	
//
//	//清除用户地区操作表t_exam_area
//	public void cleanexam_FromDB() {
//		List<String> user_List = new ArrayList<String>();
//		for(int i=0;i<t_exam_area.size();i++){
//			try {
//				deleteFromDB("t_exam_area", "id", t_exam_area.get(i));
//				user_List.add(t_exam_area.get(i));
//			} catch (Exception e) {
//				e.printStackTrace();
//				Log.logInfo("清除数据失败t_exam_area");
//			}
//			
//		}
//		t_exam_area.removeAll(user_List);
////			System.out.println(user_idList.toString());
//	}
}
