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 STUDY extends BasicsGM{
	
	public static boolean isProduct= Boolean.valueOf(((system)map.get("study")).getIsProduct());
	//public static boolean isProduct_server=Boolean.valueOf(((system)map.get("nwn_server")).getIsProduct());
	public static String Ticket = "";//mis口令
	public static String Token;//特殊字符
	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 List<String> movie_id_list = new ArrayList<String>();//movid_id的id 
	public static String level_id_List = "";//层级的id
	public static List<String> user_id_List = new ArrayList<String>();//user_id
	public static String template_id = "";
	public static String timestamp;//时间戳 
	
	public void Connectionsa(){
		//================设置数据库连接池=====================
		ConnectionsMap=getConnections(new String[]{"zxkt"});
		StatementsMap=getStatements(ConnectionsMap);
		conn=ConnectionsMap.get("zxkt");//设置默认的连接对象
		stmt=StatementsMap.get("zxkt");//设置默认的连接对象
		
		//================设置公共参数========================
	/*	PublicParameter.put("appid","tiku");//静态公共参数
		DynamicParameter.put("sign","code");//动态公共参数
*/
	}
	public STUDY(){
		Connectionsa();
	}

	
	public   String getCurrentYear(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Date date = new Date();
		return sdf.format(date);
	}

	public HashMap<String, Object> setPublicParameter(HashMap<String, Object> data) {

		String parameter =null;
		HashMap<String, Object> dataNew=data;
		if(PublicParameter.size()!=0){
			parameter = MapUtil.getValue("parameter", data);
			String Request = MapUtil.getValue("Request", data);
			Set<Map.Entry<String,String>> entrySet = PublicParameter.entrySet();
			Iterator<Map.Entry<String,String>> it = entrySet.iterator();
			while(it.hasNext()){
				Map.Entry<String,String> me = it.next();
				String key = me.getKey();
				String value = me.getValue();
//				Log.logInfo("公共静态参数："+key+":"+value);
				if(!parameter.contains("\""+key+"\"") && !parameter.contains(key+"=")){
					if("get".equals(Request)){
						if(parameter==null || parameter.length()==0){
							parameter=key+"="+value;
						}else{
							parameter=parameter+"&"+key+"="+value;
						}
					}else{
						if(parameter==null || parameter.length()==0){
							parameter=key+"\":\""+value+"\"";
						}else{
							parameter=parameter+",\""+key+"\":\""+value+"\"";
						}
					}
				}
			}
			dataNew.put("parameter", parameter);
		}
		return dataNew;
	}

	//动态公共参数
		public HashMap<String, Object> setDynamicParameter(HashMap<String, Object> data) {
			String parameter =null;
			HashMap<String, Object> dataNew=data;
			if(DynamicParameter.size()!=0){
				parameter = MapUtil.getValue("parameter", data);
				String Request = MapUtil.getValue("Request", data);
				Set<Map.Entry<String,String>> entrySet = DynamicParameter.entrySet();
				Iterator<Map.Entry<String,String>> it = entrySet.iterator();
				while(it.hasNext()){
					Map.Entry<String,String> me = it.next();
					String key = me.getKey();
					String value = me.getValue();
//					Log.logInfo("公共动态参数："+key+":"+value);
					if(!parameter.contains("\""+key+"\"") && !parameter.contains(key+"=")){
						if("get".equals(Request)){
							if(parameter==null || parameter.length()==0){
								parameter=key+"="+"parameter";//需要根据实际变化
							}else{
								parameter=parameter+"&"+key+"="+"parameter";//需要根据实际变化
							}
						}else{
							if(parameter==null || parameter.length()==0){
								parameter=key+"\":\""+"parameter"+"\"";//需要根据实际变化+"\"";
							}else{
								parameter=parameter+",\""+key+"\":\""+"parameter"+"\"";//需要根据实际变化+"\"";
							}
						}
					}
				}
				dataNew.put("parameter", parameter);
			}
			return dataNew;
		}


	
	//清除getcode_id_List
	public void cleann_moment_FromDB() {
	
			try {
				deleteFromDB("zxkt.moment", "id", "565");
				
				
			} catch (Exception e) {
				e.printStackTrace();
				Log.logInfo("清除数据失败moment");
			}
			
		}
		
	
	public void cleanMysqlData() {
		 if (!isClearMysql) {
			 
			 conn=ConnectionsMap.get("zxkt");//设置默认的连接对象
			 stmt=StatementsMap.get("zxkt");//设置默认的连接对象

			 this.cleann_moment_FromDB();
		  }
	}


}
