Constant.java 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  1. package com.saga.util;
  2. import java.io.File;
  3. import java.io.UnsupportedEncodingException;
  4. import java.sql.Connection;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Arrays;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.HashSet;
  12. import java.util.List;
  13. import java.util.Map;
  14. import java.util.Map.Entry;
  15. import java.util.Set;
  16. import org.zillion.util.log.LogUtil;
  17. import com.saga.entity.Data;
  18. import com.saga.entity.EntityHbase;
  19. import com.saga.entity.EntityMysql;
  20. import com.saga.entity.PointSet;
  21. import com.saga.entity.Record;
  22. import com.saga.entity.RecordMsg;
  23. import com.saga.entity.Server;
  24. import com.saga.entity.Transfer;
  25. import com.zillion.database.agent.ZillionAgent;
  26. public class Constant {
  27. public static int PacketId = 0;
  28. public static int InsertThread = 1;
  29. public static ZillionAgent agent;
  30. public static Connection conn;
  31. public static ZillionAgent agentUpload;
  32. public static Connection connUpload;
  33. // public static List<ZillionAgent> agents = new ArrayList<ZillionAgent>();
  34. // public static boolean DBConn = true;
  35. public static String WaitingTimeControl = "5Second";
  36. public static long Disconnect = Constant.Millisecond.MINUTE_15;
  37. public static Map<String, Object> DbConnection = new HashMap<String, Object>();
  38. public static File setlog = new File(System.getProperty("user.dir") + "/setlog.log");
  39. public static List<String> CollectReportList = new ArrayList<String>();
  40. public static List<String> TransferReportList = new ArrayList<String>();
  41. public static List<Record> RecordListToDB = new ArrayList<Record>();
  42. public static Map<String, String> Meter_Collector = new HashMap<String, String>();
  43. public static Map<String, String> Meter_Collector_Control = new HashMap<String, String>();
  44. public static List<PointSet> pointSetList = new ArrayList<PointSet>();
  45. // public static Map<String, String> CollectorPointSetList = new
  46. // HashMap<String, String>();
  47. // public static Map<String, String> BuildingDB = new HashMap<String,
  48. // String>();
  49. public static Map<String, Boolean> BuildingOffset = new HashMap<String, Boolean>();
  50. public static String Database;
  51. // public static String UploadSource = null;
  52. // public static List<String> uploadList = new ArrayList<String>();
  53. public static Map<String, String> BuildingConv = new HashMap<String, String>();
  54. public static Map<String, List<String>> BuildingAdds = new HashMap<String, List<String>>();
  55. public static Map<String, String> FunctionConv = new HashMap<String, String>();
  56. public static Map<String, String> FunctionConvReverse = new HashMap<String, String>();
  57. // public static Map<String, String> TypePort = new HashMap<String,
  58. // String>();
  59. // public static Map<Integer, String> PortCompress = new HashMap<Integer,
  60. // String>();
  61. // public static Map<Integer, String> PortHistory = new HashMap<Integer,
  62. // String>();
  63. public static Map<String, Server> TypeServer = new HashMap<String, Server>();
  64. public static Transfer transfer = new Transfer();
  65. public static Map<String, Integer> RecordAddress = new HashMap<String, Integer>();
  66. public static List<Record> RecordList = new ArrayList<Record>();
  67. public static Map<String, Long> PresentFlag = new HashMap<String, Long>();
  68. // public static Map<String, Long> ps_NodeStatus = new HashMap<String,
  69. // Long>();
  70. public static Map<String, Long> ps_PointStatusUp = new HashMap<String, Long>();
  71. public static Map<String, Long> ps_PhysicalStatus = new HashMap<String, Long>();
  72. public static Map<String, Long> ps_ProjectStatus = new HashMap<String, Long>();
  73. public static Map<String, Long> ps_MeterStatusUp = new HashMap<String, Long>();
  74. public static Map<String, Long> ps_PointStatusDown = new HashMap<String, Long>();
  75. public static Map<String, Long> ps_MeterStatusDown = new HashMap<String, Long>();
  76. public static Map<String, List<String>> ps_PhysicalList = new HashMap<String, List<String>>();
  77. public static Map<String, List<String>> ps_ProjectList = new HashMap<String, List<String>>();
  78. public static Map<String, List<String>> ps_MeterList = new HashMap<String, List<String>>();
  79. public static Map<String, String> pointInfo = new HashMap<String, String>();
  80. public static Map<String, Data> nodeCache = new HashMap<String, Data>();
  81. public static Map<String, Data> pointCache = new HashMap<String, Data>();
  82. // public static Map<String, Long> pointListDown = new HashMap<String,
  83. // Long>();
  84. public static Map<String, Long> ps_ID2Time = new HashMap<String, Long>();
  85. public static Map<String, String> ps_ID2Point = new HashMap<String, String>();
  86. public static Map<String, String> ps_ID2Function = new HashMap<String, String>();
  87. public static Map<String, String> ps_ID2Status = new HashMap<String, String>();
  88. public static int collectRec = 0;
  89. public static int collectSend = 0;
  90. public static int sendRec = 0;
  91. public static int sendSend = 0;
  92. public static int writeDB = 0;
  93. public static int collectCount = 0;
  94. public static int transferSendCount = 0;
  95. public static int transferRecCount = 0;
  96. public static int collectReportCount = 0;
  97. public static int report2DBCount = 0;
  98. public static Map<String, String> pointMAC = new HashMap<String, String>();
  99. public static Map<String, String> black_Buildings = new HashMap<String, String>();
  100. public static Map<String, String> whilte_Points = new HashMap<String, String>();
  101. public static Map<String, String> transfer_List = new HashMap<String, String>();
  102. public static Map<String, Integer> pSeq = new HashMap<String, Integer>();
  103. public static Map<String, Integer> pMonth = new HashMap<String, Integer>();
  104. public static Set<String> saveTypeList = new HashSet<String>();
  105. public static long delay = Constant.Millisecond.SECOND_1;
  106. public static String activeMqBrokerUrl;
  107. public static String queueName;
  108. public static Set<String> activeMqPointSet = new HashSet<>();
  109. // static {
  110. // String resource = "\\config.json";
  111. // String path = null;
  112. // JsonParser config = new JsonParser();
  113. //
  114. // try {
  115. // LogUtil.info("System.get " + System.getProperty("user.dir") + resource);
  116. // LogUtil.info("LogUtil.get " + LogUtil.GetPath() + resource);
  117. // path = LogUtil.GetPath() + resource;
  118. //
  119. // JsonObject object = (JsonObject) config.parse(new FileReader(path));
  120. //
  121. // JsonArray db = object.get("DB").getAsJsonArray();
  122. // for (int i = 0; i < db.size(); i++) {
  123. // JsonObject subObject = db.get(i).getAsJsonObject();
  124. // if (subObject.get("building") != null) {
  125. // String building = subObject.get("building").getAsString();
  126. // Constant.BuildingDB.put(building,
  127. // subObject.get("database").getAsString());
  128. // Constant.Database = subObject.get("database").getAsString();
  129. //
  130. // if (subObject.get("buildingadds") != null) {
  131. // JsonArray buildingAdds = subObject.get("buildingadds").getAsJsonArray();
  132. // for (int j = 0; j < buildingAdds.size(); j++) {
  133. // JsonObject addObject = buildingAdds.get(j).getAsJsonObject();
  134. // if (!Constant.BuildingAdds.containsKey(building)) {
  135. // Constant.BuildingAdds.put(building, new ArrayList<String>());
  136. // }
  137. // Constant.BuildingAdds.get(building).add(addObject.get("building").getAsString());
  138. // Constant.BuildingDB.put(addObject.get("building").getAsString(),
  139. // subObject.get("database").getAsString());
  140. // Constant.Database = subObject.get("database").getAsString();
  141. // Constant.BuildingConv.put(addObject.get("building").getAsString(),
  142. // building);
  143. // }
  144. //
  145. // }
  146. // } else if (subObject.get("insertthread") != null) {
  147. // Constant.InsertThread = subObject.get("insertthread").getAsInt();
  148. // }
  149. // }
  150. // JsonArray port = object.get("Port").getAsJsonArray();
  151. // for (int i = 0; i < port.size(); i++) {
  152. // JsonObject subObject = port.get(i).getAsJsonObject();
  153. // String ports = subObject.get("port").getAsString();
  154. // Constant.TypePort.put(subObject.get("type").getAsString(), ports);
  155. // Constant.PortCompress.put(Integer.valueOf(ports),
  156. // subObject.get("Compress").getAsString());
  157. // Constant.PortHistory.put(Integer.valueOf(ports),
  158. // subObject.get("History").getAsString());
  159. // // for (String p : ports.split(",")) {
  160. // // Constant.PortCompress.put(Integer.valueOf(p),
  161. // // subObject.get("Compress").getAsString());
  162. // // Constant.PortHistory.put(Integer.valueOf(p),
  163. // // subObject.get("History").getAsString());
  164. // // }
  165. // }
  166. //
  167. // JsonArray blackList = object.get("BlackList").getAsJsonArray();
  168. // for (int i = 0; i < blackList.size(); i++) {
  169. // JsonObject subObject = blackList.get(i).getAsJsonObject();
  170. // if (subObject.get("buildings") != null) {
  171. // if (subObject.get("buildings") != null) {
  172. // JsonArray buildings = subObject.get("buildings").getAsJsonArray();
  173. // for (int j = 0; j < buildings.size(); j++) {
  174. // JsonObject addObject = buildings.get(j).getAsJsonObject();
  175. // Constant.black_Buildings.put(addObject.get("building").getAsString(),
  176. // null);
  177. // }
  178. // }
  179. // }
  180. // }
  181. //
  182. // JsonArray whiteList = object.get("WhiteList").getAsJsonArray();
  183. // for (int i = 0; i < whiteList.size(); i++) {
  184. // JsonObject subObject = whiteList.get(i).getAsJsonObject();
  185. // if (subObject.get("funcids") != null) {
  186. // if (subObject.get("funcids") != null) {
  187. // JsonArray funcids = subObject.get("funcids").getAsJsonArray();
  188. // for (int j = 0; j < funcids.size(); j++) {
  189. // JsonObject addObject = funcids.get(j).getAsJsonObject();
  190. // Constant.whilte_Funcs.put(addObject.get("funcid").getAsInt(), null);
  191. // }
  192. // }
  193. // }
  194. // }
  195. //
  196. // } catch (Exception e) {
  197. // // TODO Auto-generated catch block
  198. // // LogUtil.info(e.getMessage());
  199. // LogUtil.warn(e.toString());
  200. // LogUtil.warn("No Config File(config.json) in " + path + ",Now Exit!");
  201. // System.exit(0);
  202. // }
  203. //
  204. // }
  205. // public static long getWaitingtime() {
  206. // // TODO Auto-generated method stub
  207. // try {
  208. // if (WaitingTimeControl.contains("Second")) {
  209. // return Integer.valueOf(WaitingTimeControl.replace(" ",
  210. // "").replace("Second", ""))
  211. // * Constant.Millisecond.SECOND_1;
  212. // } else if (WaitingTimeControl.contains("second")) {
  213. // return Integer.valueOf(WaitingTimeControl.replace(" ",
  214. // "").replace("second", ""))
  215. // * Constant.Millisecond.SECOND_1;
  216. // } else {
  217. // return Constant.Millisecond.SECOND_3;
  218. // }
  219. // } catch (Exception e) {
  220. // return Constant.Millisecond.SECOND_3;
  221. // }
  222. // }
  223. public static Map<String, Integer> toLower(Map<String, Integer> pty) {
  224. // TODO Auto-generated method stub
  225. Map<String, Integer> result = new HashMap<String, Integer>();
  226. for (Entry<String, Integer> m : pty.entrySet()) {
  227. result.put(m.getKey().toLowerCase(), m.getValue());
  228. // Constant.info(m.getKey() + "-->" + m.getKey().toLowerCase());
  229. }
  230. return result;
  231. }
  232. public static long getWaitingtime() {
  233. // TODO Auto-generated method stub
  234. try {
  235. if (WaitingTimeControl.contains("Second")) {
  236. return Integer.valueOf(WaitingTimeControl.replace(" ", "").replace("Second", ""))
  237. * Constant.Millisecond.SECOND_1;
  238. } else if (WaitingTimeControl.contains("second")) {
  239. return Integer.valueOf(WaitingTimeControl.replace(" ", "").replace("second", ""))
  240. * Constant.Millisecond.SECOND_1;
  241. } else {
  242. return Constant.Millisecond.SECOND_3;
  243. }
  244. } catch (Exception e) {
  245. return Constant.Millisecond.SECOND_3;
  246. }
  247. }
  248. // @SuppressWarnings("rawtypes")
  249. // public static InetAddress getLocalHostLANAddress() throws
  250. // UnknownHostException {
  251. // try {
  252. // InetAddress candidateAddress = null;
  253. // // 遍历所有的网络接口
  254. // for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces();
  255. // ifaces.hasMoreElements();) {
  256. // NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
  257. // // 在所有的接口下再遍历IP
  258. // for (Enumeration inetAddrs = iface.getInetAddresses();
  259. // inetAddrs.hasMoreElements();) {
  260. // InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
  261. // if (!inetAddr.isLoopbackAddress()) {// 排除loopback类型地址
  262. // if (inetAddr.isSiteLocalAddress()) {
  263. // // 如果是site-local地址,就是它了
  264. // return inetAddr;
  265. // } else if (candidateAddress == null) {
  266. // // site-local类型的地址未被发现,先记录候选地址
  267. // candidateAddress = inetAddr;
  268. // }
  269. // }
  270. // }
  271. // }
  272. // if (candidateAddress != null) {
  273. // return candidateAddress;
  274. // }
  275. // // 如果没有发现 non-loopback地址.只能用最次选的方案
  276. // InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
  277. // if (jdkSuppliedAddress == null) {
  278. // throw new UnknownHostException("The JDK InetAddress.getLocalHost() method
  279. // unexpectedly returned null.");
  280. // }
  281. // return jdkSuppliedAddress;
  282. // } catch (Exception e) {
  283. // UnknownHostException unknownHostException = new UnknownHostException(
  284. // "Failed to determine LAN address: " + e);
  285. // unknownHostException.initCause(e);
  286. // throw unknownHostException;
  287. // }
  288. // }
  289. private static final SimpleDateFormat SIMPLEDATEFORMAT = new SimpleDateFormat("yyyyMMddHHmmss");
  290. private static final SimpleDateFormat SIMPLEDATEFORMATDB = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  291. private static final SimpleDateFormat SIMPLEDATEFORMAT_Minute = new SimpleDateFormat("yyyyMMddHHmm");
  292. private static final SimpleDateFormat SIMPLEDATEFORMAT_DAY = new SimpleDateFormat("yyyyMMdd");
  293. private static final SimpleDateFormat SIMPLEDATEFORMAT_MONTH = new SimpleDateFormat("yyyyMM");
  294. private static final SimpleDateFormat SIMPLEDATEFORMATLOG = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
  295. // private static final SimpleDateFormat SIMPLEDATEFORMAT_LOG = new
  296. // SimpleDateFormat("yyyyMMddHHmmssSSS");
  297. // public synchronized static String format_LOG(Date value) {
  298. // return SIMPLEDATEFORMAT_LOG.format(value);
  299. // }
  300. public synchronized static String format_Minute(Date value) {
  301. return SIMPLEDATEFORMAT_Minute.format(value);
  302. }
  303. public synchronized static String format_DB(Date value) {
  304. return SIMPLEDATEFORMATDB.format(value);
  305. }
  306. public synchronized static String format_Log(Date value) {
  307. return SIMPLEDATEFORMATLOG.format(value);
  308. }
  309. // public synchronized static Date parse_LOG(String value) throws
  310. // ParseException {
  311. // return SIMPLEDATEFORMAT_LOG.parse(value);
  312. // }
  313. public synchronized static Date parse_Minute(String value) throws ParseException {
  314. return SIMPLEDATEFORMAT_Minute.parse(value);
  315. }
  316. public synchronized static Date parse_DB(String value) throws ParseException {
  317. return SIMPLEDATEFORMATDB.parse(value);
  318. }
  319. public synchronized static Date parse_MONTH(String value) throws ParseException {
  320. return SIMPLEDATEFORMAT_MONTH.parse(value);
  321. }
  322. public synchronized static String format(Date value) {
  323. if (value == null) {
  324. return "null";
  325. }
  326. return SIMPLEDATEFORMAT.format(value);
  327. }
  328. public synchronized static Date parse(String value) throws ParseException {
  329. return SIMPLEDATEFORMAT.parse(value);
  330. }
  331. public synchronized static String format_day(Date value) {
  332. return SIMPLEDATEFORMAT_DAY.format(value);
  333. }
  334. public synchronized static String format_month(Date value) {
  335. return SIMPLEDATEFORMAT_MONTH.format(value);
  336. }
  337. public synchronized static Date parse_day(String value) throws ParseException {
  338. return SIMPLEDATEFORMAT_DAY.parse(value);
  339. }
  340. public static void showStatus() {
  341. // TODO Auto-generated method stub
  342. LogUtil.info("ps_PointStatusUp:");
  343. for (Entry<String, Long> d : Constant.ps_PointStatusUp.entrySet()) {
  344. LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue())));
  345. }
  346. LogUtil.info("-----------------------------------------------------");
  347. LogUtil.info("ps_PhysicalStatus:");
  348. for (Entry<String, Long> d : Constant.ps_PhysicalStatus.entrySet()) {
  349. LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue())));
  350. }
  351. LogUtil.info("-----------------------------------------------------");
  352. LogUtil.info("ps_ProjectStatus:");
  353. for (Entry<String, Long> d : Constant.ps_ProjectStatus.entrySet()) {
  354. LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue())));
  355. }
  356. LogUtil.info("-----------------------------------------------------");
  357. LogUtil.info("ps_MeterStatusUp:");
  358. for (Entry<String, Long> d : Constant.ps_MeterStatusUp.entrySet()) {
  359. LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue())));
  360. }
  361. LogUtil.info("-----------------------------------------------------");
  362. LogUtil.info("ps_PointStatusDown:");
  363. for (Entry<String, Long> d : Constant.ps_PointStatusDown.entrySet()) {
  364. LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue())));
  365. }
  366. LogUtil.info("-----------------------------------------------------");
  367. LogUtil.info("ps_MeterStatusDown:");
  368. for (Entry<String, Long> d : Constant.ps_MeterStatusDown.entrySet()) {
  369. LogUtil.info(d.getKey() + " " + Constant.format(new Date(d.getValue())));
  370. }
  371. LogUtil.info("-----------------------------------------------------");
  372. LogUtil.info("ps_PhysicalList:\n" + Constant.ps_PhysicalList);
  373. LogUtil.info("-----------------------------------------------------");
  374. LogUtil.info("ps_ProjectList:\n" + Constant.ps_ProjectList);
  375. LogUtil.info("-----------------------------------------------------");
  376. LogUtil.info("ps_MeterList:\n" + Constant.ps_MeterList);
  377. LogUtil.info("-----------------------------------------------------");
  378. }
  379. // public static void Insert_agents_ps_physical_log(String project, String
  380. // address_1, String address_2,
  381. // String address_3, String address_4, String receivetime, String status) {
  382. // // TODO Auto-generated method stub
  383. // try {
  384. // HBaseUtil.Insert_ps_physical_log(Constant.BuildingDB.get(project),
  385. // project, address_1, address_2, address_3,
  386. // address_4, receivetime, status);
  387. // LogUtil.info(agent.getFull_name() + " insert into ps_physical_log " + "
  388. // project " + project + " address_1 "
  389. // + address_1 + " address_2 " + address_2 + " address_3 " + address_3 + "
  390. // address_4 " + address_4
  391. // + " receivetime " + receivetime + " status " + status);
  392. // } catch (Exception e) {
  393. // // TODO Auto-generated catch block
  394. // e.printStackTrace();
  395. // }
  396. //
  397. // }
  398. //
  399. // public static void Insert_agents_ps_physical_status(String project,
  400. // String address_1, String address_2,
  401. // String address_3, String address_4, String status, String receivetime,
  402. // String detail) {
  403. // // TODO Auto-generated method stub
  404. // try {
  405. // HBaseUtil.Insert_ps_physical_status(Constant.BuildingDB.get(project),
  406. // project, address_1, address_2,
  407. // address_3, address_4, status, receivetime, detail);
  408. // LogUtil.info(agent.getFull_name() + " insert into ps_physical_status " +
  409. // " project " + project
  410. // + " address_1 " + address_1 + " address_2 " + address_2 + " address_3 " +
  411. // address_3 + " address_4 "
  412. // + address_4 + " receivetime " + receivetime + " status " + status);
  413. // } catch (Exception e) {
  414. // // TODO Auto-generated catch block
  415. // e.printStackTrace();
  416. // }
  417. // }
  418. //
  419. // public static void Insert_agents_ps_virtual_meter_log(String project,
  420. // String meter, String updown,
  421. // String receivetime, String status) {
  422. // // TODO Auto-generated method stub
  423. //
  424. // try {
  425. // HBaseUtil.Insert_ps_virtual_meter_log(Constant.BuildingDB.get(project),
  426. // project, meter, updown, receivetime,
  427. // status);
  428. // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_meter_log "
  429. // + " project " + project + " meter "
  430. // + meter + " updown " + updown + " receivetime " + receivetime + " status
  431. // " + status);
  432. // } catch (Exception e) {
  433. // // TODO Auto-generated catch block
  434. // e.printStackTrace();
  435. // }
  436. // }
  437. //
  438. // public static void Insert_agents_ps_virtual_meter_status(String project,
  439. // String meter, String updown, String status,
  440. // String receivetime, String detail) {
  441. // // TODO Auto-generated method stub
  442. // try {
  443. // HBaseUtil.Insert_ps_virtual_meter_status(Constant.BuildingDB.get(project),
  444. // project, meter, updown, status,
  445. // receivetime, detail);
  446. // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_meter_status
  447. // " + " project " + project
  448. // + " meter " + meter + " updown " + updown + " receivetime " + receivetime
  449. // + " status " + status);
  450. // } catch (Exception e) {
  451. // // TODO Auto-generated catch block
  452. // e.printStackTrace();
  453. // }
  454. // }
  455. //
  456. // public static void Insert_agents_ps_virtual_point_log(String building,
  457. // String meter, Long funcid, String updown,
  458. // Long time, Long seq, String status, String feedback) {
  459. // // TODO Auto-generated method stub
  460. // try {
  461. // if (time == null || time == 0) {
  462. // HBaseUtil.Insert_ps_virtual_point_log(Constant.BuildingDB.get(building),
  463. // building, meter,
  464. // Long.valueOf(funcid), updown, Constant.format(new Date()), seq, status,
  465. // feedback);
  466. // } else {
  467. // HBaseUtil.Insert_ps_virtual_point_log(Constant.BuildingDB.get(building),
  468. // building, meter,
  469. // Long.valueOf(funcid), updown, Constant.format(new Date(time)), seq,
  470. // status, feedback);
  471. // }
  472. // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_point_log "
  473. // + " building " + building
  474. // + " meter " + meter + " updown " + updown + " funcid " + funcid + "
  475. // status " + status + " feedback "
  476. // + feedback);
  477. // } catch (Exception e) {
  478. // // TODO Auto-generated catch block
  479. // e.printStackTrace();
  480. // }
  481. // }
  482. //
  483. // public static void Insert_agents_ps_virtual_point_status(String building,
  484. // String meter, Long funcid, String updown,
  485. // String status, Long time, String detail) {
  486. // // TODO Auto-generated method stub
  487. // try {
  488. // if (time == null || time == 0) {
  489. // HBaseUtil.Insert_ps_virtual_point_status(Constant.BuildingDB.get(building),
  490. // building, meter,
  491. // Long.valueOf(funcid), "up", status, Constant.format(new Date()), "");
  492. //
  493. // } else {
  494. // HBaseUtil.Insert_ps_virtual_point_status(Constant.BuildingDB.get(building),
  495. // building, meter,
  496. // Long.valueOf(funcid), "up", status, Constant.format(new Date(time)), "");
  497. // }
  498. // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_point_status
  499. // " + " building " + building
  500. // + " meter " + meter + " updown " + updown + " funcid " + funcid + "
  501. // status " + status + " detail "
  502. // + detail);
  503. // } catch (Exception e) {
  504. // // TODO Auto-generated catch block
  505. // e.printStackTrace();
  506. // }
  507. // }
  508. //
  509. // public static void Insert_agents_ps_virtual_project_log(String project,
  510. // String receivetime, String status) {
  511. // // TODO Auto-generated method stub
  512. // try {
  513. // HBaseUtil.Insert_ps_virtual_project_log(Constant.BuildingDB.get(project),
  514. // project, receivetime, status);
  515. // LogUtil.info(agent.getFull_name() + " insert into ps_virtual_project_log
  516. // " + " project " + project
  517. // + " receivetime " + receivetime + " status " + status);
  518. // } catch (Exception e) {
  519. // // TODO Auto-generated catch block
  520. // e.printStackTrace();
  521. // }
  522. //
  523. // }
  524. //
  525. // public static void Insert_agents_ps_virtual_project_status(String
  526. // project, String status, String receivetime,
  527. // String detail) {
  528. // // TODO Auto-generated method stub
  529. // try {
  530. // HBaseUtil.Insert_ps_virtual_project_status(Constant.BuildingDB.get(project),
  531. // project, status, receivetime,
  532. // detail);
  533. // LogUtil.info(agent.getFull_name() + " insert into
  534. // ps_virtual_project_status " + " project " + project
  535. // + " receivetime " + receivetime + " status " + status);
  536. // } catch (Exception e) {
  537. // // TODO Auto-generated catch block
  538. // e.printStackTrace();
  539. // }
  540. // }
  541. // public static List<String> getConfigFile(String directoryPath, String
  542. // directoryKey, String fileKey) {
  543. // List<String> list = new ArrayList<String>();
  544. // File baseFile = new File(directoryPath);
  545. // if (baseFile.isFile() || !baseFile.exists()) {
  546. // return list;
  547. // }
  548. // try {
  549. // File[] files = baseFile.listFiles();
  550. // SAXReader saxReader = new SAXReader();
  551. // for (File file : files) {
  552. // if (file.isDirectory() && file.getName().contains(directoryKey)) {
  553. // list.addAll(getConfigFile(file.getAbsolutePath(), directoryKey,
  554. // fileKey));
  555. // } else {
  556. // if (file.getName().contains(fileKey)) {
  557. // list.add(file.getAbsolutePath());
  558. // Document document = saxReader.read(file);
  559. // List<Element> devList = document.selectNodes("/root/portdev/devtype");
  560. // // LogUtil.info(file.getName());
  561. // // LogUtil.info(file.getName().indexOf(fileKey));
  562. // // LogUtil.info(file.getName().indexOf(".xml"));
  563. // String port = file.getName().substring(file.getName().indexOf(fileKey) +
  564. // fileKey.length(),
  565. // file.getName().indexOf(".xml"));
  566. // // LogUtil.info(port);
  567. // // LogUtil.info(file.getParentFile().getName());
  568. // // String building =
  569. // // file.getParentFile().getName().replace(directoryKey,
  570. // // "").substring(0, 10);
  571. // // String mac =
  572. // // file.getParentFile().getName().replace(directoryKey,
  573. // // "").substring(10);
  574. // String building = file.getParentFile().getName().replace(directoryKey,
  575. // "").split("-")[0];
  576. // String mac = file.getParentFile().getName().replace(directoryKey,
  577. // "").split("-")[1];
  578. // // LogUtil.info(building);
  579. // // LogUtil.info(mac);
  580. //
  581. // for (Element portdev : devList) {
  582. // String meter = portdev.attributeValue("meterid");
  583. // String info = port + "-" + portdev.element("addr").getText();
  584. // String point = building + "-" + mac + "-" + meter;
  585. // Constant.pointInfo.put(point, info);
  586. // // Iterator funcList =
  587. // // portdev.selectNodes("funset/funid").iterator();
  588. // // while (funcList.hasNext()) {
  589. // // Element func = (Element) funcList.next();
  590. // // String point = building + "-" + mac + "-" + meter
  591. // // + "." + func.getText();
  592. // // String info = port + "-" +
  593. // // portdev.element("addr").getText();
  594. // // Constant.pointInfo.put(point, info);
  595. // // LogUtil.info(meter + "." +
  596. // // func.getText());
  597. // // }
  598. // }
  599. //
  600. // }
  601. // }
  602. // }
  603. // } catch (Exception e) {
  604. // // TODO Auto-generated catch block
  605. // e.printStackTrace();
  606. // }
  607. //
  608. // return list;
  609. // }
  610. public synchronized static int getSeq(String point) {
  611. int month = Integer.valueOf(Constant.format_month(new Date()).substring(4));
  612. if (Constant.pMonth.containsKey(point) && (month == Constant.pMonth.get(point))) {
  613. int seq = Constant.pSeq.get(point) + 1;
  614. Constant.pMonth.put(point, month);
  615. Constant.pSeq.put(point, seq);
  616. return seq;
  617. }
  618. Constant.pMonth.put(point, month);
  619. Constant.pSeq.put(point, 1);
  620. return 1;
  621. }
  622. public synchronized static int getID() {
  623. if (PacketId > 65535) {
  624. PacketId = 1;
  625. } else {
  626. PacketId = PacketId + 1;
  627. }
  628. return PacketId;
  629. }
  630. public static class Millisecond {
  631. public static final long SECOND_1 = 1000L;
  632. public static final long SECOND_3 = 1000L * 3;
  633. public static final long SECOND_10 = 1000L * 10;
  634. public static final long SECOND_20 = 1000L * 20;
  635. public static final long SECOND_30 = 1000L * 30;
  636. public static final long MINUTE_1 = 1000L * 60 * 1;
  637. public static final long MINUTE_3 = 1000L * 60 * 3;
  638. public static final long MINUTE_5 = 1000L * 60 * 5;
  639. public static final long MINUTE_10 = 1000L * 60 * 10;
  640. public static final long MINUTE_15 = 1000L * 60 * 15;
  641. public static final long MINUTE_30 = 1000L * 60 * 30;
  642. public static final long MINUTE_60 = 1000L * 60 * 60;
  643. public static final long MINUTE_1440 = 1000L * 60 * 60 * 24;
  644. public static final long HOUR = 1000L * 60 * 60;
  645. public static final long DAY = 1000L * 60 * 60 * 24;
  646. }
  647. public static long getMillisecond(String request) {
  648. // TODO Auto-generated method stub
  649. try {
  650. if (request.contains("Second")) {
  651. return Integer.valueOf(request.replace(" ", "").replace("Second", "")) * Constant.Millisecond.SECOND_1;
  652. } else if (request.contains("second")) {
  653. return Integer.valueOf(request.replace(" ", "").replace("second", "")) * Constant.Millisecond.SECOND_1;
  654. } else if (request.contains("min")) {
  655. return Millisecond.MINUTE_1 * Integer.valueOf(request.replace("min", "").replace(" ", ""));
  656. } else {
  657. return Constant.Millisecond.SECOND_20;
  658. }
  659. } catch (Exception e) {
  660. return Constant.Millisecond.SECOND_20;
  661. }
  662. }
  663. public static void Insert_dy_pointlist(String building, String meter, Integer funcid, String system, String source,
  664. String address1, String ip_port, String address2, String address3, String address4, String collect_cycle,
  665. String data_type, String unit) {
  666. // TODO Auto-generated method stub
  667. try {
  668. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  669. MySQLUtil.Insert_dy_pointlist(Constant.Database, building, meter, funcid, system, source, address1,
  670. ip_port, address2, "", "", collect_cycle, data_type, unit);
  671. LogUtil.info(
  672. "insert into dy_pointlist " + "building " + building + " meter " + meter + " funcid " + funcid);
  673. } else {
  674. HBaseUtil.Insert_dy_pointlist(Constant.Database, building, meter, funcid, system, source, address1,
  675. ip_port, address2, "", "", collect_cycle, data_type, unit);
  676. LogUtil.info(agent.getFull_name() + " insert into dy_pointlist " + "building " + building + " meter "
  677. + meter + " funcid " + funcid);
  678. }
  679. } catch (Exception e) {
  680. // TODO Auto-generated catch block
  681. e.printStackTrace();
  682. }
  683. }
  684. // public static void AgentsBatchInsert(String db, List<Record>
  685. // wtdbrecordList) {
  686. // // TODO Auto-generated method stub
  687. //
  688. // try {
  689. // HBaseUtil.BatchInsert(db, wtdbrecordList);
  690. // } catch (Exception e) {
  691. // // TODO Auto-generated catch block
  692. // e.printStackTrace();
  693. // }
  694. //
  695. // }
  696. //
  697. // public static void AgentsBatchInsert_Set2(String db, PointSet ps) {
  698. // // TODO Auto-generated method stub
  699. //
  700. // try {
  701. // HBaseUtil.BatchInsert_Set2(db, ps);
  702. // } catch (Exception e) {
  703. // // TODO Auto-generated catch block
  704. // e.printStackTrace();
  705. // }
  706. // }
  707. //
  708. // public static void AgentsBatchInsert_Set3(String db, PointSet ps) {
  709. // // TODO Auto-generated method stub
  710. // try {
  711. // HBaseUtil.BatchInsert_Set3(db, ps);
  712. // } catch (Exception e) {
  713. // // TODO Auto-generated catch block
  714. // e.printStackTrace();
  715. // }
  716. // }
  717. //
  718. // public static void AgentsBatchInsert_Set1(String db, PointSet ps) {
  719. // // TODO Auto-generated method stub
  720. // try {
  721. // HBaseUtil.BatchInsert_Set1(db, ps);
  722. // } catch (Exception e) {
  723. // // TODO Auto-generated catch block
  724. // e.printStackTrace();
  725. // }
  726. // }
  727. public static Map<String, List<Integer>> GetDBPointList2Cache(String db, String tb, String building) {
  728. // TODO Auto-generated method stub
  729. Map<String, List<Integer>> dbPointList = new HashMap<String, List<Integer>>();
  730. try {
  731. Map<String, List<Integer>> pl = GetDBPointList(db, tb, building);
  732. for (Entry<String, List<Integer>> m : pl.entrySet()) {
  733. if (!dbPointList.containsKey(m.getKey())) {
  734. dbPointList.put(m.getKey(), new ArrayList<Integer>());
  735. }
  736. for (Integer f : m.getValue()) {
  737. if (!dbPointList.get(m.getKey()).contains(f)) {
  738. dbPointList.get(m.getKey()).add(f);
  739. }
  740. }
  741. }
  742. } catch (Exception e) {
  743. // TODO Auto-generated catch block
  744. e.printStackTrace();
  745. }
  746. return dbPointList;
  747. }
  748. public static void loadDB2Cache_dy_pointlist() {
  749. // TODO Auto-generated method stub
  750. try {
  751. Constant.LoadDB2Cache_dy_pointlist(Constant.Database, "dy_pointlist");
  752. } catch (Exception e) {
  753. // TODO Auto-generated catch block
  754. e.printStackTrace();
  755. }
  756. }
  757. public static Map<String, String> ps_physical_status(String db, String tb) throws Exception {
  758. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  759. return MySQLUtil.ps_physical_status(db, tb);
  760. } else {
  761. return HBaseUtil.ps_physical_status(db, tb);
  762. }
  763. }
  764. public static Map<String, String> ps_virtual_point_status(String db, String tb) throws Exception {
  765. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  766. return MySQLUtil.ps_virtual_point_status(db, tb);
  767. } else {
  768. return HBaseUtil.ps_virtual_point_status(db, tb);
  769. }
  770. }
  771. public static Map<String, String> ps_virtual_meter_status(String db, String tb) throws Exception {
  772. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  773. return MySQLUtil.ps_virtual_meter_status(db, tb);
  774. } else {
  775. return HBaseUtil.ps_virtual_meter_status(db, tb);
  776. }
  777. }
  778. public static Map<String, String> ps_virtual_project_status(String db, String tb) throws Exception {
  779. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  780. return MySQLUtil.ps_virtual_project_status(db, tb);
  781. } else {
  782. return HBaseUtil.ps_virtual_project_status(db, tb);
  783. }
  784. }
  785. public static void LoadDB2Cache_dy_pointlist(String db, String tb) throws Exception {
  786. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  787. MySQLUtil.LoadDB2Cache_dy_pointlist(db, tb);
  788. } else {
  789. HBaseUtil.LoadDB2Cache_dy_pointlist(db, tb);
  790. }
  791. }
  792. public static void LoadDB2Cache_ps_physical_status(String db, String tb) throws Exception {
  793. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  794. MySQLUtil.LoadDB2Cache_ps_physical_status(db, tb);
  795. } else {
  796. HBaseUtil.LoadDB2Cache_ps_physical_status(db, tb);
  797. }
  798. }
  799. public static void LoadDB2Cache_ps_virtual_point_status(String db, String tb) throws Exception {
  800. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  801. MySQLUtil.LoadDB2Cache_ps_virtual_point_status(db, tb);
  802. } else {
  803. HBaseUtil.LoadDB2Cache_ps_virtual_point_status(db, tb);
  804. }
  805. }
  806. public static void LoadDB2Cache_ps_virtual_meter_status(String db, String tb) throws Exception {
  807. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  808. MySQLUtil.LoadDB2Cache_ps_virtual_meter_status(db, tb);
  809. } else {
  810. HBaseUtil.LoadDB2Cache_ps_virtual_meter_status(db, tb);
  811. }
  812. }
  813. public static void LoadDB2Cache_ps_virtual_project_status(String db, String tb) throws Exception {
  814. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  815. MySQLUtil.LoadDB2Cache_ps_virtual_project_status(db, tb);
  816. } else {
  817. HBaseUtil.LoadDB2Cache_ps_virtual_project_status(db, tb);
  818. }
  819. }
  820. public static Map<String, List<Integer>> GetDBPointList(String db, String tb, String building) throws Exception {
  821. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  822. return MySQLUtil.GetDBPointList(db, tb, building);
  823. } else {
  824. return HBaseUtil.GetDBPointList(db, tb, building);
  825. }
  826. }
  827. public static void Getset(String db, String tb, String building, String meter, long funcid, String query_from,
  828. String query_to) throws Exception {
  829. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  830. MySQLUtil.Getset(db, tb, building, meter, funcid, query_from, query_to);
  831. } else {
  832. HBaseUtil.Getset(db, tb, building, meter, funcid, query_from, query_to);
  833. }
  834. }
  835. public static void Getset_present(String db, String tb, String building, String meter, long funcid)
  836. throws Exception {
  837. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  838. MySQLUtil.Getset_present(db, tb, building, meter, funcid);
  839. } else {
  840. HBaseUtil.Getset_present(db, tb, building, meter, funcid);
  841. }
  842. }
  843. public static void CreateDB(String DB) throws Exception {
  844. try {
  845. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  846. MySQLUtil.CreateDB(DB);
  847. } else {
  848. HBaseUtil.CreateDB(DB);
  849. }
  850. } catch (Exception e) {
  851. e.printStackTrace();
  852. }
  853. }
  854. public static boolean tableExist(String DBName, String tableName) throws Exception {
  855. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  856. return MySQLUtil.tableExist(DBName, tableName);
  857. } else {
  858. return HBaseUtil.tableExist(DBName, tableName);
  859. }
  860. }
  861. public static void CreateTable(String DB, String tableName) throws Exception {
  862. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  863. MySQLUtil.CreateTable(DB, tableName);
  864. } else {
  865. HBaseUtil.CreateTable(DB, tableName);
  866. }
  867. }
  868. public static void CreateTable_present(String DB, String tableName) throws Exception {
  869. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  870. MySQLUtil.CreateTable_present(DB, tableName);
  871. } else {
  872. HBaseUtil.CreateTable_present(DB, tableName);
  873. }
  874. }
  875. public static void CreateTable_set(String DB, String tableName) throws Exception {
  876. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  877. MySQLUtil.CreateTable_set(DB, tableName);
  878. } else {
  879. HBaseUtil.CreateTable_set(DB, tableName);
  880. }
  881. }
  882. public static void CreateTable_setpresent(String DB, String tableName) throws Exception {
  883. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  884. MySQLUtil.CreateTable_setpresent(DB, tableName);
  885. } else {
  886. HBaseUtil.CreateTable_setpresent(DB, tableName);
  887. }
  888. }
  889. public static void CreateTable_fjd_0_buildingcomputetime(String DB, String tableName) throws Exception {
  890. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  891. MySQLUtil.CreateTable_fjd_0_buildingcomputetime(DB, tableName);
  892. } else {
  893. HBaseUtil.CreateTable_fjd_0_buildingcomputetime(DB, tableName);
  894. }
  895. }
  896. public static void CreateTable_dy_pointlist(String DB, String tableName) throws Exception {
  897. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  898. MySQLUtil.CreateTable_dy_pointlist(DB, tableName);
  899. } else {
  900. HBaseUtil.CreateTable_dy_pointlist(DB, tableName);
  901. }
  902. }
  903. public static void CreateTable_ps_physical_status(String DB, String tableName) throws Exception {
  904. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  905. MySQLUtil.CreateTable_ps_physical_status(DB, tableName);
  906. } else {
  907. HBaseUtil.CreateTable_ps_physical_status(DB, tableName);
  908. }
  909. }
  910. public static void CreateTable_ps_physical_log(String DB, String tableName) throws Exception {
  911. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  912. MySQLUtil.CreateTable_ps_physical_log(DB, tableName);
  913. } else {
  914. HBaseUtil.CreateTable_ps_physical_log(DB, tableName);
  915. }
  916. }
  917. public static void CreateTable_ps_virtual_point_status(String DB, String tableName) throws Exception {
  918. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  919. MySQLUtil.CreateTable_ps_virtual_point_status(DB, tableName);
  920. } else {
  921. HBaseUtil.CreateTable_ps_virtual_point_status(DB, tableName);
  922. }
  923. }
  924. public static void CreateTable_ps_virtual_point_log(String DB, String tableName) throws Exception {
  925. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  926. MySQLUtil.CreateTable_ps_virtual_point_log(DB, tableName);
  927. } else {
  928. HBaseUtil.CreateTable_ps_virtual_point_log(DB, tableName);
  929. }
  930. }
  931. public static void CreateTable_ps_virtual_meter_status(String DB, String tableName) throws Exception {
  932. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  933. MySQLUtil.CreateTable_ps_virtual_meter_status(DB, tableName);
  934. } else {
  935. HBaseUtil.CreateTable_ps_virtual_meter_status(DB, tableName);
  936. }
  937. }
  938. public static void CreateTable_ps_virtual_meter_log(String DB, String tableName) throws Exception {
  939. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  940. MySQLUtil.CreateTable_ps_virtual_meter_log(DB, tableName);
  941. } else {
  942. HBaseUtil.CreateTable_ps_virtual_meter_log(DB, tableName);
  943. }
  944. }
  945. public static void CreateTable_ps_virtual_project_status(String DB, String tableName) throws Exception {
  946. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  947. MySQLUtil.CreateTable_ps_virtual_project_status(DB, tableName);
  948. } else {
  949. HBaseUtil.CreateTable_ps_virtual_project_status(DB, tableName);
  950. }
  951. }
  952. public static void CreateTable_ps_virtual_project_log(String DB, String tableName) throws Exception {
  953. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  954. MySQLUtil.CreateTable_ps_virtual_project_log(DB, tableName);
  955. } else {
  956. HBaseUtil.CreateTable_ps_virtual_project_log(DB, tableName);
  957. }
  958. }
  959. public static void Insert_fjd_0_buildingcomputetime(String DB, String building, String compute_time,
  960. String first_compute_time) throws Exception {
  961. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  962. MySQLUtil.Insert_fjd_0_buildingcomputetime(DB, building, compute_time, first_compute_time);
  963. } else {
  964. HBaseUtil.Insert_fjd_0_buildingcomputetime(DB, building, compute_time, first_compute_time);
  965. }
  966. }
  967. public static void Insert_ps_physical_status(String DB, String project, String address_1, String address_2,
  968. String address_3, String address_4, String status, String receivetime, String detail) throws Exception {
  969. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  970. MySQLUtil.Insert_ps_physical_status(DB, project, address_1, address_2, address_3, address_4, status,
  971. receivetime, detail);
  972. } else {
  973. HBaseUtil.Insert_ps_physical_status(DB, project, address_1, address_2, address_3, address_4, status,
  974. receivetime, detail);
  975. }
  976. }
  977. public static void Insert_ps_physical_log(String DB, String project, String address_1, String address_2,
  978. String address_3, String address_4, String receivetime, String function) throws Exception {
  979. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  980. MySQLUtil.Insert_ps_physical_log(DB, project, address_1, address_2, address_3, address_4, receivetime,
  981. function);
  982. } else {
  983. HBaseUtil.Insert_ps_physical_log(DB, project, address_1, address_2, address_3, address_4, receivetime,
  984. function);
  985. }
  986. }
  987. public static void Insert_ps_virtual_point_status(String DB, String project, String meter, long funcid,
  988. String updown, String status, String receivetime, String detail) throws Exception {
  989. if (receivetime == null || Constant.parse(receivetime).getTime() == 0) {
  990. receivetime = Constant.format(new Date());
  991. }
  992. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  993. MySQLUtil.Insert_ps_virtual_point_status(DB, project, meter, funcid, updown, status, receivetime, detail);
  994. } else {
  995. HBaseUtil.Insert_ps_virtual_point_status(DB, project, meter, funcid, updown, status, receivetime, detail);
  996. }
  997. }
  998. public static void Insert_ps_virtual_point_log(String DB, String project, String meter, long funcid, String updown,
  999. String receivetime, long seq, String function, String feedback) throws Exception {
  1000. if (receivetime == null || Constant.parse(receivetime).getTime() == 0) {
  1001. receivetime = Constant.format(new Date());
  1002. }
  1003. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1004. MySQLUtil.Insert_ps_virtual_point_log(DB, project, meter, funcid, updown, receivetime, seq, function,
  1005. feedback);
  1006. } else {
  1007. HBaseUtil.Insert_ps_virtual_point_log(DB, project, meter, funcid, updown, receivetime, seq, function,
  1008. feedback);
  1009. }
  1010. }
  1011. public static void Insert_ps_virtual_meter_status(String DB, String project, String meter, String updown,
  1012. String status, String receivetime, String detail) throws Exception {
  1013. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1014. MySQLUtil.Insert_ps_virtual_meter_status(DB, project, meter, updown, status, receivetime, detail);
  1015. } else {
  1016. HBaseUtil.Insert_ps_virtual_meter_status(DB, project, meter, updown, status, receivetime, detail);
  1017. }
  1018. }
  1019. public static void Insert_ps_virtual_meter_log(String DB, String project, String meter, String updown,
  1020. String receivetime, String function) throws Exception {
  1021. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1022. MySQLUtil.Insert_ps_virtual_meter_log(DB, project, meter, updown, receivetime, function);
  1023. } else {
  1024. HBaseUtil.Insert_ps_virtual_meter_log(DB, project, meter, updown, receivetime, function);
  1025. }
  1026. }
  1027. public static void Insert_ps_virtual_project_status(String DB, String project, String status, String receivetime,
  1028. String detail) throws Exception {
  1029. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1030. MySQLUtil.Insert_ps_virtual_project_status(DB, project, status, receivetime, detail);
  1031. } else {
  1032. HBaseUtil.Insert_ps_virtual_project_status(DB, project, status, receivetime, detail);
  1033. }
  1034. }
  1035. public static void Insert_ps_virtual_project_log(String DB, String project, String receivetime, String function)
  1036. throws Exception {
  1037. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1038. MySQLUtil.Insert_ps_virtual_project_log(DB, project, receivetime, function);
  1039. } else {
  1040. HBaseUtil.Insert_ps_virtual_project_log(DB, project, receivetime, function);
  1041. }
  1042. }
  1043. public static void MsgBatchInsert(String DB, List<RecordMsg> dataList) throws Exception {
  1044. LogUtil.warn("MsgBatchInsert Start, time:" + new Date().toString() + " ,size:" + dataList.size());
  1045. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1046. MySQLUtil.MsgBatchInsert(DB, dataList);
  1047. } else {
  1048. HBaseUtil.MsgBatchInsert(DB, dataList);
  1049. }
  1050. LogUtil.warn("MsgBatchInsert End, time:" + new Date().toString() + " ,size:" + dataList.size());
  1051. }
  1052. public static void MsgBatchDelte(String DB, List<RecordMsg> dataList) throws Exception {
  1053. LogUtil.warn("MsgBatchDelte Start, time:" + new Date().toString() + " ,size:" + dataList.size());
  1054. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1055. MySQLUtil.MsgBatchDelte(DB, dataList);
  1056. } else {
  1057. // HBaseUtil.MsgBatchDelte(DB, dataList);
  1058. }
  1059. LogUtil.warn("MsgBatchInsert End, time:" + new Date().toString() + " ,size:" + dataList.size());
  1060. }
  1061. public static void BatchInsert(String DB, List<Record> dataList) throws Exception {
  1062. LogUtil.warn("BatchInsert Start, time:" + new Date().toString() + " ,size:" + dataList.size());
  1063. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1064. MySQLUtil.BatchInsert(DB, dataList);
  1065. } else {
  1066. HBaseUtil.BatchInsert(DB, dataList);
  1067. }
  1068. LogUtil.warn("BatchInsert End, time:" + new Date().toString() + " ,size:" + dataList.size());
  1069. }
  1070. public static void BatchInsertUpload(List<Record> dataList) throws Exception {
  1071. LogUtil.warn("BatchInsertUpload Start, time:" + new Date().toString() + " ,size:" + dataList.size());
  1072. if (Constant.DbConnection.containsKey("Upload-Mysql") && Constant.DbConnection.get("Upload-Mysql") != null) {
  1073. EntityMysql entityMysql = new EntityMysql();
  1074. entityMysql = (EntityMysql) Constant.DbConnection.get("Upload-Mysql");
  1075. MySQLUtil.BatchInsertUpload(entityMysql.UploadDatabase, Arrays.asList(entityMysql.UploadTable.split(",")),
  1076. dataList);
  1077. } else if (Constant.DbConnection.containsKey("Upload-Hbase")
  1078. && Constant.DbConnection.get("Upload-Hbase") != null) {
  1079. EntityHbase entityHbase = new EntityHbase();
  1080. entityHbase = (EntityHbase) Constant.DbConnection.get("Upload-Hbase");
  1081. HBaseUtil.BatchInsertUpload(entityHbase.UploadDatabase, Arrays.asList(entityHbase.UploadTable.split(",")),
  1082. dataList);
  1083. }
  1084. LogUtil.warn("BatchInsertUpload End, time:" + new Date().toString() + " ,size:" + dataList.size());
  1085. }
  1086. public static void BatchInsert_Set1(String DB, PointSet ps) throws Exception {
  1087. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1088. MySQLUtil.BatchInsert_Set1(DB, ps);
  1089. } else {
  1090. HBaseUtil.BatchInsert_Set1(DB, ps);
  1091. }
  1092. }
  1093. public static void BatchInsert_Set2(String DB, PointSet ps) throws Exception {
  1094. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1095. MySQLUtil.BatchInsert_Set2(DB, ps);
  1096. } else {
  1097. HBaseUtil.BatchInsert_Set2(DB, ps);
  1098. }
  1099. }
  1100. public static void BatchInsert_Set3(String DB, PointSet ps) throws Exception {
  1101. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1102. MySQLUtil.BatchInsert_Set3(DB, ps);
  1103. } else {
  1104. HBaseUtil.BatchInsert_Set3(DB, ps);
  1105. }
  1106. }
  1107. public static Date getOffSetTime(Record record) {
  1108. // TODO Auto-generated method stub
  1109. if (Constant.BuildingOffset.containsKey(record.buildingSign)
  1110. && Constant.BuildingOffset.get(record.buildingSign)) {
  1111. return new Date(record.receivetime.getTime() + 8 * Constant.Millisecond.HOUR);
  1112. }
  1113. return record.receivetime;
  1114. }
  1115. public static int getFunctionConv(Record record) {
  1116. // TODO Auto-generated method stub
  1117. if (Constant.FunctionConv.containsKey(record.funcID) && Constant.FunctionConv.get(record.funcID) != null) {
  1118. return Integer.valueOf(Constant.FunctionConv.get(record.funcID));
  1119. }
  1120. return record.funcID;
  1121. }
  1122. public static void CreateTable_upload() throws Exception {
  1123. if (Constant.DbConnection.containsKey("Upload-Mysql") && Constant.DbConnection.get("Upload-Mysql") != null) {
  1124. EntityMysql entityMysql = new EntityMysql();
  1125. entityMysql = (EntityMysql) Constant.DbConnection.get("Upload-Mysql");
  1126. MySQLUtil.CreateUploadDB(entityMysql.UploadDatabase);
  1127. MySQLUtil.CreateTable_upload(entityMysql.UploadDatabase, Arrays.asList(entityMysql.UploadTable.split(",")));
  1128. } else if (Constant.DbConnection.containsKey("Upload-Hbase")
  1129. && Constant.DbConnection.get("Upload-Hbase") != null) {
  1130. EntityHbase entityHbase = new EntityHbase();
  1131. entityHbase = (EntityHbase) Constant.DbConnection.get("Upload-Hbase");
  1132. HBaseUtil.CreateUploadDB(entityHbase.UploadDatabase);
  1133. HBaseUtil.CreateTable_upload(entityHbase.UploadDatabase, Arrays.asList(entityHbase.UploadTable.split(",")));
  1134. }
  1135. }
  1136. public static void CreateTable_detail(String DB, String tableName) throws Exception {
  1137. // TODO Auto-generated method stub
  1138. if (Constant.DbConnection.containsKey("Db-Mysql") && Constant.DbConnection.get("Db-Mysql") != null) {
  1139. MySQLUtil.CreateTable_detail(DB, tableName);
  1140. } else {
  1141. HBaseUtil.CreateTable_detail(DB, tableName);
  1142. }
  1143. }
  1144. public static String unicodeDecode(String string) {
  1145. String result = string;
  1146. try {
  1147. LogUtil.info(new String(string.getBytes("gbk")));
  1148. LogUtil.info(new String(string.getBytes("utf-8"), "gbk"));
  1149. LogUtil.info(new String(string.getBytes("iso-8859-1"), "gbk"));
  1150. LogUtil.info(new String(string.getBytes("gb2312"), "gbk"));
  1151. LogUtil.info(new String(string.getBytes("utf-8")));
  1152. LogUtil.info(new String(string.getBytes("gbk"), "utf-8"));
  1153. LogUtil.info(new String(string.getBytes("iso-8859-1"), "utf-8"));
  1154. LogUtil.info(new String(string.getBytes("gb2312"), "utf-8"));
  1155. LogUtil.info(new String(string.getBytes("iso-8859-1")));
  1156. LogUtil.info(new String(string.getBytes("gbk"), "iso-8859-1"));
  1157. LogUtil.info(new String(string.getBytes("utf-8"), "iso-8859-1"));
  1158. LogUtil.info(new String(string.getBytes("gb2312"), "iso-8859-1"));
  1159. LogUtil.info(new String(string.getBytes("gb2312")));
  1160. LogUtil.info(new String(string.getBytes("gbk"), "gb2312"));
  1161. LogUtil.info(new String(string.getBytes("utf-8"), "gb2312"));
  1162. LogUtil.info(new String(string.getBytes("iso-8859-1"), "gb2312"));
  1163. // result = new String(string.getBytes("ISO-8859-1"), "UTF-8");
  1164. result = new String(string.getBytes("GB2312"), "8859_1");
  1165. } catch (UnsupportedEncodingException e) {
  1166. // TODO Auto-generated catch block
  1167. e.printStackTrace();
  1168. }
  1169. return result;
  1170. // Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
  1171. // Matcher matcher = pattern.matcher(string);
  1172. // char ch;
  1173. // while (matcher.find()) {
  1174. // ch = (char) Integer.parseInt(matcher.group(2), 16);
  1175. // string = string.replace(matcher.group(1), ch + "");
  1176. // }
  1177. // return string;
  1178. }
  1179. // 相似度计算
  1180. public static double xiangsidu(String a, String b) {
  1181. // 相似度公式:1 - 最小编辑距离/两个串中较长的长度
  1182. int n = a.length();
  1183. int m = b.length();
  1184. if (n < 1 && m < 1)
  1185. return 0; // 两个空串
  1186. return 1 - minEditDist(a, b) / Math.max(n, m);
  1187. }
  1188. public static String xiangsidu(String s, List<String> m) {
  1189. String result = s;
  1190. Double xiangsi = 0d;
  1191. for (int i = 0; i < m.size(); i++) {
  1192. if (xiangsidu(s, m.get(i)) > xiangsi) {
  1193. result = m.get(i);
  1194. xiangsi = xiangsidu(s, m.get(i));
  1195. }
  1196. if (xiangsi == 1) {
  1197. break;
  1198. }
  1199. }
  1200. return result;
  1201. }
  1202. // 最小编辑距离计算
  1203. public static double minEditDist(String a, String b) {
  1204. int n = a.length();
  1205. int m = b.length();
  1206. if (n < 1 || m < 1)
  1207. return (n + m) * 1.00; // 两个空串
  1208. double[][] d = new double[n + 1][m + 1];
  1209. double cost;
  1210. for (int i = 0; i <= n; ++i)
  1211. d[i][0] = i;
  1212. for (int i = 0; i <= m; ++i)
  1213. d[0][i] = i;
  1214. for (int i = 1; i <= n; i++) {
  1215. for (int j = 1; j <= m; j++) {
  1216. if (a.charAt(i - 1) == b.charAt(j - 1))
  1217. cost = 0;
  1218. else
  1219. cost = 1;
  1220. d[i][j] = Minimum(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
  1221. }
  1222. }
  1223. return d[n][m];
  1224. }
  1225. private static double Minimum(double a, double b, double c) {
  1226. double mi = a;
  1227. if (b < mi) {
  1228. mi = b;
  1229. }
  1230. if (c < mi) {
  1231. mi = c;
  1232. }
  1233. return mi;
  1234. }
  1235. public static List<String> xuzhousuning() {
  1236. List<String> result = new ArrayList<String>();
  1237. result.add("7配2#变压器");
  1238. result.add("7配1#变压器");
  1239. result.add("10配1#变压器");
  1240. result.add("10配2#变压器");
  1241. result.add("8配1#变压器");
  1242. result.add("8配2#变压器");
  1243. result.add("9配1#变压器");
  1244. result.add("9配2#变压器");
  1245. result.add("11配1#变压器");
  1246. result.add("11配2#变压器");
  1247. result.add("1905D_低压进线柜");
  1248. result.add("1907D_无功自动补偿电容柜");
  1249. result.add("1910D_母联");
  1250. result.add("1911D-1_一般照明1");
  1251. result.add("1911D-2_备用");
  1252. result.add("1912D-1_一般动力1");
  1253. result.add("1912D-2_备用");
  1254. result.add("1913D-1_M3区货梯1");
  1255. result.add("1913D-2_C塔楼照明");
  1256. result.add("1913D-3_变电所用电(主)");
  1257. result.add("1913D-4_会所一般动力");
  1258. result.add("1913D-5_D塔楼消防动力(常)");
  1259. result.add("1913D-6_预留泛光照明");
  1260. result.add("1914D-1_M3乘客电梯1(常)");
  1261. result.add("1914D-2_M3乘客电梯2(常)");
  1262. result.add("1914D-3_M3乘客电梯4(常)");
  1263. result.add("1914D-4_M3乘客电梯5(常)");
  1264. result.add("1914D-5_C塔楼进线客梯总电源(常)");
  1265. result.add("1914D-6_CDE生活水泵房(常)");
  1266. result.add("1914D-7_备用");
  1267. result.add("1915D-1_C塔楼客梯总电源(常)");
  1268. result.add("1915D-2_超市3");
  1269. result.add("1915D-3_M3乘客电梯3(备)");
  1270. result.add("1916D-1_D塔楼消防总电源(常)");
  1271. result.add("1916D-2_备用");
  1272. result.add("1916D-3_备用");
  1273. result.add("1917D-1_消防动力1(常)");
  1274. result.add("1917D-2_备用");
  1275. result.add("1918D-1_消防动力2(备)电梯");
  1276. result.add("1918D-2_备用");
  1277. result.add("1919D-1_会所应急照明(常)");
  1278. result.add("1919D-2_备用");
  1279. result.add("1919D-3_备用");
  1280. result.add("1919D-4_消防动力3(备)");
  1281. result.add("1919D-5_商业应急照明(备)");
  1282. result.add("1919D-6_B2充电桩");
  1283. result.add("1920D-1_C塔楼公共应急照明(备)");
  1284. result.add("1920D-2_C塔楼消防动力(常)");
  1285. result.add("1920D-3_备用C塔楼消防电梯");
  1286. result.add("1920D-4_C塔楼消防电梯备");
  1287. result.add("1921D-1_D塔楼消控室");
  1288. result.add("1921D-2_商业2变电所(常)");
  1289. result.add("1921D-3_M3消防电梯(备)");
  1290. result.add("1921D-4_D塔楼公共应急照明");
  1291. result.add("1921D-5_穹顶膜(备)");
  1292. result.add("1921D-6_D塔楼消防电梯总电源(常)");
  1293. result.add("2005D_低压进线柜");
  1294. result.add("2007D_无功自动补偿电容柜");
  1295. result.add("2010D-1_一般照明2");
  1296. result.add("2010D-2_备用");
  1297. result.add("2011D-1_一般动力2");
  1298. result.add("2011D-2_备用");
  1299. result.add("2012D-1_会所一般照明");
  1300. result.add("2012D-2_D塔照明");
  1301. result.add("2012D-3_M3区货梯2");
  1302. result.add("2012D-4_M3区扶梯");
  1303. result.add("2012D-5_变电所用电(备)");
  1304. result.add("2012D-6_D塔楼消防动力(备)");
  1305. result.add("2012D-7_备用");
  1306. result.add("2013D-1_M3乘客电梯1(备)");
  1307. result.add("2013D-2_M3乘客电梯2(备)");
  1308. result.add("2013D-3_M3乘客电梯4(备)");
  1309. result.add("2013D-4_M3乘客电梯5(备)");
  1310. result.add("2013D-5_C塔进线室电源");
  1311. result.add("2013D-6_CDE生活水泵房(备)");
  1312. result.add("2013D-7_备用");
  1313. result.add("2014D-1_C塔楼客梯总电源(备)");
  1314. result.add("2014D-2_备用");
  1315. result.add("2014D-3_M3乘客电梯3(常)");
  1316. result.add("2015D-1_D塔楼客梯总电源(备)");
  1317. result.add("2015D-2_超市");
  1318. result.add("2015D-3_备用");
  1319. result.add("2016D-1_消防动力1(备)");
  1320. result.add("2016D-2_备用");
  1321. result.add("2017D-1_消防动力2(常)电梯");
  1322. result.add("2017D-2_备用");
  1323. result.add("2018D-1_会所应急照明(备)");
  1324. result.add("2018D-2_备用");
  1325. result.add("2018D-3_备用");
  1326. result.add("2018D-4_消防动力3(常)");
  1327. result.add("2018D-5_商业应急照明(常)");
  1328. result.add("2018D-6_备用+商铺");
  1329. result.add("2019D-1_C塔楼公共应急照明(常)");
  1330. result.add("2019D-2_C塔楼消防动力(备)");
  1331. result.add("2019D-3_备用");
  1332. result.add("2019D-4_C塔楼消防电梯总电源(常)");
  1333. result.add("2020D-1_D塔楼消控室(备)");
  1334. result.add("2020D-2_商业2变电所(备)");
  1335. result.add("2020D-3_M3消防电梯(常)");
  1336. result.add("2020D-4_穹顶膜(常)");
  1337. result.add("2020D-5_D塔楼公共应急照明(常)");
  1338. result.add("2020D-6_D塔楼消防电梯总电源(备)");
  1339. result.add("1505D_低压进线柜");
  1340. result.add("1507D_无功自动补偿电容柜");
  1341. result.add("1510D_低压母联柜");
  1342. result.add("1511D-1_M4区一般照明1");
  1343. result.add("1511D-2_备用");
  1344. result.add("1512D-1_M4区一般照明3");
  1345. result.add("1512D-2_备用");
  1346. result.add("1513D-1_M4区一般动力1");
  1347. result.add("1513D-2_备用");
  1348. result.add("1514D-1_冷冻机房控制柜1");
  1349. result.add("1514D-2_备用");
  1350. result.add("1515D-1_M4区扶梯");
  1351. result.add("1515D-2_备用");
  1352. result.add("1515D-3_变电所用电(主)");
  1353. result.add("1515D-4_电制冷水冷式冷水机组1");
  1354. result.add("1515D-5_备用");
  1355. result.add("1516D-1_M4区客梯1(常)");
  1356. result.add("1516D-2_备用");
  1357. result.add("1516D-3_M4区客梯2(备)");
  1358. result.add("1516D-4_F塔楼电梯");
  1359. result.add("1516D-5_公寓生活水泵房(常)");
  1360. result.add("1516D-6_备用");
  1361. result.add("1517D-1_M4区消防动力(备)");
  1362. result.add("1517D-2_备用");
  1363. result.add("1518D-1_M4区变电所(常)+8#AT");
  1364. result.add("1518D-2_B楼消控室(常)");
  1365. result.add("1518D-3_百货消防客梯(常)");
  1366. result.add("1518D-4_M4区应急照明(常)");
  1367. result.add("1518D-5_影院空调1(常)");
  1368. result.add("1518D-6_影院空调2(备)");
  1369. result.add("1519D-1_商业消控室(常)");
  1370. result.add("1519D-2_影院空调3(常)");
  1371. result.add("1519D-3_KTV 空调1(常)");
  1372. result.add("1519D-4_KTV 空调2(备)");
  1373. result.add("1519D-5_备用");
  1374. result.add("1605D_低压进线柜");
  1375. result.add("1607D_无功自动补偿电容柜");
  1376. result.add("1610D-1_M4区一般照明2");
  1377. result.add("1610D-2_备用");
  1378. result.add("1611D-1_M4区一般照明4");
  1379. result.add("1611D-2_备用");
  1380. result.add("1612D-1_M4区一般动力2");
  1381. result.add("1612D-2_备用");
  1382. result.add("1613D-1_冷冻机房控制柜1");
  1383. result.add("1613D-2_备用");
  1384. result.add("1614D-1_变电所用电(备)");
  1385. result.add("1614D-2_电制冷水冷式冷水机组2");
  1386. result.add("1614D-3_LED屏(3F)");
  1387. result.add("1614D-4_备用");
  1388. result.add("1615D-1_M4区客梯1(备)");
  1389. result.add("1615D-2_备用");
  1390. result.add("1615D-3_M4区客梯2(常)");
  1391. result.add("1615D-4_F塔M4TAT3");
  1392. result.add("1615D-5_公寓生活水泵房(备)");
  1393. result.add("1615D-6_备用");
  1394. result.add("1616D-1_M4区消防动力(常)");
  1395. result.add("1616D-2_备用");
  1396. result.add("1617D-1_M4区变电所(备)");
  1397. result.add("1617D-2_B楼消控室(备)");
  1398. result.add("1617D-3_百货消防客梯(备)");
  1399. result.add("1617D-4_M4区应急照明(备)");
  1400. result.add("1617D-5_影院空调1(备)");
  1401. result.add("1617D-6_影院空调2(常)");
  1402. result.add("1618D-1_商业消控室(备)");
  1403. result.add("1618D-2_影院空调3(备)");
  1404. result.add("1618D-3_KTV 空调1(备)");
  1405. result.add("1618D-4_KTV 空调2(常)");
  1406. result.add("1618D-5_备用");
  1407. result.add("2103D_低压进线柜");
  1408. result.add("2104D_无功自动补偿电容柜");
  1409. result.add("2107D-1_冰机2号");
  1410. result.add("2107D-2_备用");
  1411. result.add("2108D-1_冰机1号");
  1412. result.add("2108D-2_变电所用电(主)");
  1413. result.add("2109D-1_基载冷水机组");
  1414. result.add("2109D-2_备用");
  1415. result.add("2110D-1_发电机");
  1416. result.add("2110D-2_市电");
  1417. result.add("2111D-1_办公+商业冷冻机房控柜电源1");
  1418. result.add("2111D-2_备用");
  1419. result.add("2203D_低压进线柜");
  1420. result.add("2204D_无功自动补偿电容柜");
  1421. result.add("2207D-1_冰机3号");
  1422. result.add("2207D-2_备用");
  1423. result.add("2208D-1_冰机4号");
  1424. result.add("2208D-2_变电所用电(主)");
  1425. result.add("2209D-1_冷冻机房控柜电源2");
  1426. result.add("2209D-2_备用");
  1427. result.add("2110D_母联");
  1428. result.add("1705D_低压进线柜");
  1429. result.add("1706D_无功自动补偿电容柜");
  1430. result.add("1707D_低压母联柜");
  1431. result.add("1710D-1_一般照明1");
  1432. result.add("1710D-2_备用");
  1433. result.add("1711D-1_一般动力1");
  1434. result.add("1711D-2_备用");
  1435. result.add("1712D-1_扶梯");
  1436. result.add("1712D-2_备用");
  1437. result.add("1712D-3_变电所用电(主)");
  1438. result.add("1713D-1_备用");
  1439. result.add("1713D-2_预留泛光照明");
  1440. result.add("1713D-3_商业1B3层水动力(备)");
  1441. result.add("1713D-4_E塔楼客梯总电源(常)");
  1442. result.add("1714D-1_消防动力1(常)");
  1443. result.add("1714D-2_备用");
  1444. result.add("1714D-3_M3乘客电梯2(备)");
  1445. result.add("1715D-1_F-L117 E-JX-AT(客梯)");
  1446. result.add("1715D-2_应急照明(备)");
  1447. result.add("1715D-3_消防动力3(备)电梯");
  1448. result.add("1715D-4_消防动力2(备)");
  1449. result.add("1716D-1_M3区消防电梯(备)");
  1450. result.add("1716D-2_商业1变电所(备)");
  1451. result.add("1716D-3_备用");
  1452. result.add("1716D-4_消防脑动力4(常)");
  1453. result.add("1716D-5_E塔楼总消防动力(常)");
  1454. result.add("1716D-6_备用");
  1455. result.add("1717D-1_备用");
  1456. result.add("1717D-2_E塔楼消防电梯总电源(常)");
  1457. result.add("1718D-1_备用");
  1458. result.add("1718D-2_E塔楼公共应急照明(备)");
  1459. result.add("1718D-3_备用");
  1460. result.add("1718D-4_备用");
  1461. result.add("1718D-5_D塔楼F4插座");
  1462. result.add("1805D_低压进线柜");
  1463. result.add("1807D_无功自动补偿电容柜");
  1464. result.add("1809D-1_一般照明2");
  1465. result.add("1809D-2_备用");
  1466. result.add("1810D-1_一般动力2");
  1467. result.add("1810D-2_备用");
  1468. result.add("1811D-1_E塔楼照明");
  1469. result.add("1811D-2_备用");
  1470. result.add("1811D-3_变电所用电(备)");
  1471. result.add("1811D-4_备用");
  1472. result.add("1811D-5_备用");
  1473. result.add("1812D-1_备用");
  1474. result.add("1812D-2_备用");
  1475. result.add("1812D-3_商业1B3层水动力(常)");
  1476. result.add("1812D-4_E塔楼客梯总电源(备)");
  1477. result.add("1813D-1_消防动力1(备)");
  1478. result.add("1813D-2_备用");
  1479. result.add("1813D-3_M3乘客电梯2(常)");
  1480. result.add("1814D-1_F-L217 E-JX-AT(客梯)");
  1481. result.add("1814D-2_应急照明(常)");
  1482. result.add("1814D-3_消防动力3(常)");
  1483. result.add("1814D-4_消防动力2(常)");
  1484. result.add("1815D-1_M3区消防电梯(常)");
  1485. result.add("1815D-2_商业1变电所(常)");
  1486. result.add("1815D-3_备用");
  1487. result.add("1815D-4_消防动力4(备)");
  1488. result.add("1815D-5_E塔楼消防动力(备)");
  1489. result.add("1815D-6_备用");
  1490. result.add("1816D-1_备用");
  1491. result.add("1816D-2_E塔楼消防电梯总电源(备)");
  1492. result.add("1817D-1_备用");
  1493. result.add("1817D-2_E塔楼公共应急照明(常)");
  1494. result.add("1817D-3_备用");
  1495. result.add("1817D-4_备用");
  1496. result.add("1817D-5_F4M2APXZ1 F-L 105 D塔楼");
  1497. result.add("1405D_低压进线柜支路");
  1498. result.add("1407D_无功自动补偿电容柜");
  1499. result.add("1409D-1_一般照明2");
  1500. result.add("1409D-2_备用");
  1501. result.add("1410D-1_一般照明3");
  1502. result.add("1410D-2_备用");
  1503. result.add("1411D-1_配电所用电(备)");
  1504. result.add("1411D-2_备用");
  1505. result.add("1411D-3_备用");
  1506. result.add("1411D-4_溜冰场制冷机房动力(备)");
  1507. result.add("1412D-1_商业水泵房(备)");
  1508. result.add("1412D-2_M1区乘客电梯(备)");
  1509. result.add("1412D-3_B塔配电所用电");
  1510. result.add("1412D-4_备用");
  1511. result.add("1412D-5_备用");
  1512. result.add("1413D-1_开闭所直流屏");
  1513. result.add("1413D-2_M1区应急照明(备)");
  1514. result.add("1413D-3_消防动力2(备)");
  1515. result.add("1413D-4_消防动力3(备)");
  1516. result.add("1413D-5_消防动力1(备)");
  1517. result.add("1414D-1_开闭所照明(备)");
  1518. result.add("1414D-2_开闭所直流屏(常)");
  1519. result.add("1414D-3_商业冷冻机房变电所(备)");
  1520. result.add("1414D-4_备用");
  1521. result.add("1414D-5_超市");
  1522. result.add("1305D_低压进线柜");
  1523. result.add("1307D_无功自动补偿电容柜");
  1524. result.add("1309D_低压母联柜");
  1525. result.add("1310D-1_一般照明");
  1526. result.add("1310D-2_备用");
  1527. result.add("1311D-1_变电所用电(主)");
  1528. result.add("1311D-2_扶梯");
  1529. result.add("1311D-3_备用");
  1530. result.add("1311D-4_溜冰场制冷机房动力(常)");
  1531. result.add("1312D-1_商业水泵房(常)");
  1532. result.add("1312D-2_M1区乘客电梯(常)");
  1533. result.add("1312D-3_BDS-AT(6#客梯)");
  1534. result.add("1312D-4_备用");
  1535. result.add("1312D-5_B1M1-AP2");
  1536. result.add("1313D-1_开闭所直流屏");
  1537. result.add("1313D-2_M1区应急照明(常)");
  1538. result.add("1313D-3_消防动力2(常)");
  1539. result.add("1313D-4_消防动力3(常)");
  1540. result.add("1313D-5_消防动力1(常)");
  1541. result.add("1314D-1_开闭所照明(常)");
  1542. result.add("1314D-2_开闭所直流屏(备)");
  1543. result.add("1314D-3_商业冷冻机房变电所(常)");
  1544. result.add("1314D-4_预留泛光照明");
  1545. result.add("1314D-5_超市");
  1546. result.add("1#直流屏");
  1547. result.add("2#直流屏");
  1548. result.add("1#进线总柜");
  1549. result.add("1#出线柜");
  1550. result.add("3#出线柜");
  1551. result.add("5#出线柜");
  1552. result.add("7#出线柜");
  1553. result.add("母联断路器柜");
  1554. result.add("2#进线总柜");
  1555. result.add("2#出线柜");
  1556. result.add("4#出线柜");
  1557. result.add("6#出线柜");
  1558. result.add("8#出线柜");
  1559. result.add("1#进线总柜");
  1560. result.add("1#出线柜");
  1561. result.add("3#出线柜");
  1562. result.add("5#出线柜");
  1563. result.add("7#出线柜");
  1564. result.add("母联断路器柜");
  1565. result.add("2#进线总柜");
  1566. result.add("2#出线柜");
  1567. result.add("4#出线柜");
  1568. result.add("6#出线柜");
  1569. result.add("8#出线柜");
  1570. result.add("1#高压进线柜");
  1571. result.add("1#高压出线柜");
  1572. result.add("母联断路器柜");
  1573. result.add("2#高压进线柜");
  1574. result.add("2#高压出线柜");
  1575. result.add("1#高压进线柜");
  1576. result.add("1#高压出线柜");
  1577. result.add("母联断路器柜");
  1578. result.add("2#高压进线柜");
  1579. result.add("2#高压出线柜");
  1580. result.add("1#高压进线柜");
  1581. result.add("1#高压出线柜");
  1582. result.add("母联断路器柜");
  1583. result.add("2#高压进线柜");
  1584. result.add("2#高压出线柜");
  1585. result.add("1#高压进线柜");
  1586. result.add("1#高压出线柜");
  1587. result.add("母联断路器柜");
  1588. result.add("2#高压进线柜");
  1589. result.add("2#高压出线柜");
  1590. result.add("1#高压出线柜");
  1591. result.add("2#高压出线柜");
  1592. return result;
  1593. }
  1594. public byte[] gbk2utf8(String chenese) {
  1595. char c[] = chenese.toCharArray();
  1596. byte[] fullByte = new byte[3 * c.length];
  1597. for (int i = 0; i < c.length; i++) {
  1598. int m = (int) c[i];
  1599. String word = Integer.toBinaryString(m);
  1600. // System.out.println(word);
  1601. StringBuffer sb = new StringBuffer();
  1602. int len = 16 - word.length();
  1603. // 补零
  1604. for (int j = 0; j < len; j++) {
  1605. sb.append("0");
  1606. }
  1607. sb.append(word);
  1608. sb.insert(0, "1110");
  1609. sb.insert(8, "10");
  1610. sb.insert(16, "10");
  1611. // System.out.println(sb.toString());
  1612. String s1 = sb.substring(0, 8);
  1613. String s2 = sb.substring(8, 16);
  1614. String s3 = sb.substring(16);
  1615. byte b0 = Integer.valueOf(s1, 2).byteValue();
  1616. byte b1 = Integer.valueOf(s2, 2).byteValue();
  1617. byte b2 = Integer.valueOf(s3, 2).byteValue();
  1618. byte[] bf = new byte[3];
  1619. bf[0] = b0;
  1620. fullByte[i * 3] = bf[0];
  1621. bf[1] = b1;
  1622. fullByte[i * 3 + 1] = bf[1];
  1623. bf[2] = b2;
  1624. fullByte[i * 3 + 2] = bf[2];
  1625. }
  1626. return fullByte;
  1627. }
  1628. }