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 TK extends BasicsGM{
	
	public static boolean isClearMysql =false;
	
	public static boolean isProduct=Boolean.valueOf(((system)map.get("tk")).getIsProduct());
	
//	public static HashMap<String, Object> phoneMap=new HashMap<String, Object>();//
	
	public static String phoneNeb = "";//手机号
	public static String phone_code = "";//手机号验证码
	
	public static List<String> user_idList = new ArrayList<String>();//user_id
	
	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("tk")).getSqlurl(),
						((system)map.get("tk")).getSqlname(),
						((system)map.get("tk")).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("tkxs")).getSqlurl(),
						((system)map.get("tkxs")).getSqlname(),
						((system)map.get("tkxs")).getSqlpwd());
				stmt = conn.createStatement();
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	//清除注册数据根据user_idList
	public void cleanUser_FromDB() {
		List<String> user_List = new ArrayList<String>();
		for(int i=0;i<user_idList.size();i++){
			try {
				deleteFromDB("t_user", "user_id", user_idList.get(i));
				user_List.add(user_idList.get(i));
			} catch (Exception e) {
				e.printStackTrace();
				Log.logInfo("清除数据失败t_user");
			}
			
		}
		user_idList.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());
	}
}
