package com.saga.thread.common;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.zillion.util.log.LogUtil;
import com.saga.entity.EntityHbase;
import com.saga.entity.EntityMysql;
import com.saga.entity.Server;
import com.saga.entity.Transfer;
import com.saga.util.Constant;
import com.saga.util.ExcelUtil;

/**
 * 加载配置信息
 *
 * @author 李井强
 */
public class LoadConfigThread extends Thread {
	public LoadConfigThread() {
		try {
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.error("LoadConfigThread.Exception: " + e.toString());
			System.exit(0);
		}
	}

	public void run() {
		LogUtil.info("LoadConfigThread" + this.getName() + " Starting ...");
		while (true) {
			try {
				// 加载config配置文件
				// this.loadJsonConfig();
				loadExcelConfig();
				// 加载DB点位列表
				this.loadPointList2();
				// 加载采集器配置文件
				// this.loadCJQ();
				Thread.sleep(Constant.Millisecond.MINUTE_5);

			} catch (Exception e) {
				// TODO Auto-generated catch block
				LogUtil.error("LoadConfigThread.run.Exception: " + e.toString());
			}
		}
	}

	/**
	 * 加载DB点位列表
	 */
	private void loadPointList2() {
		// TODO Auto-generated method stub
		LogUtil.info("Clear Project Point List" + " Begin...");
		synchronized (Constant.ps_PhysicalList) {
			Constant.ps_PhysicalList = null;
			Constant.ps_PhysicalList = new HashMap<String, List<String>>();
			// Constant.ps_PhysicalList.clear();
		}
		synchronized (Constant.ps_ProjectList) {
			Constant.ps_ProjectList = null;
			Constant.ps_ProjectList = new HashMap<String, List<String>>();
			// Constant.ps_ProjectList.clear();
		}
		synchronized (Constant.ps_MeterList) {
			Constant.ps_MeterList = null;
			Constant.ps_MeterList = new HashMap<String, List<String>>();
			// Constant.ps_MeterList.clear();
		}
		LogUtil.info("Clear Project Point List" + " End...");
		try {
			Constant.LoadDB2Cache_dy_pointlist(Constant.Database, "dy_pointlist");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			LogUtil.error("LoadConfigThread.loadPointList2: " + e.toString());
		}
	}

	// private void loadCJQ() {
	// // TODO Auto-generated method stub
	// // 文件夹命名格式：config+"-"+楼号+"-"+mac序号，示例：config-1101080002-1
	// Constant.getConfigFile(LogUtil.GetPath(), "config-", "port");
	// // 采集器点位位置信息写入数据库
	// for (Entry<String, String> pi : Constant.pointInfo.entrySet()) {
	// String building = pi.getKey().split("-")[0];
	// String mac = pi.getKey().split("-")[1];
	// String node = mac;
	// String point = pi.getKey().split("-")[2];
	// String busno = pi.getValue().split("-")[0];
	// String site = pi.getValue().split("-")[1];
	// try {
	// LogUtil.info(building + " " + node + " " + point + " " + busno + " " +
	// site);
	// HBaseUtil.InsertPointInfo(Constant.agent,
	// Constant.BuildingDB.get(building), building, node, point,
	// busno, site);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// // System.out.println(building + node + point + busno +
	// // site);
	// }
	// try {
	// Thread.sleep(Constant.Millisecond.MINUTE_1);
	// } catch (InterruptedException e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }

	/**
	 * 加载config配置文件
	 */
	public static void loadExcelConfig() {
		// TODO Auto-generated method stub
		String resource = "/config.xls";
		String path = null;
		try {
			LogUtil.info("System.get " + System.getProperty("user.dir") + resource);
			LogUtil.info("LogUtil.get " + LogUtil.GetPath() + resource);
			path = LogUtil.GetPath() + resource;
			File file = new File(path);
			if (file.exists()) {
				excuteDbMysql(file);
				excuteDbHbase(file);
				excuteNetworkTransfer(file);
				excuteNetworkUp(file);
				excuteNetworkDown(file);
				excuteRulesGlobal(file);
				excuteRulesBuildingConvert(file);
				excuteRulesFuncConvert(file);
				excuteRulesWhiteList(file);
				excuteRulesTransferList(file);
				excuteRulesBlackList(file);
				excuteUploadMysql(file);
				excuteUploadHbase(file);

				/**获取消息队列begin**/
				executeActiveMQ(file);
				executeActiveMqPointList(file);
				/**获取消息队列end**/

			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 加载黑名单
	 */
	private static void excuteRulesBlackList(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Rules-BlackList".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Rules-BlackList begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Rules-BlackList".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Rules-BlackList end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Rules-BlackList add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}

					pty = Constant.toLower(pty);
					String building = rowData.get(pty.get("building"));

					Constant.black_Buildings.put(building, null);
				}
			}
		}
	}

	/**
	 * 加载白名单
	 */
	private static void excuteRulesWhiteList(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Rules-WhiteList".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Rules-WhiteList begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Rules-WhiteList".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Rules-WhiteList end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Rules-WhiteList add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}

					pty = Constant.toLower(pty);

					String building = rowData.get(pty.get("building"));
					String meter = rowData.get(pty.get("meter"));
					String funcid = rowData.get(pty.get("funcid"));

					Constant.whilte_Points.put(building + "-" + meter + "-" + funcid, null);
				}
			}
		}
	}

	/**
	 * 加载转发列表
	 */
	private static void excuteRulesTransferList(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Rules-TransferList".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Rules-TransferList begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Rules-TransferList".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Rules-TransferList end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Rules-TransferList add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}

					pty = Constant.toLower(pty);

					String building = rowData.get(pty.get("building"));
					String meter = rowData.get(pty.get("meter"));
					String funcid = rowData.get(pty.get("funcid"));

					Constant.transfer_List.put(building + "-" + meter + "-" + funcid, null);
				}
			}
		}
	}

	/**
	 * 加载表号转换规则
	 */
	private static void excuteRulesFuncConvert(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Rules-FuncConvert".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Rules-FuncConvert begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Rules-FuncConvert".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Rules-FuncConvert end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Rules-FuncConvert add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}

					pty = Constant.toLower(pty);
					String funcidOld = rowData.get(pty.get("oldfuncid"));
					String funcidNew = rowData.get(pty.get("newfuncid"));

					Constant.FunctionConv.put(funcidOld, funcidNew);
					Constant.FunctionConvReverse.put(funcidNew, funcidOld);
				}
			}
		}
	}

	/**
	 * 加载建筑转换规则
	 */
	private static void excuteRulesBuildingConvert(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Rules-BuildingConvert".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Rules-BuildingConvert begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0)
						&& !("Rules-BuildingConvert".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Rules-BuildingConvert end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Rules-BuildingConvert add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);
					String buildingOld = rowData.get(pty.get("oldbuilding"));
					String buildingNew = rowData.get(pty.get("newbuilding"));
					String timeOffset = rowData.get(pty.get("timeoffset"));
					if (!Constant.BuildingAdds.containsKey(buildingOld)) {
						Constant.BuildingAdds.put(buildingOld, new ArrayList<String>());
					}
					Constant.BuildingAdds.get(buildingOld).add(buildingNew);
					Constant.BuildingConv.put(buildingNew, buildingOld);
					Constant.BuildingOffset.put(buildingOld, Boolean.getBoolean(timeOffset));
				}
			}
		}
	}

	/**
	 * 加载全局配置
	 */
	private static void excuteRulesGlobal(File file) {
		// TODO Auto-generated method stub
		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Rules-Global".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Rules-Global begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Rules-Global".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Rules-Global end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Rules-Global add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);

					Constant.Disconnect = Constant.getMillisecond(rowData.get(pty.get("disconnect")));
					Constant.Database = rowData.get(pty.get("database"));
					Constant.InsertThread = Integer.valueOf(rowData.get(pty.get("insertthread")));
					// if (rowData.get(pty.get("uploadtable")) != null) {
					// for (String upload :
					// rowData.get(pty.get("uploadtable")).split(",")) {
					// Constant.uploadList.add(upload);
					// }
					// }
					if (rowData.get(pty.get("savetype")) != null) {
						for (String savetype : rowData.get(pty.get("savetype")).split(",")) {
							Constant.saveTypeList.add(savetype);
						}
					}
					if (rowData.get(pty.get("delay")) != null) {
						String delay = rowData.get(pty.get("delay"));
						delay = delay.replace("Second", "").replace("second", "").replace("s", "").replace("S", "");
						Constant.delay = Constant.Millisecond.SECOND_1 * Long.parseLong(delay);
					}
				}
			}
		}
	}

	/**
	 * 加载网络配置（对下）
	 */
	private static void excuteNetworkDown(File file) {
		// TODO Auto-generated method stub
		int begin = 65535;
		int end = 65535;

		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();
		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Network-Down".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Network-Down begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Network-Down".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Network-Down end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Network-Down add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);
					Server server = new Server();
					server.IP = rowData.get(pty.get("ip"));
					server.Port = Integer.valueOf(rowData.get(pty.get("port")));
					server.compress = Boolean.getBoolean(rowData.get(pty.get("compress")));

					Constant.TypeServer.put("Down", server);
				}
			}
		}
	}

	/**
	 * 加载网络配置（对上）
	 */
	private static void excuteNetworkTransfer(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();
		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Network-Transfer".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Network-Transfer begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Network-Transfer".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Network-Transfer end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Network-Transfer add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);
					Constant.transfer.PROTOCOL = rowData.get(pty.get("protocol"));
					Constant.transfer.IP = rowData.get(pty.get("ip"));
					Constant.transfer.Port = Integer.valueOf(rowData.get(pty.get("port")));
					Constant.transfer.ServerIP = rowData.get(pty.get("serverip"));
					Constant.transfer.ServerPort = Integer.valueOf(rowData.get(pty.get("serverport")));
					Constant.transfer.Mode = rowData.get(pty.get("mode"));
					Constant.transfer.Max_size = Integer.valueOf(rowData.get(pty.get("max_size")));
					Constant.transfer.SleepCount = Integer.valueOf(rowData.get(pty.get("sleepcount")));
					Constant.transfer.Separate = rowData.get(pty.get("separate"));
					Constant.transfer.Separate_begin = rowData.get(pty.get("separate_begin"));
					Constant.transfer.Separate_end = rowData.get(pty.get("separate_end"));
					Constant.transfer.compress = Boolean.getBoolean(rowData.get(pty.get("compress")));
				}
			}
		}
	}

	/**
	 * 加载网络配置（对上）
	 */
	private static void excuteNetworkUp(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();
		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Network-Up".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Network-Up begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Network-Up".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Network-Up end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Network-Up add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);
					Server server = new Server();
					server.IP = rowData.get(pty.get("ip"));
					server.Port = Integer.valueOf(rowData.get(pty.get("port")));
					server.compress = Boolean.getBoolean(rowData.get(pty.get("compress")));

					Constant.TypeServer.put("Up", server);
				}
			}
		}
	}

	/**
	 * 加载HBase配置
	 */
	private static void excuteDbHbase(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Db-Hbase".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Db-Hbase begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Db-Hbase".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Db-Hbase end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Db-Hbase add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);
					EntityHbase entityHbase = new EntityHbase();
					entityHbase.Address = rowData.get(pty.get("address"));

					Constant.DbConnection.put("Db-Hbase", entityHbase);
				}
			}
		}
	}

	/**
	 * 加载activeMQ配置
	 */
	private static void executeActiveMQ(File file) {
		// TODO Auto-generated method stub
		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("ActiveMQ".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Db-Hbase begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("ActiveMQ".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Db-Hbase end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Db-Hbase add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);
					Constant.activeMqBrokerUrl = rowData.get(pty.get("broker-url"));
				}
			}
		}
	}

	/**
	 * 加载activeMQ配置
	 */
	private static void executeActiveMqPointList(File file) {
		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("ActiveMQ-PointList".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Rules-TransferList begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("ActiveMQ-PointList".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Rules-TransferList end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Rules-TransferList add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}

					pty = Constant.toLower(pty);

					String building = rowData.get(pty.get("building"));
					String meter = rowData.get(pty.get("meter"));
					String funcid = rowData.get(pty.get("funcid"));

					Constant.activeMqPointSet.add(building + "-" + meter + "-" + funcid);
				}
			}
		}
	}

	/**
	 * 加载mysql配置
	 */
	private static void excuteDbMysql(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Db-Mysql".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Db-Mysql begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Db-Mysql".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Db-Mysql end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Db-Mysql add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);
					EntityMysql entityMysql = new EntityMysql();
					entityMysql.Ip = rowData.get(pty.get("ip"));
					entityMysql.Port = Integer.valueOf(rowData.get(pty.get("port")));
					entityMysql.User = rowData.get(pty.get("user"));
					entityMysql.Password = rowData.get(pty.get("password"));

					Constant.DbConnection.put("Db-Mysql", entityMysql);
				}
			}
		}
	}

	/**
	 * 加载mysql配置
	 */
	private static void excuteUploadMysql(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Upload-Mysql".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Upload-Mysql begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Upload-Mysql".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Upload-Mysql end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Upload-Mysql add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);
					EntityMysql entityMysql = new EntityMysql();
					entityMysql.Ip = rowData.get(pty.get("ip"));
					entityMysql.Port = Integer.valueOf(rowData.get(pty.get("port")));
					entityMysql.User = rowData.get(pty.get("user"));
					entityMysql.Password = rowData.get(pty.get("password"));
					entityMysql.UploadDatabase = rowData.get(pty.get("uploaddatabase"));
					entityMysql.UploadTable = rowData.get(pty.get("uploadtable"));
					Constant.DbConnection.put("Upload-Mysql", entityMysql);
				}
			}
		}
	}

	/**
	 * 加载HBase配置
	 */
	private static void excuteUploadHbase(File file) {
		// TODO Auto-generated method stub

		int begin = 65535;
		int end = 65535;
		Map<String, Integer> pty = new HashMap<String, Integer>();
		// Map<Integer, String> ptyValue = new HashMap<Integer, String>();

		Map<Integer, Map<Integer, Map<Integer, String>>> excelData = ExcelUtil.readExcel(file);
		for (int k = 0; k < excelData.size(); k++) {
			Map<Integer, Map<Integer, String>> sheetData = excelData.get(k);
			for (int i = 0; i < sheetData.size(); i++) {
				Map<Integer, String> rowData = sheetData.get(i);
				if ("Upload-Hbase".equalsIgnoreCase(rowData.get(0))) {
					begin = i;
					// Constant.info("Upload-Hbase begin: " + i);
					for (int j = 1; j < rowData.size(); j++) {
						pty.put(rowData.get(j), j);
						// ptyValue.put(j, rowData.get(j));
					}
				} else if ((rowData.get(0).length() > 0) && !("Upload-Hbase".equalsIgnoreCase(rowData.get(0)))) {
					begin = 65535;
					end = 65535;
					pty = new HashMap<String, Integer>();
					// ptyValue = new HashMap<Integer, String>();
					// Constant.info("Upload-Hbase end: " + i);
				} else if (i > begin && i < end) {
					// Constant.info("Upload-Hbase add: " + i);
					if (rowData.get(1) == null || rowData.get(1).length() == 0) {
						continue;
					}
					pty = Constant.toLower(pty);
					EntityHbase entityHbase = new EntityHbase();
					entityHbase.Address = rowData.get(pty.get("address"));
					entityHbase.UploadDatabase = rowData.get(pty.get("UploadDatabase"));
					entityHbase.UploadTable = rowData.get(pty.get("UploadTable"));

					Constant.DbConnection.put("Upload-Hbase", entityHbase);
				}
			}
		}
	}
	// private void loadJsonConfig() {
	// // TODO Auto-generated method stub
	// String resource = "/config.json";
	// String path = null;
	// JsonParser config = new JsonParser();
	//
	// try {
	// LogUtil.info("System.get " + System.getProperty("user.dir") + resource);
	// LogUtil.info("LogUtil.get " + LogUtil.GetPath() + resource);
	// path = LogUtil.GetPath() + resource;
	//
	// JsonObject object = (JsonObject) config.parse(new FileReader(path));
	//
	// JsonArray db = object.get("DB").getAsJsonArray();
	// for (int i = 0; i < db.size(); i++) {
	// JsonObject subObject = db.get(i).getAsJsonObject();
	// if (subObject.get("building") != null) {
	// String building = subObject.get("building").getAsString();
	// // if(Constant.BuildingDB.containsKey(building)){
	// // continue;
	// // }
	// Constant.BuildingDB.put(building,
	// subObject.get("database").getAsString());
	//
	// if (subObject.get("buildingadds") != null) {
	// JsonArray buildingAdds = subObject.get("buildingadds").getAsJsonArray();
	// for (int j = 0; j < buildingAdds.size(); j++) {
	// JsonObject addObject = buildingAdds.get(j).getAsJsonObject();
	// String builing_new = addObject.get("building").getAsString();
	// if (!Constant.BuildingAdds.containsKey(building)) {
	// Constant.BuildingAdds.put(building, new ArrayList<String>());
	// }
	// if (!exist(builing_new)) {
	// Constant.BuildingAdds.get(building).add(builing_new);
	// Constant.BuildingConv.put(builing_new, building);
	// }
	// }
	//
	// }
	// } else if (subObject.get("insertthread") != null) {
	// Constant.InsertThread = subObject.get("insertthread").getAsInt();
	// }
	// }
	// JsonArray port = object.get("Port").getAsJsonArray();
	// for (int i = 0; i < port.size(); i++) {
	// JsonObject subObject = port.get(i).getAsJsonObject();
	// Constant.TypePort.put(subObject.get("type").getAsString(),
	// subObject.get("port").getAsString());
	// Constant.PortCompress.put(Integer.valueOf(subObject.get("port").getAsString()),
	// subObject.get("Compress").getAsString());
	// Constant.PortHistory.put(Integer.valueOf(subObject.get("port").getAsString()),
	// subObject.get("History").getAsString());
	// }
	//
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }
	//
	// private boolean exist(String builing_new) {
	// // TODO Auto-generated method stub
	// if (Constant.BuildingConv.containsKey(builing_new)) {
	// return true;
	// }
	// return false;
	// }
}
