package com.saga.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.zillion.util.log.LogUtil;

import com.saga.entity.PointSet;
import com.saga.entity.Record;
import com.saga.entity.RecordMsg;
import com.sagacloud.json.JSONArray;
import com.sagacloud.json.JSONObject;
import com.zillion.database.agent.ZillionAgent;

/**
 * HBase工具
 *
 * @author 李井强
 */
public class HBaseUtil {

	/**
	 * 加载状态-物理结构
	 */
	public static Map<String, String> ps_physical_status(String db, String tb) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 address_1 String 一级地址 主键
		// 3 address_2 String 二级地址 主键
		// 4 address_3 String 三级地址 主键
		// 5 address_4 String 四级地址 主键
		// 6 status String 状态 conn/disconn
		// 7 receivetime String 时间 最近通讯时间
		// 8 detail String 详情
		Map<String, String> dbPhysicalStatus = new HashMap<String, String>();
		JSONObject Criteria = new JSONObject();
		// Criteria.put("project", project);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");
		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);
			String project = (String) dataItem.get("project");
			String address_1 = (String) dataItem.get("address_1");
			String address_2 = (String) dataItem.get("address_2");
			String address_3 = (String) dataItem.get("address_3");
			String address_4 = (String) dataItem.get("address_4");
			String key = project + ";" + address_1 + ";" + address_2 + ";" + address_3 + ";" + address_4;
			String status = (String) dataItem.get("status");
			dbPhysicalStatus.put(key, status);

		}
		return dbPhysicalStatus;
	}

	/**
	 * 加载状态-点位
	 */
	public static Map<String, String> ps_virtual_point_status(String db, String tb) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 funcid Long 功能号 主键
		// 4 updown String 上/下行 主键
		// 5 status String 状态
		// 6 receivetime String 时间
		// 7 detail String 详情
		Map<String, String> dbPointStatus = new HashMap<String, String>();

		JSONObject Criteria = new JSONObject();
		// Criteria.put("project", project);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");

		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);
			String meter = (String) dataItem.get("meter");
			long funcid = (long) dataItem.get("funcid");
			String updown = (String) dataItem.get("updown");
			if ("up".equalsIgnoreCase(updown)) {
				String project = (String) dataItem.get("project");
				String key = project + "-" + meter + "." + funcid;
				String status = (String) dataItem.get("status");
				dbPointStatus.put(key, status);
			}
		}
		return dbPointStatus;
	}

	/**
	 * 加载状态-meter
	 */
	public static Map<String, String> ps_virtual_meter_status(String db, String tb) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 updown String 上/下行 主键
		// 4 status String 状态
		// 5 receivetime String 时间
		// 6 detail String 详情

		Map<String, String> dbMeterStatus = new HashMap<String, String>();

		JSONObject Criteria = new JSONObject();
		// Criteria.put("project", project);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");

		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);
			String meter = (String) dataItem.get("meter");
			String updown = (String) dataItem.get("updown");
			if ("up".equalsIgnoreCase(updown)) {
				String project = (String) dataItem.get("project");
				String key = project + "-" + meter;
				String status = (String) dataItem.get("status");
				dbMeterStatus.put(key, status);
			}
		}
		return dbMeterStatus;
	}

	/**
	 * 加载状态-project
	 */
	public static Map<String, String> ps_virtual_project_status(String db, String tb) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 status String 状态
		// 3 receivetime String 时间
		// 4 detail String 详情

		Map<String, String> dbProjectStatus = new HashMap<String, String>();

		JSONObject Criteria = new JSONObject();
		// Criteria.put("project", project);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");

		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);
			String project = (String) dataItem.get("project");
			String key = project;
			String status = (String) dataItem.get("status");
			dbProjectStatus.put(key, status);

		}
		return dbProjectStatus;
	}

	/**
	 * 加载配置点表
	 */
	public static void LoadDB2Cache_dy_pointlist(String db, String tb) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 building String 楼号 主键
		// 2 meter String 表号 主键
		// 3 funcid Long 功能号 主键
		// 4 system String 系统
		// 5 source String 数据来源
		// 6 address_1 String 一级地址 采集器网关ID
		// 7 address_2 String 二级地址 总线端口号
		// 8 address_3 String 三级地址 仪表地址
		// 9 address_4 String 四级地址
		// 10 collect_cycle String 采集频率 采集器上传频率
		// 11 data_type String 点位类型 Acc:累积变量；Inst:瞬时变量；Boolv:通断变量；
		// Enumv:状态变量；Step:阶跃变量
		// 12 unit String 单位
		JSONObject Criteria = new JSONObject();
		// Criteria.put("building", project);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);

		LogUtil.info(Constant.agent.getFull_name() + " Reload Point List:" + "  dy_pointlist Begin...");
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");
		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);
			String project = (String) dataItem.get("building");
			String meter = (String) dataItem.get("meter");
			long funcid = (long) dataItem.get("funcid");
			String address_1 = (String) dataItem.get("address_1");
			String address_2 = (String) dataItem.get("address_2");
			String address_3 = (String) dataItem.get("address_3");
			String address_4 = (String) dataItem.get("address_4");
			String key4 = project + ";" + address_1 + ";" + address_2 + ";" + address_3 + ";" + address_4;
			String key3 = project + ";" + address_1 + ";" + address_2 + ";" + address_3 + ";" + "";
			String key2 = project + ";" + address_1 + ";" + address_2 + ";" + "" + ";" + "";
			String key1 = project + ";" + address_1 + ";" + "" + ";" + "" + ";" + "";

			String value = project + "-" + meter + "." + funcid;
			synchronized (Constant.ps_PhysicalList) {
				if (!Constant.ps_PhysicalList.containsKey(key4)) {
					Constant.ps_PhysicalList.put(key4, new ArrayList<String>());
				}
				if (!Constant.ps_PhysicalList.containsKey(key3)) {
					Constant.ps_PhysicalList.put(key3, new ArrayList<String>());
				}
				if (!Constant.ps_PhysicalList.containsKey(key2)) {
					Constant.ps_PhysicalList.put(key2, new ArrayList<String>());
				}
				if (!Constant.ps_PhysicalList.containsKey(key1)) {
					Constant.ps_PhysicalList.put(key1, new ArrayList<String>());
				}
				if (!Constant.ps_PhysicalList.get(key4).contains(value)) {
					Constant.ps_PhysicalList.get(key4).add(value);
				}
				if (!Constant.ps_PhysicalList.get(key3).contains(value)) {
					Constant.ps_PhysicalList.get(key3).add(value);
				}
				if (!Constant.ps_PhysicalList.get(key2).contains(value)) {
					Constant.ps_PhysicalList.get(key2).add(value);
				}
				if (!Constant.ps_PhysicalList.get(key1).contains(value)) {
					Constant.ps_PhysicalList.get(key1).add(value);
				}
			}

			synchronized (Constant.ps_MeterList) {
				if (!Constant.ps_MeterList.containsKey(project + "-" + meter)) {
					Constant.ps_MeterList.put(project + "-" + meter, new ArrayList<String>());
				}
				if (!Constant.ps_MeterList.get(project + "-" + meter).contains(value)) {
					Constant.ps_MeterList.get(project + "-" + meter).add(value);
				}
			}
			synchronized (Constant.ps_ProjectList) {

				if (!Constant.ps_ProjectList.containsKey(project)) {
					Constant.ps_ProjectList.put(project, new ArrayList<String>());
				}
				if (!Constant.ps_ProjectList.get(project).contains(value)) {
					Constant.ps_ProjectList.get(project).add(value);
				}
			}

			checkStatus(project, meter, funcid, address_1, address_2, address_3, address_4);
		}
		LogUtil.info(Constant.agent.getFull_name() + " Reload Point List:" + "  dy_pointlist End...");

	}

	/**
	 * 记录状态
	 */
	private static void checkStatus(String project, String meter, long funcid, String address_1, String address_2,
			String address_3, String address_4) {
		// TODO Auto-generated method stub
		if (!Constant.ps_PointStatusUp.containsKey(project + "-" + meter + "." + funcid)) {
			Constant.ps_PointStatusUp.put((project + "-" + meter + "." + funcid), null);
		}
		if (!Constant.ps_MeterStatusUp.containsKey(project + "-" + meter)) {
			Constant.ps_MeterStatusUp.put((project + "-" + meter), null);
		}
		if (!Constant.ps_ProjectStatus.containsKey(project)) {
			Constant.ps_ProjectStatus.put((project), null);
		}
		String key4 = project + ";" + address_1 + ";" + address_2 + ";" + address_3 + ";" + address_4;
		String key3 = project + ";" + address_1 + ";" + address_2 + ";" + address_3 + ";" + "";
		String key2 = project + ";" + address_1 + ";" + address_2 + ";" + "" + ";" + "";
		String key1 = project + ";" + address_1 + ";" + "" + ";" + "" + ";" + "";
		if (!Constant.ps_PhysicalStatus.containsKey(key4)) {
			Constant.ps_PhysicalStatus.put((key4), null);
		}
		if (!Constant.ps_PhysicalStatus.containsKey(key3)) {
			Constant.ps_PhysicalStatus.put((key3), null);
		}
		if (!Constant.ps_PhysicalStatus.containsKey(key2)) {
			Constant.ps_PhysicalStatus.put((key2), null);
		}
		if (!Constant.ps_PhysicalStatus.containsKey(key1)) {
			Constant.ps_PhysicalStatus.put((key1), null);
		}
	}

	/**
	 * 加载状态-物理结构
	 */
	public static void LoadDB2Cache_ps_physical_status(String db, String tb) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 address_1 String 一级地址 主键
		// 3 address_2 String 二级地址 主键
		// 4 address_3 String 三级地址 主键
		// 5 address_4 String 四级地址 主键
		// 6 status String 状态 conn/disconn
		// 7 receivetime String 时间 最近通讯时间
		// 8 detail String 详情
		JSONObject Criteria = new JSONObject();
		// Criteria.put("project", project);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		LogUtil.info(Constant.agent.getFull_name() + " Reload:" + "  ps_physical_status Begin...");
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");
		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);
			String project = (String) dataItem.get("project");
			String address_1 = (String) dataItem.get("address_1");
			String address_2 = (String) dataItem.get("address_2");
			String address_3 = (String) dataItem.get("address_3");
			String address_4 = (String) dataItem.get("address_4");
			String key = project + ";" + address_1 + ";" + address_2 + ";" + address_3 + ";" + address_4;
			String receivetime = (String) dataItem.get("receivetime");
			Constant.ps_PhysicalStatus.put(key, Constant.parse(receivetime).getTime());

		}
		LogUtil.info(Constant.agent.getFull_name() + " Reload :" + "  ps_physical_status End...");

	}

	/**
	 * 加载状态-point
	 */
	public static void LoadDB2Cache_ps_virtual_point_status(String db, String tb) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 funcid Long 功能号 主键
		// 4 updown String 上/下行 主键
		// 5 status String 状态
		// 6 receivetime String 时间
		// 7 detail String 详情
		JSONObject Criteria = new JSONObject();
		// Criteria.put("project", project);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");
		LogUtil.info(Constant.agent.getFull_name() + " Reload :" + " ps_virtual_point_status Begin...");

		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);
			String meter = (String) dataItem.get("meter");
			long funcid = (long) dataItem.get("funcid");
			String updown = (String) dataItem.get("updown");
			if ("up".equalsIgnoreCase(updown)) {
				String project = (String) dataItem.get("project");
				String key = project + "-" + meter + "." + funcid;
				String receivetime = (String) dataItem.get("receivetime");
				Constant.ps_PointStatusUp.put(key, Constant.parse(receivetime).getTime());
				LogUtil.info(Constant.agent.getFull_name() + " project " + project + " meter " + meter + " funcid "
						+ funcid + " " + System.currentTimeMillis() + " " + Constant.parse(receivetime).getTime());
			}
		}
		// }
		LogUtil.info(Constant.agent.getFull_name() + " Reload :" + "  ps_virtual_point_status End...");
	}

	/**
	 * 加载状态-meter
	 */
	public static void LoadDB2Cache_ps_virtual_meter_status(String db, String tb) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 updown String 上/下行 主键
		// 4 status String 状态
		// 5 receivetime String 时间
		// 6 detail String 详情
		JSONObject Criteria = new JSONObject();
		// Criteria.put("project", project);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");
		LogUtil.info(Constant.agent.getFull_name() + " Reload :" + " ps_virtual_meter_status Begin...");

		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);
			String meter = (String) dataItem.get("meter");
			String updown = (String) dataItem.get("updown");
			if ("up".equalsIgnoreCase(updown)) {
				String project = (String) dataItem.get("project");
				String key = project + "-" + meter;
				String receivetime = (String) dataItem.get("receivetime");
				Constant.ps_MeterStatusUp.put(key, Constant.parse(receivetime).getTime());
				LogUtil.info(Constant.agent.getFull_name() + " project " + project + " meter " + meter + " "
						+ System.currentTimeMillis() + " " + Constant.parse(receivetime).getTime());
			}
		}
		LogUtil.info(Constant.agent.getFull_name() + " Reload :" + "  ps_virtual_meter_status End...");
	}

	/**
	 * 加载状态-project
	 */
	public static void LoadDB2Cache_ps_virtual_project_status(String db, String tb) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 status String 状态
		// 3 receivetime String 时间
		// 4 detail String 详情
		JSONObject Criteria = new JSONObject();
		// Criteria.put("project", project);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");
		LogUtil.info(Constant.agent.getFull_name() + " Reload :" + " ps_virtual_project_status Begin...");

		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);
			String project = (String) dataItem.get("project");
			String key = project;
			String receivetime = (String) dataItem.get("receivetime");
			Constant.ps_ProjectStatus.put(key, Constant.parse(receivetime).getTime());
			LogUtil.info(Constant.agent.getFull_name() + " project " + project + " " + System.currentTimeMillis() + " "
					+ Constant.parse(receivetime).getTime());

		}
		LogUtil.info(Constant.agent.getFull_name() + " Reload :" + "  ps_virtual_project_status End...");
	}

	// public static void GetCollectorStatus(ZillionAgent agent, String db,
	// String tb, String project) throws Exception {
	//
	// JSONObject Criteria = new JSONObject();
	// Criteria.put("project", project);
	// Criteria.put("collector",
	// Constant.getLocalHostLANAddress().getHostAddress() + ":" +
	// Constant.TypePort.get("Down"));
	//
	// JSONObject wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "select");
	// wrapperObject.put("Database", db);
	// wrapperObject.put("Datatable", tb);
	// wrapperObject.put("Criteria", Criteria);
	// JSONObject queryResult = agent.Query(wrapperObject);
	// JSONArray resultContent = (JSONArray) queryResult.get("Content");
	// LogUtil.info("Reload Project:" + project + " CollectorStatus Begin...");
	// for (int i = 0; i < resultContent.size(); i++) {
	// JSONObject dataItem = (JSONObject) resultContent.get(i);
	// String node = (String) dataItem.get("gateway");
	// String key = project + "-" + node;
	// String receivetime = (String) dataItem.get("receivetime");
	// Constant.ps_NodeStatus.put(key, Constant.parse(receivetime).getTime());
	// LogUtil.info("project " + project + " collector " +
	// Constant.getLocalHostLANAddress().getHostAddress() + ":"
	// + Constant.TypePort.get("Down") + " gateway " + node + " " +
	// System.currentTimeMillis() + " "
	// + Constant.parse(receivetime).getTime());
	// }
	// LogUtil.info("Reload Project:" + project + " CollectorStatus End...");
	// }

	// public static void GetPointStatus(ZillionAgent agent, String db, String
	// tb, String project) throws Exception {
	//
	// JSONObject Criteria = new JSONObject();
	// Criteria.put("project", project);
	// Criteria.put("collector",
	// Constant.getLocalHostLANAddress().getHostAddress() + ":" +
	// Constant.TypePort.get("Down"));
	//
	// JSONObject wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "select");
	// wrapperObject.put("Database", db);
	// wrapperObject.put("Datatable", tb);
	// wrapperObject.put("Criteria", Criteria);
	// JSONObject queryResult = agent.Query(wrapperObject);
	// JSONArray resultContent = (JSONArray) queryResult.get("Content");
	// LogUtil.info("Reload Project:" + project + " PointStatus Begin...");
	// // synchronized (Constant.pointListUp) {
	// for (int i = 0; i < resultContent.size(); i++) {
	// JSONObject dataItem = (JSONObject) resultContent.get(i);
	// String node = (String) dataItem.get("gateway");
	// String meter = (String) dataItem.get("meter");
	// String funcid = (String) dataItem.get("funcid");
	// String updown = (String) dataItem.get("updown");
	// if ("up".equalsIgnoreCase(updown)) {
	// String key = project + "-" + node + "-" + meter + "." + funcid;
	// String receivetime = (String) dataItem.get("receivetime");
	// Constant.ps_PointStatusUp.put(key,
	// Constant.parse(receivetime).getTime());
	// LogUtil.info("project " + project + " collector " +
	// Constant.getLocalHostLANAddress().getHostAddress()
	// + ":" + Constant.TypePort.get("Down") + " gateway " + node + " meter " +
	// meter + " funcid "
	// + funcid + " " + System.currentTimeMillis() + " " +
	// Constant.parse(receivetime).getTime());
	// }
	// }
	// // }
	// LogUtil.info("Reload Project:" + project + " PointStatus End...");
	// }

	/**
	 * 加载状态-配置点表
	 */
	public static Map<String, List<Integer>> GetDBPointList(String db, String tb, String building) throws Exception {

		Map<String, List<Integer>> dbPointList = new HashMap<String, List<Integer>>();
		JSONObject Criteria = new JSONObject();
		Criteria.put("building", building);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");

		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);

			String meter = (String) dataItem.get("meter");
			Long f = (long) dataItem.get("funcid");

			Integer funcid = f.intValue();
			if (!dbPointList.containsKey(meter)) {
				dbPointList.put(meter, new ArrayList<Integer>());
			}
			dbPointList.get(meter).add(funcid);

		}
		return dbPointList;

	}

	/**
	 * 加载指令列表
	 */
	public static void Getset(String db, String tb, String building, String meter, long funcid, String query_from,
			String query_to) throws Exception {

		JSONObject Criteria = new JSONObject();
		Criteria.put("building", building);
		Criteria.put("meter", meter);
		Criteria.put("funcid", funcid);
		JSONObject range = new JSONObject();
		range.put("$gt", query_from);
		range.put("$lt", query_to);
		Criteria.put("receivetime", range);
		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");
		// File test = new File(System.getProperty("user.dir") + "/test.log");
		// CSVUtil.insert(test, new StringBuffer("Getset" + " " + db + " " + tb
		// + " " + building + " " + meter + " "
		// + funcid + " " + query_from + " " + query_to + "\r\n"));
		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);

			String receivetime = (String) dataItem.get("receivetime");
			String endtime = (String) dataItem.get("endtime");
			Double data = (Double) dataItem.get("data");
			String status = (String) dataItem.get("status");
			System.out.println(
					"receivetime " + receivetime + " endtime " + endtime + " data:" + data + " status " + status);
			// CSVUtil.insert(test, new StringBuffer("receivetime " +
			// receivetime + " endtime " + endtime + " data:" + data
			// + " status " + status + "\r\n"));
		}
	}

	/**
	 * 加载当前指令
	 */
	public static void Getset_present(String db, String tb, String building, String meter, long funcid)
			throws Exception {

		JSONObject Criteria = new JSONObject();
		Criteria.put("building", building);
		Criteria.put("meter", meter);
		Criteria.put("funcid", funcid);

		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "select");
		wrapperObject.put("Database", db);
		wrapperObject.put("Datatable", tb);
		wrapperObject.put("Criteria", Criteria);
		JSONObject queryResult = Constant.agent.Query(wrapperObject);
		JSONArray resultContent = (JSONArray) queryResult.get("Content");
		// File test = new File(System.getProperty("user.dir") + "/test.log");
		// CSVUtil.insert(test, new StringBuffer(
		// "Getset_present" + " " + db + " " + tb + " " + building + " " + meter
		// + " " + funcid + "\r\n"));
		for (int i = 0; i < resultContent.size(); i++) {
			JSONObject dataItem = (JSONObject) resultContent.get(i);

			String receivetime = (String) dataItem.get("receivetime");
			String endtime = (String) dataItem.get("endtime");
			Double data = (Double) dataItem.get("data");
			String status = (String) dataItem.get("status");
			// CSVUtil.insert(test, new StringBuffer("receivetime " +
			// receivetime + " endtime " + endtime + " data:" + data
			// + " status " + status + "\r\n"));
			System.out.println(
					"receivetime " + receivetime + " endtime " + endtime + " data:" + data + " status " + status);
		}
	}

	// public static void GetOriginal_month(String db, String tb, String
	// building, String meter, long funcid,
	// String query_from, String query_to) throws Exception {
	//
	// JSONObject Criteria = new JSONObject();
	// Criteria.put("building", building);
	// Criteria.put("meter", meter);
	// Criteria.put("funcid", funcid);
	// JSONObject range = new JSONObject();
	// range.put("$gt", query_from);
	// range.put("$lt", query_to);
	// Criteria.put("receivetime", range);
	// JSONObject wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "select");
	// wrapperObject.put("Database", db);
	// wrapperObject.put("Datatable", tb);
	// wrapperObject.put("Criteria", Criteria);
	// JSONObject queryResult = Constant.agent.Query(wrapperObject);
	// JSONArray resultContent = (JSONArray) queryResult.get("Content");
	// // File test = new File(System.getProperty("user.dir") + "/test.log");
	// // CSVUtil.insert(test, new StringBuffer("GetOriginal_month" + " " + db
	// // + " " + tb + " " + building + " " + meter
	// // + " " + funcid + " " + query_from + " " + query_to + "\r\n"));
	// for (int i = 0; i < resultContent.size(); i++) {
	// JSONObject dataItem = (JSONObject) resultContent.get(i);
	//
	// String receivetime = (String) dataItem.get("receivetime");
	// Double data = (Double) dataItem.get("data");
	// // CSVUtil.insert(test, new StringBuffer("receivetime " +
	// // receivetime + " data:" + data + "\r\n"));
	// }
	// }
	//
	// public static void GetOriginal_present(String db, String tb, String
	// building, String meter, long funcid)
	// throws Exception {
	//
	// JSONObject Criteria = new JSONObject();
	// Criteria.put("building", building);
	// Criteria.put("meter", meter);
	// Criteria.put("funcid", funcid);
	// JSONObject wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "select");
	// wrapperObject.put("Database", db);
	// wrapperObject.put("Datatable", tb);
	// wrapperObject.put("Criteria", Criteria);
	// JSONObject queryResult = Constant.agent.Query(wrapperObject);
	// JSONArray resultContent = (JSONArray) queryResult.get("Content");
	// // File test = new File(System.getProperty("user.dir") + "/test.log");
	// // CSVUtil.insert(test, new StringBuffer(
	// // "GetOriginal_present" + " " + db + " " + tb + " " + building + " " +
	// // meter + " " + funcid + "\r\n"));
	// for (int i = 0; i < resultContent.size(); i++) {
	// JSONObject dataItem = (JSONObject) resultContent.get(i);
	// String receivetime = (String) dataItem.get("receivetime");
	// Double data = (Double) dataItem.get("data");
	// // CSVUtil.insert(test, new StringBuffer("receivetime " +
	// // receivetime + " data:" + data + "\r\n"));
	// System.out
	// .println("meter " + meter + " funcid " + funcid + " receivetime " +
	// receivetime + " data:" + data);
	// }
	// }

	/**
	 * 生成json
	 */
	public static JSONObject CreateJSON(String Name, String Type) {
		JSONObject result = new JSONObject();
		result.put("Name", Name);
		result.put("Type", Type);
		return result;
	}

	/**
	 * 建库
	 */
	public static void CreateDB(String DB) throws Exception {
		LogUtil.info(Constant.agent.getFull_name() + " CreateDB:" + DB);
		Constant.agent.NDL_AddDatabase(DB);
	}

	/**
	 * 建库
	 */
	public static void CreateUploadDB(String DB) throws Exception {
		if (Constant.agentUpload == null) {
			return;
		}
		LogUtil.info(Constant.agentUpload.getFull_name() + " CreateDB:" + DB);
		Constant.agentUpload.NDL_AddDatabase(DB);
	}

	/**
	 * 判断表是否存在
	 */
	public static boolean tableExist(String DBName, String tableName) throws Exception {
		JSONObject wrapperObject = new JSONObject();
		wrapperObject.put("QueryType", "table_list");
		wrapperObject.put("Database", DBName);
		LogUtil.info(Constant.agent.getFull_name() + " " + DBName + "." + tableName + " tableExist ?");
		JSONObject result = Constant.agent.Query(wrapperObject);
		JSONArray array = (JSONArray) result.get("Content");
		for (int i = 0; i < array.size(); i++) {
			String tableNameInner = (String) array.get(i);
			if (tableNameInner.equalsIgnoreCase(tableName)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 建表-monthdata
	 */
	public static void CreateTable(String DB, String tableName) throws Exception {
		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("building", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("funcid", "Long"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("data", "Double"));
			JSONArray Key = new JSONArray();
			Key.add("building");
			Key.add("meter");
			Key.add("funcid");
			Key.add("receivetime");
			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			Definition.put("delete_UsePutV", false);
			Definition.put("table_type", "split_month");
			Definition.put("split_column", "receivetime");
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-detail
	 */
	public static void CreateTable_detail(String DB, String tableName) throws Exception {
		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("building", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("funcid", "Long"));
			Columns.add(CreateJSON("seq", "Long"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("logtime", "String"));
			Columns.add(CreateJSON("data", "Double"));
			JSONArray Key = new JSONArray();
			Key.add("building");
			Key.add("meter");
			Key.add("funcid");
			Key.add("seq");
			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			Definition.put("delete_UsePutV", false);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-upload
	 */
	public static void CreateTable_upload(String DB, List<String> uploadList) throws Exception {
		if (Constant.agentUpload == null) {
			return;
		}
		for (String tableName : uploadList) {
			if (!tableExist(DB, tableName)) {
				JSONArray Columns = new JSONArray();
				Columns.add(CreateJSON("building", "String"));
				Columns.add(CreateJSON("meter", "String"));
				Columns.add(CreateJSON("funcid", "Long"));
				Columns.add(CreateJSON("receivetime", "String"));
				Columns.add(CreateJSON("data", "Double"));
				JSONArray Key = new JSONArray();
				Key.add("building");
				Key.add("meter");
				Key.add("funcid");
				Key.add("receivetime");
				JSONObject Definition = new JSONObject();
				Definition.put("Columns", Columns);
				Definition.put("Key", Key);
				Definition.put("delete_UsePutV", false);
				JSONArray Indexes = new JSONArray();
				Constant.agentUpload.DDL_AddTable(DB, tableName, Definition, Indexes);
			}
		}
	}

	/**
	 * 建表-present
	 */
	public static void CreateTable_present(String DB, String tableName) throws Exception {
		if (!tableExist(DB, tableName)) {

			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("building", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("funcid", "Long"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("data", "Double"));
			JSONArray Key = new JSONArray();
			Key.add("building");
			Key.add("meter");
			Key.add("funcid");
			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			Definition.put("delete_UsePutV", false);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-指令记录
	 */
	public static void CreateTable_set(String DB, String tableName) throws Exception {
		if (!tableExist(DB, tableName)) {

			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("building", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("funcid", "Long"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("data", "Double"));
			Columns.add(CreateJSON("status", "String"));
			Columns.add(CreateJSON("endtime", "String"));
			JSONArray Key = new JSONArray();
			Key.add("building");
			Key.add("meter");
			Key.add("funcid");
			Key.add("receivetime");
			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-当前指令
	 */
	public static void CreateTable_setpresent(String DB, String tableName) throws Exception {
		if (!tableExist(DB, tableName)) {

			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("building", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("funcid", "Long"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("data", "Double"));
			Columns.add(CreateJSON("status", "String"));
			Columns.add(CreateJSON("endtime", "String"));
			JSONArray Key = new JSONArray();
			Key.add("building");
			Key.add("meter");
			Key.add("funcid");
			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	// public static void CreateTable_CollectorStatus(String DB, String
	// tableName) throws Exception {
	// if (!tableExist(DB, tableName)) {
	//
	// JSONArray Columns = new JSONArray();
	// Columns.add(CreateJSON("project", "String"));
	// Columns.add(CreateJSON("collector", "String"));
	// Columns.add(CreateJSON("gateway", "String"));
	// Columns.add(CreateJSON("status", "String"));
	// Columns.add(CreateJSON("receivetime", "String"));
	// Columns.add(CreateJSON("detail", "String"));
	//
	// JSONArray Key = new JSONArray();
	// Key.add("project");
	// Key.add("collector");
	// Key.add("gateway");
	// JSONObject Definition = new JSONObject();
	// Definition.put("Columns", Columns);
	// Definition.put("Key", Key);
	// JSONArray Indexes = new JSONArray();
	// Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
	// }
	// }
	//
	// public static void CreateTable_CollectorCommunicationLog(String DB,
	// String tableName) throws Exception {
	// if (!tableExist(DB, tableName)) {
	//
	// JSONArray Columns = new JSONArray();
	// Columns.add(CreateJSON("project", "String"));
	// Columns.add(CreateJSON("collector", "String"));
	// Columns.add(CreateJSON("gateway", "String"));
	// Columns.add(CreateJSON("receivetime", "String"));
	// Columns.add(CreateJSON("function", "String"));
	//
	// JSONArray Key = new JSONArray();
	// Key.add("project");
	// Key.add("collector");
	// Key.add("gateway");
	// Key.add("receivetime");
	// JSONObject Definition = new JSONObject();
	// Definition.put("Columns", Columns);
	// Definition.put("Key", Key);
	// JSONArray Indexes = new JSONArray();
	// Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
	// }
	// }

	/**
	 * 建表-fjd_0_buildingcomputetime
	 */
	public static void CreateTable_fjd_0_buildingcomputetime(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 building String 楼号 主键
		// 2 compute_time String 计算时间
		// 3 first_compute_time String 首次计算时间

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("building", "String"));
			Columns.add(CreateJSON("compute_time", "String"));
			Columns.add(CreateJSON("first_compute_time", "String"));

			JSONArray Key = new JSONArray();
			Key.add("building");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-dy_pointlist
	 */
	public static void CreateTable_dy_pointlist(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 building String 楼号 主键
		// 2 meter String 表号 主键
		// 3 funcid Long 功能号 主键
		// 4 system String 系统
		// 5 source String 数据来源
		// 6 address_1 String 一级地址 采集器网关ID
		// 7 ip_port String 一级地址IP_PORT 如无端口，可缺省
		// 8 address_2 String 二级地址 总线端口号
		// 9 address_3 String 三级地址 仪表地址
		// 10 address_4 String 四级地址
		// 11 collect_cycle String 采集频率 采集器上传频率
		// 12 data_type String 点位类型 Acc:累积变量；Inst:瞬时变量；Boolv:通断变量；
		// Enumv:状态变量；Step:阶跃变量
		// 13 unit String 单位
		// 14 remark1 String 备注1 预留
		// 15 remark2 String 备注2 预留
		// 16 remark3 String 备注3 预留

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("building", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("funcid", "Long"));
			Columns.add(CreateJSON("system", "String"));
			Columns.add(CreateJSON("source", "String"));
			Columns.add(CreateJSON("address_1", "String"));
			Columns.add(CreateJSON("ip_port", "String"));
			Columns.add(CreateJSON("address_2", "String"));
			Columns.add(CreateJSON("address_3", "String"));
			Columns.add(CreateJSON("address_4", "String"));
			Columns.add(CreateJSON("collect_cycle", "String"));
			Columns.add(CreateJSON("data_type", "String"));
			Columns.add(CreateJSON("unit", "String"));
			Columns.add(CreateJSON("remark1", "String"));
			Columns.add(CreateJSON("remark2", "String"));
			Columns.add(CreateJSON("remark3", "String"));

			JSONArray Key = new JSONArray();
			Key.add("building");
			Key.add("meter");
			Key.add("funcid");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();

			// Indexes.add("building");
			// Indexes.add("address_1");
			// Indexes.add("address_2");
			// Indexes.add("address_3");
			// Indexes.add("address_4");
			// Indexes.add("meter");
			// Indexes.add("funcid");
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-physical_status
	 */
	public static void CreateTable_ps_physical_status(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 address_1 String 一级地址 主键
		// 3 address_2 String 二级地址 主键
		// 4 address_3 String 三级地址 主键
		// 5 address_4 String 四级地址 主键
		// 6 status String 状态 conn/disconn
		// 7 receivetime String 时间 最近通讯时间
		// 8 detail String 详情
		// 9 manual_inspection String 人工检查记录

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("project", "String"));
			Columns.add(CreateJSON("address_1", "String"));
			Columns.add(CreateJSON("address_2", "String"));
			Columns.add(CreateJSON("address_3", "String"));
			Columns.add(CreateJSON("address_4", "String"));
			Columns.add(CreateJSON("status", "String"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("detail", "String"));
			Columns.add(CreateJSON("manual_inspection", "String"));

			JSONArray Key = new JSONArray();
			Key.add("project");
			Key.add("address_1");
			Key.add("address_2");
			Key.add("address_3");
			Key.add("address_4");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-physical_log
	 */
	public static void CreateTable_ps_physical_log(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 address_1 String 一级地址 主键
		// 3 address_2 String 二级地址 主键
		// 4 address_3 String 三级地址 主键
		// 5 address_4 String 四级地址 主键
		// 6 receivetime String 时间 主键，触发时间
		// 7 function String 通讯功能 主键，conn/disconn
		// 8 manual_inspection String 人工检查记录

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("project", "String"));
			Columns.add(CreateJSON("address_1", "String"));
			Columns.add(CreateJSON("address_2", "String"));
			Columns.add(CreateJSON("address_3", "String"));
			Columns.add(CreateJSON("address_4", "String"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("function", "String"));
			Columns.add(CreateJSON("manual_inspection", "String"));

			JSONArray Key = new JSONArray();
			Key.add("project");
			Key.add("address_1");
			Key.add("address_2");
			Key.add("address_3");
			Key.add("address_4");
			Key.add("receivetime");
			Key.add("function");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-ps_virtual_point_status
	 */
	public static void CreateTable_ps_virtual_point_status(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 funcid Long 功能号 主键
		// 4 updown String 上/下行 主键
		// 5 status String 状态
		// 6 receivetime String 时间
		// 7 detail String 详情
		// 8 manual_inspection String 人工检查记录

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("project", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("funcid", "Long"));
			Columns.add(CreateJSON("updown", "String"));
			Columns.add(CreateJSON("status", "String"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("detail", "String"));
			Columns.add(CreateJSON("manual_inspection", "String"));

			JSONArray Key = new JSONArray();
			Key.add("project");
			Key.add("meter");
			Key.add("funcid");
			Key.add("updown");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-ps_virtual_point_log
	 */
	public static void CreateTable_ps_virtual_point_log(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 funcid Long 功能号 主键
		// 4 updown String 上/下行 主键
		// 5 receivetime String 时间 主键
		// 6 seq Long 报文序号 主键
		// 7 function String 通讯功能 主键
		// 8 feedback String 反馈 processing:rcvd(采集软件已收到)
		// processing:sent(采集软件已发出)
		// processing:finish:finish:+采集节点反馈标识(采集软件已收到反馈)
		// finish:finish:+采集节点反馈标识(采集软件已反馈)
		// 其中采集节点反馈标识，分两级，分别为：
		// 1、success/fail
		// 2、如success，该级空；如fail，则该级描述fail原因
		// 9 manual_inspection String 人工检查记录

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("project", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("funcid", "Long"));
			Columns.add(CreateJSON("updown", "String"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("seq", "Long"));
			Columns.add(CreateJSON("function", "String"));
			Columns.add(CreateJSON("feedback", "String"));
			Columns.add(CreateJSON("manual_inspection", "String"));

			JSONArray Key = new JSONArray();
			Key.add("project");
			Key.add("meter");
			Key.add("funcid");
			Key.add("updown");
			Key.add("receivetime");
			Key.add("seq");
			Key.add("function");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-ps_virtual_meter_status
	 */
	public static void CreateTable_ps_virtual_meter_status(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 updown String 上/下行 主键
		// 4 status String 状态
		// 5 receivetime String 时间
		// 6 detail String 详情
		// 7 manual_inspection String 人工检查记录

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("project", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("updown", "String"));
			Columns.add(CreateJSON("status", "String"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("detail", "String"));
			Columns.add(CreateJSON("manual_inspection", "String"));

			JSONArray Key = new JSONArray();
			Key.add("project");
			Key.add("meter");
			Key.add("updown");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-ps_virtual_meter_log
	 */
	public static void CreateTable_ps_virtual_meter_log(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 updown String 上/下行 主键
		// 4 receivetime String 时间 主键
		// 5 function String 通讯功能 主键
		// 6 manual_inspection String 人工检查记录

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("project", "String"));
			Columns.add(CreateJSON("meter", "String"));
			Columns.add(CreateJSON("updown", "String"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("function", "String"));
			Columns.add(CreateJSON("manual_inspection", "String"));

			JSONArray Key = new JSONArray();
			Key.add("project");
			Key.add("meter");
			Key.add("updown");
			Key.add("receivetime");
			Key.add("function");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-ps_virtual_project_status
	 */
	public static void CreateTable_ps_virtual_project_status(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 status String 状态
		// 3 receivetime String 时间
		// 4 detail String 详情
		// 5 manual_inspection String 人工检查记录

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("project", "String"));
			Columns.add(CreateJSON("status", "String"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("detail", "String"));
			Columns.add(CreateJSON("manual_inspection", "String"));

			JSONArray Key = new JSONArray();
			Key.add("project");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	/**
	 * 建表-ps_virtual_project_log
	 */
	public static void CreateTable_ps_virtual_project_log(String DB, String tableName) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 receivetime String 时间 主键
		// 3 function String 通讯功能 主键
		// 4 manual_inspection String 人工检查记录

		if (!tableExist(DB, tableName)) {
			JSONArray Columns = new JSONArray();
			Columns.add(CreateJSON("project", "String"));
			Columns.add(CreateJSON("receivetime", "String"));
			Columns.add(CreateJSON("function", "String"));
			Columns.add(CreateJSON("manual_inspection", "String"));

			JSONArray Key = new JSONArray();
			Key.add("project");
			Key.add("receivetime");
			Key.add("function");

			JSONObject Definition = new JSONObject();
			Definition.put("Columns", Columns);
			Definition.put("Key", Key);
			JSONArray Indexes = new JSONArray();
			Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
		}
	}

	// public static void CreateTable_PointStatus(String DB, String tableName)
	// throws Exception {
	// if (!tableExist(DB, tableName)) {
	//
	// JSONArray Columns = new JSONArray();
	// Columns.add(CreateJSON("project", "String"));
	// Columns.add(CreateJSON("collector", "String"));
	// Columns.add(CreateJSON("gateway", "String"));
	// Columns.add(CreateJSON("meter", "String"));
	// Columns.add(CreateJSON("funcid", "String"));
	// Columns.add(CreateJSON("updown", "String"));
	// Columns.add(CreateJSON("status", "String"));
	// Columns.add(CreateJSON("receivetime", "String"));
	// Columns.add(CreateJSON("detail", "String"));
	//
	// JSONArray Key = new JSONArray();
	// Key.add("project");
	// Key.add("collector");
	// Key.add("gateway");
	// Key.add("meter");
	// Key.add("funcid");
	// Key.add("updown");
	// JSONObject Definition = new JSONObject();
	// Definition.put("Columns", Columns);
	// Definition.put("Key", Key);
	// JSONArray Indexes = new JSONArray();
	// Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
	// }
	// }
	//
	// public static void CreateTable_PointInfo(String DB, String tableName)
	// throws Exception {
	// if (!tableExist(DB, tableName)) {
	//
	// JSONArray Columns = new JSONArray();
	// Columns.add(CreateJSON("project", "String"));
	// Columns.add(CreateJSON("gateway", "String"));
	// Columns.add(CreateJSON("meter", "String"));
	// Columns.add(CreateJSON("BusNo", "String"));
	// Columns.add(CreateJSON("site", "String"));
	//
	// JSONArray Key = new JSONArray();
	// Key.add("project");
	// Key.add("gateway");
	// Key.add("meter");
	// JSONObject Definition = new JSONObject();
	// Definition.put("Columns", Columns);
	// Definition.put("Key", Key);
	// JSONArray Indexes = new JSONArray();
	// Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
	// }
	// }
	//
	// public static void CreateTable_PointCommunicationLog(String DB, String
	// tableName) throws Exception {
	// if (!tableExist(DB, tableName)) {
	//
	// JSONArray Columns = new JSONArray();
	// Columns.add(CreateJSON("project", "String"));
	// Columns.add(CreateJSON("collector", "String"));
	// Columns.add(CreateJSON("gateway", "String"));
	// Columns.add(CreateJSON("meter", "String"));
	// Columns.add(CreateJSON("funcid", "String"));
	// Columns.add(CreateJSON("updown", "String"));
	// Columns.add(CreateJSON("function", "String"));
	// Columns.add(CreateJSON("seq", "String"));
	// Columns.add(CreateJSON("receivetime", "String"));
	// Columns.add(CreateJSON("feedback", "String"));
	//
	// JSONArray Key = new JSONArray();
	// Key.add("project");
	// Key.add("collector");
	// Key.add("gateway");
	// Key.add("meter");
	// Key.add("funcid");
	// Key.add("updown");
	// Key.add("function");
	// Key.add("seq");
	// Key.add("receivetime");
	// JSONObject Definition = new JSONObject();
	// Definition.put("Columns", Columns);
	// Definition.put("Key", Key);
	// JSONArray Indexes = new JSONArray();
	// Constant.agent.DDL_AddTable(DB, tableName, Definition, Indexes);
	// }
	// }
	//
	// public static void InsertCollectorStatus(String DB, String project,
	// String collector, String node, String status,
	// String receivetime) throws Exception {
	//
	// JSONArray InsertObjects = new JSONArray();
	// try {
	// if (DB == null) {
	// DB = Constant.Database;
	// }
	// if (DB != null) {
	//
	// JSONObject InsertObject = new JSONObject();
	// InsertObject.put("project", project);
	// InsertObject.put("collector", collector);
	// InsertObject.put("gateway", node);
	// InsertObject.put("status", status);
	// InsertObject.put("receivetime", receivetime);
	//
	// InsertObjects.add(InsertObject);
	//
	// JSONObject wrapperObject = new JSONObject();
	//
	// wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "batch_put");
	// wrapperObject.put("Database", DB);
	// wrapperObject.put("Datatable", "pointgatewaystatus");
	// wrapperObject.put("InsertObjects", InsertObjects);
	// Constant.agent.Query(wrapperObject);
	// }
	//
	// } catch (Exception e) {
	// LogUtil.error(
	// Constant.agent.getFull_name() + "
	// HBaseUtil.InsertCollectorStatus.Exception: " + e.toString());
	// }
	// }
	//
	// public static void InsertCollectorCommunicationLog(String DB, String
	// project, String collector, String node,
	// String receivetime, String function) throws Exception {
	//
	// JSONArray InsertObjects = new JSONArray();
	// try {
	// if (DB == null) {
	// DB = Constant.Database;
	// }
	// if (DB != null) {
	//
	// JSONObject InsertObject = new JSONObject();
	// InsertObject.put("project", project);
	// InsertObject.put("collector", collector);
	// InsertObject.put("gateway", node);
	// InsertObject.put("receivetime", receivetime);
	// InsertObject.put("function", function);
	//
	// InsertObjects.add(InsertObject);
	//
	// JSONObject wrapperObject = new JSONObject();
	//
	// wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "batch_insert");
	// wrapperObject.put("Database", DB);
	// wrapperObject.put("Datatable", "pointgatewaylog");
	// wrapperObject.put("InsertObjects", InsertObjects);
	// Constant.agent.Query(wrapperObject);
	// }
	//
	// } catch (Exception e) {
	// LogUtil.error(Constant.agent.getFull_name() + "
	// HBaseUtil.BatchInsert.Exception: " + e.toString());
	// }
	// }
	//
	// public static void InsertPointStatus(String DB, String project, String
	// collector, String node, String meter,
	// String funcid, String updown, String status, String receivetime, String
	// detail) throws Exception {
	//
	// JSONArray InsertObjects = new JSONArray();
	// try {
	// if (DB == null) {
	// DB = Constant.Database;
	// }
	// if (DB != null) {
	//
	// JSONObject InsertObject = new JSONObject();
	// InsertObject.put("project", project);
	// InsertObject.put("collector", collector);
	// InsertObject.put("gateway", node);
	// InsertObject.put("meter", meter);
	// InsertObject.put("funcid", funcid);
	// InsertObject.put("updown", updown);
	// InsertObject.put("status", status);
	// InsertObject.put("receivetime", receivetime);
	// InsertObject.put("detail", detail);
	//
	// InsertObjects.add(InsertObject);
	//
	// JSONObject wrapperObject = new JSONObject();
	//
	// wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "batch_put");
	// wrapperObject.put("Database", DB);
	// wrapperObject.put("Datatable", "pointstatus");
	// wrapperObject.put("InsertObjects", InsertObjects);
	// Constant.agent.Query(wrapperObject);
	// }
	//
	// } catch (Exception e) {
	// LogUtil.error(Constant.agent.getFull_name() + "
	// HBaseUtil.InsertPointStatus.Exception: " + e.toString());
	// }
	// }
	//
	// public static void InsertDBPointList(String DB, String building, String
	// meter, Map<Integer, String> funcidList)
	// throws Exception {
	// JSONArray InsertObjects = new JSONArray();
	// for (Entry<Integer, String> f : funcidList.entrySet()) {
	// JSONObject InsertObject = new JSONObject();
	// InsertObject.put("building", building);
	// InsertObject.put("meter", meter);
	// InsertObject.put("funcid", (long) f.getKey());
	// InsertObject.put("data_type", f.getValue());
	// InsertObject.put("collect_cycle", "15min");
	// InsertObjects.add(InsertObject);
	// }
	//
	// if (InsertObjects.size() > 0) {
	//
	// JSONObject wrapperObject = new JSONObject();
	// wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "batch_insert");
	// wrapperObject.put("Database", DB);
	// wrapperObject.put("Datatable", "dy_pointlist");
	// wrapperObject.put("InsertObjects", InsertObjects);
	// LogUtil.info(Constant.agent.getFull_name() + " InsertDBPointList" +
	// wrapperObject);
	// Constant.agent.Query(wrapperObject);
	// }
	// }
	//
	// public static void InsertPointInfo(String DB, String project, String
	// node, String point, String BusNo, String site)
	// throws Exception {
	//
	// JSONArray InsertObjects = new JSONArray();
	// try {
	// if (DB == null) {
	// DB = Constant.Database;
	// }
	// if (DB != null) {
	//
	// JSONObject InsertObject = new JSONObject();
	// InsertObject.put("project", project);
	// InsertObject.put("gateway", node);
	// InsertObject.put("meter", point);
	// InsertObject.put("BusNo", BusNo);
	// InsertObject.put("site", site);
	//
	// InsertObjects.add(InsertObject);
	//
	// JSONObject wrapperObject = new JSONObject();
	//
	// wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "batch_put");
	// wrapperObject.put("Database", DB);
	// wrapperObject.put("Datatable", "pointinfo");
	// wrapperObject.put("InsertObjects", InsertObjects);
	// Constant.agent.Query(wrapperObject);
	// }
	//
	// } catch (Exception e) {
	// e.printStackTrace();
	// LogUtil.error(Constant.agent.getFull_name() + "
	// HBaseUtil.InsertPointInfo.Exception: " + e.toString());
	// }
	// }
	//
	// public static void InsertPointCommunicationLog(String DB, String project,
	// String collector, String node,
	// String meter, String funcid, String updown, String function, String seq,
	// String receivetime,
	// String feedback) throws Exception {
	//
	// JSONArray InsertObjects = new JSONArray();
	// try {
	// if (DB == null) {
	// DB = Constant.Database;
	// }
	// if (DB != null) {
	//
	// JSONObject InsertObject = new JSONObject();
	// InsertObject.put("project", project);
	// InsertObject.put("collector", collector);
	// InsertObject.put("gateway", node);
	// InsertObject.put("meter", meter);
	// InsertObject.put("funcid", funcid);
	// InsertObject.put("updown", updown);
	// InsertObject.put("function", function);
	// InsertObject.put("seq", seq);
	// InsertObject.put("receivetime", receivetime);
	// InsertObject.put("feedback", feedback);
	//
	// InsertObjects.add(InsertObject);
	//
	// JSONObject wrapperObject = new JSONObject();
	//
	// wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "batch_insert");
	// wrapperObject.put("Database", DB);
	// wrapperObject.put("Datatable", "pointlog");
	// wrapperObject.put("InsertObjects", InsertObjects);
	// Constant.agent.Query(wrapperObject);
	// }
	//
	// } catch (Exception e) {
	// LogUtil.error(Constant.agent.getFull_name() + "
	// HBaseUtil.InsertPointCommunicationLog.Exception: "
	// + e.toString());
	// }
	// }

	/**
	 * 写fjd_0_buildingcomputetime
	 */
	public static void Insert_fjd_0_buildingcomputetime(String DB, String building, String compute_time,
			String first_compute_time) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 building String 楼号 主键
		// 2 compute_time String 计算时间
		// 3 first_compute_time String 首次计算时间

		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("building", building);
				InsertObject.put("compute_time", compute_time);
				InsertObject.put("first_compute_time", first_compute_time);

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_put");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "fjd_0_buildingcomputetime");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.Insert_fjd_0_buildingcomputetime.Exception: "
					+ e.toString());
		}
	}

	/**
	 * 写dy_pointlist
	 */
	public static void Insert_dy_pointlist(String DB, String building, String meter, long funcid, String system,
			String source, String address_1, String ip_port, String address_2, String address_3, String address_4,
			String collect_cycle, String data_type, String unit) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 building String 楼号 主键
		// 2 meter String 表号 主键
		// 3 funcid Long 功能号 主键
		// 4 system String 系统
		// 5 source String 数据来源
		// 6 address_1 String 一级地址 采集器网关ID
		// 7 ip_port String 一级地址IP_PORT 如无端口，可缺省
		// 8 address_2 String 二级地址 总线端口号
		// 9 address_3 String 三级地址 仪表地址
		// 10 address_4 String 四级地址
		// 11 collect_cycle String 采集频率 采集器上传频率
		// 12 data_type String 点位类型 Acc:累积变量；Inst:瞬时变量；Boolv:通断变量；
		// Enumv:状态变量；Step:阶跃变量
		// 13 unit String 单位
		// 14 remark1 String 备注1 预留
		// 15 remark2 String 备注2 预留
		// 16 remark3 String 备注3 预留
		if (addressNull(address_1, address_2, address_3, address_4)) {
			return;
		}

		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("building", building);
				InsertObject.put("meter", meter);
				InsertObject.put("funcid", funcid);
				InsertObject.put("system", system);
				InsertObject.put("source", source);
				InsertObject.put("address_1", address_1);
				InsertObject.put("ip_port", ip_port);
				InsertObject.put("address_2", address_2);
				InsertObject.put("address_3", address_3);
				InsertObject.put("address_4", address_4);
				InsertObject.put("collect_cycle", collect_cycle);
				InsertObject.put("data_type", data_type);
				InsertObject.put("unit", unit);

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_put");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "dy_pointlist");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.Insert_dy_pointlist.Exception: " + e.toString());
		}
	}

	/**
	 * 判断地址是否为空
	 */
	private static boolean addressNull(String address_1, String address_2, String address_3, String address_4) {
		// TODO Auto-generated method stub
		if ("null".equalsIgnoreCase(address_1) || "null".equalsIgnoreCase(address_2)
				|| "null".equalsIgnoreCase(address_3) || "null".equalsIgnoreCase(address_4)) {
			return true;
		}
		return false;
	}

	/**
	 * 写ps_physical_status
	 */
	public static void Insert_ps_physical_status(String DB, String project, String address_1, String address_2,
			String address_3, String address_4, String status, String receivetime, String detail) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 address_1 String 一级地址 主键
		// 3 address_2 String 二级地址 主键
		// 4 address_3 String 三级地址 主键
		// 5 address_4 String 四级地址 主键
		// 6 status String 状态 conn/disconn
		// 7 receivetime String 时间 最近通讯时间
		// 8 detail String 详情
		// 9 manual_inspection String 人工检查记录
		if (addressNull(address_1, address_2, address_3, address_4)) {
			return;
		}
		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("project", project);
				InsertObject.put("address_1", address_1);
				InsertObject.put("address_2", address_2);
				InsertObject.put("address_3", address_3);
				InsertObject.put("address_4", address_4);
				InsertObject.put("status", status);
				InsertObject.put("receivetime", receivetime);
				InsertObject.put("detail", detail);
				InsertObject.put("manual_inspection", "");

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_put");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "ps_physical_status");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
			}

		} catch (Exception e) {
			LogUtil.error(
					Constant.agent.getFull_name() + " HBaseUtil.Insert_ps_physical_status.Exception: " + e.toString());
		}
	}

	/**
	 * 写ps_physical_log
	 */
	public static void Insert_ps_physical_log(String DB, String project, String address_1, String address_2,
			String address_3, String address_4, String receivetime, String function) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 address_1 String 一级地址 主键
		// 3 address_2 String 二级地址 主键
		// 4 address_3 String 三级地址 主键
		// 5 address_4 String 四级地址 主键
		// 6 receivetime String 时间 主键，触发时间
		// 7 function String 通讯功能 主键，conn/disconn

		if (addressNull(address_1, address_2, address_3, address_4)) {
			return;
		}
		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("project", project);
				InsertObject.put("address_1", address_1);
				InsertObject.put("address_2", address_2);
				InsertObject.put("address_3", address_3);
				InsertObject.put("address_4", address_4);
				InsertObject.put("receivetime", receivetime);
				InsertObject.put("function", function);

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_insert");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "ps_physical_log");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
			}

		} catch (Exception e) {
			LogUtil.error(
					Constant.agent.getFull_name() + " HBaseUtil.Insert_ps_physical_log.Exception: " + e.toString());
		}
	}

	/**
	 * 写ps_virtual_point_status
	 */
	public static void Insert_ps_virtual_point_status(String DB, String project, String meter, long funcid,
			String updown, String status, String receivetime, String detail) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 funcid Long 功能号 主键
		// 4 updown String 上/下行 主键
		// 5 status String 状态
		// 6 receivetime String 时间
		// 7 detail String 详情
		// 8 manual_inspection String 人工检查记录

		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("project", project);
				InsertObject.put("meter", meter);
				InsertObject.put("funcid", funcid);
				InsertObject.put("updown", updown);
				InsertObject.put("status", status);
				InsertObject.put("receivetime", receivetime);
				InsertObject.put("detail", detail);
				InsertObject.put("manual_inspection", "");

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_put");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "ps_virtual_point_status");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.Insert_ps_virtual_point_status.Exception: "
					+ e.toString());
		}
	}

	/**
	 * 写ps_virtual_point_log
	 */
	public static void Insert_ps_virtual_point_log(String DB, String project, String meter, long funcid, String updown,
			String receivetime, long seq, String function, String feedback) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 funcid Long 功能号 主键
		// 4 updown String 上/下行 主键
		// 5 receivetime String 时间 主键
		// 6 seq Long 报文序号 主键
		// 7 function String 通讯功能 主键
		// 8 feedback String 反馈 processing:rcvd(采集软件已收到)
		// processing:sent(采集软件已发出)
		// processing:finish:finish:+采集节点反馈标识(采集软件已收到反馈)
		// finish:finish:+采集节点反馈标识(采集软件已反馈)
		// 其中采集节点反馈标识，分两级，分别为：
		// 1、success/fail
		// 2、如success，该级空；如fail，则该级描述fail原因

		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("project", project);
				InsertObject.put("meter", meter);
				InsertObject.put("funcid", funcid);
				InsertObject.put("updown", updown);
				InsertObject.put("receivetime", receivetime);
				InsertObject.put("seq", seq);
				InsertObject.put("function", function);
				InsertObject.put("feedback", feedback);

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_insert");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "ps_virtual_point_log");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
				LogUtil.info(Constant.agent.getFull_name() + " " + wrapperObject.toJSONString());
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.Insert_ps_virtual_point_log.Exception: "
					+ e.toString());
		}
	}

	/**
	 * 写ps_virtual_meter_status
	 */
	public static void Insert_ps_virtual_meter_status(String DB, String project, String meter, String updown,
			String status, String receivetime, String detail) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 updown String 上/下行 主键
		// 4 status String 状态
		// 5 receivetime String 时间
		// 6 detail String 详情
		// 7 manual_inspection String 人工检查记录

		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("project", project);
				InsertObject.put("meter", meter);
				InsertObject.put("updown", updown);
				InsertObject.put("status", status);
				InsertObject.put("receivetime", receivetime);
				InsertObject.put("detail", detail);
				InsertObject.put("manual_inspection", "");

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_put");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "ps_virtual_meter_status");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.Insert_ps_virtual_meter_status.Exception: "
					+ e.toString());
		}
	}

	/**
	 * 写ps_virtual_meter_log
	 */
	public static void Insert_ps_virtual_meter_log(String DB, String project, String meter, String updown,
			String receivetime, String function) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 meter String 仪表 主键
		// 3 updown String 上/下行 主键
		// 4 receivetime String 时间 主键
		// 5 function String 通讯功能 主键

		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("project", project);
				InsertObject.put("meter", meter);
				InsertObject.put("updown", updown);
				InsertObject.put("receivetime", receivetime);
				InsertObject.put("function", function);

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_insert");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "ps_virtual_meter_log");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.Insert_ps_virtual_meter_log.Exception: "
					+ e.toString());
		}
	}

	/**
	 * 写ps_virtual_project_status
	 */
	public static void Insert_ps_virtual_project_status(String DB, String project, String status, String receivetime,
			String detail) throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 status String 状态
		// 3 receivetime String 时间
		// 4 detail String 详情
		// 5 manual_inspection String 人工检查记录

		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("project", project);
				InsertObject.put("status", status);
				InsertObject.put("receivetime", receivetime);
				InsertObject.put("detail", detail);
				InsertObject.put("manual_inspection", "");

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_put");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "ps_virtual_project_status");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.Insert_ps_virtual_project_status.Exception: "
					+ e.toString());
		}
	}

	/**
	 * 写ps_virtual_project_log
	 */
	public static void Insert_ps_virtual_project_log(String DB, String project, String receivetime, String function)
			throws Exception {
		// 序号 名称 数据类型 释义 备注
		// 1 project String 项目名 主键
		// 2 receivetime String 时间 主键
		// 3 function String 通讯功能 主键

		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				InsertObject.put("project", project);
				InsertObject.put("receivetime", receivetime);
				InsertObject.put("function", function);

				InsertObjects.add(InsertObject);

				JSONObject wrapperObject = new JSONObject();

				wrapperObject = new JSONObject();
				wrapperObject.put("QueryType", "batch_insert");
				wrapperObject.put("Database", DB);
				wrapperObject.put("Datatable", "ps_virtual_project_log");
				wrapperObject.put("InsertObjects", InsertObjects);
				Constant.agent.Query(wrapperObject);
				LogUtil.info(Constant.agent.getFull_name() + " " + wrapperObject.toJSONString());
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.Insert_ps_virtual_project_log.Exception: "
					+ e.toString());
		}
	}

	// public static void InsertPointCommunicationLog(List<String> list) throws
	// Exception {
	// // TODO Auto-generated method stub
	// JSONArray InsertObjects = new JSONArray();
	// String DB = null;
	// try {
	// for (String s : list) {
	// String[] rlist = s.split(";");
	//
	// // 0 building,
	// // 1 Constant.getLocalHostLANAddress().getHostAddress(),
	// // 2 mac,
	// // 3 meter + "." + record.funcID,
	// // 4 function,
	// // 5 id,
	// // 6 rList[3],
	// // 7 record.addtion
	// DB = Constant.BuildingDB.get(rlist[0]) == null ? DB :
	// Constant.BuildingDB.get(rlist[0]);
	// if (DB != null) {
	// JSONObject InsertObject = new JSONObject();
	// InsertObject.put("project", rlist[0]);
	// InsertObject.put("collector", rlist[1]);
	// InsertObject.put("gateway", rlist[2]);
	// InsertObject.put("point", rlist[3]);
	// InsertObject.put("function", rlist[4]);
	// InsertObject.put("seq", rlist[5]);
	// InsertObject.put("receivetime", rlist[6]);
	// InsertObject.put("feedback", rlist.length > 7 ? rlist[7] : "");
	//
	// InsertObjects.add(InsertObject);
	// }
	// }
	// JSONObject wrapperObject = new JSONObject();
	// if (DB != null) {
	// wrapperObject = new JSONObject();
	// wrapperObject.put("QueryType", "batch_insert");
	// wrapperObject.put("Database", DB);
	// wrapperObject.put("Datatable", "pointlog");
	// wrapperObject.put("InsertObjects", InsertObjects);
	// Constant.agent.Query(wrapperObject);
	//
	// }
	// } catch (Exception e) {
	// LogUtil.error("HBaseUtil.InsertPointCommunicationLog.Exception: " +
	// e.toString());
	// }
	// }
	/**
	 * 写数据
	 */
	public static void MsgBatchInsert(String DB, List<RecordMsg> dataList) throws Exception {
		JSONArray InsertObjects = new JSONArray();
		JSONArray InsertPresentObjects = new JSONArray();

		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null && dataList.size() > 0) {
				for (int i = 0; i < dataList.size(); i++) {

					RecordMsg data = dataList.get(i);

					JSONObject InsertObject = new JSONObject();
					InsertObject.put("building", data.buildingSign);
					InsertObject.put("meter", data.meterSign);
					InsertObject.put("funcid", (long) data.funcID);
					InsertObject.put("receivetime", Constant.format(data.receivetime));
					InsertObject.put("data", data.data);
					InsertObjects.add(InsertObject);
					String key = data.buildingSign + "-" + data.meterSign + "-" + data.funcID;

					if (!Constant.PresentFlag.containsKey(key)
							|| Constant.PresentFlag.get(key) < data.receivetime.getTime()) {
						Constant.PresentFlag.put(key, data.receivetime.getTime());
						JSONObject InsertPresentObject = new JSONObject();
						InsertPresentObject.put("building", data.buildingSign);
						InsertPresentObject.put("meter", data.meterSign);
						InsertPresentObject.put("funcid", (long) data.funcID);
						InsertPresentObject.put("receivetime", Constant.format(data.receivetime));
						InsertPresentObject.put("data", data.data);
						InsertPresentObjects.add(InsertPresentObject);
					}
				}

				if (InsertObjects.size() > 0) {
					Constant.writeDB += InsertObjects.size();

					JSONObject wrapperObject = new JSONObject();

					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "original_str_data");
					wrapperObject.put("InsertObjects", InsertObjects);
					query(Constant.agent, wrapperObject);

					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "original_str_data_present");
					wrapperObject.put("InsertObjects", InsertPresentObjects);

					query(Constant.agent, wrapperObject);
					LogUtil.info(Constant.agent.getFull_name() + " insert into " + DB + "." + "original_str_data&"
							+ "original_str_data_present " + InsertPresentObjects.toFormatString());
					LogUtil.info(Constant.agent.getFull_name() + " insert into " + DB + "." + "original_str_data&"
							+ "original_str_data_present " + InsertPresentObjects.size());
				}
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.MsgBatchInsert.Exception: " + e.toString());
			// Constant.DBConn = false;
		} finally {
			InsertObjects = null;
			InsertPresentObjects = null;
		}
	}

	/**
	 * 写数据
	 */
	public static void BatchInsertUpload(String DB, List<String> tableList, List<Record> dataList) throws Exception {
		if (Constant.agentUpload == null) {
			return;
		}
		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null && dataList.size() > 0) {
				for (int i = 0; i < dataList.size(); i++) {
					Record data = dataList.get(i);

					JSONObject InsertObject = new JSONObject();
					InsertObject.put("building", data.buildingSign);
					InsertObject.put("meter", data.meterSign);
					InsertObject.put("funcid", (long) data.funcID);
					InsertObject.put("receivetime", Constant.format(data.receivetime));
					InsertObject.put("data", data.data);
					InsertObjects.add(InsertObject);
				}

				if (InsertObjects.size() > 0) {

					JSONObject wrapperObject = new JSONObject();
					for (String upload : tableList) {
						wrapperObject = new JSONObject();
						wrapperObject.put("QueryType", "batch_put");
						wrapperObject.put("Database", DB);
						wrapperObject.put("Datatable", upload);
						wrapperObject.put("InsertObjects", InsertObjects);
						query(Constant.agentUpload, wrapperObject);
					}
				}
			}

		} catch (Exception e) {
			LogUtil.error(
					Constant.agentUpload.getFull_name() + " HBaseUtil.BatchInsertUpload.Exception: " + e.toString());
		} finally {
			InsertObjects = null;
		}
	}

	/**
	 * 写数据
	 */
	public static void BatchInsert(String DB, List<Record> dataList) throws Exception {
		JSONArray InsertObjects = new JSONArray();
		JSONArray InsertPresentObjects = new JSONArray();
		JSONArray InsertLogObjects = new JSONArray();

		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null && dataList.size() > 0) {
				for (int i = 0; i < dataList.size(); i++) {

					Record data = dataList.get(i);

					JSONObject InsertObject = new JSONObject();
					InsertObject.put("building", data.buildingSign);
					InsertObject.put("meter", data.meterSign);
					InsertObject.put("funcid", (long) data.funcID);
					InsertObject.put("receivetime", Constant.format(data.receivetime));
					InsertObject.put("data", data.data);
					InsertObjects.add(InsertObject);
					String key = data.buildingSign + "-" + data.meterSign + "-" + data.funcID;

					if (!Constant.PresentFlag.containsKey(key)
							|| Constant.PresentFlag.get(key) < data.receivetime.getTime()) {
						Constant.PresentFlag.put(key, data.receivetime.getTime());
						JSONObject InsertPresentObject = new JSONObject();
						InsertPresentObject.put("building", data.buildingSign);
						InsertPresentObject.put("meter", data.meterSign);
						InsertPresentObject.put("funcid", (long) data.funcID);
						InsertPresentObject.put("receivetime", Constant.format(data.receivetime));
						InsertPresentObject.put("data", data.data);
						InsertPresentObjects.add(InsertPresentObject);
					}

					JSONObject InsertLogObject = new JSONObject();
					InsertLogObject.put("building", data.buildingSign);
					InsertLogObject.put("meter", data.meterSign);
					InsertLogObject.put("funcid", (long) data.funcID);
					InsertLogObject.put("seq", (long) Constant.getSeq(key));
					InsertLogObject.put("receivetime", Constant.format(data.receivetime));
					InsertLogObject.put("logtime", Constant.format(new Date()));
					InsertLogObject.put("data", data.data);
					InsertLogObjects.add(InsertLogObject);

				}

				if (InsertObjects.size() > 0) {
					Constant.writeDB += InsertObjects.size();

					JSONObject wrapperObject = new JSONObject();

					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "original_month");
					wrapperObject.put("InsertObjects", InsertObjects);
					query(Constant.agent, wrapperObject);

					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "original_detail");
					wrapperObject.put("InsertObjects", InsertLogObjects);
					query(Constant.agent, wrapperObject);

					// for (String upload : Constant.uploadList) {
					// wrapperObject = new JSONObject();
					// wrapperObject.put("QueryType", "batch_put");
					// wrapperObject.put("Database", DB);
					// wrapperObject.put("Datatable", upload);
					// wrapperObject.put("InsertObjects", InsertObjects);
					// query(Constant.agent, wrapperObject);
					//
					// }
					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "original_present");
					wrapperObject.put("InsertObjects", InsertPresentObjects);

					query(Constant.agent, wrapperObject);
					LogUtil.info(Constant.agent.getFull_name() + " insert into " + DB + "." + "original_month&"
							+ "original_present " + InsertPresentObjects.toFormatString());
					LogUtil.info(Constant.agent.getFull_name() + " insert into " + DB + "." + "original_month&"
							+ "original_present " + InsertPresentObjects.size());
				}
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.BatchInsert.Exception: " + e.toString());
			// Constant.DBConn = false;
		} finally {
			InsertObjects = null;
			InsertPresentObjects = null;
			InsertLogObjects = null;
		}
	}

	private static void query(ZillionAgent agent, JSONObject wrapperObject) {
		try {
			long start = System.currentTimeMillis();
			agent.Query(wrapperObject);
			long end = System.currentTimeMillis();
			LogUtil.warn(wrapperObject.get("QueryType") + " " + wrapperObject.get("Database") + "."
					+ wrapperObject.get("Datatable") + " " + ((JSONArray) wrapperObject.get("InsertObjects")).size()
					+ " " + (end - start) + "ms");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 写指令记录-sent
	 */
	public static void BatchInsert_Set1(String DB, PointSet ps) throws Exception {
		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				// InsertObject.put("building", ps.buildingSign);
				InsertObject.put("building", ps.buildingSignUP);
				InsertObject.put("meter", ps.meterSign);
				InsertObject.put("funcid", (long) ps.funcID);
				InsertObject.put("receivetime", Constant.format(new Date((long) ps.sendTime)));
				InsertObject.put("data", ps.dataSet);
				InsertObject.put("status", "processing:sent");

				LogUtil.info(Constant.agent.getFull_name() + " " + InsertObject.toFormatString());

				InsertObjects.add(InsertObject);

				if (InsertObjects.size() > 0) {

					JSONObject wrapperObject = new JSONObject();

					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_insert");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "originalset");
					wrapperObject.put("InsertObjects", InsertObjects);
					Constant.agent.Query(wrapperObject);
					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "originalset_present");
					wrapperObject.put("InsertObjects", InsertObjects);
					Constant.agent.Query(wrapperObject);
					LogUtil.info(Constant.agent.getFull_name() + " insert into " + DB + "." + "originalset&"
							+ "originalset_present " + InsertObject.toFormatString());
				}
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.BatchInsert_Set1.Exception: " + e.toString());
		}
	}

	/**
	 * 写指令记录-其他状态
	 */
	public static void BatchInsert_Set2(String DB, PointSet ps) throws Exception {
		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				// InsertObject.put("building", ps.buildingSign);
				InsertObject.put("building", ps.buildingSignUP);
				InsertObject.put("meter", ps.meterSign);
				InsertObject.put("funcid", (long) ps.funcID);
				InsertObject.put("receivetime", Constant.format(new Date((long) ps.sendTime)));
				InsertObject.put("data", ps.dataSet);
				InsertObject.put("status", "finish:finish:" + ps.status);
				InsertObject.put("endtime", Constant.format(new Date()));

				LogUtil.info(Constant.agent.getFull_name() + " " + InsertObject.toFormatString());

				InsertObjects.add(InsertObject);

				if (InsertObjects.size() > 0) {

					JSONObject wrapperObject = new JSONObject();

					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "originalset");
					wrapperObject.put("InsertObjects", InsertObjects);
					Constant.agent.Query(wrapperObject);
					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "originalset_present");
					wrapperObject.put("InsertObjects", InsertObjects);
					Constant.agent.Query(wrapperObject);
					LogUtil.info(Constant.agent.getFull_name() + " insert into " + DB + "." + "originalset&"
							+ "originalset_present " + InsertObject.toFormatString());
				}
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.BatchInsert_Set2.Exception: " + e.toString());
		}
	}

	/**
	 * 写指令记录-timeout
	 */
	public static void BatchInsert_Set3(String DB, PointSet ps) throws Exception {
		JSONArray InsertObjects = new JSONArray();
		try {
			if (DB == null) {
				DB = Constant.Database;
			}
			if (DB != null) {

				JSONObject InsertObject = new JSONObject();
				// InsertObject.put("building", ps.buildingSign);
				InsertObject.put("building", ps.buildingSignUP);
				InsertObject.put("meter", ps.meterSign);
				InsertObject.put("funcid", (long) ps.funcID);
				InsertObject.put("receivetime", Constant.format(new Date((long) ps.sendTime)));
				InsertObject.put("data", ps.dataSet);
				InsertObject.put("status", "finish:finish:" + "fail:timeout");
				InsertObject.put("endtime", Constant.format(new Date()));

				LogUtil.info(Constant.agent.getFull_name() + " " + InsertObject.toFormatString());

				InsertObjects.add(InsertObject);

				if (InsertObjects.size() > 0) {
					JSONObject wrapperObject = new JSONObject();

					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "originalset");
					wrapperObject.put("InsertObjects", InsertObjects);
					Constant.agent.Query(wrapperObject);
					wrapperObject = new JSONObject();
					wrapperObject.put("QueryType", "batch_put");
					wrapperObject.put("Database", DB);
					wrapperObject.put("Datatable", "originalset_present");
					wrapperObject.put("InsertObjects", InsertObjects);
					Constant.agent.Query(wrapperObject);
					LogUtil.info(Constant.agent.getFull_name() + " insert into " + DB + "." + "originalset&"
							+ "originalset_present " + InsertObject.toFormatString());
				}
			}

		} catch (Exception e) {
			LogUtil.error(Constant.agent.getFull_name() + " HBaseUtil.BatchInsert_Set3.Exception: " + e.toString());
		}
	}

}
