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.ReadProperties;
import com.offcn.TestUnti.cmdUtil;
import com.offcn.system.system;


public class XYZB extends BasicsGM{
	
	public static boolean isProduct =  false;
	
	public static String Page_token="";//登录页面token
	
	public static HashMap<String, Object> Enterprise_users=new HashMap<String, Object>();//企业用户
	
	public static HashMap<String, Object> Business_Administrator=new HashMap<String, Object>();//业务管理员
	
	public static String Salesman_token="";//业务员登录token
	
	public static String Client_token="";//客户端登录token
	
	public static String laravel_session="";//cookie
	
	public static String XSRF_token="";// XSRF-token
	
	public static String Current_mails_id="";// 当前用户通讯录表主键
	
	public static String Current_user_id="";// 当前用户user表主键
	public static String Current_questions_id="";// questions表id主键
	public static String Current_announcement_id="";// 公告announcement表id主键
	public static String Current_suggest_id="";// 反馈列表id
	
	public static String Current_user="";// 当前用户口令
	public static String Current_room="";// 当前房间号
	public static String Current_room_id="";// 当前房间主键id
	
	
	public static String Current_nickname="";// 当前用户昵称
	public static String Current_uuid="";// 当前用户uuid
	public static String Current_password="";// 当前用户类型
	public static String Current_id="";// 房间文件id
	
	//未编辑--口令
	public static HashMap<String, Object> Not_edited_xyzb=new HashMap<String, Object>();
	//未开始--口令
	public static HashMap<String, Object> Not_started_xyzb=new HashMap<String, Object>();
	//直播中--口令
	public static HashMap<String, Object> Running_xyzb=new HashMap<String, Object>();
	//已结束--口令
	public static HashMap<String, Object> Finished_xyzb=new HashMap<String, Object>();
	//已失效--口令
	public static HashMap<String, Object> Invalid_xyzb=new HashMap<String, Object>();
	
	//房间编号
	public static HashMap<String, Object> room_nums=new HashMap<String, Object>();
	//房间名称
	public static HashMap<String, Object> room_names=new HashMap<String, Object>();
	
	//推流
	public static HashMap<String, Object> push_xyzb=new HashMap<String, Object>();
	//拉流
	public static HashMap<String, Object> pull_xyzb=new HashMap<String, Object>();
	
	static{
		//初始环境设置DNS
//		if(!cmdUtil.run("nslookup www.qq.com").contains("192.168.10.222")){
//			Log.logInfo("正在设置dns地址为：192.168.10.222,如果失败，请断开有限网络，用无线网络连接");
//			cmdUtil.run("netsh interface ip set dns \"无线网络连接(media-test)\" static 192.168.10.222");
//		}else{
//			Log.logInfo("dns地址正确无需设置");
//		}
		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("xyzb")).getSqlurl(),
						((system)map.get("xyzb")).getSqlname(),
						((system)map.get("xyzb")).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("xyzbxs")).getSqlurl(),
						((system)map.get("xyzbxs")).getSqlname(),
						((system)map.get("xyzbxs")).getSqlpwd());
				stmt = conn.createStatement();
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		//初始化数据录入
		if(!ReadProperties.isBoolean()){
			Log.logInfo("加载数据源。。。");
			Enterprise_users.put("name",  ReadProperties.GetinformationByKey("Enterprise_users"));
			Business_Administrator.put("name", ReadProperties.GetinformationByKey("Business_Administrator"));
			
			Not_edited_xyzb.put("teacher_password", ReadProperties.GetinformationByKey("Not_edited_xyzbteacher_password"));
			Not_edited_xyzb.put("student_password", ReadProperties.GetinformationByKey("Not_edited_xyzbstudent_password"));
			Not_edited_xyzb.put("assistant_password", ReadProperties.GetinformationByKey("Not_edited_xyzbassistant_password"));
			Not_edited_xyzb.put("host_password", ReadProperties.GetinformationByKey("Not_edited_xyzbhost_password"));
			room_nums.put("Not_edited", ReadProperties.GetinformationByKey("Not_edited_xyzbroom_nums"));//存储房间编号
			room_names.put("Not_edited", ReadProperties.GetinformationByKey("Not_edited_xyzbroom_names"));//存储房间名称
			
			Not_started_xyzb.put("teacher_password", ReadProperties.GetinformationByKey("Not_started_xyzbteacher_password"));
			Not_started_xyzb.put("student_password", ReadProperties.GetinformationByKey("Not_started_xyzbstudent_password"));
			Not_started_xyzb.put("assistant_password", ReadProperties.GetinformationByKey("Not_started_xyzbassistant_password"));
			Not_started_xyzb.put("host_password", ReadProperties.GetinformationByKey("Not_started_xyzbhost_password"));
			room_nums.put("Not_started",  ReadProperties.GetinformationByKey("Not_started_xyzbroom_nums"));
			room_names.put("Not_started", ReadProperties.GetinformationByKey("Not_started_xyzbroom_names"));
			
			Running_xyzb.put("teacher_password", ReadProperties.GetinformationByKey("Running_xyzbteacher_password"));
			Running_xyzb.put("student_password", ReadProperties.GetinformationByKey("Running_xyzbstudent_password"));
			Running_xyzb.put("assistant_password", ReadProperties.GetinformationByKey("Running_xyzbassistant_password"));
			Running_xyzb.put("host_password", ReadProperties.GetinformationByKey("Running_xyzbhost_password"));
			room_nums.put("Running_xyzb",  ReadProperties.GetinformationByKey("Running_xyzbroom_nums"));
			room_names.put("Running_xyzb", ReadProperties.GetinformationByKey("Running_xyzbroom_names"));
			
			Finished_xyzb.put("teacher_password", ReadProperties.GetinformationByKey("Finished_xyzbteacher_password"));
			Finished_xyzb.put("student_password", ReadProperties.GetinformationByKey("Finished_xyzbstudent_password"));
			Finished_xyzb.put("assistant_password",ReadProperties.GetinformationByKey("Finished_xyzbassistant_password"));
			Finished_xyzb.put("host_password", ReadProperties.GetinformationByKey("Finished_xyzbhost_password"));
			room_nums.put("Finished_xyzb",  ReadProperties.GetinformationByKey("Finished_xyzbroom_nums"));
			room_names.put("Finished_xyzb", ReadProperties.GetinformationByKey("Finished_xyzbroom_names"));
			
			Invalid_xyzb.put("teacher_password", ReadProperties.GetinformationByKey("Invalid_xyzbteacher_password"));
			Invalid_xyzb.put("student_password",ReadProperties.GetinformationByKey("Invalid_xyzbstudent_password"));
			Invalid_xyzb.put("assistant_password", ReadProperties.GetinformationByKey("Invalid_xyzbassistant_password"));
			Invalid_xyzb.put("host_password", ReadProperties.GetinformationByKey("Invalid_xyzbhost_password"));
			room_nums.put("Invalid_xyzb",  ReadProperties.GetinformationByKey("Invalid_xyzbroom_nums"));
			room_names.put("Invalid_xyzb", ReadProperties.GetinformationByKey("Invalid_xyzbroom_names"));
		}
	}
	
	//清除map集合Enterprise_users(企业用户)，表名"xyu_users"，列名name，
	public void cleanEnterprise_usersFromDB() {
		try {
			deleteFromDB("xyu_users", "name", Enterprise_users.get("name").toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	//清除map集合room_nums，表名"xyu_room_users"，列名room_num，
		public void cleanRoom_numsFromDB() {
			try {
				deleteFromDB("xyu_room_users", "room_num", room_nums.get("Not_edited").toString());
				deleteFromDB("xyu_room_users", "room_num", room_nums.get("Not_started").toString());
				deleteFromDB("xyu_room_users", "room_num", room_nums.get("Running_xyzb").toString());
				deleteFromDB("xyu_room_users", "room_num", room_nums.get("Finished_xyzb").toString());
				deleteFromDB("xyu_room_users", "room_num", room_nums.get("Invalid_xyzb").toString());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	
	//清除map集合Business_Administrator（业务管理员），表名"xyu_users"，列名name，
	public void cleanBusiness_AdministratorFromDB() {
		try {
			deleteFromDB("xyu_users", "name", Business_Administrator.get("name").toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
