package com.saga.util; import java.io.File; import java.io.UnsupportedEncodingException; import java.sql.Connection; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.zillion.util.log.LogUtil; import com.saga.entity.Data; import com.saga.entity.EntityHbase; import com.saga.entity.EntityMysql; import com.saga.entity.PointSet; import com.saga.entity.Record; import com.saga.entity.RecordMsg; import com.saga.entity.Server; import com.saga.entity.Transfer; import com.zillion.database.agent.ZillionAgent; public class Constant { public static int PacketId = 0; public static int InsertThread = 1; public static ZillionAgent agent; public static Connection conn; public static ZillionAgent agentUpload; public static Connection connUpload; // public static List agents = new ArrayList(); // public static boolean DBConn = true; public static String WaitingTimeControl = "5Second"; public static long Disconnect = Constant.Millisecond.MINUTE_15; public static Map DbConnection = new HashMap(); public static File setlog = new File(System.getProperty("user.dir") + "/setlog.log"); public static List CollectReportList = new ArrayList(); public static List TransferReportList = new ArrayList(); public static List RecordListToDB = new ArrayList(); public static Map Meter_Collector = new HashMap(); public static Map Meter_Collector_Control = new HashMap(); public static List pointSetList = new ArrayList(); // public static Map CollectorPointSetList = new // HashMap(); // public static Map BuildingDB = new HashMap(); public static Map BuildingOffset = new HashMap(); public static String Database; // public static String UploadSource = null; // public static List uploadList = new ArrayList(); public static Map BuildingConv = new HashMap(); public static Map> BuildingAdds = new HashMap>(); public static Map FunctionConv = new HashMap(); public static Map FunctionConvReverse = new HashMap(); // public static Map TypePort = new HashMap(); // public static Map PortCompress = new HashMap(); // public static Map PortHistory = new HashMap(); public static Map TypeServer = new HashMap(); public static Transfer transfer = new Transfer(); public static Map RecordAddress = new HashMap(); public static List RecordList = new ArrayList(); public static Map PresentFlag = new HashMap(); // public static Map ps_NodeStatus = new HashMap(); public static Map ps_PointStatusUp = new HashMap(); public static Map ps_PhysicalStatus = new HashMap(); public static Map ps_ProjectStatus = new HashMap(); public static Map ps_MeterStatusUp = new HashMap(); public static Map ps_PointStatusDown = new HashMap(); public static Map ps_MeterStatusDown = new HashMap(); public static Map> ps_PhysicalList = new HashMap>(); public static Map> ps_ProjectList = new HashMap>(); public static Map> ps_MeterList = new HashMap>(); public static Map pointInfo = new HashMap(); public static Map nodeCache = new HashMap(); public static Map pointCache = new HashMap(); // public static Map pointListDown = new HashMap(); public static Map ps_ID2Time = new HashMap(); public static Map ps_ID2Point = new HashMap(); public static Map ps_ID2Function = new HashMap(); public static Map ps_ID2Status = new HashMap(); public static int collectRec = 0; public static int collectSend = 0; public static int sendRec = 0; public static int sendSend = 0; public static int writeDB = 0; public static int collectCount = 0; public static int transferSendCount = 0; public static int transferRecCount = 0; public static int collectReportCount = 0; public static int report2DBCount = 0; public static Map pointMAC = new HashMap(); public static Map black_Buildings = new HashMap(); public static Map whilte_Points = new HashMap(); public static Map transfer_List = new HashMap(); public static Map pSeq = new HashMap(); public static Map pMonth = new HashMap(); public static Set saveTypeList = new HashSet(); public static long delay = Constant.Millisecond.SECOND_1; public static String activeMqBrokerUrl; public static String queueName; public static Set activeMqPointSet = new HashSet<>(); // static { // 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(); // Constant.BuildingDB.put(building, // subObject.get("database").getAsString()); // Constant.Database = 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(); // if (!Constant.BuildingAdds.containsKey(building)) { // Constant.BuildingAdds.put(building, new ArrayList()); // } // Constant.BuildingAdds.get(building).add(addObject.get("building").getAsString()); // Constant.BuildingDB.put(addObject.get("building").getAsString(), // subObject.get("database").getAsString()); // Constant.Database = subObject.get("database").getAsString(); // Constant.BuildingConv.put(addObject.get("building").getAsString(), // 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(); // String ports = subObject.get("port").getAsString(); // Constant.TypePort.put(subObject.get("type").getAsString(), ports); // Constant.PortCompress.put(Integer.valueOf(ports), // subObject.get("Compress").getAsString()); // Constant.PortHistory.put(Integer.valueOf(ports), // subObject.get("History").getAsString()); // // for (String p : ports.split(",")) { // // Constant.PortCompress.put(Integer.valueOf(p), // // subObject.get("Compress").getAsString()); // // Constant.PortHistory.put(Integer.valueOf(p), // // subObject.get("History").getAsString()); // // } // } // // JsonArray blackList = object.get("BlackList").getAsJsonArray(); // for (int i = 0; i < blackList.size(); i++) { // JsonObject subObject = blackList.get(i).getAsJsonObject(); // if (subObject.get("buildings") != null) { // if (subObject.get("buildings") != null) { // JsonArray buildings = subObject.get("buildings").getAsJsonArray(); // for (int j = 0; j < buildings.size(); j++) { // JsonObject addObject = buildings.get(j).getAsJsonObject(); // Constant.black_Buildings.put(addObject.get("building").getAsString(), // null); // } // } // } // } // // JsonArray whiteList = object.get("WhiteList").getAsJsonArray(); // for (int i = 0; i < whiteList.size(); i++) { // JsonObject subObject = whiteList.get(i).getAsJsonObject(); // if (subObject.get("funcids") != null) { // if (subObject.get("funcids") != null) { // JsonArray funcids = subObject.get("funcids").getAsJsonArray(); // for (int j = 0; j < funcids.size(); j++) { // JsonObject addObject = funcids.get(j).getAsJsonObject(); // Constant.whilte_Funcs.put(addObject.get("funcid").getAsInt(), null); // } // } // } // } // // } catch (Exception e) { // // TODO Auto-generated catch block // // LogUtil.info(e.getMessage()); // LogUtil.warn(e.toString()); // LogUtil.warn("No Config File(config.json) in " + path + ",Now Exit!"); // System.exit(0); // } // // } // public static long getWaitingtime() { // // TODO Auto-generated method stub // try { // if (WaitingTimeControl.contains("Second")) { // return Integer.valueOf(WaitingTimeControl.replace(" ", // "").replace("Second", "")) // * Constant.Millisecond.SECOND_1; // } else if (WaitingTimeControl.contains("second")) { // return Integer.valueOf(WaitingTimeControl.replace(" ", // "").replace("second", "")) // * Constant.Millisecond.SECOND_1; // } else { // return Constant.Millisecond.SECOND_3; // } // } catch (Exception e) { // return Constant.Millisecond.SECOND_3; // } // } public static Map toLower(Map pty) { // TODO Auto-generated method stub Map result = new HashMap(); for (Entry m : pty.entrySet()) { result.put(m.getKey().toLowerCase(), m.getValue()); // Constant.info(m.getKey() + "-->" + m.getKey().toLowerCase()); } return result; } public static long getWaitingtime() { // TODO Auto-generated method stub try { if (WaitingTimeControl.contains("Second")) { return Integer.valueOf(WaitingTimeControl.replace(" ", "").replace("Second", "")) * Constant.Millisecond.SECOND_1; } else if (WaitingTimeControl.contains("second")) { return Integer.valueOf(WaitingTimeControl.replace(" ", "").replace("second", "")) * Constant.Millisecond.SECOND_1; } else { return Constant.Millisecond.SECOND_3; } } catch (Exception e) { return Constant.Millisecond.SECOND_3; } } // @SuppressWarnings("rawtypes") // public static InetAddress getLocalHostLANAddress() throws // UnknownHostException { // try { // InetAddress candidateAddress = null; // // 遍历所有的网络接口 // for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); // ifaces.hasMoreElements();) { // NetworkInterface iface = (NetworkInterface) ifaces.nextElement(); // // 在所有的接口下再遍历IP // for (Enumeration inetAddrs = iface.getInetAddresses(); // inetAddrs.hasMoreElements();) { // InetAddress inetAddr = (InetAddress) inetAddrs.nextElement(); // if (!inetAddr.isLoopbackAddress()) {// 排除loopback类型地址 // if (inetAddr.isSiteLocalAddress()) { // // 如果是site-local地址,就是它了 // return inetAddr; // } else if (candidateAddress == null) { // // site-local类型的地址未被发现,先记录候选地址 // candidateAddress = inetAddr; // } // } // } // } // if (candidateAddress != null) { // return candidateAddress; // } // // 如果没有发现 non-loopback地址.只能用最次选的方案 // InetAddress jdkSuppliedAddress = InetAddress.getLocalHost(); // if (jdkSuppliedAddress == null) { // throw new UnknownHostException("The JDK InetAddress.getLocalHost() method // unexpectedly returned null."); // } // return jdkSuppliedAddress; // } catch (Exception e) { // UnknownHostException unknownHostException = new UnknownHostException( // "Failed to determine LAN address: " + e); // unknownHostException.initCause(e); // throw unknownHostException; // } // } private static final SimpleDateFormat SIMPLEDATEFORMAT = new SimpleDateFormat("yyyyMMddHHmmss"); private static final SimpleDateFormat SIMPLEDATEFORMATDB = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static final SimpleDateFormat SIMPLEDATEFORMAT_Minute = new SimpleDateFormat("yyyyMMddHHmm"); private static final SimpleDateFormat SIMPLEDATEFORMAT_DAY = new SimpleDateFormat("yyyyMMdd"); private static final SimpleDateFormat SIMPLEDATEFORMAT_MONTH = new SimpleDateFormat("yyyyMM"); private static final SimpleDateFormat SIMPLEDATEFORMATLOG = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS"); // private static final SimpleDateFormat SIMPLEDATEFORMAT_LOG = new // SimpleDateFormat("yyyyMMddHHmmssSSS"); // public synchronized static String format_LOG(Date value) { // return SIMPLEDATEFORMAT_LOG.format(value); // } public synchronized static String format_Minute(Date value) { return SIMPLEDATEFORMAT_Minute.format(value); } public synchronized static String format_DB(Date value) { return SIMPLEDATEFORMATDB.format(value); } public synchronized static String format_Log(Date value) { return SIMPLEDATEFORMATLOG.format(value); } // public synchronized static Date parse_LOG(String value) throws // ParseException { // return SIMPLEDATEFORMAT_LOG.parse(value); // } public synchronized static Date parse_Minute(String value) throws ParseException { return SIMPLEDATEFORMAT_Minute.parse(value); } public synchronized static Date parse_DB(String value) throws ParseException { return SIMPLEDATEFORMATDB.parse(value); } public synchronized static Date parse_MONTH(String value) throws ParseException { return SIMPLEDATEFORMAT_MONTH.parse(value); } public synchronized static String format(Date value) { if (value == null) { return "null"; } return SIMPLEDATEFORMAT.format(value); } public synchronized static Date parse(String value) throws ParseException { return SIMPLEDATEFORMAT.parse(value); } public synchronized static String format_day(Date value) { return SIMPLEDATEFORMAT_DAY.format(value); } public synchronized static String format_month(Date value) { return SIMPLEDATEFORMAT_MONTH.format(value); } public synchronized static Date parse_day(String value) throws ParseException { return SIMPLEDATEFORMAT_DAY.parse(value); } public static void showStatus() { // TODO Auto-generated method stub LogUtil.info("ps_PointStatusUp:"); for (Entry d : Constant.ps_PointStatusUp.entrySet()) { LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue()))); } LogUtil.info("-----------------------------------------------------"); LogUtil.info("ps_PhysicalStatus:"); for (Entry d : Constant.ps_PhysicalStatus.entrySet()) { LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue()))); } LogUtil.info("-----------------------------------------------------"); LogUtil.info("ps_ProjectStatus:"); for (Entry d : Constant.ps_ProjectStatus.entrySet()) { LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue()))); } LogUtil.info("-----------------------------------------------------"); LogUtil.info("ps_MeterStatusUp:"); for (Entry d : Constant.ps_MeterStatusUp.entrySet()) { LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue()))); } LogUtil.info("-----------------------------------------------------"); LogUtil.info("ps_PointStatusDown:"); for (Entry d : Constant.ps_PointStatusDown.entrySet()) { LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue()))); } LogUtil.info("-----------------------------------------------------"); LogUtil.info("ps_MeterStatusDown:"); for (Entry d : Constant.ps_MeterStatusDown.entrySet()) { LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue()))); } LogUtil.info("-----------------------------------------------------"); LogUtil.info("ps_PhysicalList:\n" + Constant.ps_PhysicalList); LogUtil.info("-----------------------------------------------------"); LogUtil.info("ps_ProjectList:\n" + Constant.ps_ProjectList); LogUtil.info("-----------------------------------------------------"); LogUtil.info("ps_MeterList:\n" + Constant.ps_MeterList); LogUtil.info("-----------------------------------------------------"); } // public static void Insert_agents_ps_physical_log(String project, String // address_1, String address_2, // String address_3, String address_4, String receivetime, String status) { // // TODO Auto-generated method stub // try { // HBaseUtil.Insert_ps_physical_log(Constant.BuildingDB.get(project), // project, address_1, address_2, address_3, // address_4, receivetime, status); // LogUtil.info(agent.getFull_name() + " insert into ps_physical_log " + " // project " + project + " address_1 " // + address_1 + " address_2 " + address_2 + " address_3 " + address_3 + " // address_4 " + address_4 // + " receivetime " + receivetime + " status " + status); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // } // // public static void Insert_agents_ps_physical_status(String project, // String address_1, String address_2, // String address_3, String address_4, String status, String receivetime, // String detail) { // // TODO Auto-generated method stub // try { // HBaseUtil.Insert_ps_physical_status(Constant.BuildingDB.get(project), // project, address_1, address_2, // address_3, address_4, status, receivetime, detail); // LogUtil.info(agent.getFull_name() + " insert into ps_physical_status " + // " project " + project // + " address_1 " + address_1 + " address_2 " + address_2 + " address_3 " + // address_3 + " address_4 " // + address_4 + " receivetime " + receivetime + " status " + status); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // public static void Insert_agents_ps_virtual_meter_log(String project, // String meter, String updown, // String receivetime, String status) { // // TODO Auto-generated method stub // // try { // HBaseUtil.Insert_ps_virtual_meter_log(Constant.BuildingDB.get(project), // project, meter, updown, receivetime, // status); // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_meter_log " // + " project " + project + " meter " // + meter + " updown " + updown + " receivetime " + receivetime + " status // " + status); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // public static void Insert_agents_ps_virtual_meter_status(String project, // String meter, String updown, String status, // String receivetime, String detail) { // // TODO Auto-generated method stub // try { // HBaseUtil.Insert_ps_virtual_meter_status(Constant.BuildingDB.get(project), // project, meter, updown, status, // receivetime, detail); // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_meter_status // " + " project " + project // + " meter " + meter + " updown " + updown + " receivetime " + receivetime // + " status " + status); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // public static void Insert_agents_ps_virtual_point_log(String building, // String meter, Long funcid, String updown, // Long time, Long seq, String status, String feedback) { // // TODO Auto-generated method stub // try { // if (time == null || time == 0) { // HBaseUtil.Insert_ps_virtual_point_log(Constant.BuildingDB.get(building), // building, meter, // Long.valueOf(funcid), updown, Constant.format(new Date()), seq, status, // feedback); // } else { // HBaseUtil.Insert_ps_virtual_point_log(Constant.BuildingDB.get(building), // building, meter, // Long.valueOf(funcid), updown, Constant.format(new Date(time)), seq, // status, feedback); // } // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_point_log " // + " building " + building // + " meter " + meter + " updown " + updown + " funcid " + funcid + " // status " + status + " feedback " // + feedback); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // public static void Insert_agents_ps_virtual_point_status(String building, // String meter, Long funcid, String updown, // String status, Long time, String detail) { // // TODO Auto-generated method stub // try { // if (time == null || time == 0) { // HBaseUtil.Insert_ps_virtual_point_status(Constant.BuildingDB.get(building), // building, meter, // Long.valueOf(funcid), "up", status, Constant.format(new Date()), ""); // // } else { // HBaseUtil.Insert_ps_virtual_point_status(Constant.BuildingDB.get(building), // building, meter, // Long.valueOf(funcid), "up", status, Constant.format(new Date(time)), ""); // } // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_point_status // " + " building " + building // + " meter " + meter + " updown " + updown + " funcid " + funcid + " // status " + status + " detail " // + detail); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // public static void Insert_agents_ps_virtual_project_log(String project, // String receivetime, String status) { // // TODO Auto-generated method stub // try { // HBaseUtil.Insert_ps_virtual_project_log(Constant.BuildingDB.get(project), // project, receivetime, status); // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_project_log // " + " project " + project // + " receivetime " + receivetime + " status " + status); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // } // // public static void Insert_agents_ps_virtual_project_status(String // project, String status, String receivetime, // String detail) { // // TODO Auto-generated method stub // try { // HBaseUtil.Insert_ps_virtual_project_status(Constant.BuildingDB.get(project), // project, status, receivetime, // detail); // LogUtil.info(agent.getFull_name() + " insert into // ps_virtual_project_status " + " project " + project // + " receivetime " + receivetime + " status " + status); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // public static List getConfigFile(String directoryPath, String // directoryKey, String fileKey) { // List list = new ArrayList(); // File baseFile = new File(directoryPath); // if (baseFile.isFile() || !baseFile.exists()) { // return list; // } // try { // File[] files = baseFile.listFiles(); // SAXReader saxReader = new SAXReader(); // for (File file : files) { // if (file.isDirectory() && file.getName().contains(directoryKey)) { // list.addAll(getConfigFile(file.getAbsolutePath(), directoryKey, // fileKey)); // } else { // if (file.getName().contains(fileKey)) { // list.add(file.getAbsolutePath()); // Document document = saxReader.read(file); // List devList = document.selectNodes("/root/portdev/devtype"); // // LogUtil.info(file.getName()); // // LogUtil.info(file.getName().indexOf(fileKey)); // // LogUtil.info(file.getName().indexOf(".xml")); // String port = file.getName().substring(file.getName().indexOf(fileKey) + // fileKey.length(), // file.getName().indexOf(".xml")); // // LogUtil.info(port); // // LogUtil.info(file.getParentFile().getName()); // // String building = // // file.getParentFile().getName().replace(directoryKey, // // "").substring(0, 10); // // String mac = // // file.getParentFile().getName().replace(directoryKey, // // "").substring(10); // String building = file.getParentFile().getName().replace(directoryKey, // "").split("-")[0]; // String mac = file.getParentFile().getName().replace(directoryKey, // "").split("-")[1]; // // LogUtil.info(building); // // LogUtil.info(mac); // // for (Element portdev : devList) { // String meter = portdev.attributeValue("meterid"); // String info = port + "-" + portdev.element("addr").getText(); // String point = building + "-" + mac + "-" + meter; // Constant.pointInfo.put(point, info); // // Iterator funcList = // // portdev.selectNodes("funset/funid").iterator(); // // while (funcList.hasNext()) { // // Element func = (Element) funcList.next(); // // String point = building + "-" + mac + "-" + meter // // + "." + func.getText(); // // String info = port + "-" + // // portdev.element("addr").getText(); // // Constant.pointInfo.put(point, info); // // LogUtil.info(meter + "." + // // func.getText()); // // } // } // // } // } // } // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // return list; // } public synchronized static int getSeq(String point) { int month = Integer.valueOf(Constant.format_month(new Date()).substring(4)); if (Constant.pMonth.containsKey(point) && (month == Constant.pMonth.get(point))) { int seq = Constant.pSeq.get(point) + 1; Constant.pMonth.put(point, month); Constant.pSeq.put(point, seq); return seq; } Constant.pMonth.put(point, month); Constant.pSeq.put(point, 1); return 1; } public synchronized static int getID() { if (PacketId > 65535) { PacketId = 1; } else { PacketId = PacketId + 1; } return PacketId; } public static class Millisecond { public static final long SECOND_1 = 1000L; public static final long SECOND_3 = 1000L * 3; public static final long SECOND_10 = 1000L * 10; public static final long SECOND_20 = 1000L * 20; public static final long SECOND_30 = 1000L * 30; public static final long MINUTE_1 = 1000L * 60 * 1; public static final long MINUTE_3 = 1000L * 60 * 3; public static final long MINUTE_5 = 1000L * 60 * 5; public static final long MINUTE_10 = 1000L * 60 * 10; public static final long MINUTE_15 = 1000L * 60 * 15; public static final long MINUTE_30 = 1000L * 60 * 30; public static final long MINUTE_60 = 1000L * 60 * 60; public static final long MINUTE_1440 = 1000L * 60 * 60 * 24; public static final long HOUR = 1000L * 60 * 60; public static final long DAY = 1000L * 60 * 60 * 24; } public static long getMillisecond(String request) { // TODO Auto-generated method stub try { if (request.contains("Second")) { return Integer.valueOf(request.replace(" ", "").replace("Second", "")) * Constant.Millisecond.SECOND_1; } else if (request.contains("second")) { return Integer.valueOf(request.replace(" ", "").replace("second", "")) * Constant.Millisecond.SECOND_1; } else if (request.contains("min")) { return Millisecond.MINUTE_1 * Integer.valueOf(request.replace("min", "").replace(" ", "")); } else { return Constant.Millisecond.SECOND_20; } } catch (Exception e) { return Constant.Millisecond.SECOND_20; } } public static void Insert_dy_pointlist(String building, String meter, Integer funcid, String system, String source, String address1, String ip_port, String address2, String address3, String address4, String collect_cycle, String data_type, String unit) { // TODO Auto-generated method stub try { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_dy_pointlist(Constant.Database, building, meter, funcid, system, source, address1, ip_port, address2, "", "", collect_cycle, data_type, unit); LogUtil.info( "insert into dy_pointlist " + "building " + building + " meter " + meter + " funcid " + funcid); } else { HBaseUtil.Insert_dy_pointlist(Constant.Database, building, meter, funcid, system, source, address1, ip_port, address2, "", "", collect_cycle, data_type, unit); LogUtil.info(agent.getFull_name() + " insert into dy_pointlist " + "building " + building + " meter " + meter + " funcid " + funcid); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } // public static void AgentsBatchInsert(String db, List // wtdbrecordList) { // // TODO Auto-generated method stub // // try { // HBaseUtil.BatchInsert(db, wtdbrecordList); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // } // // public static void AgentsBatchInsert_Set2(String db, PointSet ps) { // // TODO Auto-generated method stub // // try { // HBaseUtil.BatchInsert_Set2(db, ps); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // public static void AgentsBatchInsert_Set3(String db, PointSet ps) { // // TODO Auto-generated method stub // try { // HBaseUtil.BatchInsert_Set3(db, ps); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // public static void AgentsBatchInsert_Set1(String db, PointSet ps) { // // TODO Auto-generated method stub // try { // HBaseUtil.BatchInsert_Set1(db, ps); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } public static Map> GetDBPointList2Cache(String db, String tb, String building) { // TODO Auto-generated method stub Map> dbPointList = new HashMap>(); try { Map> pl = GetDBPointList(db, tb, building); for (Entry> m : pl.entrySet()) { if (!dbPointList.containsKey(m.getKey())) { dbPointList.put(m.getKey(), new ArrayList()); } for (Integer f : m.getValue()) { if (!dbPointList.get(m.getKey()).contains(f)) { dbPointList.get(m.getKey()).add(f); } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return dbPointList; } public static void loadDB2Cache_dy_pointlist() { // TODO Auto-generated method stub try { Constant.LoadDB2Cache_dy_pointlist(Constant.Database, "dy_pointlist"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static Map ps_physical_status(String db, String tb) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { return MySQLUtil.ps_physical_status(db, tb); } else { return HBaseUtil.ps_physical_status(db, tb); } } public static Map ps_virtual_point_status(String db, String tb) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { return MySQLUtil.ps_virtual_point_status(db, tb); } else { return HBaseUtil.ps_virtual_point_status(db, tb); } } public static Map ps_virtual_meter_status(String db, String tb) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { return MySQLUtil.ps_virtual_meter_status(db, tb); } else { return HBaseUtil.ps_virtual_meter_status(db, tb); } } public static Map ps_virtual_project_status(String db, String tb) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { return MySQLUtil.ps_virtual_project_status(db, tb); } else { return HBaseUtil.ps_virtual_project_status(db, tb); } } public static void LoadDB2Cache_dy_pointlist(String db, String tb) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.LoadDB2Cache_dy_pointlist(db, tb); } else { HBaseUtil.LoadDB2Cache_dy_pointlist(db, tb); } } public static void LoadDB2Cache_ps_physical_status(String db, String tb) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.LoadDB2Cache_ps_physical_status(db, tb); } else { HBaseUtil.LoadDB2Cache_ps_physical_status(db, tb); } } public static void LoadDB2Cache_ps_virtual_point_status(String db, String tb) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.LoadDB2Cache_ps_virtual_point_status(db, tb); } else { HBaseUtil.LoadDB2Cache_ps_virtual_point_status(db, tb); } } public static void LoadDB2Cache_ps_virtual_meter_status(String db, String tb) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.LoadDB2Cache_ps_virtual_meter_status(db, tb); } else { HBaseUtil.LoadDB2Cache_ps_virtual_meter_status(db, tb); } } public static void LoadDB2Cache_ps_virtual_project_status(String db, String tb) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.LoadDB2Cache_ps_virtual_project_status(db, tb); } else { HBaseUtil.LoadDB2Cache_ps_virtual_project_status(db, tb); } } public static Map> GetDBPointList(String db, String tb, String building) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { return MySQLUtil.GetDBPointList(db, tb, building); } else { return HBaseUtil.GetDBPointList(db, tb, building); } } public static void Getset(String db, String tb, String building, String meter, long funcid, String query_from, String query_to) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Getset(db, tb, building, meter, funcid, query_from, query_to); } else { HBaseUtil.Getset(db, tb, building, meter, funcid, query_from, query_to); } } public static void Getset_present(String db, String tb, String building, String meter, long funcid) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Getset_present(db, tb, building, meter, funcid); } else { HBaseUtil.Getset_present(db, tb, building, meter, funcid); } } public static void CreateDB(String DB) throws Exception { try { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateDB(DB); } else { HBaseUtil.CreateDB(DB); } } catch (Exception e) { e.printStackTrace(); } } public static boolean tableExist(String DBName, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { return MySQLUtil.tableExist(DBName, tableName); } else { return HBaseUtil.tableExist(DBName, tableName); } } public static void CreateTable(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable(DB, tableName); } else { HBaseUtil.CreateTable(DB, tableName); } } public static void CreateTable_present(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_present(DB, tableName); } else { HBaseUtil.CreateTable_present(DB, tableName); } } public static void CreateTable_set(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_set(DB, tableName); } else { HBaseUtil.CreateTable_set(DB, tableName); } } public static void CreateTable_setpresent(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_setpresent(DB, tableName); } else { HBaseUtil.CreateTable_setpresent(DB, tableName); } } public static void CreateTable_fjd_0_buildingcomputetime(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_fjd_0_buildingcomputetime(DB, tableName); } else { HBaseUtil.CreateTable_fjd_0_buildingcomputetime(DB, tableName); } } public static void CreateTable_dy_pointlist(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_dy_pointlist(DB, tableName); } else { HBaseUtil.CreateTable_dy_pointlist(DB, tableName); } } public static void CreateTable_ps_physical_status(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_ps_physical_status(DB, tableName); } else { HBaseUtil.CreateTable_ps_physical_status(DB, tableName); } } public static void CreateTable_ps_physical_log(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_ps_physical_log(DB, tableName); } else { HBaseUtil.CreateTable_ps_physical_log(DB, tableName); } } public static void CreateTable_ps_virtual_point_status(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_ps_virtual_point_status(DB, tableName); } else { HBaseUtil.CreateTable_ps_virtual_point_status(DB, tableName); } } public static void CreateTable_ps_virtual_point_log(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_ps_virtual_point_log(DB, tableName); } else { HBaseUtil.CreateTable_ps_virtual_point_log(DB, tableName); } } public static void CreateTable_ps_virtual_meter_status(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_ps_virtual_meter_status(DB, tableName); } else { HBaseUtil.CreateTable_ps_virtual_meter_status(DB, tableName); } } public static void CreateTable_ps_virtual_meter_log(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_ps_virtual_meter_log(DB, tableName); } else { HBaseUtil.CreateTable_ps_virtual_meter_log(DB, tableName); } } public static void CreateTable_ps_virtual_project_status(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_ps_virtual_project_status(DB, tableName); } else { HBaseUtil.CreateTable_ps_virtual_project_status(DB, tableName); } } public static void CreateTable_ps_virtual_project_log(String DB, String tableName) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_ps_virtual_project_log(DB, tableName); } else { HBaseUtil.CreateTable_ps_virtual_project_log(DB, tableName); } } public static void Insert_fjd_0_buildingcomputetime(String DB, String building, String compute_time, String first_compute_time) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_fjd_0_buildingcomputetime(DB, building, compute_time, first_compute_time); } else { HBaseUtil.Insert_fjd_0_buildingcomputetime(DB, building, compute_time, first_compute_time); } } 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 { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_ps_physical_status(DB, project, address_1, address_2, address_3, address_4, status, receivetime, detail); } else { HBaseUtil.Insert_ps_physical_status(DB, project, address_1, address_2, address_3, address_4, status, receivetime, detail); } } 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 { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_ps_physical_log(DB, project, address_1, address_2, address_3, address_4, receivetime, function); } else { HBaseUtil.Insert_ps_physical_log(DB, project, address_1, address_2, address_3, address_4, receivetime, function); } } 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 { if (receivetime == null || Constant.parse(receivetime).getTime() == 0) { receivetime = Constant.format(new Date()); } if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_ps_virtual_point_status(DB, project, meter, funcid, updown, status, receivetime, detail); } else { HBaseUtil.Insert_ps_virtual_point_status(DB, project, meter, funcid, updown, status, receivetime, detail); } } 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 { if (receivetime == null || Constant.parse(receivetime).getTime() == 0) { receivetime = Constant.format(new Date()); } if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_ps_virtual_point_log(DB, project, meter, funcid, updown, receivetime, seq, function, feedback); } else { HBaseUtil.Insert_ps_virtual_point_log(DB, project, meter, funcid, updown, receivetime, seq, function, feedback); } } public static void Insert_ps_virtual_meter_status(String DB, String project, String meter, String updown, String status, String receivetime, String detail) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_ps_virtual_meter_status(DB, project, meter, updown, status, receivetime, detail); } else { HBaseUtil.Insert_ps_virtual_meter_status(DB, project, meter, updown, status, receivetime, detail); } } public static void Insert_ps_virtual_meter_log(String DB, String project, String meter, String updown, String receivetime, String function) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_ps_virtual_meter_log(DB, project, meter, updown, receivetime, function); } else { HBaseUtil.Insert_ps_virtual_meter_log(DB, project, meter, updown, receivetime, function); } } public static void Insert_ps_virtual_project_status(String DB, String project, String status, String receivetime, String detail) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_ps_virtual_project_status(DB, project, status, receivetime, detail); } else { HBaseUtil.Insert_ps_virtual_project_status(DB, project, status, receivetime, detail); } } public static void Insert_ps_virtual_project_log(String DB, String project, String receivetime, String function) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.Insert_ps_virtual_project_log(DB, project, receivetime, function); } else { HBaseUtil.Insert_ps_virtual_project_log(DB, project, receivetime, function); } } public static void MsgBatchInsert(String DB, List dataList) throws Exception { LogUtil.warn("MsgBatchInsert Start, time:" + new Date().toString() + " ,size:" + dataList.size()); if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.MsgBatchInsert(DB, dataList); } else { HBaseUtil.MsgBatchInsert(DB, dataList); } LogUtil.warn("MsgBatchInsert End, time:" + new Date().toString() + " ,size:" + dataList.size()); } public static void MsgBatchDelte(String DB, List dataList) throws Exception { LogUtil.warn("MsgBatchDelte Start, time:" + new Date().toString() + " ,size:" + dataList.size()); if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.MsgBatchDelte(DB, dataList); } else { // HBaseUtil.MsgBatchDelte(DB, dataList); } LogUtil.warn("MsgBatchInsert End, time:" + new Date().toString() + " ,size:" + dataList.size()); } public static void BatchInsert(String DB, List dataList) throws Exception { LogUtil.warn("BatchInsert Start, time:" + new Date().toString() + " ,size:" + dataList.size()); if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.BatchInsert(DB, dataList); } else { HBaseUtil.BatchInsert(DB, dataList); } LogUtil.warn("BatchInsert End, time:" + new Date().toString() + " ,size:" + dataList.size()); } public static void BatchInsertUpload(List dataList) throws Exception { LogUtil.warn("BatchInsertUpload Start, time:" + new Date().toString() + " ,size:" + dataList.size()); if (Constant.DbConnection.containsKey("Upload-Mysql") && Constant.DbConnection.get("Upload-Mysql") != null) { EntityMysql entityMysql = new EntityMysql(); entityMysql = (EntityMysql) Constant.DbConnection.get("Upload-Mysql"); MySQLUtil.BatchInsertUpload(entityMysql.UploadDatabase, Arrays.asList(entityMysql.UploadTable.split(",")), dataList); } else if (Constant.DbConnection.containsKey("Upload-Hbase") && Constant.DbConnection.get("Upload-Hbase") != null) { EntityHbase entityHbase = new EntityHbase(); entityHbase = (EntityHbase) Constant.DbConnection.get("Upload-Hbase"); HBaseUtil.BatchInsertUpload(entityHbase.UploadDatabase, Arrays.asList(entityHbase.UploadTable.split(",")), dataList); } LogUtil.warn("BatchInsertUpload End, time:" + new Date().toString() + " ,size:" + dataList.size()); } public static void BatchInsert_Set1(String DB, PointSet ps) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.BatchInsert_Set1(DB, ps); } else { HBaseUtil.BatchInsert_Set1(DB, ps); } } public static void BatchInsert_Set2(String DB, PointSet ps) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.BatchInsert_Set2(DB, ps); } else { HBaseUtil.BatchInsert_Set2(DB, ps); } } public static void BatchInsert_Set3(String DB, PointSet ps) throws Exception { if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.BatchInsert_Set3(DB, ps); } else { HBaseUtil.BatchInsert_Set3(DB, ps); } } public static Date getOffSetTime(Record record) { // TODO Auto-generated method stub if (Constant.BuildingOffset.containsKey(record.buildingSign) && Constant.BuildingOffset.get(record.buildingSign)) { return new Date(record.receivetime.getTime() + 8 * Constant.Millisecond.HOUR); } return record.receivetime; } public static int getFunctionConv(Record record) { // TODO Auto-generated method stub if (Constant.FunctionConv.containsKey(record.funcID) && Constant.FunctionConv.get(record.funcID) != null) { return Integer.valueOf(Constant.FunctionConv.get(record.funcID)); } return record.funcID; } public static void CreateTable_upload() throws Exception { if (Constant.DbConnection.containsKey("Upload-Mysql") && Constant.DbConnection.get("Upload-Mysql") != null) { EntityMysql entityMysql = new EntityMysql(); entityMysql = (EntityMysql) Constant.DbConnection.get("Upload-Mysql"); MySQLUtil.CreateUploadDB(entityMysql.UploadDatabase); MySQLUtil.CreateTable_upload(entityMysql.UploadDatabase, Arrays.asList(entityMysql.UploadTable.split(","))); } else if (Constant.DbConnection.containsKey("Upload-Hbase") && Constant.DbConnection.get("Upload-Hbase") != null) { EntityHbase entityHbase = new EntityHbase(); entityHbase = (EntityHbase) Constant.DbConnection.get("Upload-Hbase"); HBaseUtil.CreateUploadDB(entityHbase.UploadDatabase); HBaseUtil.CreateTable_upload(entityHbase.UploadDatabase, Arrays.asList(entityHbase.UploadTable.split(","))); } } public static void CreateTable_detail(String DB, String tableName) throws Exception { // TODO Auto-generated method stub if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) { MySQLUtil.CreateTable_detail(DB, tableName); } else { HBaseUtil.CreateTable_detail(DB, tableName); } } public static String unicodeDecode(String string) { String result = string; try { LogUtil.info(new String(string.getBytes("gbk"))); LogUtil.info(new String(string.getBytes("utf-8"), "gbk")); LogUtil.info(new String(string.getBytes("iso-8859-1"), "gbk")); LogUtil.info(new String(string.getBytes("gb2312"), "gbk")); LogUtil.info(new String(string.getBytes("utf-8"))); LogUtil.info(new String(string.getBytes("gbk"), "utf-8")); LogUtil.info(new String(string.getBytes("iso-8859-1"), "utf-8")); LogUtil.info(new String(string.getBytes("gb2312"), "utf-8")); LogUtil.info(new String(string.getBytes("iso-8859-1"))); LogUtil.info(new String(string.getBytes("gbk"), "iso-8859-1")); LogUtil.info(new String(string.getBytes("utf-8"), "iso-8859-1")); LogUtil.info(new String(string.getBytes("gb2312"), "iso-8859-1")); LogUtil.info(new String(string.getBytes("gb2312"))); LogUtil.info(new String(string.getBytes("gbk"), "gb2312")); LogUtil.info(new String(string.getBytes("utf-8"), "gb2312")); LogUtil.info(new String(string.getBytes("iso-8859-1"), "gb2312")); // result = new String(string.getBytes("ISO-8859-1"), "UTF-8"); result = new String(string.getBytes("GB2312"), "8859_1"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; // Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))"); // Matcher matcher = pattern.matcher(string); // char ch; // while (matcher.find()) { // ch = (char) Integer.parseInt(matcher.group(2), 16); // string = string.replace(matcher.group(1), ch + ""); // } // return string; } // 相似度计算 public static double xiangsidu(String a, String b) { // 相似度公式:1 - 最小编辑距离/两个串中较长的长度 int n = a.length(); int m = b.length(); if (n < 1 && m < 1) return 0; // 两个空串 return 1 - minEditDist(a, b) / Math.max(n, m); } public static String xiangsidu(String s, List m) { String result = s; Double xiangsi = 0d; for (int i = 0; i < m.size(); i++) { if (xiangsidu(s, m.get(i)) > xiangsi) { result = m.get(i); xiangsi = xiangsidu(s, m.get(i)); } if (xiangsi == 1) { break; } } return result; } // 最小编辑距离计算 public static double minEditDist(String a, String b) { int n = a.length(); int m = b.length(); if (n < 1 || m < 1) return (n + m) * 1.00; // 两个空串 double[][] d = new double[n + 1][m + 1]; double cost; for (int i = 0; i <= n; ++i) d[i][0] = i; for (int i = 0; i <= m; ++i) d[0][i] = i; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a.charAt(i - 1) == b.charAt(j - 1)) cost = 0; else cost = 1; d[i][j] = Minimum(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost); } } return d[n][m]; } private static double Minimum(double a, double b, double c) { double mi = a; if (b < mi) { mi = b; } if (c < mi) { mi = c; } return mi; } public static List xuzhousuning() { List result = new ArrayList(); result.add("7配2#变压器"); result.add("7配1#变压器"); result.add("10配1#变压器"); result.add("10配2#变压器"); result.add("8配1#变压器"); result.add("8配2#变压器"); result.add("9配1#变压器"); result.add("9配2#变压器"); result.add("11配1#变压器"); result.add("11配2#变压器"); result.add("1905D_低压进线柜"); result.add("1907D_无功自动补偿电容柜"); result.add("1910D_母联"); result.add("1911D-1_一般照明1"); result.add("1911D-2_备用"); result.add("1912D-1_一般动力1"); result.add("1912D-2_备用"); result.add("1913D-1_M3区货梯1"); result.add("1913D-2_C塔楼照明"); result.add("1913D-3_变电所用电(主)"); result.add("1913D-4_会所一般动力"); result.add("1913D-5_D塔楼消防动力(常)"); result.add("1913D-6_预留泛光照明"); result.add("1914D-1_M3乘客电梯1(常)"); result.add("1914D-2_M3乘客电梯2(常)"); result.add("1914D-3_M3乘客电梯4(常)"); result.add("1914D-4_M3乘客电梯5(常)"); result.add("1914D-5_C塔楼进线客梯总电源(常)"); result.add("1914D-6_CDE生活水泵房(常)"); result.add("1914D-7_备用"); result.add("1915D-1_C塔楼客梯总电源(常)"); result.add("1915D-2_超市3"); result.add("1915D-3_M3乘客电梯3(备)"); result.add("1916D-1_D塔楼消防总电源(常)"); result.add("1916D-2_备用"); result.add("1916D-3_备用"); result.add("1917D-1_消防动力1(常)"); result.add("1917D-2_备用"); result.add("1918D-1_消防动力2(备)电梯"); result.add("1918D-2_备用"); result.add("1919D-1_会所应急照明(常)"); result.add("1919D-2_备用"); result.add("1919D-3_备用"); result.add("1919D-4_消防动力3(备)"); result.add("1919D-5_商业应急照明(备)"); result.add("1919D-6_B2充电桩"); result.add("1920D-1_C塔楼公共应急照明(备)"); result.add("1920D-2_C塔楼消防动力(常)"); result.add("1920D-3_备用C塔楼消防电梯"); result.add("1920D-4_C塔楼消防电梯备"); result.add("1921D-1_D塔楼消控室"); result.add("1921D-2_商业2变电所(常)"); result.add("1921D-3_M3消防电梯(备)"); result.add("1921D-4_D塔楼公共应急照明"); result.add("1921D-5_穹顶膜(备)"); result.add("1921D-6_D塔楼消防电梯总电源(常)"); result.add("2005D_低压进线柜"); result.add("2007D_无功自动补偿电容柜"); result.add("2010D-1_一般照明2"); result.add("2010D-2_备用"); result.add("2011D-1_一般动力2"); result.add("2011D-2_备用"); result.add("2012D-1_会所一般照明"); result.add("2012D-2_D塔照明"); result.add("2012D-3_M3区货梯2"); result.add("2012D-4_M3区扶梯"); result.add("2012D-5_变电所用电(备)"); result.add("2012D-6_D塔楼消防动力(备)"); result.add("2012D-7_备用"); result.add("2013D-1_M3乘客电梯1(备)"); result.add("2013D-2_M3乘客电梯2(备)"); result.add("2013D-3_M3乘客电梯4(备)"); result.add("2013D-4_M3乘客电梯5(备)"); result.add("2013D-5_C塔进线室电源"); result.add("2013D-6_CDE生活水泵房(备)"); result.add("2013D-7_备用"); result.add("2014D-1_C塔楼客梯总电源(备)"); result.add("2014D-2_备用"); result.add("2014D-3_M3乘客电梯3(常)"); result.add("2015D-1_D塔楼客梯总电源(备)"); result.add("2015D-2_超市"); result.add("2015D-3_备用"); result.add("2016D-1_消防动力1(备)"); result.add("2016D-2_备用"); result.add("2017D-1_消防动力2(常)电梯"); result.add("2017D-2_备用"); result.add("2018D-1_会所应急照明(备)"); result.add("2018D-2_备用"); result.add("2018D-3_备用"); result.add("2018D-4_消防动力3(常)"); result.add("2018D-5_商业应急照明(常)"); result.add("2018D-6_备用+商铺"); result.add("2019D-1_C塔楼公共应急照明(常)"); result.add("2019D-2_C塔楼消防动力(备)"); result.add("2019D-3_备用"); result.add("2019D-4_C塔楼消防电梯总电源(常)"); result.add("2020D-1_D塔楼消控室(备)"); result.add("2020D-2_商业2变电所(备)"); result.add("2020D-3_M3消防电梯(常)"); result.add("2020D-4_穹顶膜(常)"); result.add("2020D-5_D塔楼公共应急照明(常)"); result.add("2020D-6_D塔楼消防电梯总电源(备)"); result.add("1505D_低压进线柜"); result.add("1507D_无功自动补偿电容柜"); result.add("1510D_低压母联柜"); result.add("1511D-1_M4区一般照明1"); result.add("1511D-2_备用"); result.add("1512D-1_M4区一般照明3"); result.add("1512D-2_备用"); result.add("1513D-1_M4区一般动力1"); result.add("1513D-2_备用"); result.add("1514D-1_冷冻机房控制柜1"); result.add("1514D-2_备用"); result.add("1515D-1_M4区扶梯"); result.add("1515D-2_备用"); result.add("1515D-3_变电所用电(主)"); result.add("1515D-4_电制冷水冷式冷水机组1"); result.add("1515D-5_备用"); result.add("1516D-1_M4区客梯1(常)"); result.add("1516D-2_备用"); result.add("1516D-3_M4区客梯2(备)"); result.add("1516D-4_F塔楼电梯"); result.add("1516D-5_公寓生活水泵房(常)"); result.add("1516D-6_备用"); result.add("1517D-1_M4区消防动力(备)"); result.add("1517D-2_备用"); result.add("1518D-1_M4区变电所(常)+8#AT"); result.add("1518D-2_B楼消控室(常)"); result.add("1518D-3_百货消防客梯(常)"); result.add("1518D-4_M4区应急照明(常)"); result.add("1518D-5_影院空调1(常)"); result.add("1518D-6_影院空调2(备)"); result.add("1519D-1_商业消控室(常)"); result.add("1519D-2_影院空调3(常)"); result.add("1519D-3_KTV 空调1(常)"); result.add("1519D-4_KTV 空调2(备)"); result.add("1519D-5_备用"); result.add("1605D_低压进线柜"); result.add("1607D_无功自动补偿电容柜"); result.add("1610D-1_M4区一般照明2"); result.add("1610D-2_备用"); result.add("1611D-1_M4区一般照明4"); result.add("1611D-2_备用"); result.add("1612D-1_M4区一般动力2"); result.add("1612D-2_备用"); result.add("1613D-1_冷冻机房控制柜1"); result.add("1613D-2_备用"); result.add("1614D-1_变电所用电(备)"); result.add("1614D-2_电制冷水冷式冷水机组2"); result.add("1614D-3_LED屏(3F)"); result.add("1614D-4_备用"); result.add("1615D-1_M4区客梯1(备)"); result.add("1615D-2_备用"); result.add("1615D-3_M4区客梯2(常)"); result.add("1615D-4_F塔M4TAT3"); result.add("1615D-5_公寓生活水泵房(备)"); result.add("1615D-6_备用"); result.add("1616D-1_M4区消防动力(常)"); result.add("1616D-2_备用"); result.add("1617D-1_M4区变电所(备)"); result.add("1617D-2_B楼消控室(备)"); result.add("1617D-3_百货消防客梯(备)"); result.add("1617D-4_M4区应急照明(备)"); result.add("1617D-5_影院空调1(备)"); result.add("1617D-6_影院空调2(常)"); result.add("1618D-1_商业消控室(备)"); result.add("1618D-2_影院空调3(备)"); result.add("1618D-3_KTV 空调1(备)"); result.add("1618D-4_KTV 空调2(常)"); result.add("1618D-5_备用"); result.add("2103D_低压进线柜"); result.add("2104D_无功自动补偿电容柜"); result.add("2107D-1_冰机2号"); result.add("2107D-2_备用"); result.add("2108D-1_冰机1号"); result.add("2108D-2_变电所用电(主)"); result.add("2109D-1_基载冷水机组"); result.add("2109D-2_备用"); result.add("2110D-1_发电机"); result.add("2110D-2_市电"); result.add("2111D-1_办公+商业冷冻机房控柜电源1"); result.add("2111D-2_备用"); result.add("2203D_低压进线柜"); result.add("2204D_无功自动补偿电容柜"); result.add("2207D-1_冰机3号"); result.add("2207D-2_备用"); result.add("2208D-1_冰机4号"); result.add("2208D-2_变电所用电(主)"); result.add("2209D-1_冷冻机房控柜电源2"); result.add("2209D-2_备用"); result.add("2110D_母联"); result.add("1705D_低压进线柜"); result.add("1706D_无功自动补偿电容柜"); result.add("1707D_低压母联柜"); result.add("1710D-1_一般照明1"); result.add("1710D-2_备用"); result.add("1711D-1_一般动力1"); result.add("1711D-2_备用"); result.add("1712D-1_扶梯"); result.add("1712D-2_备用"); result.add("1712D-3_变电所用电(主)"); result.add("1713D-1_备用"); result.add("1713D-2_预留泛光照明"); result.add("1713D-3_商业1B3层水动力(备)"); result.add("1713D-4_E塔楼客梯总电源(常)"); result.add("1714D-1_消防动力1(常)"); result.add("1714D-2_备用"); result.add("1714D-3_M3乘客电梯2(备)"); result.add("1715D-1_F-L117 E-JX-AT(客梯)"); result.add("1715D-2_应急照明(备)"); result.add("1715D-3_消防动力3(备)电梯"); result.add("1715D-4_消防动力2(备)"); result.add("1716D-1_M3区消防电梯(备)"); result.add("1716D-2_商业1变电所(备)"); result.add("1716D-3_备用"); result.add("1716D-4_消防脑动力4(常)"); result.add("1716D-5_E塔楼总消防动力(常)"); result.add("1716D-6_备用"); result.add("1717D-1_备用"); result.add("1717D-2_E塔楼消防电梯总电源(常)"); result.add("1718D-1_备用"); result.add("1718D-2_E塔楼公共应急照明(备)"); result.add("1718D-3_备用"); result.add("1718D-4_备用"); result.add("1718D-5_D塔楼F4插座"); result.add("1805D_低压进线柜"); result.add("1807D_无功自动补偿电容柜"); result.add("1809D-1_一般照明2"); result.add("1809D-2_备用"); result.add("1810D-1_一般动力2"); result.add("1810D-2_备用"); result.add("1811D-1_E塔楼照明"); result.add("1811D-2_备用"); result.add("1811D-3_变电所用电(备)"); result.add("1811D-4_备用"); result.add("1811D-5_备用"); result.add("1812D-1_备用"); result.add("1812D-2_备用"); result.add("1812D-3_商业1B3层水动力(常)"); result.add("1812D-4_E塔楼客梯总电源(备)"); result.add("1813D-1_消防动力1(备)"); result.add("1813D-2_备用"); result.add("1813D-3_M3乘客电梯2(常)"); result.add("1814D-1_F-L217 E-JX-AT(客梯)"); result.add("1814D-2_应急照明(常)"); result.add("1814D-3_消防动力3(常)"); result.add("1814D-4_消防动力2(常)"); result.add("1815D-1_M3区消防电梯(常)"); result.add("1815D-2_商业1变电所(常)"); result.add("1815D-3_备用"); result.add("1815D-4_消防动力4(备)"); result.add("1815D-5_E塔楼消防动力(备)"); result.add("1815D-6_备用"); result.add("1816D-1_备用"); result.add("1816D-2_E塔楼消防电梯总电源(备)"); result.add("1817D-1_备用"); result.add("1817D-2_E塔楼公共应急照明(常)"); result.add("1817D-3_备用"); result.add("1817D-4_备用"); result.add("1817D-5_F4M2APXZ1 F-L 105 D塔楼"); result.add("1405D_低压进线柜支路"); result.add("1407D_无功自动补偿电容柜"); result.add("1409D-1_一般照明2"); result.add("1409D-2_备用"); result.add("1410D-1_一般照明3"); result.add("1410D-2_备用"); result.add("1411D-1_配电所用电(备)"); result.add("1411D-2_备用"); result.add("1411D-3_备用"); result.add("1411D-4_溜冰场制冷机房动力(备)"); result.add("1412D-1_商业水泵房(备)"); result.add("1412D-2_M1区乘客电梯(备)"); result.add("1412D-3_B塔配电所用电"); result.add("1412D-4_备用"); result.add("1412D-5_备用"); result.add("1413D-1_开闭所直流屏"); result.add("1413D-2_M1区应急照明(备)"); result.add("1413D-3_消防动力2(备)"); result.add("1413D-4_消防动力3(备)"); result.add("1413D-5_消防动力1(备)"); result.add("1414D-1_开闭所照明(备)"); result.add("1414D-2_开闭所直流屏(常)"); result.add("1414D-3_商业冷冻机房变电所(备)"); result.add("1414D-4_备用"); result.add("1414D-5_超市"); result.add("1305D_低压进线柜"); result.add("1307D_无功自动补偿电容柜"); result.add("1309D_低压母联柜"); result.add("1310D-1_一般照明"); result.add("1310D-2_备用"); result.add("1311D-1_变电所用电(主)"); result.add("1311D-2_扶梯"); result.add("1311D-3_备用"); result.add("1311D-4_溜冰场制冷机房动力(常)"); result.add("1312D-1_商业水泵房(常)"); result.add("1312D-2_M1区乘客电梯(常)"); result.add("1312D-3_BDS-AT(6#客梯)"); result.add("1312D-4_备用"); result.add("1312D-5_B1M1-AP2"); result.add("1313D-1_开闭所直流屏"); result.add("1313D-2_M1区应急照明(常)"); result.add("1313D-3_消防动力2(常)"); result.add("1313D-4_消防动力3(常)"); result.add("1313D-5_消防动力1(常)"); result.add("1314D-1_开闭所照明(常)"); result.add("1314D-2_开闭所直流屏(备)"); result.add("1314D-3_商业冷冻机房变电所(常)"); result.add("1314D-4_预留泛光照明"); result.add("1314D-5_超市"); result.add("1#直流屏"); result.add("2#直流屏"); result.add("1#进线总柜"); result.add("1#出线柜"); result.add("3#出线柜"); result.add("5#出线柜"); result.add("7#出线柜"); result.add("母联断路器柜"); result.add("2#进线总柜"); result.add("2#出线柜"); result.add("4#出线柜"); result.add("6#出线柜"); result.add("8#出线柜"); result.add("1#进线总柜"); result.add("1#出线柜"); result.add("3#出线柜"); result.add("5#出线柜"); result.add("7#出线柜"); result.add("母联断路器柜"); result.add("2#进线总柜"); result.add("2#出线柜"); result.add("4#出线柜"); result.add("6#出线柜"); result.add("8#出线柜"); result.add("1#高压进线柜"); result.add("1#高压出线柜"); result.add("母联断路器柜"); result.add("2#高压进线柜"); result.add("2#高压出线柜"); result.add("1#高压进线柜"); result.add("1#高压出线柜"); result.add("母联断路器柜"); result.add("2#高压进线柜"); result.add("2#高压出线柜"); result.add("1#高压进线柜"); result.add("1#高压出线柜"); result.add("母联断路器柜"); result.add("2#高压进线柜"); result.add("2#高压出线柜"); result.add("1#高压进线柜"); result.add("1#高压出线柜"); result.add("母联断路器柜"); result.add("2#高压进线柜"); result.add("2#高压出线柜"); result.add("1#高压出线柜"); result.add("2#高压出线柜"); return result; } public byte[] gbk2utf8(String chenese) { char c[] = chenese.toCharArray(); byte[] fullByte = new byte[3 * c.length]; for (int i = 0; i < c.length; i++) { int m = (int) c[i]; String word = Integer.toBinaryString(m); // System.out.println(word); StringBuffer sb = new StringBuffer(); int len = 16 - word.length(); // 补零 for (int j = 0; j < len; j++) { sb.append("0"); } sb.append(word); sb.insert(0, "1110"); sb.insert(8, "10"); sb.insert(16, "10"); // System.out.println(sb.toString()); String s1 = sb.substring(0, 8); String s2 = sb.substring(8, 16); String s3 = sb.substring(16); byte b0 = Integer.valueOf(s1, 2).byteValue(); byte b1 = Integer.valueOf(s2, 2).byteValue(); byte b2 = Integer.valueOf(s3, 2).byteValue(); byte[] bf = new byte[3]; bf[0] = b0; fullByte[i * 3] = bf[0]; bf[1] = b1; fullByte[i * 3 + 1] = bf[1]; bf[2] = b2; fullByte[i * 3 + 2] = bf[2]; } return fullByte; } }