Browse Source

首次上传。

Jay Lee 6 years ago
commit
690440611a
62 changed files with 5206 additions and 0 deletions
  1. 56 0
      collect/.classpath
  2. 1 0
      collect/.gitignore
  3. 23 0
      collect/.project
  4. 5 0
      collect/.settings/org.eclipse.core.resources.prefs
  5. 5 0
      collect/.settings/org.eclipse.jdt.core.prefs
  6. 4 0
      collect/.settings/org.eclipse.m2e.core.prefs
  7. BIN
      collect/c3p0-0.9.5.2.jar
  8. BIN
      collect/commons-beanutils-1.8.0.jar
  9. BIN
      collect/commons-collections-3.2.1.jar
  10. BIN
      collect/commons-lang-2.5.jar
  11. BIN
      collect/commons-logging-1.1.1.jar
  12. 42 0
      collect/config-1101080001-1/port1.xml
  13. 35 0
      collect/config-1101080001-1/port2.xml
  14. 11 0
      collect/config-1101080001-1/port3.xml
  15. 52 0
      collect/config-1101080001-1/port4.xml
  16. 61 0
      collect/config.json
  17. BIN
      collect/dom4j-1.6.1.jar
  18. BIN
      collect/ems-com.jar
  19. BIN
      collect/ezmorph-1.0.6.jar
  20. BIN
      collect/gson-2.2.4-javadoc.jar
  21. BIN
      collect/gson-2.2.4-sources.jar
  22. BIN
      collect/gson-2.2.4.jar
  23. 34 0
      collect/hbase-site.xml
  24. BIN
      collect/jaxen-1.1-beta-7.jar
  25. BIN
      collect/json-lib-2.4-jdk15.jar
  26. BIN
      collect/lib-mysql-connector-java-5.1.13/mysql-connector-java-5.1.13-bin.jar
  27. BIN
      collect/log4j-1.2.11.jar
  28. 17 0
      collect/log4j.properties
  29. BIN
      collect/mchange-commons-java-0.2.11.jar
  30. BIN
      collect/mina-core-2.0.7.jar
  31. BIN
      collect/poi-3.9.jar
  32. 165 0
      collect/pom.xml
  33. BIN
      collect/slf4j-api-1.6.1.jar
  34. BIN
      collect/slf4j-log4j12-1.6.1.jar
  35. BIN
      collect/src/ems-com.jar
  36. 10 0
      collect/src/main/java/com/saga/entity/Collector.java
  37. 6 0
      collect/src/main/java/com/saga/entity/Data.java
  38. 5 0
      collect/src/main/java/com/saga/entity/Device.java
  39. 5 0
      collect/src/main/java/com/saga/entity/Function.java
  40. 11 0
      collect/src/main/java/com/saga/entity/Point.java
  41. 20 0
      collect/src/main/java/com/saga/entity/PointSet.java
  42. 13 0
      collect/src/main/java/com/saga/entity/Record.java
  43. 8 0
      collect/src/main/java/com/saga/entity/Report.java
  44. 15 0
      collect/src/main/java/com/saga/entity/Upload.java
  45. 204 0
      collect/src/main/java/com/saga/main/Main.java
  46. 301 0
      collect/src/main/java/com/saga/test/ShenQI.java
  47. 203 0
      collect/src/main/java/com/saga/test/Sunyifu.java
  48. 172 0
      collect/src/main/java/com/saga/test/Test.java
  49. 267 0
      collect/src/main/java/com/saga/thread/common/CheckThread.java
  50. 131 0
      collect/src/main/java/com/saga/thread/common/LoadConfigThread.java
  51. 394 0
      collect/src/main/java/com/saga/thread/common/SaveThread.java
  52. 68 0
      collect/src/main/java/com/saga/thread/common/StatsThread.java
  53. 393 0
      collect/src/main/java/com/saga/thread/common/WTDBThread.java
  54. 776 0
      collect/src/main/java/com/saga/thread/down/CollectThread.java
  55. 372 0
      collect/src/main/java/com/saga/thread/up/SendThread.java
  56. 57 0
      collect/src/main/java/com/saga/util/CSVUtil.java
  57. 343 0
      collect/src/main/java/com/saga/util/Constant.java
  58. 865 0
      collect/src/main/java/com/saga/util/HBaseUtil.java
  59. 5 0
      collect/src/main/java/com/saga/util/MySQLUtil.java
  60. 34 0
      collect/src/main/resources/hbase-site.xml
  61. 17 0
      collect/src/main/resources/log4j.properties
  62. BIN
      collect/zillion-util-1.5.jar

+ 56 - 0
collect/.classpath

@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="ems-com.jar"/>
+	<classpathentry kind="lib" path="dom4j-1.6.1.jar"/>
+	<classpathentry kind="lib" path="log4j-1.2.11.jar"/>
+	<classpathentry kind="lib" path="gson-2.2.4-javadoc.jar"/>
+	<classpathentry kind="lib" path="gson-2.2.4.jar"/>
+	<classpathentry kind="lib" path="gson-2.2.4-sources.jar"/>
+	<classpathentry kind="lib" path="c3p0-0.9.5.2.jar"/>
+	<classpathentry kind="lib" path="commons-beanutils-1.8.0.jar"/>
+	<classpathentry kind="lib" path="commons-collections-3.2.1.jar"/>
+	<classpathentry kind="lib" path="commons-lang-2.5.jar"/>
+	<classpathentry kind="lib" path="commons-logging-1.1.1.jar"/>
+	<classpathentry kind="lib" path="ezmorph-1.0.6.jar"/>
+	<classpathentry kind="lib" path="jaxen-1.1-beta-7.jar"/>
+	<classpathentry kind="lib" path="json-lib-2.4-jdk15.jar"/>
+	<classpathentry kind="lib" path="mchange-commons-java-0.2.11.jar"/>
+	<classpathentry kind="lib" path="mina-core-2.0.7.jar"/>
+	<classpathentry kind="lib" path="slf4j-api-1.6.1.jar"/>
+	<classpathentry kind="lib" path="slf4j-log4j12-1.6.1.jar"/>
+	<classpathentry kind="lib" path="zillion-util-1.5.jar"/>
+	<classpathentry kind="lib" path="poi-3.9.jar"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 1 - 0
collect/.gitignore

@@ -0,0 +1 @@
+/target/

+ 23 - 0
collect/.project

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>collect</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 5 - 0
collect/.settings/org.eclipse.core.resources.prefs

@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+encoding//src/main/java=gbk
+encoding//src/main/resources=UTF-8
+encoding//src/test/java=gbk
+encoding//src/test/resources=UTF-8

+ 5 - 0
collect/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.8

+ 4 - 0
collect/.settings/org.eclipse.m2e.core.prefs

@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1

BIN
collect/c3p0-0.9.5.2.jar


BIN
collect/commons-beanutils-1.8.0.jar


BIN
collect/commons-collections-3.2.1.jar


BIN
collect/commons-lang-2.5.jar


BIN
collect/commons-logging-1.1.1.jar


+ 42 - 0
collect/config-1101080001-1/port1.xml

@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <portpara>
+    <baud>9600</baud>
+    <databit>8</databit>
+    <parity>N</parity>
+    <stopbit>1</stopbit>
+    <timeout>1000</timeout>
+  </portpara>
+  <portdev>
+    <devtype meterid="1000">
+      <addr>01</addr>
+      <loacation>BIM</loacation>
+      <protocolname>persagy-spb</protocolname>
+      <interval>1</interval>
+      <factor></factor>
+      <offset></offset>
+      <funset>
+        <funid>11101</funid>
+        <funid>11201</funid>
+        <funid>11301</funid>
+        <funid>11303</funid>
+        <funid>11401</funid>
+      </funset>
+    </devtype>
+    <devtype meterid="1001">
+      <addr>00</addr>
+      <loacation>BIM</loacation>
+      <protocolname>persagy-spb</protocolname>
+      <interval>1</interval>
+      <factor></factor>
+      <offset></offset>
+      <funset>
+        <funid>11101</funid>
+        <funid>11201</funid>
+        <funid>11301</funid>
+        <funid>11303</funid>
+        <funid>11401</funid>
+      </funset>
+    </devtype>
+  </portdev>
+</root>

+ 35 - 0
collect/config-1101080001-1/port2.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <portpara>
+    <baud>9600</baud>
+    <databit>8</databit>
+    <parity>N</parity>
+    <stopbit>1</stopbit>
+    <timeout>1000</timeout>
+  </portpara>
+  <portdev>
+    <devtype meterid="1002">
+      <addr>02</addr>
+      <loacation>BIM</loacation>
+      <protocolname>cyw11</protocolname>
+      <interval>1</interval>
+      <factor></factor>
+      <offset></offset>
+      <funset>
+        <funid>12109</funid>
+      </funset>
+    </devtype>
+    <devtype meterid="1003">
+      <addr>06</addr>
+      <loacation></loacation>
+      <protocolname>07dlt645</protocolname>
+      <interval>0</interval>
+      <factor></factor>
+      <offset></offset>
+      <funset>
+        <funid>10101</funid>
+        <funid>10704</funid>
+      </funset>
+    </devtype>
+  </portdev>
+</root>

+ 11 - 0
collect/config-1101080001-1/port3.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <portpara>
+    <baud>9600</baud>
+    <databit>8</databit>
+    <parity>N</parity>
+    <stopbit>1</stopbit>
+    <timeout>1000</timeout>
+  </portpara>
+  <portdev />
+</root>

+ 52 - 0
collect/config-1101080001-1/port4.xml

@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <portpara>
+    <baud>9600</baud>
+    <databit>8</databit>
+    <parity>N</parity>
+    <stopbit>1</stopbit>
+    <timeout>1000</timeout>
+  </portpara>
+  <portdev>
+    <devtype meterid="4001">
+      <addr>05</addr>
+      <loacation>测试</loacation>
+      <protocolname>pqm1001-4</protocolname>
+      <interval>10</interval>
+      <factor />
+      <offset />
+      <funset>
+        <funid>10101</funid>
+        <funid>10102</funid>
+        <funid>10103</funid>
+        <funid>10104</funid>
+        <funid>10201</funid>
+        <funid>10202</funid>
+        <funid>10203</funid>
+        <funid>10204</funid>
+        <funid>10205</funid>
+        <funid>10206</funid>
+        <funid>10207</funid>
+        <funid>10208</funid>
+        <funid>10209</funid>
+        <funid>10214</funid>
+        <funid>10301</funid>
+        <funid>10302</funid>
+        <funid>10303</funid>
+        <funid>10304</funid>
+        <funid>10305</funid>
+        <funid>10306</funid>
+        <funid>10307</funid>
+        <funid>10308</funid>
+        <funid>10309</funid>
+        <funid>10310</funid>
+        <funid>10311</funid>
+        <funid>10312</funid>
+        <funid>10313</funid>
+        <funid>10314</funid>
+        <funid>10315</funid>
+        <funid>10316</funid>
+      </funset>
+    </devtype>
+  </portdev>
+</root>

+ 61 - 0
collect/config.json

@@ -0,0 +1,61 @@
+{
+    "DB": [
+        {
+            "building": "1101080001", 
+            "database": "db_public_2", 
+            "buildingadds": [
+                {
+                    "building": "1101020001"
+                }, 
+                {
+                    "building": "1101020002"
+                }
+            ]
+        }, 
+        {
+            "building": "1101080002", 
+            "database": "db_public_2"
+        }, 
+        {
+            "building": "1101080003", 
+            "database": "db_public_2"
+        }, 
+        {
+            "building": "1101080004", 
+            "database": "db_public_2"
+        }, 
+        {
+            "building": "1101080005", 
+            "database": "db_public_2"
+        },
+        {
+            "building": "1101050001", 
+            "database": "db_public_2"
+        }, 
+        {
+            "building": "6666666666", 
+            "database": "db_public_2"
+        }, 
+        {
+            "building": "7777777777", 
+            "database": "db_public_2"
+        }, 
+        {
+            "building": "3101140002", 
+            "database": "db_public_2"
+        }, 
+        {
+            "insertthread": "1"
+        }
+    ], 
+    "Port": [
+        {
+            "type": "Up", 
+            "port": "9999"
+        }, 
+        {
+            "type": "Down", 
+            "port": "80"
+        }
+    ]
+}

BIN
collect/dom4j-1.6.1.jar


BIN
collect/ems-com.jar


BIN
collect/ezmorph-1.0.6.jar


BIN
collect/gson-2.2.4-javadoc.jar


BIN
collect/gson-2.2.4-sources.jar


BIN
collect/gson-2.2.4.jar


+ 34 - 0
collect/hbase-site.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+<configuration>
+	<!-- hbase-site.xml -->
+	<property>
+		<name>dfs.replication</name>
+		<value>1</value>
+	</property>
+
+	<property>
+		<name>hbase.rootdir</name>
+		<value>hdfs://namenode:8020/hbase</value>
+	</property>
+	<property>
+		<name>hbase.cluster.distributed</name>
+		<value>true</value>
+	</property>
+	<property>
+		<name>hbase.zookeeper.quorum</name>
+		<value>zookeeper1,zookeeper2,zookeeper3</value>
+	</property>
+	<property>
+		<name>hbase.zookeeper.property.dataDir</name>
+		<value>/var/zookeeper/data</value>
+	</property>
+
+	<!--
+	<property>
+		<name>hbase.security.authentication</name>
+		<value>simple</value>
+	</property>
+	-->
+
+</configuration>

BIN
collect/jaxen-1.1-beta-7.jar


BIN
collect/json-lib-2.4-jdk15.jar


BIN
collect/lib-mysql-connector-java-5.1.13/mysql-connector-java-5.1.13-bin.jar


BIN
collect/log4j-1.2.11.jar


+ 17 - 0
collect/log4j.properties

@@ -0,0 +1,17 @@
+log4j.rootLogger=INFO,ConsoleAppender,RollingLogFileAppender
+
+log4j.appender.RollingLogFileAppender=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.RollingLogFileAppender.Threshold=INFO
+log4j.appender.RollingLogFileAppender.ImmediateFlush=true
+log4j.appender.RollingLogFileAppender.File=log.log
+log4j.appender.RollingLogFileAppender.DatePattern=yyyy-MM-dd'.log'  
+log4j.appender.RollingLogFileAppender.Append=true
+log4j.appender.RollingLogFileAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.RollingLogFileAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss SSS} %t %m%n
+
+log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender
+log4j.appender.ConsoleAppender.Threshold=INFO
+log4j.appender.ConsoleAppender.ImmediateFlush=true
+log4j.appender.ConsoleAppender.Target=System.out
+log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.ConsoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss SSS} %t %m%n

BIN
collect/mchange-commons-java-0.2.11.jar


BIN
collect/mina-core-2.0.7.jar


BIN
collect/poi-3.9.jar


+ 165 - 0
collect/pom.xml

@@ -0,0 +1,165 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.sagacloud</groupId>
+	<artifactId>collect</artifactId>
+	<version>1.0-SNAPSHOT</version>
+	<properties>
+		<maven.compiler.source>1.8</maven.compiler.source>
+		<maven.compiler.target>1.8</maven.compiler.target>
+	</properties>
+
+	<repositories>
+		<repository>
+			<id>SagaCloud</id>
+			<name>SagaCloud</name>
+			<url>http://172.16.0.86:8081/repository/SagaCloud/</url>
+			<snapshots>
+				<enabled>true</enabled>
+			</snapshots>
+			<releases>
+				<enabled>true</enabled>
+			</releases>
+		</repository>
+		<repository>
+			<id>alimaven</id>
+			<name>aliyun maven</name>
+			<url>http://maven.aliyun.com/nexus/content/groups/public</url>
+		</repository>
+		<repository>
+			<id>mvnrepository</id>
+			<url>https://mvnrepository.com/</url>
+		</repository>
+		<repository>
+			<id>sonatype-nexus-snapshots</id>
+			<name>Sonatype Nexus Snapshots</name>
+			<url>http://oss.sonatype.org/content/repositories/snapshots</url>
+		</repository>
+	</repositories>
+
+	<dependencies>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<version>5.1.13</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.hbase</groupId>
+			<artifactId>hbase-server</artifactId>
+			<version>1.3.0</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.hbase</groupId>
+			<artifactId>hbase-client</artifactId>
+			<version>1.3.0</version>
+		</dependency>
+		<dependency>
+			<groupId>dom4j</groupId>
+			<artifactId>dom4j</artifactId>
+			<version>1.6.1</version>
+		</dependency>
+		<dependency>
+			<groupId>jaxen</groupId>
+			<artifactId>jaxen</artifactId>
+			<version>1.1.6</version>
+		</dependency>
+		<!--- <dependency> <groupId>com.sagacloud</groupId> <artifactId>zillion-util</artifactId> 
+			<version>1.2</version> <type>jar</type> </dependency> -->
+		<dependency>
+			<groupId>com.sagacloud</groupId>
+			<artifactId>json-lib-zillion</artifactId>
+			<version>1.0</version>
+			<type>jar</type>
+		</dependency>
+		<dependency>
+			<groupId>jdk.tools</groupId>
+			<artifactId>jdk.tools</artifactId>
+			<version>1.8</version>
+			<scope>system</scope>
+			<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<resources>
+			<resource>
+				<directory>src/main/resources</directory>
+				<targetPath>${project.build.directory}</targetPath>
+			</resource>
+		</resources>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.4</version>
+				<configuration>
+					<defaultLibBundleDir></defaultLibBundleDir>
+					<source>1.8</source>
+					<target>1.8</target>
+					<encoding>gbk</encoding>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<version>2.4</version>
+				<configuration>
+					<archive>
+						<manifest>
+							<addClasspath>true</addClasspath>
+							<classpathPrefix></classpathPrefix>
+							<mainClass>com.persagy.compute.main.ComputeMain</mainClass>
+						</manifest>
+					</archive>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+				<version>2.4</version>
+				<executions>
+					<execution>
+						<id>copy</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-dependencies</goal>
+						</goals>
+						<configuration>
+							<outputDirectory>
+								${project.build.directory}
+							</outputDirectory>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-resources-plugin</artifactId>
+				<version>2.4</version>
+				<configuration>
+					<encoding>UTF-8</encoding>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+	<profiles>
+		<profile>
+			<id>dev</id>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.apache.maven.plugins</groupId>
+						<artifactId>maven-shade-plugin</artifactId>
+						<executions>
+							<execution>
+								<phase>none</phase>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+
+</project>

BIN
collect/slf4j-api-1.6.1.jar


BIN
collect/slf4j-log4j12-1.6.1.jar


BIN
collect/src/ems-com.jar


+ 10 - 0
collect/src/main/java/com/saga/entity/Collector.java

@@ -0,0 +1,10 @@
+package com.saga.entity;
+
+public class Collector {
+	public String IP;
+	public int Port;
+	public String MAC;
+	public String PROTOCOL;
+	public String Mode;
+	public int Max_size;
+}

+ 6 - 0
collect/src/main/java/com/saga/entity/Data.java

@@ -0,0 +1,6 @@
+package com.saga.entity;
+
+public class Data {
+	public String value;
+	public String receivetime;
+}

+ 5 - 0
collect/src/main/java/com/saga/entity/Device.java

@@ -0,0 +1,5 @@
+package com.saga.entity;
+
+public class Device {
+	public String MACID;
+}

+ 5 - 0
collect/src/main/java/com/saga/entity/Function.java

@@ -0,0 +1,5 @@
+package com.saga.entity;
+
+public class Function {
+	public long functionID;
+}

+ 11 - 0
collect/src/main/java/com/saga/entity/Point.java

@@ -0,0 +1,11 @@
+package com.saga.entity;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Point {
+	public String MAC;
+	public String buildingSign;
+	public String meterSign;
+	public Set<Function> functionList = new HashSet<Function>();
+}

+ 20 - 0
collect/src/main/java/com/saga/entity/PointSet.java

@@ -0,0 +1,20 @@
+package com.saga.entity;
+
+public class PointSet {
+	public String uploadName;
+	public String address;
+	public String[] content;
+	public int ID;
+	public double sendTime = 0;
+	public double recTime = 0;
+	public String status;
+	public String buildingSignUP;
+	public String buildingSign;
+	public String mac;
+
+	public String meterSign;
+	public int funcID;
+	public String collectorMAC;
+	public String cmd;
+	public double dataSet;
+}

+ 13 - 0
collect/src/main/java/com/saga/entity/Record.java

@@ -0,0 +1,13 @@
+package com.saga.entity;
+
+import java.util.Date;
+
+public class Record {
+	public String seq;
+	public String buildingSign;
+	public String meterSign;
+	public int funcID;
+	public Date receivetime;
+	public double data;
+	public String addtion;
+}

+ 8 - 0
collect/src/main/java/com/saga/entity/Report.java

@@ -0,0 +1,8 @@
+package com.saga.entity;
+
+public class Report {
+	public String UploadName;
+	public int ReportID;
+	public long resend;
+	public Record record;
+}

+ 15 - 0
collect/src/main/java/com/saga/entity/Upload.java

@@ -0,0 +1,15 @@
+package com.saga.entity;
+
+public class Upload {
+	public String PROTOCOL;
+	public String IP;
+	public int Port;
+	public String ServerIP;
+	public int ServerPort;
+	public String Mode;
+	public int Max_size;
+	public int SleepCount;
+	public String Separate;
+	public String Separate_begin;
+	public String Separate_end;
+}

+ 204 - 0
collect/src/main/java/com/saga/main/Main.java

@@ -0,0 +1,204 @@
+package com.saga.main;
+
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.hadoop.conf.Configuration;
+import org.zillion.util.log.LogUtil;
+
+import com.persagy.communication.mina.tcp.server.TCPServerManager;
+import com.persagy.communication.mina.udp.server.UDPServerManager;
+import com.persagy.communication.util.IServerManager;
+import com.saga.thread.common.CheckThread;
+import com.saga.thread.common.LoadConfigThread;
+import com.saga.thread.common.SaveThread;
+import com.saga.thread.common.StatsThread;
+import com.saga.thread.common.WTDBThread;
+import com.saga.thread.down.CollectThread;
+import com.saga.thread.up.SendThread;
+import com.saga.util.Constant;
+import com.saga.util.HBaseUtil;
+import com.zillion.database.agent.ZillionAgent;
+
+public class Main {
+
+	public static void main(String[] args) {
+		// TODO Auto-generated method stub
+		try {
+			String resource = "/hbase-site.xml";
+			Configuration configuration = new Configuration();
+
+			configuration.addResource(new FileInputStream(System.getProperty("user.dir") + resource));
+			String zookeeper_connectionAddress = "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181";
+			int zookeeper_sessionTimeout = 300000;
+			Constant.agent = new ZillionAgent(configuration, zookeeper_connectionAddress, zookeeper_sessionTimeout);
+
+			Constant.agent.Start();
+			LogUtil.info("" + Constant.BuildingDB);
+			LogUtil.info("" + Constant.BuildingAdds);
+			LogUtil.info("" + Constant.BuildingConv);
+
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("Main: " + e.toString());
+		}
+		try {
+			Map<String, String> dbList = new HashMap<String, String>();
+			for (Entry<String, String> bd : Constant.BuildingDB.entrySet()) {
+				dbList.put(bd.getValue(), bd.getValue());
+			}
+			for (String db : dbList.keySet()) {
+				HBaseUtil.CreateDB(Constant.agent, db);
+				Thread.sleep(Constant.Millisecond.SECOND_1);
+
+				// Constant.agent.DDL_DropTable(db, "original_month");
+				// Thread.sleep(Constant.Millisecond.SECOND_3);
+				// Constant.agent.DDL_DropTable(db, "original_present");
+				// Thread.sleep(Constant.Millisecond.SECOND_3);
+				// Constant.agent.DDL_DropTable(db, "originalset");
+				// Thread.sleep(Constant.Millisecond.SECOND_3);
+				// Constant.agent.DDL_DropTable(db, "originalset_present");
+				// Thread.sleep(Constant.Millisecond.SECOND_3);
+				// Constant.agent.DDL_DropTable(db, "collectorstatus");
+				// Thread.sleep(Constant.Millisecond.SECOND_3);
+				// Constant.agent.DDL_DropTable(db,
+				// "collectorcommunicationlog");
+				// Thread.sleep(Constant.Millisecond.SECOND_3);
+				// Constant.agent.DDL_DropTable(db, "pointstatus");
+				// Thread.sleep(Constant.Millisecond.SECOND_3);
+				// Constant.agent.DDL_DropTable(db, "pointcommunicationlog");
+				// Thread.sleep(Constant.Millisecond.SECOND_3);
+				// Constant.agent.DDL_DropTable(db, "pointinfo");
+				// Thread.sleep(Constant.Millisecond.SECOND_30);
+				// System.exit(0);
+
+				HBaseUtil.CreateTable(Constant.agent, db, "original_month");
+				Thread.sleep(Constant.Millisecond.SECOND_3);
+				HBaseUtil.CreateTable_present(Constant.agent, db, "original_present");
+				Thread.sleep(Constant.Millisecond.SECOND_3);
+				HBaseUtil.CreateTable_set(Constant.agent, db, "originalset");
+				Thread.sleep(Constant.Millisecond.SECOND_3);
+				HBaseUtil.CreateTable_setpresent(Constant.agent, db, "originalset_present");
+				Thread.sleep(Constant.Millisecond.SECOND_3);
+				HBaseUtil.CreateTable_CollectorStatus(Constant.agent, db, "pointgatewaystatus");
+				Thread.sleep(Constant.Millisecond.SECOND_3);
+				HBaseUtil.CreateTable_CollectorCommunicationLog(Constant.agent, db, "pointgatewaylog");
+				Thread.sleep(Constant.Millisecond.SECOND_3);
+				HBaseUtil.CreateTable_PointStatus(Constant.agent, db, "pointstatus");
+				Thread.sleep(Constant.Millisecond.SECOND_3);
+				HBaseUtil.CreateTable_PointCommunicationLog(Constant.agent, db, "pointlog");
+				Thread.sleep(Constant.Millisecond.SECOND_3);
+				HBaseUtil.CreateTable_PointInfo(Constant.agent, db, "pointinfo");
+			}
+
+			// 重新启动加载节点、点位历史列表
+			for (Entry<String, String> bd : Constant.BuildingDB.entrySet()) {
+				try {
+					String project = bd.getKey();
+					String db = bd.getValue();
+					HBaseUtil.GetCollectorStatus(Constant.agent, db, "pointgatewaystatus", project);
+					HBaseUtil.GetPointStatus(Constant.agent, db, "pointstatus", project);
+				} catch (Exception e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+					LogUtil.error("Main: " + e.toString());
+				}
+			}
+
+			// 加载采集器配置文件
+			// 文件夹命名格式:config+"-"+楼号+"-"+mac序号,示例:config-1101080002-1
+			Constant.getConfigFile(LogUtil.GetPath(), "config-", "port");
+			// 采集器点位位置信息写入数据库
+			for (Entry<String, String> pi : Constant.pointInfo.entrySet()) {
+				String building = pi.getKey().split("-")[0];
+				String mac = pi.getKey().split("-")[1];
+				String node = mac;
+				String point = pi.getKey().split("-")[2];
+				String busno = pi.getValue().split("-")[0];
+				String site = pi.getValue().split("-")[1];
+				HBaseUtil.InsertPointInfo(Constant.agent, Constant.BuildingDB.get(building), building, node, point,
+						busno, site);
+				// System.out.println(building + node + point + busno + site);
+			}
+
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			LogUtil.error("Main: " + e.toString());
+			System.exit(0);
+		}
+		try {
+			new LoadConfigThread().start();
+			Thread.sleep(3L);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("Main.LoadConfigThread: " + e.toString());
+		}
+
+		try {
+			new CollectThread(Integer.valueOf(Constant.TypePort.get("Down"))).start();
+			Thread.sleep(3L);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("Main.CollectThread: " + e.toString());
+		}
+		List<IServerManager> udpserverList = new ArrayList<IServerManager>();
+		List<IServerManager> tcpserverList = new ArrayList<IServerManager>();
+		udpserverList.add(new UDPServerManager("0.0.0.0", Integer.valueOf(Constant.TypePort.get("Up")), "utf-8", 1000));
+		tcpserverList.add(new TCPServerManager("0.0.0.0", Integer.valueOf(Constant.TypePort.get("Up")), "utf-8", 1000));
+
+		for (IServerManager server : udpserverList) {
+			new SendThread(server).start();
+			try {
+				Thread.sleep(3L);
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				LogUtil.error("Main.SendThread: " + e.toString());
+			}
+		}
+		for (IServerManager server : tcpserverList) {
+			new SendThread(server).start();
+			try {
+				Thread.sleep(3L);
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				LogUtil.error("Main.SendThread: " + e.toString());
+			}
+		}
+		try {
+			new SaveThread().start();
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("Main.SaveThread: " + e.toString());
+		}
+
+		try {
+			List<WTDBThread> wtdbthreadList = new ArrayList<WTDBThread>();
+			for (int i = 0; i < Constant.InsertThread; i++) {
+				WTDBThread thread = new WTDBThread(Constant.agent);
+				thread.start();
+				wtdbthreadList.add(thread);
+			}
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("Main.WTDBThread: " + e.toString());
+		}
+		try {
+			new CheckThread(Constant.agent).start();
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("Main.CheckThread: " + e.toString());
+		}
+		try {
+			new StatsThread().start();
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("Main.StatsThread: " + e.toString());
+		}
+	}
+
+}

+ 301 - 0
collect/src/main/java/com/saga/test/ShenQI.java

@@ -0,0 +1,301 @@
+package com.saga.test;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.zillion.util.log.LogUtil;
+
+import com.saga.util.Constant;
+import com.sagacloud.json.JSONArray;
+import com.sagacloud.json.JSONObject;
+import com.zillion.database.agent.ZillionAgent;
+
+public class ShenQI {
+	public ShenQI() {
+
+	}
+
+	static Map<String, String> meterList = new HashMap<String, String>();
+	static Map<String, Map<String, Map<String, Double>>> dataList = new HashMap<String, Map<String, Map<String, Double>>>();
+	static Map<String, String> funcList = new HashMap<String, String>();
+	static ZillionAgent agent;
+	static String building = "1101010001";
+
+	public static void main(String[] args) {
+		// TODO Auto-generated method stub
+		try {
+			String resource = "/hbase-site.xml";
+			Configuration configuration = new Configuration();
+
+			configuration.addResource(new FileInputStream(System.getProperty("user.dir") + resource));
+			String zookeeper_connectionAddress = "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181";
+			int zookeeper_sessionTimeout = 300000;
+			agent = new ZillionAgent(configuration, zookeeper_connectionAddress, zookeeper_sessionTimeout);
+			agent.Start();
+			Thread.sleep(10L);
+			// 创建HSSFWorkbook对象(excel的文档对象)
+
+			GetPointList(agent, "db_time_data", "dy_pointlist", building);
+
+			String timefrom = "20171001000000";
+			String timeto = "20171101000000";
+			export2(timefrom, timeto);
+			timefrom = "20171101000000";
+			timeto = "20171201000000";
+			export2(timefrom, timeto);
+			timefrom = "20180301000000";
+			timeto = "20180401000000";
+			export2(timefrom, timeto);
+			timefrom = "20180701000000";
+			timeto = "20180801000000";
+			export2(timefrom, timeto);
+
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("Main: " + e.toString());
+		}
+	}
+
+	private static void export2(String timefrom, String timeto) {
+		// TODO Auto-generated method stub
+
+		try {
+			LogUtil.info("get data begin...");
+			LogUtil.info("from " + Constant.parse(timefrom) + " to " + Constant.parse(timeto));
+
+			HSSFWorkbook wb = new HSSFWorkbook();
+
+			for (Entry<String, String> m : meterList.entrySet()) {
+				LogUtil.info("create sheet " + m.getKey());
+				HSSFSheet sheet = wb.createSheet(m.getKey());
+				// 抬头
+				HSSFRow row = sheet.createRow(0);
+				row.createCell(1).setCellValue("meter");
+				row.createCell(2).setCellValue("funcid");
+				row.createCell(3).setCellValue("receivetime");
+				row.createCell(4).setCellValue("data");
+				int r = 0;
+				for (Entry<String, String> funcid : funcList.entrySet()) {
+
+					try {
+						Map<String, Double> data = new HashMap<String, Double>();
+						data = GetFJD(agent, "db_time_data", "fjd_0_near_15min", building, m.getKey(),
+								Long.parseLong(funcid.getKey()), timefrom, timeto);
+						// 数据
+						for (Entry<String, Double> d : data.entrySet()) {
+							r++;
+							row = sheet.createRow(r);
+							row.createCell(1).setCellValue(m.getKey());
+							row.createCell(2).setCellValue(funcid.getKey());
+							row.createCell(3).setCellValue(d.getKey());
+							row.createCell(4).setCellValue(d.getValue());
+						}
+						Thread.sleep(10L);
+					} catch (Exception e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+				}
+			}
+			LogUtil.info("get data end...");
+			LogUtil.info("insert excel start...");
+
+			// 输出Excel文件
+			OutputStream output = new FileOutputStream("d:/data" + timefrom.substring(0, 6) + ".xls");
+			wb.write(output);
+			output.close();
+			LogUtil.info("insert excel end...");
+		} catch (Exception e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+	}
+
+	private static void export(String timefrom, String timeto) {
+		// TODO Auto-generated method stub
+
+		try {
+			LogUtil.info("get data begin...");
+			LogUtil.info("from " + Constant.parse(timefrom) + " to " + Constant.parse(timeto));
+
+			HSSFWorkbook wb = new HSSFWorkbook();
+			for (Entry<String, String> m : meterList.entrySet()) {
+				for (Entry<String, String> funcid : funcList.entrySet()) {
+
+					// 建立新的sheet对象(excel的表单)
+					// LogUtil.info("create sheet " + timefrom.substring(0,
+					// 8)+"~"+ timeto.substring(0, 8));
+					// HSSFSheet sheet = wb.createSheet(timefrom.substring(0,
+					// 8)+"~"+ timeto.substring(0, 8));
+					LogUtil.info("create sheet " + m.getKey() + "-" + funcid.getKey());
+					HSSFSheet sheet = wb.createSheet(m.getKey() + "-" + funcid.getKey());
+					// 抬头
+					HSSFRow row = sheet.createRow(1);
+					row.createCell(1).setCellValue("meter");
+					row.createCell(2).setCellValue("funcid");
+					row.createCell(3).setCellValue("receivetime");
+					row.createCell(4).setCellValue("data");
+					int r = 0;
+
+					try {
+						Map<String, Double> data = new HashMap<String, Double>();
+						data = GetOriginal(agent, "db_time_data", "original_month", building, m.getKey(),
+								Long.parseLong(funcid.getKey()), timefrom, timeto);
+						// 数据
+						for (Entry<String, Double> d : data.entrySet()) {
+
+							r++;
+							row = sheet.createRow(r);
+							row.createCell(1).setCellValue(m.getKey());
+							row.createCell(2).setCellValue(funcid.getKey());
+							row.createCell(3).setCellValue(d.getKey());
+							row.createCell(4).setCellValue(d.getValue());
+						}
+						Thread.sleep(10L);
+					} catch (Exception e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+				}
+			}
+			LogUtil.info("get data end...");
+			LogUtil.info("insert excel start...");
+
+			// 输出Excel文件
+			OutputStream output = new FileOutputStream(
+					"d:/data" + timefrom.substring(0, 8) + "-" + timeto.substring(0, 8) + ".xls");
+			wb.write(output);
+			output.close();
+			LogUtil.info("insert excel end...");
+		} catch (Exception e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+	}
+
+	private static Map<String, Double> GetFJD(ZillionAgent agent, String db, String tb, String building, String meter,
+			long funcid, String query_from, String query_to) throws Exception {
+		Map<String, Double> result = new HashMap<String, Double>();
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+		Criteria.put("meter", meter);
+		Criteria.put("funcid", funcid);
+		JSONObject range = new JSONObject();
+		range.put("$gte", query_from);
+		range.put("$lte", query_to);
+		Criteria.put("data_time", range);
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+
+		// LogUtil.info("GetFJD" + " " + db + " " + tb + " " + building + " " +
+		// meter + " " + funcid + " " + query_from
+		// + " " + query_to);
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+			String receivetime = (String) dataItem.get("data_time");
+			Double data = (Double) dataItem.get("data_value");
+			result.put(receivetime, data);
+			// dataList.get(meter).get(String.valueOf(funcid)).put(receivetime,
+			// data);
+			// LogUtil.info(("receivetime " + receivetime + " data:" + data));
+		}
+		return result;
+	}
+
+	private static Map<String, Double> GetOriginal(ZillionAgent agent, String db, String tb, String building,
+			String meter, long funcid, String query_from, String query_to) throws Exception {
+		Map<String, Double> result = new HashMap<String, Double>();
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+		Criteria.put("meter", meter);
+		Criteria.put("funcid", funcid);
+		JSONObject range = new JSONObject();
+		range.put("$gte", query_from);
+		range.put("$lte", query_to);
+		Criteria.put("receivetime", range);
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+
+		LogUtil.info("GetOriginal" + " " + db + " " + tb + " " + building + " " + meter + " " + funcid + " "
+				+ query_from + " " + query_to);
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+
+			String receivetime = (String) dataItem.get("receivetime");
+			Double data = (Double) dataItem.get("data");
+			result.put(receivetime, data);
+			// dataList.get(meter).get(String.valueOf(funcid)).put(receivetime,
+			// data);
+			// LogUtil.info(("receivetime " + receivetime + " data:" + data));
+		}
+		return result;
+	}
+
+	private static void GetPointList(ZillionAgent agent, String db, String tb, String building) throws Exception {
+
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+
+			meterList.put(String.valueOf(dataItem.get("meter")), null);
+			funcList.put(String.valueOf(dataItem.get("funcid")), null);
+
+		}
+	}
+
+	private static void Set_buildingcomputetime(ZillionAgent agent, String db, String tb, String building,
+			String compute_time) throws Exception {
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+		JSONObject Set = new JSONObject();
+		Set.put("compute_time", compute_time);
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "update");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		wrapperObject.put("Set", Set);
+		agent.Query(wrapperObject);
+		LogUtil.info(wrapperObject.toFormatString());
+	}
+
+	private static boolean in(long[] funcs, long funcid) {
+		for (long func : funcs) {
+			if (func == funcid) {
+				return true;
+			}
+		}
+		return false;
+	}
+}

+ 203 - 0
collect/src/main/java/com/saga/test/Sunyifu.java

@@ -0,0 +1,203 @@
+package com.saga.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.zillion.util.log.LogUtil;
+
+import com.saga.util.Constant;
+import com.sagacloud.json.JSONArray;
+import com.sagacloud.json.JSONObject;
+import com.zillion.database.agent.ZillionAgent;
+
+public class Sunyifu {
+	static Map<String, String> meterList = new HashMap<String, String>();
+	static Map<String, Map<String, Map<String, Double>>> dataList = new HashMap<String, Map<String, Map<String, Double>>>();
+	static long[] funcs = { 11011, 11012, 11013, 11014 };
+	static ZillionAgent agent;
+
+	public static void main(String[] args) {
+		// TODO Auto-generated method stub
+		try {
+			String resource = "/hbase-site.xml";
+			Configuration configuration = new Configuration();
+
+			configuration.addResource(new FileInputStream(System.getProperty("user.dir") + resource));
+			String zookeeper_connectionAddress = "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181";
+			int zookeeper_sessionTimeout = 300000;
+			agent = new ZillionAgent(configuration, zookeeper_connectionAddress, zookeeper_sessionTimeout);
+			agent.Start();
+			Thread.sleep(10L);
+			// for (int i = 0; i < 20; i++) {
+			// Set_buildingcomputetime(agent, "db_time_data",
+			// "fjd_0_buildingcomputetime", "1101080002",
+			// "20170701000000");
+			// Thread.sleep(1L);
+			// }
+			// Thread.sleep(Constant.Millisecond.MINUTE_30);
+			LogUtil.info("get data begin...");
+			String timefrom = "20170701000000";
+			String timeto = "20170801000000";
+			// long[] funcs = { 11011, 11012, 11013, 11014 };
+
+			GetPointList(agent, "db_time_data", "dy_pointlist", "1101080002");
+			for (Entry<String, String> m : meterList.entrySet()) {
+				dataList.put(m.getKey(), new HashMap<String, Map<String, Double>>());
+				for (long funcid : funcs) {
+					dataList.get(m.getKey()).put(String.valueOf(funcid), new HashMap<String, Double>());
+					try {
+						GetFJD(agent, "db_time_data", "fjd_0_near_15min", "1101080002", m.getKey(), funcid, timefrom,
+								timeto);
+						Thread.sleep(10L);
+					} catch (Exception e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+				}
+			}
+			LogUtil.info("get data end...");
+			LogUtil.info("insert excel start...");
+			Calendar calendarFrom = Calendar.getInstance();
+			Calendar calendarTo = Calendar.getInstance();
+			Date from = Constant.parse(timefrom);
+			Date to = Constant.parse(timeto);
+			calendarFrom.setTime(from);
+			calendarTo.setTime(to);
+
+			// 模拟数据
+			// 创建HSSFWorkbook对象(excel的文档对象)
+			HSSFWorkbook wb = new HSSFWorkbook();
+			for (long funcid : funcs) {
+				// 建立新的sheet对象(excel的表单)
+				LogUtil.info("create sheet " + funcid);
+				HSSFSheet sheet = wb.createSheet(String.valueOf(funcid));
+				int col = 0;
+				// 在sheet里创建第二行
+				HSSFRow row = sheet.createRow(1);
+				for (Entry<String, String> m : meterList.entrySet()) {
+					col++;
+
+					// 创建单元格并设置单元格内容
+					row.createCell(col).setCellValue(m.getKey());
+
+				}
+				calendarFrom.setTime(from);
+				int r = 1;
+				while (calendarFrom.before(calendarTo)) {
+					col = 0;
+					r++;
+					row = sheet.createRow(r);
+					row.createCell(col).setCellValue(Constant.format(calendarFrom.getTime()));
+					for (Entry<String, String> m : meterList.entrySet()) {
+						col++;
+						if (dataList.get(m.getKey()).get(String.valueOf(funcid))
+								.get(Constant.format(calendarFrom.getTime())) != null) {
+							row.createCell(col).setCellValue(dataList.get(m.getKey()).get(String.valueOf(funcid))
+									.get(Constant.format(calendarFrom.getTime())));
+						}
+					}
+					calendarFrom.add(Calendar.MINUTE, 15);
+				}
+			}
+
+			// 输出Excel文件
+			OutputStream output = new FileOutputStream("d:/data.xls");
+			wb.write(output);
+			output.close();
+			LogUtil.info("insert excel end...");
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("Main: " + e.toString());
+		}
+	}
+
+	private static void GetFJD(ZillionAgent agent, String db, String tb, String building, String meter, long funcid,
+			String query_from, String query_to) throws Exception {
+
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+		Criteria.put("meter", meter);
+		Criteria.put("funcid", funcid);
+		JSONObject range = new JSONObject();
+		range.put("$gte", query_from);
+		range.put("$lte", query_to);
+		Criteria.put("data_time", range);
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+
+		LogUtil.info("GetFJD" + " " + db + " " + tb + " " + building + " " + meter + " " + funcid + " " + query_from
+				+ " " + query_to);
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+
+			String receivetime = (String) dataItem.get("data_time");
+
+			Double data = (Double) dataItem.get("data_value");
+			dataList.get(meter).get(String.valueOf(funcid)).put(receivetime, data);
+			LogUtil.info(("receivetime " + receivetime + " data:" + data));
+		}
+	}
+
+	private static void GetPointList(ZillionAgent agent, String db, String tb, String building) throws Exception {
+
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+			if (in(funcs, Long.parseLong(String.valueOf(dataItem.get("funcid"))))) {
+				meterList.put(String.valueOf(dataItem.get("meter")), null);
+			}
+		}
+	}
+
+	private static void Set_buildingcomputetime(ZillionAgent agent, String db, String tb, String building,
+			String compute_time) throws Exception {
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+		JSONObject Set = new JSONObject();
+		Set.put("compute_time", compute_time);
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "update");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		wrapperObject.put("Set", Set);
+		agent.Query(wrapperObject);
+		LogUtil.info(wrapperObject.toFormatString());
+	}
+
+	private static boolean in(long[] funcs, long funcid) {
+		for (long func : funcs) {
+			if (func == funcid) {
+				return true;
+			}
+		}
+		return false;
+	}
+}

+ 172 - 0
collect/src/main/java/com/saga/test/Test.java

@@ -0,0 +1,172 @@
+package com.saga.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+
+import org.apache.hadoop.conf.Configuration;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.Node;
+import org.dom4j.io.SAXReader;
+
+import org.zillion.util.log.LogUtil;
+
+import com.saga.util.Constant;
+import com.saga.util.HBaseUtil;
+import com.zillion.database.agent.ZillionAgent;
+
+public class Test {
+
+	public Test() {
+		// TODO Auto-generated constructor stub
+	}
+
+	public static void main(String[] args) {
+		// TODO Auto-generated method stub
+		System.out.println("1101080002;1;pointset;;66;666666;11024;0".length());
+		// String point = "8002.11201";
+		// System.out.println(point);
+		// String meter = point.split("\\.")[0];
+		// String funcid = (point.split("\\.")[1]);
+		// System.out.println(meter);
+		// System.out.println(funcid);
+
+		// getConfigFile(LogUtil.GetPath(), "config-", "port");
+		// System.out.println(Constant.pointInfo);
+		// for (Entry<String, String> pi : Constant.pointInfo.entrySet()) {
+		// System.out.println(pi.getKey() + " " + pi.getValue());
+		// }
+
+		// try {
+		// System.out.println(System.currentTimeMillis());
+		// Constant.getLocalHostLANAddress();
+		// System.out.println(System.currentTimeMillis());
+		// } catch (UnknownHostException e) {
+		// // TODO Auto-generated catch block
+		// e.printStackTrace();
+		// }
+		// List<String> a = new ArrayList<String>();
+		// List<String> b = new ArrayList<String>();
+		// a.add("a");
+		// a.add("b");
+		// a.add("c");
+		// b.addAll(a);
+		// a = new ArrayList<String>();
+		// for (String s : b) {
+		// System.out.println(s);
+		// }
+		// try {
+		// String resource = "/hbase-site.xml";
+		// Configuration configuration = new Configuration();
+		//
+		// configuration.addResource(new
+		// FileInputStream(System.getProperty("user.dir") + resource));
+		// String zookeeper_connectionAddress =
+		// "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181";
+		// int zookeeper_sessionTimeout = 300000;
+		// Constant.agent = new ZillionAgent(configuration,
+		// zookeeper_connectionAddress, zookeeper_sessionTimeout);
+		//
+		// Constant.agent.Start();
+		// // LogUtil.info("" + Constant.BuildingDB);
+		// // LogUtil.info("" + Constant.BuildingAdds);
+		// // LogUtil.info("" + Constant.BuildingConv);
+		//
+		// } catch (Exception e) {
+		// // TODO Auto-generated catch block
+		// LogUtil.error("Main: " + e.toString());
+		// }
+		// while (true) {
+		// // 加载采集器配置文件
+		// // 文件夹命名格式:config+"-"+楼号+"-"+mac序号,示例:config-1101080002-1
+		// Constant.getConfigFile(LogUtil.GetPath(), "config-", "port");
+		// // 采集器点位位置信息写入数据库
+		// for (Entry<String, String> pi : Constant.pointInfo.entrySet()) {
+		// String building = pi.getKey().split("-")[0];
+		// String mac = pi.getKey().split("-")[1];
+		// String node = mac;
+		// String point = pi.getKey().split("-")[2];
+		// String busno = pi.getValue().split("-")[0];
+		// String site = pi.getValue().split("-")[1];
+		// try {
+		// System.out.println(building + " " + node + " " + point + " " + busno
+		// + " " + site);
+		// // HBaseUtil.InsertPointInfo(Constant.agent,
+		// // Constant.BuildingDB.get(building), building, node, point,
+		// // busno, site);
+		// } catch (Exception e) {
+		// // TODO Auto-generated catch block
+		// e.printStackTrace();
+		// }
+		// // System.out.println(building + node + point + busno + site);
+		// }
+		// try {
+		// Thread.sleep(Constant.Millisecond.MINUTE_1);
+		// } catch (InterruptedException e) {
+		// // TODO Auto-generated catch block
+		// e.printStackTrace();
+		// }
+		// }
+
+	}
+
+	public static List<String> getConfigFile(String directoryPath, String directoryKey, String fileKey) {
+		List<String> list = new ArrayList<String>();
+		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<Element> devList = document.selectNodes("/root/portdev/devtype");
+						// System.out.println(file.getName());
+						// System.out.println(file.getName().indexOf(fileKey));
+						// System.out.println(file.getName().indexOf(".xml"));
+						String port = file.getName().substring(file.getName().indexOf(fileKey) + fileKey.length(),
+								file.getName().indexOf(".xml"));
+						// System.out.println(port);
+						// System.out.println(file.getParentFile().getName());
+						String building = file.getParentFile().getName().replace(directoryKey, "").substring(0, 10);
+						String mac = file.getParentFile().getName().replace(directoryKey, "").substring(10);
+						// System.out.println(building);
+						// System.out.println(mac);
+
+						for (Element portdev : devList) {
+							String meter = portdev.attributeValue("meterid");
+							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);
+								// System.out.println(meter + "." +
+								// func.getText());
+							}
+						}
+
+					}
+				}
+			}
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		return list;
+	}
+}

+ 267 - 0
collect/src/main/java/com/saga/thread/common/CheckThread.java

@@ -0,0 +1,267 @@
+package com.saga.thread.common;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.zillion.util.log.LogUtil;
+
+import com.saga.util.Constant;
+import com.saga.util.HBaseUtil;
+import com.zillion.database.agent.ZillionAgent;
+
+public class CheckThread extends Thread {
+	ZillionAgent agent;
+	long realCheck = 0;
+	private String ip = null;
+	private Map<String, String> nodeStatus = new HashMap<String, String>();
+	private Map<String, String> pointStatus = new HashMap<String, String>();
+
+	public CheckThread(ZillionAgent agent) {
+		try {
+			this.agent = agent;
+			try {
+				this.ip = Constant.getLocalHostLANAddress().getHostAddress() + ":" + Constant.TypePort.get("Down");
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				this.ip = "0.0.0.0" + ":" + Constant.TypePort.get("Down");
+				e.printStackTrace();
+			}
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("CheckThread.Exception: " + e.toString());
+			System.exit(0);
+		}
+	}
+
+	public void run() {
+		LogUtil.info("CheckThread-" + this.getName() + " Starting ...");
+
+		while (true) {
+			try {
+				this.realCheck();
+				Thread.sleep(Constant.Millisecond.SECOND_1);
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				LogUtil.error("CheckThread.run.Exception: " + e.toString());
+			}
+		}
+	}
+
+	private void realCheck() {
+		// TODO Auto-generated method stub
+
+		if (System.currentTimeMillis() - this.realCheck > Constant.Millisecond.SECOND_3) {
+			this.realCheck = System.currentTimeMillis();
+
+			try {
+				// CollectorStatus
+				// LogUtil.info("Constant.nodeList:" + Constant.nodeList);
+				for (Entry<String, Long> node : Constant.nodeList.entrySet()) {
+					try {
+						String building = node.getKey().split("-")[0];
+						String mac = node.getKey().split("-")[1];
+						String status = "";
+						if (node.getValue() != null
+								&& this.realCheck - node.getValue() < Constant.Millisecond.MINUTE_1) {
+							HBaseUtil.InsertCollectorStatus(Constant.agent, Constant.BuildingDB.get(building), building,
+									this.ip, mac, "conn", Constant.format(new Date(node.getValue())));
+							status = "conn";
+						} else {
+							HBaseUtil.InsertCollectorStatus(Constant.agent, Constant.BuildingDB.get(building), building,
+									this.ip, mac, "disconn", Constant.format(new Date(node.getValue())));
+							status = "disconn";
+						}
+
+						if ((!this.nodeStatus.containsKey(node.getKey()))
+								|| (!status.equalsIgnoreCase(this.nodeStatus.get(node.getKey())))) {
+							// 添加Log记录
+							HBaseUtil.InsertCollectorCommunicationLog(Constant.agent, Constant.BuildingDB.get(building),
+									building, this.ip, mac, Constant.format(new Date(node.getValue())), (status));
+						}
+						// 更新Status
+						this.nodeStatus.put(node.getKey(), status);
+					} catch (Exception e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+						LogUtil.error("CheckThread.realCheck.CollectorStatus.Exception: " + e.toString());
+					}
+				}
+				// PointStatus
+				// up
+				// LogUtil.info("Constant.pointListUp:" + Constant.pointListUp);
+				// synchronized (Constant.pointListUp) {
+				// if (Constant.pointListUp.size() > 0) {
+
+				// Iterator<Entry<String, Long>> pu =
+				// Constant.pointListUp.entrySet().iterator();
+				Map<String, Long> pu = new HashMap<String, Long>();
+				synchronized (Constant.pointListUp) {
+					if (Constant.pointListUp.size() > 0) {
+						pu.putAll(Constant.pointListUp);
+					}
+				}
+				for (Entry<String, Long> pointUp : pu.entrySet()) {
+					try {
+						String building = pointUp.getKey().split("-")[0];
+						String mac = pointUp.getKey().split("-")[1];
+						String point = pointUp.getKey().split("-")[2];
+						// System.out.println(point);
+						String meter = point.split("\\.")[0];
+						String funcid = point.split("\\.")[1];
+						// System.out.println(meter);
+						// System.out.println(funcid);
+						String status = "";
+
+						if (pointUp.getValue() != null
+								&& this.realCheck - pointUp.getValue() < Constant.Millisecond.MINUTE_10) {
+							HBaseUtil.InsertPointStatus(Constant.agent, Constant.BuildingDB.get(building), building,
+									this.ip, mac, meter, funcid, "up", "conn",
+									Constant.format(new Date(pointUp.getValue())), "");
+							status = "conn";
+						} else {
+							if (pointUp.getValue() != null) {
+								HBaseUtil.InsertPointStatus(Constant.agent, Constant.BuildingDB.get(building), building,
+										this.ip, mac, meter, funcid, "up", "disconn",
+										Constant.format(new Date(pointUp.getValue())), "");
+								status = "disconn";
+							}
+						}
+						if ((!this.pointStatus.containsKey(pointUp.getKey()))
+								|| (!status.equalsIgnoreCase(this.pointStatus.get(pointUp.getKey())))) {
+							// 添加Log记录
+							if (Constant.RecordAddress.containsKey(building + "-" + point.replace(".", "-"))) {
+								int address = Constant.RecordAddress.get(building + "-" + point.replace(".", "-"));
+								if (pointUp.getValue() != null) {
+									HBaseUtil.InsertPointCommunicationLog(Constant.agent,
+											Constant.BuildingDB.get(building), building, this.ip, mac, meter, funcid,
+											"up", (status), Constant.RecordList.get(address).seq,
+											Constant.format(new Date(pointUp.getValue())), "");
+								}
+							}
+
+						}
+						// 更新Status
+						this.pointStatus.put(pointUp.getKey(), status);
+					} catch (Exception e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+						LogUtil.error("CheckThread.realCheck.PointStatus.up.Exception:" + e.toString());
+					}
+				}
+				// down
+				try {
+					List<String> nk = new ArrayList<String>();
+					List<String> ps = new ArrayList<String>();
+					synchronized (Constant.id2time) {
+						Iterator<Entry<String, Long>> it = Constant.id2time.entrySet().iterator();
+						while (it.hasNext()) {
+							try {
+								Entry<String, Long> n = it.next();
+								String building = Constant.id2point.get(n.getKey()).split("-")[0];
+								String mac = Constant.id2point.get(n.getKey()).split("-")[1];
+								String point = Constant.id2point.get(n.getKey()).split("-")[2];
+								String meter = point.split("\\.")[0];
+								String funcid = point.split("\\.")[1];
+								// String function =
+								// Constant.id2function.get(n.getKey());
+
+								if (n.getValue() != null
+										&& System.currentTimeMillis() - n.getValue() > Constant.Millisecond.SECOND_10) {
+									try {
+										if ("finish:finish:success"
+												.equalsIgnoreCase(Constant.id2status.get(n.getKey()))) {
+											// HBaseUtil.InsertPointStatus(Constant.agent,
+											// Constant.BuildingDB.get(building),
+											// building, this.ip, mac, meter,
+											// funcid, "down", "conn",
+											// // function + ":" +
+											// Constant.format(new
+											// Date(Constant.id2time.get(n.getKey()))),
+											// Constant.id2status.get(n.getKey()));
+											ps.add(Constant.BuildingDB.get(building) + ";" + building + ";" + this.ip
+													+ ";" + mac + ";" + meter + ";" + funcid + ";" + "down" + ";"
+													+ "conn" + ";"
+													+ Constant.format(new Date(Constant.id2time.get(n.getKey()))) + ";"
+													+ Constant.id2status.get(n.getKey()));
+										} else {
+											// Constant.pointListDown.put(n.getKey(),
+											// null);
+											// HBaseUtil.InsertPointStatus(Constant.agent,
+											// Constant.BuildingDB.get(building),
+											// building, this.ip, mac, meter,
+											// funcid, "down", "disconn",
+											// // function + ":" +
+											// Constant.format(new
+											// Date(Constant.id2time.get(n.getKey()))),
+											// Constant.id2status.get(n.getKey()));
+											ps.add(Constant.BuildingDB.get(building) + ";" + building + ";" + this.ip
+													+ ";" + mac + ";" + meter + ";" + funcid + ";" + "down" + ";"
+													+ "disconn" + ";"
+													+ Constant.format(new Date(Constant.id2time.get(n.getKey()))) + ";"
+													+ Constant.id2status.get(n.getKey()));
+										}
+
+									} catch (Exception e) {
+										// TODO Auto-generated catch block
+										e.printStackTrace();
+									}
+									nk.add(n.getKey());
+									it.remove();
+								}
+							} catch (Exception e) {
+								// TODO Auto-generated catch block
+								e.printStackTrace();
+							}
+						}
+					}
+
+					synchronized (Constant.id2point) {
+						for (String k : nk) {
+							if (Constant.id2point.containsKey(k)) {
+								Constant.id2point.remove(k);
+							}
+						}
+					}
+					synchronized (Constant.id2status) {
+						for (String k : nk) {
+							if (Constant.id2status.containsKey(k)) {
+								Constant.id2status.remove(k);
+							}
+						}
+					}
+					synchronized (Constant.id2function) {
+						for (String k : nk) {
+							if (Constant.id2function.containsKey(k)) {
+								Constant.id2function.remove(k);
+							}
+						}
+					}
+
+					nk = new ArrayList<String>();
+					for (String s : ps) {
+						String[] a = s.split(";");
+						HBaseUtil.InsertPointStatus(Constant.agent, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7],
+								a[8], a[9]);
+						Thread.sleep(1L);
+					}
+					ps = new ArrayList<String>();
+
+				} catch (Exception e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+					LogUtil.error("CheckThread.realCheck.PointStatus.down.Exception:" + e.toString());
+				}
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+				LogUtil.error("CheckThread.realCheck.Exception: " + e.toString());
+			}
+		}
+	}
+
+}

+ 131 - 0
collect/src/main/java/com/saga/thread/common/LoadConfigThread.java

@@ -0,0 +1,131 @@
+package com.saga.thread.common;
+
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Map.Entry;
+
+import org.zillion.util.log.LogUtil;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.saga.util.Constant;
+import com.saga.util.HBaseUtil;
+import com.zillion.database.agent.ZillionAgent;
+
+public class LoadConfigThread extends Thread {
+	ZillionAgent agent;
+
+	public LoadConfigThread() {
+		try {
+			this.agent = Constant.agent;
+
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("LoadConfigThread.Exception: " + e.toString());
+			System.exit(0);
+		}
+	}
+
+	public void run() {
+		LogUtil.info("LoadConfigThread" + this.getName() + " Starting ...");
+
+		while (true) {
+			try {
+				// 加载config配置文件
+
+				String resource = "/config.json";
+				String path = null;
+				JsonParser config = new JsonParser();
+
+				try {
+					LogUtil.info("System.get " + System.getProperty("user.dir") + resource);
+					LogUtil.info("LogUtil.get " + LogUtil.GetPath() + resource);
+					path = LogUtil.GetPath() + resource;
+
+					JsonObject object = (JsonObject) config.parse(new FileReader(path));
+
+					JsonArray db = object.get("DB").getAsJsonArray();
+					for (int i = 0; i < db.size(); i++) {
+						JsonObject subObject = db.get(i).getAsJsonObject();
+						if (subObject.get("building") != null) {
+							String building = subObject.get("building").getAsString();
+							// if(Constant.BuildingDB.containsKey(building)){
+							// continue;
+							// }
+							Constant.BuildingDB.put(building, subObject.get("database").getAsString());
+
+							if (subObject.get("buildingadds") != null) {
+								JsonArray buildingAdds = subObject.get("buildingadds").getAsJsonArray();
+								for (int j = 0; j < buildingAdds.size(); j++) {
+									JsonObject addObject = buildingAdds.get(j).getAsJsonObject();
+									String builing_new = addObject.get("building").getAsString();
+									if (!Constant.BuildingAdds.containsKey(building)) {
+										Constant.BuildingAdds.put(building, new ArrayList<String>());
+									}
+									if (!exist(builing_new)) {
+										Constant.BuildingAdds.get(building).add(builing_new);
+										Constant.BuildingConv.put(builing_new, building);
+									}
+								}
+
+							}
+						} else if (subObject.get("insertthread") != null) {
+							Constant.InsertThread = subObject.get("insertthread").getAsInt();
+						}
+					}
+					JsonArray port = object.get("Port").getAsJsonArray();
+					for (int i = 0; i < port.size(); i++) {
+						JsonObject subObject = port.get(i).getAsJsonObject();
+						Constant.TypePort.put(subObject.get("type").getAsString(), subObject.get("port").getAsString());
+					}
+
+				} catch (Exception e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+
+				// 加载采集器配置文件
+				// 文件夹命名格式:config+"-"+楼号+"-"+mac序号,示例:config-1101080002-1
+				Constant.getConfigFile(LogUtil.GetPath(), "config-", "port");
+				// 采集器点位位置信息写入数据库
+				for (Entry<String, String> pi : Constant.pointInfo.entrySet()) {
+					String building = pi.getKey().split("-")[0];
+					String mac = pi.getKey().split("-")[1];
+					String node = mac;
+					String point = pi.getKey().split("-")[2];
+					String busno = pi.getValue().split("-")[0];
+					String site = pi.getValue().split("-")[1];
+					try {
+						LogUtil.info(building + " " + node + " " + point + " " + busno + " " + site);
+						HBaseUtil.InsertPointInfo(Constant.agent, Constant.BuildingDB.get(building), building, node,
+								point, busno, site);
+					} catch (Exception e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+					// System.out.println(building + node + point + busno +
+					// site);
+				}
+				try {
+					Thread.sleep(Constant.Millisecond.MINUTE_1);
+				} catch (InterruptedException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				LogUtil.error("LoadConfigThread.run.Exception: " + e.toString());
+			}
+		}
+	}
+
+	private boolean exist(String builing_new) {
+		// TODO Auto-generated method stub
+		if (Constant.BuildingConv.containsKey(builing_new)) {
+			return true;
+		}
+		return false;
+	}
+}

+ 394 - 0
collect/src/main/java/com/saga/thread/common/SaveThread.java

@@ -0,0 +1,394 @@
+package com.saga.thread.common;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import org.zillion.util.log.LogUtil;
+
+import com.saga.entity.Record;
+import com.saga.util.Constant;
+
+public class SaveThread extends Thread {
+	// private List<String> pointCommunicationList = new ArrayList<String>();
+	// private String ip = null;
+	private List<String> streportList = new ArrayList<String>();
+	private List<Record> strecordList = new ArrayList<Record>();
+
+	public SaveThread() {
+		try {
+			// this.ip = Constant.getLocalHostLANAddress().getHostAddress() +
+			// ":" + Constant.TypePort.get("Down");
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			// this.ip = "0.0.0.0" + ":" + Constant.TypePort.get("Down");
+			e.printStackTrace();
+		}
+	}
+
+	public void run() {
+		LogUtil.info("SaveThread" + " Starting ...");
+		while (true) {
+			try {
+				// this.insertPointCommunicationLog();
+				this.handleCollectReportList2();
+				// this.handleCollectReportList1();
+
+				Thread.sleep(1L);
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+	}
+
+	// private void insertPointCommunicationLog() {
+	// // TODO Auto-generated method stub
+	//
+	// // PointCommunicationLogÌí¼Ó¼Ç¼
+	// try {
+	// if (pointCommunicationList.size() > 0) {
+	// // LogUtil.info("pointCommunicationList.size: " +
+	// // pointCommunicationList.size());
+	// // LogUtil.info("InsertPointCommunicationLog begin...");
+	// HBaseUtil.InsertPointCommunicationLog(pointCommunicationList);
+	// // LogUtil.info("InsertPointCommunicationLog end...");
+	// pointCommunicationList = new ArrayList<String>();
+	// }
+	// } catch (Exception e) {
+	// // TODO Auto-generated catch block
+	// e.printStackTrace();
+	// }
+	// }
+
+	private void handleCollectReportList2() {
+		// TODO Auto-generated method stub
+		try {
+			synchronized (Constant.CollectReportList) {
+				if (Constant.CollectReportList.size() > 0) {
+					LogUtil.info("Constant.CollectReportList:" + Constant.CollectReportList.size());
+					this.streportList.addAll(Constant.CollectReportList);
+					Constant.CollectReportList.clear();
+					// Constant.CollectReportList = new ArrayList<String>();
+					LogUtil.info("Constant.CollectReportList:" + Constant.CollectReportList.size());
+					if (Constant.CollectReportList.size() > 0) {
+						LogUtil.warn("Constant.CollectReportList:" + Constant.CollectReportList.size());
+						Constant.CollectReportList.clear();
+						System.gc();
+					}
+
+				} else {
+					return;
+				}
+			}
+			Constant.collectReportCount += this.streportList.size();
+			LogUtil.info("ReportList:" + this.streportList.size());
+			int seq = 0;
+
+			while (this.streportList.size() > 0) {
+				seq++;
+				LogUtil.info("ReportList:" + this.streportList.size() + " seq:" + seq);
+				int no = 5000 > this.streportList.size() ? this.streportList.size() : 5000;
+				if (no == 5000 || seq > 1) {
+					LogUtil.info("ReportList:" + this.streportList.size() + " seq:" + seq);
+				}
+				String b = this.streportList.get(0).replace("(", "").replace(")", "").replace("", "");
+				if (b == null || b.length() == 0) {
+					this.streportList.remove(0);
+					return;
+				}
+				b = this.streportList.get(0).replace("(", "").replace(")", "").replace(" ", "").split(";")[0];
+
+				while (Constant.RecordListToDB.size() > 0) {
+					if (Constant.RecordListToDB.size() == 0) {
+						break;
+					} else {
+						Thread.sleep(3L);
+					}
+					Thread.sleep(1L);
+				}
+
+				// recordList = new ArrayList<Record>();
+				if (this.strecordList.size() > 0) {
+					LogUtil.warn("SaveThread.recordList " + this.strecordList.size());
+					this.strecordList.clear();
+					System.gc();
+				}
+				Iterator<String> it = this.streportList.iterator();
+				int c = 0;
+				synchronized (Constant.pointListUp) {
+					while (it.hasNext()) {
+						try {
+							String report = it.next().replace("(", "").replace(")", "").replace(" ", "");
+							if (c < no) {
+								if (report != null) {
+									String[] rList = report.replace("(", "").replace(")", "").replace(" ", "")
+											.split(";");
+									if (rList != null && rList.length > 8) {
+										String building = rList[0];
+										if (!building.equalsIgnoreCase(b)) {
+											continue;
+										}
+										String mac = rList[1];
+										String function = rList[2];
+										Date time = Constant.parse(rList[3]);
+										String meter = rList[5];
+										int count = Integer.valueOf(rList[6]);
+										// String id = rList[4];
+
+										for (int i = 0; i < count; i++) {
+											Record record = new Record();
+											if ("report".equalsIgnoreCase(function)) {
+												record.funcID = Integer.valueOf(rList[7 + 2 * i]);
+												record.data = Double.valueOf(rList[8 + 2 * i]);
+												// synchronized
+												// (Constant.pointListUp) {
+												Constant.pointListUp.put(
+														building + "-" + mac + "-" + meter + "." + record.funcID,
+														System.currentTimeMillis());
+												// }
+
+											} else if ("reportaddtion".equalsIgnoreCase(function)) {
+												record.funcID = Integer.valueOf(rList[7 + 3 * i]);
+												record.data = Double.valueOf(rList[8 + 3 * i]);
+												record.addtion = "null".equalsIgnoreCase(rList[9 + i * 3]) ? ""
+														: (rList[9 + i * 3]);
+												// synchronized
+												// (Constant.pointListUp) {
+												Constant.pointListUp.put(
+														building + "-" + mac + "-" + meter + "." + record.funcID,
+														System.currentTimeMillis());
+
+												// }
+											}
+
+											record.buildingSign = building;
+											record.meterSign = meter;
+											record.receivetime = time;
+
+											this.strecordList.add(record);
+
+										}
+										it.remove();
+										// LogUtil.info("HBase.BatchInsert "
+										// +
+										// report);
+									} else {
+										it.remove();
+									}
+
+								} else {
+									it.remove();
+								}
+							} else {
+								break;
+							}
+							c++;
+							// Thread.sleep(1L);
+						} catch (Exception e) {
+							// TODO Auto-generated catch block
+							it.remove();
+							LogUtil.error("SaveThread.run.Exception: " + e.toString());
+						}
+					}
+				}
+
+				Constant.RecordListToDB.addAll(this.strecordList);
+				Constant.report2DBCount += this.strecordList.size();
+				LogUtil.info("Constant.RecordListToDB add " + this.strecordList.size());
+				// recordList = new ArrayList<Record>();
+				this.strecordList.clear();
+
+				Thread.sleep(1L);
+
+				// Thread.sleep(Constant.Millisecond.SECOND_1);
+			}
+			if (this.streportList.size() > 0) {
+				LogUtil.warn("SaveThread.reportList " + streportList.size());
+				this.streportList.clear();
+				System.gc();
+				LogUtil.warn("SaveThread.reportList " + streportList.size());
+			}
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("SaveThread.run.Exception: " + e.toString());
+			// Constant.DBConn = false;
+		}
+	}
+
+	// private void addPointCommunicationList(String building, String ip, String
+	// mac, String point, String id,
+	// String receivetime, String addtion) {
+	// // TODO Auto-generated method stub
+	// this.pointCommunicationList.add(building + ";" + ip + ";" + mac + ";" +
+	// point + ";" + "conn/disconn" + ";" + id
+	// + ";" + receivetime + ";" + addtion);
+	// }
+
+	private void handleCollectReportList1() {
+		// TODO Auto-generated method stub
+		try {
+			synchronized (Constant.CollectReportList) {
+
+				if (Constant.CollectReportList.size() > 0) {
+					// LogUtil.info("SaveThread Challenge
+					// Constant.CollectReportList
+					// begin...");
+					// synchronized (Constant.CollectReportList) {
+					// LogUtil.info("SaveThread Challenge
+					// Constant.CollectReportList get...");
+					// LogUtil.info("Constant.CollectReportList.size(): " +
+					// Constant.CollectReportList.size());
+					int no = 5000 > Constant.CollectReportList.size() ? Constant.CollectReportList.size() : 5000;
+					String b = Constant.CollectReportList.get(0).replace("(", "").replace(")", "").replace(" ", "");
+					if (b == null || b.length() == 0) {
+						Constant.CollectReportList.remove(0);
+						return;
+					}
+					b = Constant.CollectReportList.get(0).replace("(", "").replace(")", "").replace(" ", "")
+							.split(";")[0];
+					// if (Constant.RecordListToDB.size() > 0) {
+					// LogUtil.info("wait Constant.RecordListToDB begin");
+					// LogUtil.info("size:" + Constant.RecordListToDB.size()
+					// + "-->0");
+					// }
+					while (Constant.RecordListToDB.size() > 0) {
+						if (Constant.RecordListToDB.size() == 0) {
+							LogUtil.info("wait Constant.RecordListToDB end ");
+							break;
+						} else {
+							Thread.sleep(3L);
+							LogUtil.info(
+									"wait Constant.RecordListToDB.size:" + Constant.RecordListToDB.size() + "-->0");
+						}
+						Thread.sleep(1L);
+					}
+
+					// List<Record> recordList = new ArrayList<Record>();
+					this.strecordList.clear();
+					Iterator<String> it = Constant.CollectReportList.iterator();
+					int c = 0;
+					while (it.hasNext()) {
+						// LogUtil.info("Constant.CollectReportList deal " + c);
+						try {
+
+							String report = it.next().replace("(", "").replace(")", "").replace(" ", "");
+							if (c < no) {
+								if (report != null) {
+									String[] rList = report.replace("(", "").replace(")", "").replace(" ", "")
+											.split(";");
+									if (rList != null && rList.length > 8) {
+										String building = rList[0];
+										if (!building.equalsIgnoreCase(b)) {
+											continue;
+										}
+										String mac = rList[1];
+										String function = rList[2];
+										Date time = Constant.parse(rList[3]);
+										String meter = rList[5];
+										int count = Integer.valueOf(rList[6]);
+										// String id = rList[4];
+
+										for (int i = 0; i < count; i++) {
+											Record record = new Record();
+											if ("report".equalsIgnoreCase(function)) {
+												Constant.collectReportCount++;
+												record.funcID = Integer.valueOf(rList[7 + 2 * i]);
+												record.data = Double.valueOf(rList[8 + 2 * i]);
+												Constant.pointListUp.put(
+														building + "-" + mac + "-" + meter + "." + record.funcID,
+														System.currentTimeMillis());
+												// // PointCommunicationLogÌí¼Ó¼Ç¼
+												// this.pointCommunicationList.add(building
+												// + ";" + this.ip + ";" + mac
+												// + ";" + meter + "." +
+												// record.funcID + ";" +
+												// function + ";" + id
+												// + ";" + rList[3] + ";" + "");
+											} else if ("reportaddtion".equalsIgnoreCase(function)) {
+												Constant.collectReportCount++;
+												record.funcID = Integer.valueOf(rList[7 + 3 * i]);
+												record.data = Double.valueOf(rList[8 + 3 * i]);
+												record.addtion = "null".equalsIgnoreCase(rList[9 + i * 3]) ? ""
+														: (rList[9 + i * 3]);
+												Constant.pointListUp.put(
+														building + "-" + mac + "-" + meter + "." + record.funcID,
+														System.currentTimeMillis());
+												// // PointCommunicationLogÌí¼Ó¼Ç¼
+												// this.pointCommunicationList.add(building
+												// + ";" + this.ip + ";" + mac
+												// + ";" + meter + "." +
+												// record.funcID + ";" +
+												// function + ";" + id
+												// + ";" + rList[3] + ";" +
+												// record.addtion);
+												// HBaseUtil.InsertPointCommunicationLog(Constant.agent,
+												// Constant.BuildingDB.get(building),
+												// building,
+												// Constant.getLocalHostLANAddress().getHostAddress(),
+												// mac,
+												// meter + "." + record.funcID,
+												// function, id, rList[3],
+												// record.addtion);
+
+											}
+
+											record.buildingSign = building;
+											record.meterSign = meter;
+											record.receivetime = time;
+
+											this.strecordList.add(record);
+
+										}
+										it.remove();
+										// LogUtil.info("HBase.BatchInsert "
+										// +
+										// report);
+									} else {
+										it.remove();
+									}
+
+								} else {
+									it.remove();
+								}
+							} else {
+								break;
+							}
+							c++;
+							Thread.sleep(1L);
+						} catch (Exception e) {
+							// TODO Auto-generated catch block
+							it.remove();
+							LogUtil.error("SaveThread.run.Exception: " + e.toString());
+						}
+					}
+				}
+			}
+			// LogUtil.info("SaveThread Challenge
+			// Constant.RecordListToDB begin...");
+			Constant.RecordListToDB.addAll(this.strecordList);
+			Constant.report2DBCount += this.strecordList.size();
+			this.strecordList.clear();
+			if (this.strecordList.size() > 0) {
+				this.strecordList = new ArrayList<Record>();
+				System.gc();
+			}
+			// LogUtil.info("SaveThread Challenge
+			// Constant.RecordListToDB realse...");
+			// HBaseUtil.BatchInsert(Constant.agent,
+			// Constant.BuildingDB.get(b), recordList);
+			// }
+			// LogUtil.info("SaveThread Challenge
+			// Constant.CollectReportList
+			// realse...");
+			Thread.sleep(1L);
+
+			// Thread.sleep(Constant.Millisecond.SECOND_1);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("SaveThread.run.Exception: " + e.toString());
+			// Constant.DBConn = false;
+		}
+	}
+}

+ 68 - 0
collect/src/main/java/com/saga/thread/common/StatsThread.java

@@ -0,0 +1,68 @@
+package com.saga.thread.common;
+
+import java.util.Date;
+
+import org.zillion.util.log.LogUtil;
+
+import com.saga.util.Constant;
+
+public class StatsThread extends Thread {
+	private Date from = new Date();
+
+	public StatsThread() {
+	}
+
+	public void run() {
+		LogUtil.warn("StatsThread" + " Starting ...");
+		try {
+			Thread.sleep(Constant.Millisecond.MINUTE_3);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		while (true) {
+			try {
+				LogUtil.warn("StatsThread" + " begin ...");
+				Date to = new Date();
+				this.statsCollect(to);
+				this.statsSend(to);
+				this.statsWTDB(to);
+				this.from = to;
+				LogUtil.warn("StatsThread" + " end ...");
+				Thread.sleep(Constant.Millisecond.MINUTE_5);
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+	}
+
+	private void statsWTDB(Date to) {
+		// TODO Auto-generated method stub
+		LogUtil.warn("StatsThread: " + this.from + " ~ " + to + " Report received :" + Constant.collectCount
+				+ " , saved :" + Constant.collectReportCount + " , to DB :" + Constant.report2DBCount + " Remain: "
+				+ Constant.CollectReportList.size() + " , DB writen :" + Constant.writeDB + " Remain: "
+				+ Constant.RecordListToDB.size());
+		Constant.collectCount = 0;
+		Constant.collectReportCount = 0;
+		Constant.report2DBCount = 0;
+		Constant.writeDB = 0;
+	}
+
+	private void statsSend(Date to) {
+		// TODO Auto-generated method stub
+		LogUtil.warn("StatsThread: " + this.from + " ~ " + to + " SEND received :" + Constant.sendRec + " sent :"
+				+ Constant.sendSend);
+		Constant.sendRec = 0;
+		Constant.sendSend = 0;
+	}
+
+	private void statsCollect(Date to) {
+		// TODO Auto-generated method stub
+		LogUtil.warn("StatsThread: " + this.from + " ~ " + to + " Collect received :" + Constant.collectRec + " sent :"
+				+ Constant.collectSend);
+		Constant.collectRec = 0;
+		Constant.collectSend = 0;
+	}
+
+}

+ 393 - 0
collect/src/main/java/com/saga/thread/common/WTDBThread.java

@@ -0,0 +1,393 @@
+package com.saga.thread.common;
+
+import java.util.ArrayList;
+//import java.util.Date;
+//import java.util.HashMap;
+//import java.util.Iterator;
+import java.util.List;
+//import java.util.Map;
+//import java.util.Map.Entry;
+
+import org.zillion.util.log.LogUtil;
+
+import com.saga.entity.Record;
+import com.saga.util.Constant;
+import com.saga.util.HBaseUtil;
+import com.zillion.database.agent.ZillionAgent;
+
+public class WTDBThread extends Thread {
+	ZillionAgent agent;
+	long realCheck = 0;
+	// private String ip = null;
+	private List<Record> wtdbrecordList = new ArrayList<Record>();
+	// private Map<String, String> nodeStatus = new HashMap<String, String>();
+	// private Map<String, String> pointStatus = new HashMap<String, String>();
+
+	public WTDBThread(ZillionAgent agent) {
+		try {
+			this.agent = agent;
+			// try {
+			// this.ip = Constant.getLocalHostLANAddress().getHostAddress() +
+			// ":" + Constant.TypePort.get("Down");
+			// } catch (Exception e) {
+			// // TODO Auto-generated catch block
+			// this.ip = "0.0.0.0" + ":" + Constant.TypePort.get("Down");
+			// e.printStackTrace();
+			// }
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("WTDBThread.Exception: " + e.toString());
+			System.exit(0);
+		}
+	}
+
+	public void run() {
+		LogUtil.info("WTDBThread-" + this.getName() + " Starting ...");
+
+		while (true) {
+			try {
+				// LogUtil.info("WTDBThread-" + this.getName() + " Circling
+				// ...");
+				// this.realCheck();
+				synchronized (Constant.RecordListToDB) {
+					if (Constant.RecordListToDB.size() > 0) {
+						// LogUtil.info(
+						// this.getName() + " Constant.RecordListToDB.size(): "
+						// + Constant.RecordListToDB.size());
+						wtdbrecordList.addAll(Constant.RecordListToDB);
+						LogUtil.info("Constant.RecordListToDB remove " + wtdbrecordList.size());
+						Constant.RecordListToDB = new ArrayList<Record>();
+
+						// LogUtil.info(
+						// this.getName() + " Constant.RecordListToDB.size(): "
+						// + Constant.RecordListToDB.size());
+					}
+				}
+				if (wtdbrecordList.size() > 0) {
+					String b = wtdbrecordList.get(0).buildingSign;
+					if (Constant.BuildingConv.containsKey(b)) {
+						b = Constant.BuildingConv.get(b);
+					}
+					HBaseUtil.BatchInsert(this.agent, Constant.BuildingDB.get(b), wtdbrecordList);
+					// LogUtil.info(this.getName() + " recordList size: " +
+					// recordList.size());
+					// LogUtil.info(this.getName() + " HBaseUtil.BatchInsert
+					// size: " + recordList.size());
+					wtdbrecordList = new ArrayList<Record>();
+					// LogUtil.info(this.getName() + " recordList size: " +
+					// recordList.size());
+				}
+				Thread.sleep(3L);
+				// Thread.sleep(Constant.Millisecond.SECOND_1);
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				LogUtil.error("WTDBThread.run.Exception: " + e.toString());
+			}
+		}
+	}
+
+	// private void insertCollectorCommunicationLog(String building, String mac)
+	// {
+	// // TODO Auto-generated method stub
+	// try {
+	// HBaseUtil.InsertCollectorCommunicationLog(Constant.agent,
+	// Constant.BuildingDB.get(building), building,
+	// this.ip, mac, Constant.format(new Date()), "heart");
+	// } catch (Exception e) {
+	// // TODO Auto-generated catch block
+	// e.printStackTrace();
+	// LogUtil.error("CollectThread.insertCollectorCommunicationLog.Exception: "
+	// + e.toString());
+	// }
+	// }
+
+	// private void realCheck() {
+	// // TODO Auto-generated method stub
+	//
+	// if (System.currentTimeMillis() - this.realCheck >
+	// Constant.Millisecond.SECOND_3) {
+	// this.realCheck = System.currentTimeMillis();
+	//
+	// try {
+	// // CollectorStatus
+	// // LogUtil.info("Constant.nodeList:" + Constant.nodeList);
+	// for (Entry<String, Long> node : Constant.nodeList.entrySet()) {
+	// try {
+	// String building = node.getKey().split("-")[0];
+	// String mac = node.getKey().split("-")[1];
+	// String status = "";
+	// if (node.getValue() != null
+	// && this.realCheck - node.getValue() < Constant.Millisecond.MINUTE_1) {
+	// HBaseUtil.InsertCollectorStatus(Constant.agent,
+	// Constant.BuildingDB.get(building), building,
+	// this.ip, mac, "conn", Constant.format(new Date(node.getValue())));
+	// status = "conn";
+	// } else {
+	// HBaseUtil.InsertCollectorStatus(Constant.agent,
+	// Constant.BuildingDB.get(building), building,
+	// this.ip, mac, "disconn", Constant.format(new Date(node.getValue())));
+	// status = "disconn";
+	// }
+	//
+	// if ((!this.nodeStatus.containsKey(node.getKey()))
+	// || (!status.equalsIgnoreCase(this.nodeStatus.get(node.getKey())))) {
+	// // 添加Log记录
+	// HBaseUtil.InsertCollectorCommunicationLog(Constant.agent,
+	// Constant.BuildingDB.get(building),
+	// building, this.ip, mac, Constant.format(new Date(node.getValue())),
+	// (status));
+	// }
+	// // 更新Status
+	// this.nodeStatus.put(node.getKey(), status);
+	// } catch (Exception e) {
+	// // TODO Auto-generated catch block
+	// e.printStackTrace();
+	// LogUtil.error("WTDBThread.realCheck.CollectorStatus.Exception: " +
+	// e.toString());
+	// }
+	// }
+	// // PointStatus
+	// // up
+	// // LogUtil.info("Constant.pointListUp:" + Constant.pointListUp);
+	// // synchronized (Constant.pointListUp) {
+	// // if (Constant.pointListUp.size() > 0) {
+	//
+	// // Iterator<Entry<String, Long>> pu =
+	// // Constant.pointListUp.entrySet().iterator();
+	// Map<String, Long> pu = new HashMap<String, Long>();
+	// synchronized (Constant.pointListUp) {
+	// if (Constant.pointListUp.size() > 0) {
+	// pu.putAll(Constant.pointListUp);
+	// }
+	// }
+	// for (Entry<String, Long> pointUp : pu.entrySet()) {
+	// try {
+	// String building = pointUp.getKey().split("-")[0];
+	// String mac = pointUp.getKey().split("-")[1];
+	// String point = pointUp.getKey().split("-")[2];
+	// // System.out.println(point);
+	// String meter = point.split("\\.")[0];
+	// String funcid = point.split("\\.")[1];
+	// // System.out.println(meter);
+	// // System.out.println(funcid);
+	// String status = "";
+	//
+	// if (pointUp.getValue() != null
+	// && this.realCheck - pointUp.getValue() < Constant.Millisecond.MINUTE_10)
+	// {
+	// HBaseUtil.InsertPointStatus(Constant.agent,
+	// Constant.BuildingDB.get(building), building,
+	// this.ip, mac, meter, funcid, "up", "conn",
+	// Constant.format(new Date(pointUp.getValue())), "");
+	// status = "conn";
+	// } else {
+	// if (pointUp.getValue() != null) {
+	// HBaseUtil.InsertPointStatus(Constant.agent,
+	// Constant.BuildingDB.get(building), building,
+	// this.ip, mac, meter, funcid, "up", "disconn",
+	// Constant.format(new Date(pointUp.getValue())), "");
+	// status = "disconn";
+	// }
+	// }
+	// if ((!this.pointStatus.containsKey(pointUp.getKey()))
+	// || (!status.equalsIgnoreCase(this.pointStatus.get(pointUp.getKey())))) {
+	// // 添加Log记录
+	// if (Constant.RecordAddress.containsKey(building + "-" +
+	// point.replace(".", "-"))) {
+	// int address = Constant.RecordAddress.get(building + "-" +
+	// point.replace(".", "-"));
+	// if (pointUp.getValue() != null) {
+	// HBaseUtil.InsertPointCommunicationLog(Constant.agent,
+	// Constant.BuildingDB.get(building), building, this.ip, mac, meter, funcid,
+	// "up", (status), Constant.RecordList.get(address).seq,
+	// Constant.format(new Date(pointUp.getValue())), "");
+	// }
+	// }
+	//
+	// }
+	// // 更新Status
+	// this.pointStatus.put(pointUp.getKey(), status);
+	// } catch (Exception e) {
+	// // TODO Auto-generated catch block
+	// e.printStackTrace();
+	// LogUtil.error("WTDBThread.realCheck.PointStatus.up.Exception:" +
+	// e.toString());
+	// }
+	// }
+	//
+	// // while (pu.hasNext()) {
+	// // try {
+	// // Entry<String, Long> pointUp = pu.next();
+	// // String building = pointUp.getKey().split("-")[0];
+	// // String mac = pointUp.getKey().split("-")[1];
+	// // String point = pointUp.getKey().split("-")[2];
+	// // // System.out.println(point);
+	// // String meter = point.split("\\.")[0];
+	// // String funcid = point.split("\\.")[1];
+	// // // System.out.println(meter);
+	// // // System.out.println(funcid);
+	// // String status = "";
+	// //
+	// // if (pointUp.getValue() != null
+	// // && this.realCheck - pointUp.getValue() <
+	// // Constant.Millisecond.MINUTE_10) {
+	// // HBaseUtil.InsertPointStatus(Constant.agent,
+	// // Constant.BuildingDB.get(building), building,
+	// // this.ip, mac, meter, funcid, "up", "conn",
+	// // Constant.format(new Date(pointUp.getValue())), "");
+	// // status = "conn";
+	// // } else {
+	// // if (pointUp.getValue() != null) {
+	// // HBaseUtil.InsertPointStatus(Constant.agent,
+	// // Constant.BuildingDB.get(building), building,
+	// // this.ip, mac, meter, funcid, "up", "disconn",
+	// // Constant.format(new Date(pointUp.getValue())), "");
+	// // status = "disconn";
+	// // }
+	// // }
+	// // if ((!this.pointStatus.containsKey(pointUp.getKey()))
+	// // ||
+	// // (!status.equalsIgnoreCase(this.pointStatus.get(pointUp.getKey()))))
+	// // {
+	// // // 添加Log记录
+	// // if (Constant.RecordAddress.containsKey(building + "-" +
+	// // point.replace(".", "-"))) {
+	// // int address = Constant.RecordAddress.get(building + "-" +
+	// // point.replace(".", "-"));
+	// // HBaseUtil.InsertPointCommunicationLog(Constant.agent,
+	// // Constant.BuildingDB.get(building),
+	// // building, this.ip, mac, meter, funcid, "up", (status),
+	// // Constant.RecordList.get(address).seq,
+	// // Constant.format(new Date(pointUp.getValue())), "");
+	// // }
+	// //
+	// // }
+	// // // 更新Status
+	// // this.pointStatus.put(pointUp.getKey(), status);
+	// // } catch (Exception e) {
+	// // // TODO Auto-generated catch block
+	// // e.printStackTrace();
+	// // LogUtil.error("WTDBThread.realCheck.PointStatus.up.Exception:"
+	// // + e.toString());
+	// // }
+	// //
+	// // }
+	// // }
+	// // }
+	// // down
+	//
+	// try {
+	// List<String> nk = new ArrayList<String>();
+	// List<String> ps = new ArrayList<String>();
+	// synchronized (Constant.id2time) {
+	// Iterator<Entry<String, Long>> it =
+	// Constant.id2time.entrySet().iterator();
+	// while (it.hasNext()) {
+	// try {
+	// Entry<String, Long> n = it.next();
+	// String building = Constant.id2point.get(n.getKey()).split("-")[0];
+	// String mac = Constant.id2point.get(n.getKey()).split("-")[1];
+	// String point = Constant.id2point.get(n.getKey()).split("-")[2];
+	// String meter = point.split("\\.")[0];
+	// String funcid = point.split("\\.")[1];
+	// // String function =
+	// // Constant.id2function.get(n.getKey());
+	//
+	// if (n.getValue() != null
+	// && System.currentTimeMillis() - n.getValue() >
+	// Constant.Millisecond.SECOND_10) {
+	// try {
+	// if ("finish:finish:success"
+	// .equalsIgnoreCase(Constant.id2status.get(n.getKey()))) {
+	// // HBaseUtil.InsertPointStatus(Constant.agent,
+	// // Constant.BuildingDB.get(building),
+	// // building, this.ip, mac, meter,
+	// // funcid, "down", "conn",
+	// // // function + ":" +
+	// // Constant.format(new
+	// // Date(Constant.id2time.get(n.getKey()))),
+	// // Constant.id2status.get(n.getKey()));
+	// ps.add(Constant.BuildingDB.get(building) + ";" + building + ";" + this.ip
+	// + ";" + mac + ";" + meter + ";" + funcid + ";" + "down" + ";"
+	// + "conn" + ";"
+	// + Constant.format(new Date(Constant.id2time.get(n.getKey()))) + ";"
+	// + Constant.id2status.get(n.getKey()));
+	// } else {
+	// // Constant.pointListDown.put(n.getKey(),
+	// // null);
+	// // HBaseUtil.InsertPointStatus(Constant.agent,
+	// // Constant.BuildingDB.get(building),
+	// // building, this.ip, mac, meter,
+	// // funcid, "down", "disconn",
+	// // // function + ":" +
+	// // Constant.format(new
+	// // Date(Constant.id2time.get(n.getKey()))),
+	// // Constant.id2status.get(n.getKey()));
+	// ps.add(Constant.BuildingDB.get(building) + ";" + building + ";" + this.ip
+	// + ";" + mac + ";" + meter + ";" + funcid + ";" + "down" + ";"
+	// + "disconn" + ";"
+	// + Constant.format(new Date(Constant.id2time.get(n.getKey()))) + ";"
+	// + Constant.id2status.get(n.getKey()));
+	// }
+	//
+	// } catch (Exception e) {
+	// // TODO Auto-generated catch block
+	// e.printStackTrace();
+	// }
+	// nk.add(n.getKey());
+	// it.remove();
+	// }
+	// } catch (Exception e) {
+	// // TODO Auto-generated catch block
+	// e.printStackTrace();
+	// }
+	// }
+	// }
+	//
+	// synchronized (Constant.id2point) {
+	// for (String k : nk) {
+	// if (Constant.id2point.containsKey(k)) {
+	// Constant.id2point.remove(k);
+	// }
+	// }
+	// }
+	// synchronized (Constant.id2status) {
+	// for (String k : nk) {
+	// if (Constant.id2status.containsKey(k)) {
+	// Constant.id2status.remove(k);
+	// }
+	// }
+	// }
+	// synchronized (Constant.id2function) {
+	// for (String k : nk) {
+	// if (Constant.id2function.containsKey(k)) {
+	// Constant.id2function.remove(k);
+	// }
+	// }
+	// }
+	//
+	// nk = new ArrayList<String>();
+	// for (String s : ps) {
+	// String[] a = s.split(";");
+	// HBaseUtil.InsertPointStatus(Constant.agent, a[0], a[1], a[2], a[3], a[4],
+	// a[5], a[6], a[7],
+	// a[8], a[9]);
+	// Thread.sleep(1L);
+	// }
+	// ps = new ArrayList<String>();
+	//
+	// } catch (Exception e) {
+	// // TODO Auto-generated catch block
+	// e.printStackTrace();
+	// LogUtil.error("WTDBThread.realCheck.PointStatus.down.Exception:" +
+	// e.toString());
+	// }
+	// } catch (Exception e) {
+	// // TODO Auto-generated catch block
+	// e.printStackTrace();
+	// LogUtil.error("WTDBThread.realCheck.Exception: " + e.toString());
+	// }
+	// }
+	// }
+
+}

File diff suppressed because it is too large
+ 776 - 0
collect/src/main/java/com/saga/thread/down/CollectThread.java


+ 372 - 0
collect/src/main/java/com/saga/thread/up/SendThread.java

@@ -0,0 +1,372 @@
+package com.saga.thread.up;
+
+import java.net.UnknownHostException;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.zillion.util.log.LogUtil;
+
+import com.persagy.communication.entity.Packet;
+import com.persagy.communication.entity.PacketEntity;
+import com.persagy.communication.util.IServerManager;
+import com.saga.entity.PointSet;
+import com.saga.entity.Record;
+import com.saga.util.Constant;
+import com.saga.util.HBaseUtil;
+
+public class SendThread extends Thread {
+
+	private IServerManager uploadServer = null;
+	private String ip = null;
+
+	public SendThread(IServerManager uploadServer) {
+		// TODO Auto-generated constructor stub
+		try {
+			try {
+				this.ip = Constant.getLocalHostLANAddress().getHostAddress() + ":" + Constant.TypePort.get("Down");
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				this.ip = "0.0.0.0" + ":" + Constant.TypePort.get("Down");
+				e.printStackTrace();
+			}
+			this.uploadServer = uploadServer;
+			this.uploadServer.Start();
+			LogUtil.info("SendThread" + ": " + this.uploadServer.Name() + " Created ...");
+		} catch (Exception e) {
+			LogUtil.error("SendThread.Exception: " + e.toString());
+			LogUtil.error("SendThread" + ": " + this.uploadServer.Name() + " failed to excute, exit!");
+			System.exit(0);
+		}
+	}
+
+	public void run() {
+		try {
+			this.uploadServer.Start();
+		} catch (Exception e) {
+			LogUtil.error("SendThread.run.Exception: " + e.toString());
+		}
+		LogUtil.info("SendThread" + ": " + this.uploadServer.Name() + " Starting ...");
+		while (true) {
+			try {
+				// Constant.setlog = new File(
+				// System.getProperty("user.dir") + "/setlog" +
+				// Constant.format_day(new Date()) + ".log");
+
+				// 返pointset结果包
+				this.returnPointSet();
+				// 处理PopRece包
+				PacketEntity packageRece = this.uploadServer.PopRece();
+				if (packageRece != null) {
+					this.handlePopRece(packageRece);
+				}
+
+				Thread.sleep(1L);
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				LogUtil.error("SendThread.run.Exception: " + e.toString());
+			}
+		}
+	}
+
+	private void returnPointSet() {
+		// TODO Auto-generated method stub
+		try {
+			synchronized (Constant.pointSetList) {
+				if (Constant.pointSetList.size() > 0) {
+					Iterator<PointSet> it = Constant.pointSetList.iterator();
+					while (it.hasNext()) {
+						StringBuffer sb = new StringBuffer();
+						PointSet ps = it.next();
+						// String address =
+						// Constant.CollectorPointSetList.get(ps.buildingSign + ";"
+						// + ps.ID + ";");
+						// String address = ps.address;
+
+						if (!ps.uploadName.equalsIgnoreCase(this.uploadServer.Name())) {
+							break;
+						}
+
+						if (ps.address == null) {
+							break;
+						}
+
+						// 已得到控制设备的反馈状态,移除
+						if (ps.recTime > 0 && ps.sendTime > 0 && (ps.status != null && ps.status.length() > 0)) {
+							sb.append(ps.buildingSignUP).append(";").append(ps.mac).append(";").append("pointsetack")
+									.append(";").append(Constant.format(new Date())).append(";").append(ps.ID).append(";")
+									.append(ps.meterSign).append(";").append(ps.funcID).append(";").append(ps.status)
+									.append(";");
+							this.uploadServer.AppendToSend(ps.address, new Packet(sb.toString()));
+							Constant.sendSend += sb.toString().length();
+							HBaseUtil.BatchInsert_Set2(Constant.agent, Constant.BuildingDB.get(ps.buildingSign), ps);
+							LogUtil.info(this.uploadServer.Name() + " AppendToSend: " + ps.address + " " + sb.toString());
+
+							String id = ps.buildingSignUP + "-" + ps.mac + "-" + ps.ID;
+							synchronized (Constant.id2status) {
+								Constant.id2status.put(id, "finish:finish:" + ps.status);
+							}
+
+							HBaseUtil.InsertPointCommunicationLog(Constant.agent,
+									Constant.BuildingDB.get(ps.buildingSignUP), ps.buildingSignUP, this.ip, ps.mac,
+									ps.meterSign, String.valueOf(ps.funcID), "down", "pointsetack", String.valueOf(ps.ID),
+									Constant.format(new Date()), "finish:finish:" + ps.status);
+
+							// CSVUtil.insert(Constant.setlog, new
+							// StringBuffer(Constant.format_Log(new Date())
+							// + ": "
+							// + ps.meterSign + "." + ps.funcID + " set " +
+							// ps.dataSet + " " + ps.status + "!"
+							// + " Consuming:" + (ps.recTime - ps.sendTime <
+							// 0 ? 0 : ps.recTime - ps.sendTime)
+							// + "ms!" + "\r\n"));
+							it.remove();
+
+						} // 超时未得到设备的反馈状态,移除
+						else if (ps.recTime == 0 && ps.sendTime > 0
+								&& (System.currentTimeMillis() - ps.sendTime > Constant.getWaitingtime())) {
+							sb.append(ps.buildingSignUP).append(";").append(ps.mac).append(";").append("pointsetack")
+									.append(";").append(Constant.format(new Date())).append(";").append(ps.ID).append(";")
+									.append(ps.meterSign).append(";").append(ps.funcID).append(";").append("fail:timeout")
+									.append(";");
+							this.uploadServer.AppendToSend(ps.address, new Packet(sb.toString()));
+							Constant.sendSend += sb.toString().length();
+							HBaseUtil.BatchInsert_Set3(Constant.agent, Constant.BuildingDB.get(ps.buildingSign), ps);
+							LogUtil.info(this.uploadServer.Name() + " AppendToSend: " + ps.address + " " + sb.toString());
+							String id = ps.buildingSignUP + "-" + ps.mac + "-" + ps.ID;
+
+							synchronized (Constant.id2status) {
+								Constant.id2status.put(id, "finish:finish:" + "fail:timeout");
+							}
+							// LogUtil.info("InsertPointCommunicationLog" + "
+							// begin");
+							HBaseUtil.InsertPointCommunicationLog(Constant.agent,
+									Constant.BuildingDB.get(ps.buildingSignUP), ps.buildingSignUP, this.ip, ps.mac,
+									ps.meterSign, String.valueOf(ps.funcID), "down", "pointsetack", String.valueOf(ps.ID),
+									Constant.format(new Date()), "finish:finish:" + "fail:timeout");
+							// LogUtil.info("InsertPointCommunicationLog" + " end");
+
+							// CSVUtil.insert(Constant.setlog,
+							// new StringBuffer(
+							// Constant.format_Log(new Date()) + ": " +
+							// ps.meterSign + "." + ps.funcID
+							// + " set " + ps.dataSet + " fail(timeout) " +
+							// "!" + " Consuming:"
+							// + (System.currentTimeMillis() - ps.sendTime)
+							// + "ms!" + "\r\n"));
+							it.remove();
+						}
+						if (sb.length() > 0) {
+							// Constant.CollectorPointSetList.remove(ps.buildingSign
+							// + ";" + ps.ID + ";");
+							break;
+							// CSVUtil.insert(Constant.setlog, new
+							// StringBuffer(Constant.format_Log(new Date())
+							// + ": "
+							// + this.uploadClient.Name() + " AppendToSend:
+							// " + sb.toString() + "\r\n"));
+						}
+					}
+				}
+			}
+
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			LogUtil.error("SendThread.returnPointSet.Exception: " + e.toString());
+		}
+	}
+
+	private void handlePopRece(PacketEntity packageRece) {
+		// TODO Auto-generated method stub
+		if ((packageRece != null) && (packageRece.content.packetString != null)
+				&& (packageRece.content.packetString.length() > 0)) {
+			LogUtil.info(this.uploadServer.Name() + " PopRece: " + packageRece.address + " "
+					+ packageRece.content.packetString);
+			Constant.sendRec += packageRece.content.packetString.length();
+			String results = packageRece.content.packetString.replace("(", "").replace(")", "").replace(" ", "");
+			String[] resultArray = results.split("&");
+
+			for (String result : resultArray) {
+				String[] rList = result.split(";");
+				if (rList.length > 7) {
+					String id = rList[0] + "-" + rList[1] + "-" + rList[4];
+					String key = rList[0] + "-" + rList[1] + "-" + rList[5] + "." + rList[6];
+
+					// Constant.id2time.put(id, System.currentTimeMillis());
+					// Constant.id2point.put(id, key);
+					// Constant.id2function.put(id, rList[2]);
+					// Constant.id2status.put(id, "processing:rcvd");
+
+					try {
+						HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
+								rList[0], this.ip, rList[1], rList[5], (rList[6]), this.getupdown(rList[2]), rList[2],
+								String.valueOf(rList[4]), Constant.format(new Date()), "processing:rcvd");
+					} catch (UnknownHostException e1) {
+						// TODO Auto-generated catch block
+						e1.printStackTrace();
+					} catch (Exception e1) {
+						// TODO Auto-generated catch block
+						e1.printStackTrace();
+					}
+
+					if ("pointset".equalsIgnoreCase(rList[2])) {
+						// 1101070037;1;pointset;;123;1001;11;3.1
+						synchronized (Constant.id2time) {
+							Constant.id2time.put(id, System.currentTimeMillis());
+						}
+						synchronized (Constant.id2point) {
+							Constant.id2point.put(id, key);
+						}
+						synchronized (Constant.id2function) {
+							Constant.id2function.put(id, rList[2]);
+						}
+						synchronized (Constant.id2status) {
+							Constant.id2status.put(id, "processing:rcvd");
+						}
+
+						PointSet ps = new PointSet();
+						ps.uploadName = this.uploadServer.Name();
+						ps.address = packageRece.address;
+						ps.content = rList;
+						ps.sendTime = 0;
+						ps.recTime = 0;
+						ps.buildingSign = rList[0];
+						ps.buildingSignUP = rList[0];
+						if (Constant.BuildingConv.containsKey(ps.buildingSign)) {
+							ps.buildingSign = Constant.BuildingConv.get(ps.buildingSign);
+						}
+						ps.mac = rList[1];
+						ps.ID = Integer.valueOf(rList[4]);
+						ps.meterSign = rList[5];
+						ps.funcID = Integer.valueOf(rList[6]);
+						ps.dataSet = Double.valueOf(rList[7]);
+						// String adress = packageRece.address;
+						// String cmd = ps.buildingSign + ";" + ps.ID + ";";
+						// +ps.meterSign + ";" + ps.funcID + ";"
+						// + ps.dataSet;
+
+						// Constant.CollectorPointSetList.put(cmd, adress);
+						synchronized (Constant.pointSetList) {
+							Constant.pointSetList.add(ps);
+						}
+
+					} else if (rList.length > 6 && "pointread".equalsIgnoreCase(rList[2])) {
+						try {
+							StringBuffer sb = new StringBuffer();
+							sb = this.getCacheData(rList);
+							if (sb != null && sb.toString().length() > 0) {
+								this.uploadServer.AppendToSend(packageRece.address, new Packet(sb.toString()));
+								LogUtil.info(this.uploadServer.Name() + " AppendToSend: " + packageRece.address + " "
+										+ sb.toString());
+								// Constant.id2status.put(id, "finish:finish:" +
+								// "success");
+								HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
+										rList[0], this.ip, rList[1], rList[5], (rList[6]), "down", "pointreadack",
+										String.valueOf(rList[4]), Constant.format(new Date()),
+										"finish:finish:" + "success");
+							} else {
+								// Constant.id2status.put(id, "finish:finish:" +
+								// "fail");
+								HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
+										rList[0], this.ip, rList[1], rList[5], (rList[6]), "down", "pointreadack",
+										String.valueOf(rList[4]), Constant.format(new Date()),
+										"finish:finish:" + "fail");
+							}
+
+						} catch (Exception e) {
+							e.printStackTrace();
+							LogUtil.error("SendThread.handlePopRece.pointread.Exception: " + e.toString());
+						}
+
+					} else if (rList.length > 6 && "realtimepointdata".equalsIgnoreCase(rList[2])) {
+						try {
+							StringBuffer sb = new StringBuffer();
+							sb = this.getCacheData2(rList);
+							if (sb != null && sb.toString().length() > 0) {
+								this.uploadServer.AppendToSend(packageRece.address, new Packet(sb.toString()));
+								LogUtil.info(this.uploadServer.Name() + " AppendToSend: " + packageRece.address + " "
+										+ sb.toString());
+								// Constant.id2status.put(id, "finish:finish:" +
+								// "success");
+								HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
+										rList[0], this.ip, rList[1], rList[5], (rList[6]), "down",
+										"realtimepointdataack", String.valueOf(rList[4]), Constant.format(new Date()),
+										"finish:finish:" + "success");
+							} else {
+								// Constant.id2status.put(id, "finish:finish:" +
+								// "fail");
+								HBaseUtil.InsertPointCommunicationLog(Constant.agent, Constant.BuildingDB.get(rList[0]),
+										rList[0], this.ip, rList[1], rList[5], (rList[6]), "down",
+										"realtimepointdataack", String.valueOf(rList[4]), Constant.format(new Date()),
+										"finish:finish:" + "fail");
+							}
+
+						} catch (Exception e) {
+							e.printStackTrace();
+							LogUtil.error("SendThread.handlePopRece.realtimepointdata.Exception: " + e.toString());
+						}
+					}
+				}
+			}
+		}
+	}
+
+	private String getupdown(String function) {
+		// TODO Auto-generated method stub
+		if ("report".equalsIgnoreCase(function)) {
+			return "up";
+		} else if ("reportaddtion".equalsIgnoreCase(function)) {
+			return "up";
+		} else {
+			return "down";
+		}
+
+	}
+
+	private StringBuffer getCacheData(String[] rList) {
+		// TODO Auto-generated method stub
+		Record record = new Record();
+		StringBuffer sb = new StringBuffer();
+		if (Constant.RecordAddress.get(rList[0] + "-" + rList[5] + "-" + rList[6]) != null) {
+			int address = Constant.RecordAddress.get(rList[0] + "-" + rList[5] + "-" + rList[6]);
+			record = Constant.RecordList.get(address);
+			// Constant.info("get pointread by address !");
+		} else {
+			for (Record r : Constant.RecordList) {
+				if (rList[0].equalsIgnoreCase(r.buildingSign) && rList[5].equalsIgnoreCase(r.meterSign)
+						&& Integer.valueOf(rList[6]) == r.funcID) {
+					record = r;
+					// Constant.info("get pointread by for circle !");
+					break;
+				}
+			}
+		}
+		sb.append(rList[0]).append(";").append(rList[1]).append(";").append("pointreadack").append(";")
+				.append(Constant.format(record.receivetime)).append(";").append(rList[4]).append(";")
+				.append(record.meterSign).append(";").append(record.funcID).append(";").append(record.data).append(";");
+		return sb;
+	}
+
+	private StringBuffer getCacheData2(String[] rList) {
+		// TODO Auto-generated method stub
+		Record record = new Record();
+		StringBuffer sb = new StringBuffer();
+		if (Constant.RecordAddress.get(rList[0] + "-" + rList[5] + "-" + rList[6]) != null) {
+			int address = Constant.RecordAddress.get(rList[0] + "-" + rList[5] + "-" + rList[6]);
+			record = Constant.RecordList.get(address);
+			// Constant.info("get pointread by address !");
+		} else {
+			for (Record r : Constant.RecordList) {
+				if (rList[0].equalsIgnoreCase(r.buildingSign) && rList[5].equalsIgnoreCase(r.meterSign)
+						&& Integer.valueOf(rList[6]) == r.funcID) {
+					record = r;
+					// Constant.info("get pointread by for circle !");
+					break;
+				}
+			}
+		}
+		sb.append(rList[0]).append(";").append(rList[1]).append(";").append("realtimepointdataack").append(";")
+				.append(Constant.format(record.receivetime)).append(";").append(rList[4]).append(";")
+				.append(record.meterSign).append(";").append(record.funcID).append(";").append(record.data).append(";");
+		return sb;
+	}
+}

+ 57 - 0
collect/src/main/java/com/saga/util/CSVUtil.java

@@ -0,0 +1,57 @@
+package com.saga.util;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+import org.zillion.util.log.LogUtil;
+
+public class CSVUtil {
+	public static void createFile(File csvFile) {
+		if (!csvFile.exists()) {
+			try {
+				csvFile.createNewFile();
+				LogUtil.info(csvFile.getPath() + csvFile.getName() + " Created!");
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			} finally {
+				try {
+					Thread.sleep(10L);
+				} catch (InterruptedException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+			}
+		}
+	}
+
+	public static void deleteFile(File csvFile) {
+		if (csvFile.exists()) {
+			csvFile.delete();
+			LogUtil.info(csvFile.getPath() + csvFile.getName() + " Deleted!");
+			try {
+				Thread.sleep(10L);
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+	}
+
+	public static void insert(File csvFile, StringBuffer sb) {
+		try {
+			BufferedWriter csvWtriter = new BufferedWriter(
+					new OutputStreamWriter(new FileOutputStream(csvFile, true), "GB2312"), 1024);
+			LogUtil.info(csvFile.getPath() + csvFile.getName() + " Insert into " + sb.toString());
+			csvWtriter.write(sb.toString());
+			csvWtriter.flush();
+			csvWtriter.close();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+}

+ 343 - 0
collect/src/main/java/com/saga/util/Constant.java

@@ -0,0 +1,343 @@
+package com.saga.util;
+
+import java.io.File;
+import java.io.FileReader;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.UnknownHostException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.zillion.util.log.LogUtil;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.saga.entity.Data;
+import com.saga.entity.PointSet;
+import com.saga.entity.Record;
+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 boolean DBConn = true;
+	public static String WaitingTimeControl = "5Second";
+	public static File setlog = new File(System.getProperty("user.dir") + "/setlog.log");
+	public static List<String> CollectReportList = new ArrayList<String>();
+
+	public static List<Record> RecordListToDB = new ArrayList<Record>();
+	public static Map<String, String> Meter_Collector = new HashMap<String, String>();
+	public static Map<String, String> Meter_Collector_Control = new HashMap<String, String>();
+	public static List<PointSet> pointSetList = new ArrayList<PointSet>();
+	// public static Map<String, String> CollectorPointSetList = new
+	// HashMap<String, String>();
+	public static Map<String, String> BuildingDB = new HashMap<String, String>();
+	public static Map<String, String> BuildingConv = new HashMap<String, String>();
+	public static Map<String, List<String>> BuildingAdds = new HashMap<String, List<String>>();
+	public static Map<String, String> TypePort = new HashMap<String, String>();
+	public static Map<String, Integer> RecordAddress = new HashMap<String, Integer>();
+	public static List<Record> RecordList = new ArrayList<Record>();
+	public static Map<String, Long> nodeList = new HashMap<String, Long>();
+	public static Map<String, Long> pointListUp = new HashMap<String, Long>();
+	public static Map<String, String> pointInfo = new HashMap<String, String>();
+	public static Map<String, Data> nodeCache = new HashMap<String, Data>();
+	public static Map<String, Data> pointCache = new HashMap<String, Data>();
+	// public static Map<String, Long> pointListDown = new HashMap<String,
+	// Long>();
+	public static Map<String, Long> id2time = new HashMap<String, Long>();
+	public static Map<String, String> id2point = new HashMap<String, String>();
+	public static Map<String, String> id2function = new HashMap<String, String>();
+	public static Map<String, String> id2status = new HashMap<String, String>();
+	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 collectReportCount = 0;
+	public static int report2DBCount = 0;
+
+	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());
+
+					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<String>());
+							}
+							Constant.BuildingAdds.get(building).add(addObject.get("building").getAsString());
+							Constant.BuildingDB.put(addObject.get("building").getAsString(),
+									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();
+				Constant.TypePort.put(subObject.get("type").getAsString(), subObject.get("port").getAsString());
+			}
+
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			// System.out.println(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 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 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 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 String format(Date value) {
+		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 Date parse_day(String value) throws ParseException {
+		return SIMPLEDATEFORMAT_DAY.parse(value);
+	}
+
+	public static List<String> getConfigFile(String directoryPath, String directoryKey, String fileKey) {
+		List<String> list = new ArrayList<String>();
+		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<Element> devList = document.selectNodes("/root/portdev/devtype");
+						// System.out.println(file.getName());
+						// System.out.println(file.getName().indexOf(fileKey));
+						// System.out.println(file.getName().indexOf(".xml"));
+						String port = file.getName().substring(file.getName().indexOf(fileKey) + fileKey.length(),
+								file.getName().indexOf(".xml"));
+						// System.out.println(port);
+						// System.out.println(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];
+						// System.out.println(building);
+						// System.out.println(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);
+							// System.out.println(meter + "." +
+							// func.getText());
+							// }
+						}
+
+					}
+				}
+			}
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		return list;
+	}
+
+	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;
+
+	}
+}

+ 865 - 0
collect/src/main/java/com/saga/util/HBaseUtil.java

@@ -0,0 +1,865 @@
+package com.saga.util;
+
+import java.io.File;
+import java.util.Date;
+import java.util.List;
+
+import org.zillion.util.log.LogUtil;
+
+import com.saga.entity.PointSet;
+import com.saga.entity.Record;
+import com.sagacloud.json.JSONArray;
+import com.sagacloud.json.JSONObject;
+import com.zillion.database.agent.ZillionAgent;
+
+public class HBaseUtil {
+	public static void GetCollectorStatus(ZillionAgent agent, String db, String tb, String project) throws Exception {
+
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("project", project);
+		Criteria.put("collector",
+				Constant.getLocalHostLANAddress().getHostAddress() + ":" + Constant.TypePort.get("Down"));
+
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+		LogUtil.info("Reload Project:" + project + "  CollectorStatus Begin...");
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+			String node = (String) dataItem.get("gateway");
+			String key = project + "-" + node;
+			String receivetime = (String) dataItem.get("receivetime");
+			Constant.nodeList.put(key, Constant.parse(receivetime).getTime());
+			LogUtil.info("project " + project + " collector " + Constant.getLocalHostLANAddress().getHostAddress() + ":"
+					+ Constant.TypePort.get("Down") + " gateway " + node + " " + System.currentTimeMillis() + " "
+					+ Constant.parse(receivetime).getTime());
+		}
+		LogUtil.info("Reload Project:" + project + "  CollectorStatus End...");
+	}
+
+	public static void GetPointStatus(ZillionAgent agent, String db, String tb, String project) throws Exception {
+
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("project", project);
+		Criteria.put("collector",
+				Constant.getLocalHostLANAddress().getHostAddress() + ":" + Constant.TypePort.get("Down"));
+
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+		LogUtil.info("Reload Project:" + project + " PointStatus Begin...");
+		// synchronized (Constant.pointListUp) {
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+			String node = (String) dataItem.get("gateway");
+			String meter = (String) dataItem.get("meter");
+			String funcid = (String) dataItem.get("funcid");
+			String updown = (String) dataItem.get("updown");
+			if ("up".equalsIgnoreCase(updown)) {
+				String key = project + "-" + node + "-" + meter + "." + funcid;
+				String receivetime = (String) dataItem.get("receivetime");
+				Constant.pointListUp.put(key, Constant.parse(receivetime).getTime());
+				LogUtil.info("project " + project + " collector " + Constant.getLocalHostLANAddress().getHostAddress()
+						+ ":" + Constant.TypePort.get("Down") + " gateway " + node + " meter " + meter + " funcid "
+						+ funcid + " " + System.currentTimeMillis() + " " + Constant.parse(receivetime).getTime());
+			}
+		}
+		// }
+		LogUtil.info("Reload Project:" + project + "  PointStatus End...");
+	}
+
+	public static void Getset(ZillionAgent agent, String db, String tb, String building, String meter, long funcid,
+			String query_from, String query_to) throws Exception {
+
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+		Criteria.put("meter", meter);
+		Criteria.put("funcid", funcid);
+		JSONObject range = new JSONObject();
+		range.put("$gt", query_from);
+		range.put("$lt", query_to);
+		Criteria.put("receivetime", range);
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+		// File test = new File(System.getProperty("user.dir") + "/test.log");
+		// CSVUtil.insert(test, new StringBuffer("Getset" + " " + db + " " + tb
+		// + " " + building + " " + meter + " "
+		// + funcid + " " + query_from + " " + query_to + "\r\n"));
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+
+			String receivetime = (String) dataItem.get("receivetime");
+			String endtime = (String) dataItem.get("endtime");
+			Double data = (Double) dataItem.get("data");
+			String status = (String) dataItem.get("status");
+			System.out.println(
+					"receivetime " + receivetime + " endtime " + endtime + " data:" + data + " status " + status);
+			// CSVUtil.insert(test, new StringBuffer("receivetime " +
+			// receivetime + " endtime " + endtime + " data:" + data
+			// + " status " + status + "\r\n"));
+		}
+	}
+
+	public static void Getset_present(ZillionAgent agent, String db, String tb, String building, String meter,
+			long funcid) throws Exception {
+
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+		Criteria.put("meter", meter);
+		Criteria.put("funcid", funcid);
+
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+		// File test = new File(System.getProperty("user.dir") + "/test.log");
+		// CSVUtil.insert(test, new StringBuffer(
+		// "Getset_present" + " " + db + " " + tb + " " + building + " " + meter
+		// + " " + funcid + "\r\n"));
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+
+			String receivetime = (String) dataItem.get("receivetime");
+			String endtime = (String) dataItem.get("endtime");
+			Double data = (Double) dataItem.get("data");
+			String status = (String) dataItem.get("status");
+			// CSVUtil.insert(test, new StringBuffer("receivetime " +
+			// receivetime + " endtime " + endtime + " data:" + data
+			// + " status " + status + "\r\n"));
+			System.out.println(
+					"receivetime " + receivetime + " endtime " + endtime + " data:" + data + " status " + status);
+		}
+	}
+
+	public static void GetOriginal_month(ZillionAgent agent, String db, String tb, String building, String meter,
+			long funcid, String query_from, String query_to) throws Exception {
+
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+		Criteria.put("meter", meter);
+		Criteria.put("funcid", funcid);
+		JSONObject range = new JSONObject();
+		range.put("$gt", query_from);
+		range.put("$lt", query_to);
+		Criteria.put("receivetime", range);
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+		// File test = new File(System.getProperty("user.dir") + "/test.log");
+		// CSVUtil.insert(test, new StringBuffer("GetOriginal_month" + " " + db
+		// + " " + tb + " " + building + " " + meter
+		// + " " + funcid + " " + query_from + " " + query_to + "\r\n"));
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+
+			String receivetime = (String) dataItem.get("receivetime");
+
+			Double data = (Double) dataItem.get("data");
+			// CSVUtil.insert(test, new StringBuffer("receivetime " +
+			// receivetime + " data:" + data + "\r\n"));
+		}
+	}
+
+	public static void GetOriginal_present(ZillionAgent agent, String db, String tb, String building, String meter,
+			long funcid) throws Exception {
+
+		JSONObject Criteria = new JSONObject();
+		Criteria.put("building", building);
+		Criteria.put("meter", meter);
+		Criteria.put("funcid", funcid);
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "select");
+		wrapperObject.put("Database", db);
+		wrapperObject.put("Datatable", tb);
+		wrapperObject.put("Criteria", Criteria);
+		JSONObject queryResult = agent.Query(wrapperObject);
+		JSONArray resultContent = (JSONArray) queryResult.get("Content");
+		// File test = new File(System.getProperty("user.dir") + "/test.log");
+		// CSVUtil.insert(test, new StringBuffer(
+		// "GetOriginal_present" + " " + db + " " + tb + " " + building + " " +
+		// meter + " " + funcid + "\r\n"));
+		for (int i = 0; i < resultContent.size(); i++) {
+			JSONObject dataItem = (JSONObject) resultContent.get(i);
+			String receivetime = (String) dataItem.get("receivetime");
+			Double data = (Double) dataItem.get("data");
+			// CSVUtil.insert(test, new StringBuffer("receivetime " +
+			// receivetime + " data:" + data + "\r\n"));
+			System.out
+					.println("meter " + meter + " funcid " + funcid + " receivetime " + receivetime + " data:" + data);
+		}
+	}
+
+	public static JSONObject CreateJSON(String Name, String Type) {
+		JSONObject result = new JSONObject();
+		result.put("Name", Name);
+		result.put("Type", Type);
+		return result;
+	}
+
+	public static void CreateDB(ZillionAgent agent, String DB) throws Exception {
+		agent.NDL_AddDatabase(DB);
+	}
+
+	public static boolean tableExist(ZillionAgent agent, String DBName, String tableName) throws Exception {
+		JSONObject wrapperObject = new JSONObject();
+		wrapperObject.put("QueryType", "table_list");
+		wrapperObject.put("Database", DBName);
+		JSONObject result = agent.Query(wrapperObject);
+		JSONArray array = (JSONArray) result.get("Content");
+		for (int i = 0; i < array.size(); i++) {
+			String tableNameInner = (String) array.get(i);
+			if (tableNameInner.equalsIgnoreCase(tableName)) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public static void CreateTable(ZillionAgent agent, String DB, String tableName) throws Exception {
+		if (!tableExist(agent, DB, tableName)) {
+			JSONArray Columns = new JSONArray();
+			Columns.add(CreateJSON("building", "String"));
+			Columns.add(CreateJSON("meter", "String"));
+			Columns.add(CreateJSON("funcid", "Long"));
+			Columns.add(CreateJSON("receivetime", "String"));
+			Columns.add(CreateJSON("data", "Double"));
+			JSONArray Key = new JSONArray();
+			Key.add("building");
+			Key.add("meter");
+			Key.add("funcid");
+			Key.add("receivetime");
+			JSONObject Definition = new JSONObject();
+			Definition.put("Columns", Columns);
+			Definition.put("Key", Key);
+			Definition.put("delete_UsePutV", false);
+			Definition.put("table_type", "split_month");
+			Definition.put("split_column", "receivetime");
+			JSONArray Indexes = new JSONArray();
+			agent.DDL_AddTable(DB, tableName, Definition, Indexes);
+		}
+	}
+
+	public static void CreateTable_present(ZillionAgent agent, String DB, String tableName) throws Exception {
+		if (!tableExist(agent, DB, tableName)) {
+
+			JSONArray Columns = new JSONArray();
+			Columns.add(CreateJSON("building", "String"));
+			Columns.add(CreateJSON("meter", "String"));
+			Columns.add(CreateJSON("funcid", "Long"));
+			Columns.add(CreateJSON("receivetime", "String"));
+			Columns.add(CreateJSON("data", "Double"));
+			JSONArray Key = new JSONArray();
+			Key.add("building");
+			Key.add("meter");
+			Key.add("funcid");
+			JSONObject Definition = new JSONObject();
+			Definition.put("Columns", Columns);
+			Definition.put("Key", Key);
+			Definition.put("delete_UsePutV", false);
+			JSONArray Indexes = new JSONArray();
+			agent.DDL_AddTable(DB, tableName, Definition, Indexes);
+		}
+	}
+
+	public static void CreateTable_set(ZillionAgent agent, String DB, String tableName) throws Exception {
+		if (!tableExist(agent, DB, tableName)) {
+
+			JSONArray Columns = new JSONArray();
+			Columns.add(CreateJSON("building", "String"));
+			Columns.add(CreateJSON("meter", "String"));
+			Columns.add(CreateJSON("funcid", "Long"));
+			Columns.add(CreateJSON("receivetime", "String"));
+			Columns.add(CreateJSON("data", "Double"));
+			Columns.add(CreateJSON("status", "String"));
+			Columns.add(CreateJSON("endtime", "String"));
+			JSONArray Key = new JSONArray();
+			Key.add("building");
+			Key.add("meter");
+			Key.add("funcid");
+			Key.add("receivetime");
+			JSONObject Definition = new JSONObject();
+			Definition.put("Columns", Columns);
+			Definition.put("Key", Key);
+			JSONArray Indexes = new JSONArray();
+			agent.DDL_AddTable(DB, tableName, Definition, Indexes);
+		}
+	}
+
+	public static void CreateTable_setpresent(ZillionAgent agent, String DB, String tableName) throws Exception {
+		if (!tableExist(agent, DB, tableName)) {
+
+			JSONArray Columns = new JSONArray();
+			Columns.add(CreateJSON("building", "String"));
+			Columns.add(CreateJSON("meter", "String"));
+			Columns.add(CreateJSON("funcid", "Long"));
+			Columns.add(CreateJSON("receivetime", "String"));
+			Columns.add(CreateJSON("data", "Double"));
+			Columns.add(CreateJSON("status", "String"));
+			Columns.add(CreateJSON("endtime", "String"));
+			JSONArray Key = new JSONArray();
+			Key.add("building");
+			Key.add("meter");
+			Key.add("funcid");
+			JSONObject Definition = new JSONObject();
+			Definition.put("Columns", Columns);
+			Definition.put("Key", Key);
+			JSONArray Indexes = new JSONArray();
+			agent.DDL_AddTable(DB, tableName, Definition, Indexes);
+		}
+	}
+
+	public static void CreateTable_CollectorStatus(ZillionAgent agent, String DB, String tableName) throws Exception {
+		if (!tableExist(agent, DB, tableName)) {
+
+			JSONArray Columns = new JSONArray();
+			Columns.add(CreateJSON("project", "String"));
+			Columns.add(CreateJSON("collector", "String"));
+			Columns.add(CreateJSON("gateway", "String"));
+			Columns.add(CreateJSON("status", "String"));
+			Columns.add(CreateJSON("receivetime", "String"));
+			Columns.add(CreateJSON("detail", "String"));
+
+			JSONArray Key = new JSONArray();
+			Key.add("project");
+			Key.add("collector");
+			Key.add("gateway");
+			JSONObject Definition = new JSONObject();
+			Definition.put("Columns", Columns);
+			Definition.put("Key", Key);
+			JSONArray Indexes = new JSONArray();
+			agent.DDL_AddTable(DB, tableName, Definition, Indexes);
+		}
+	}
+
+	public static void CreateTable_CollectorCommunicationLog(ZillionAgent agent, String DB, String tableName)
+			throws Exception {
+		if (!tableExist(agent, DB, tableName)) {
+
+			JSONArray Columns = new JSONArray();
+			Columns.add(CreateJSON("project", "String"));
+			Columns.add(CreateJSON("collector", "String"));
+			Columns.add(CreateJSON("gateway", "String"));
+			Columns.add(CreateJSON("receivetime", "String"));
+			Columns.add(CreateJSON("function", "String"));
+
+			JSONArray Key = new JSONArray();
+			Key.add("project");
+			Key.add("collector");
+			Key.add("gateway");
+			Key.add("receivetime");
+			JSONObject Definition = new JSONObject();
+			Definition.put("Columns", Columns);
+			Definition.put("Key", Key);
+			JSONArray Indexes = new JSONArray();
+			agent.DDL_AddTable(DB, tableName, Definition, Indexes);
+		}
+	}
+
+	public static void CreateTable_PointStatus(ZillionAgent agent, String DB, String tableName) throws Exception {
+		if (!tableExist(agent, DB, tableName)) {
+
+			JSONArray Columns = new JSONArray();
+			Columns.add(CreateJSON("project", "String"));
+			Columns.add(CreateJSON("collector", "String"));
+			Columns.add(CreateJSON("gateway", "String"));
+			Columns.add(CreateJSON("meter", "String"));
+			Columns.add(CreateJSON("funcid", "String"));
+			Columns.add(CreateJSON("updown", "String"));
+			Columns.add(CreateJSON("status", "String"));
+			Columns.add(CreateJSON("receivetime", "String"));
+			Columns.add(CreateJSON("detail", "String"));
+
+			JSONArray Key = new JSONArray();
+			Key.add("project");
+			Key.add("collector");
+			Key.add("gateway");
+			Key.add("meter");
+			Key.add("funcid");
+			Key.add("updown");
+			JSONObject Definition = new JSONObject();
+			Definition.put("Columns", Columns);
+			Definition.put("Key", Key);
+			JSONArray Indexes = new JSONArray();
+			agent.DDL_AddTable(DB, tableName, Definition, Indexes);
+		}
+	}
+
+	public static void CreateTable_PointInfo(ZillionAgent agent, String DB, String tableName) throws Exception {
+		if (!tableExist(agent, DB, tableName)) {
+
+			JSONArray Columns = new JSONArray();
+			Columns.add(CreateJSON("project", "String"));
+			Columns.add(CreateJSON("gateway", "String"));
+			Columns.add(CreateJSON("meter", "String"));
+			Columns.add(CreateJSON("BusNo", "String"));
+			Columns.add(CreateJSON("site", "String"));
+
+			JSONArray Key = new JSONArray();
+			Key.add("project");
+			Key.add("gateway");
+			Key.add("meter");
+			JSONObject Definition = new JSONObject();
+			Definition.put("Columns", Columns);
+			Definition.put("Key", Key);
+			JSONArray Indexes = new JSONArray();
+			agent.DDL_AddTable(DB, tableName, Definition, Indexes);
+		}
+	}
+
+	public static void CreateTable_PointCommunicationLog(ZillionAgent agent, String DB, String tableName)
+			throws Exception {
+		if (!tableExist(agent, DB, tableName)) {
+
+			JSONArray Columns = new JSONArray();
+			Columns.add(CreateJSON("project", "String"));
+			Columns.add(CreateJSON("collector", "String"));
+			Columns.add(CreateJSON("gateway", "String"));
+			Columns.add(CreateJSON("meter", "String"));
+			Columns.add(CreateJSON("funcid", "String"));
+			Columns.add(CreateJSON("updown", "String"));
+			Columns.add(CreateJSON("function", "String"));
+			Columns.add(CreateJSON("seq", "String"));
+			Columns.add(CreateJSON("receivetime", "String"));
+			Columns.add(CreateJSON("feedback", "String"));
+
+			JSONArray Key = new JSONArray();
+			Key.add("project");
+			Key.add("collector");
+			Key.add("gateway");
+			Key.add("meter");
+			Key.add("funcid");
+			Key.add("updown");
+			Key.add("function");
+			Key.add("seq");
+			Key.add("receivetime");
+			JSONObject Definition = new JSONObject();
+			Definition.put("Columns", Columns);
+			Definition.put("Key", Key);
+			JSONArray Indexes = new JSONArray();
+			agent.DDL_AddTable(DB, tableName, Definition, Indexes);
+		}
+	}
+
+	public static void InsertCollectorStatus(ZillionAgent agent, String DB, String project, String collector,
+			String node, String status, String receivetime) throws Exception {
+
+		JSONArray InsertObjects = new JSONArray();
+		try {
+			if (DB != null) {
+
+				JSONObject InsertObject = new JSONObject();
+				InsertObject.put("project", project);
+				InsertObject.put("collector", collector);
+				InsertObject.put("gateway", node);
+				InsertObject.put("status", status);
+				InsertObject.put("receivetime", receivetime);
+
+				InsertObjects.add(InsertObject);
+
+				JSONObject wrapperObject = new JSONObject();
+
+				wrapperObject = new JSONObject();
+				wrapperObject.put("QueryType", "batch_put");
+				wrapperObject.put("Database", DB);
+				wrapperObject.put("Datatable", "pointgatewaystatus");
+				wrapperObject.put("InsertObjects", InsertObjects);
+				agent.Query(wrapperObject);
+			}
+
+		} catch (Exception e) {
+			LogUtil.error("HBaseUtil.InsertCollectorStatus.Exception: " + e.toString());
+		}
+	}
+
+	public static void InsertCollectorCommunicationLog(ZillionAgent agent, String DB, String project, String collector,
+			String node, String receivetime, String function) throws Exception {
+
+		JSONArray InsertObjects = new JSONArray();
+		try {
+			if (DB != null) {
+
+				JSONObject InsertObject = new JSONObject();
+				InsertObject.put("project", project);
+				InsertObject.put("collector", collector);
+				InsertObject.put("gateway", node);
+				InsertObject.put("receivetime", receivetime);
+				InsertObject.put("function", function);
+
+				InsertObjects.add(InsertObject);
+
+				JSONObject wrapperObject = new JSONObject();
+
+				wrapperObject = new JSONObject();
+				wrapperObject.put("QueryType", "batch_insert");
+				wrapperObject.put("Database", DB);
+				wrapperObject.put("Datatable", "pointgatewaylog");
+				wrapperObject.put("InsertObjects", InsertObjects);
+				agent.Query(wrapperObject);
+			}
+
+		} catch (Exception e) {
+			LogUtil.error("HBaseUtil.BatchInsert.Exception: " + e.toString());
+		}
+	}
+
+	public static void InsertPointStatus(ZillionAgent agent, String DB, String project, String collector, String node,
+			String meter, String funcid, String updown, String status, String receivetime, String detail)
+			throws Exception {
+
+		JSONArray InsertObjects = new JSONArray();
+		try {
+			if (DB != null) {
+
+				JSONObject InsertObject = new JSONObject();
+				InsertObject.put("project", project);
+				InsertObject.put("collector", collector);
+				InsertObject.put("gateway", node);
+				InsertObject.put("meter", meter);
+				InsertObject.put("funcid", funcid);
+				InsertObject.put("updown", updown);
+				InsertObject.put("status", status);
+				InsertObject.put("receivetime", receivetime);
+				InsertObject.put("detail", detail);
+
+				InsertObjects.add(InsertObject);
+
+				JSONObject wrapperObject = new JSONObject();
+
+				wrapperObject = new JSONObject();
+				wrapperObject.put("QueryType", "batch_put");
+				wrapperObject.put("Database", DB);
+				wrapperObject.put("Datatable", "pointstatus");
+				wrapperObject.put("InsertObjects", InsertObjects);
+				agent.Query(wrapperObject);
+			}
+
+		} catch (Exception e) {
+			LogUtil.error("HBaseUtil.InsertPointStatus.Exception: " + e.toString());
+		}
+	}
+
+	public static void InsertPointInfo(ZillionAgent agent, String DB, String project, String node, String point,
+			String BusNo, String site) throws Exception {
+
+		JSONArray InsertObjects = new JSONArray();
+		try {
+			if (DB != null) {
+
+				JSONObject InsertObject = new JSONObject();
+				InsertObject.put("project", project);
+				InsertObject.put("gateway", node);
+				InsertObject.put("meter", point);
+				InsertObject.put("BusNo", BusNo);
+				InsertObject.put("site", site);
+
+				InsertObjects.add(InsertObject);
+
+				JSONObject wrapperObject = new JSONObject();
+
+				wrapperObject = new JSONObject();
+				wrapperObject.put("QueryType", "batch_put");
+				wrapperObject.put("Database", DB);
+				wrapperObject.put("Datatable", "pointinfo");
+				wrapperObject.put("InsertObjects", InsertObjects);
+				agent.Query(wrapperObject);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+			LogUtil.error("HBaseUtil.InsertPointInfo.Exception: " + e.toString());
+		}
+	}
+
+	public static void InsertPointCommunicationLog(ZillionAgent agent, String DB, String project, String collector,
+			String node, String meter, String funcid, String updown, String function, String seq, String receivetime,
+			String feedback) throws Exception {
+
+		JSONArray InsertObjects = new JSONArray();
+		try {
+			if (DB != null) {
+
+				JSONObject InsertObject = new JSONObject();
+				InsertObject.put("project", project);
+				InsertObject.put("collector", collector);
+				InsertObject.put("gateway", node);
+				InsertObject.put("meter", meter);
+				InsertObject.put("funcid", funcid);
+				InsertObject.put("updown", updown);
+				InsertObject.put("function", function);
+				InsertObject.put("seq", seq);
+				InsertObject.put("receivetime", receivetime);
+				InsertObject.put("feedback", feedback);
+
+				InsertObjects.add(InsertObject);
+
+				JSONObject wrapperObject = new JSONObject();
+
+				wrapperObject = new JSONObject();
+				wrapperObject.put("QueryType", "batch_insert");
+				wrapperObject.put("Database", DB);
+				wrapperObject.put("Datatable", "pointlog");
+				wrapperObject.put("InsertObjects", InsertObjects);
+				agent.Query(wrapperObject);
+			}
+
+		} catch (Exception e) {
+			LogUtil.error("HBaseUtil.InsertPointCommunicationLog.Exception: " + e.toString());
+		}
+	}
+
+	// public static void InsertPointCommunicationLog(List<String> list) throws
+	// Exception {
+	// // TODO Auto-generated method stub
+	// JSONArray InsertObjects = new JSONArray();
+	// String DB = null;
+	// try {
+	// for (String s : list) {
+	// String[] rlist = s.split(";");
+	//
+	// // 0 building,
+	// // 1 Constant.getLocalHostLANAddress().getHostAddress(),
+	// // 2 mac,
+	// // 3 meter + "." + record.funcID,
+	// // 4 function,
+	// // 5 id,
+	// // 6 rList[3],
+	// // 7 record.addtion
+	// DB = Constant.BuildingDB.get(rlist[0]) == null ? DB :
+	// Constant.BuildingDB.get(rlist[0]);
+	// if (DB != null) {
+	// JSONObject InsertObject = new JSONObject();
+	// InsertObject.put("project", rlist[0]);
+	// InsertObject.put("collector", rlist[1]);
+	// InsertObject.put("gateway", rlist[2]);
+	// InsertObject.put("point", rlist[3]);
+	// InsertObject.put("function", rlist[4]);
+	// InsertObject.put("seq", rlist[5]);
+	// InsertObject.put("receivetime", rlist[6]);
+	// InsertObject.put("feedback", rlist.length > 7 ? rlist[7] : "");
+	//
+	// InsertObjects.add(InsertObject);
+	// }
+	// }
+	// JSONObject wrapperObject = new JSONObject();
+	// if (DB != null) {
+	// wrapperObject = new JSONObject();
+	// wrapperObject.put("QueryType", "batch_insert");
+	// wrapperObject.put("Database", DB);
+	// wrapperObject.put("Datatable", "pointlog");
+	// wrapperObject.put("InsertObjects", InsertObjects);
+	// Constant.agent.Query(wrapperObject);
+	//
+	// }
+	// } catch (Exception e) {
+	// LogUtil.error("HBaseUtil.InsertPointCommunicationLog.Exception: " +
+	// e.toString());
+	// }
+	// }
+
+	public static void BatchInsert(ZillionAgent agent, String DB, List<Record> dataList) throws Exception {
+		JSONArray InsertObjects = new JSONArray();
+		try {
+			if (DB != null && dataList.size() > 0) {
+				for (int i = 0; i < dataList.size(); i++) {
+
+					Record data = dataList.get(i);
+
+					JSONObject InsertObject = new JSONObject();
+					InsertObject.put("building", data.buildingSign);
+					InsertObject.put("meter", data.meterSign);
+					InsertObject.put("funcid", (long) data.funcID);
+					InsertObject.put("receivetime", Constant.format(data.receivetime));
+					InsertObject.put("data", data.data);
+
+					InsertObjects.add(InsertObject);
+
+				}
+
+				if (InsertObjects.size() > 0) {
+					Constant.writeDB += InsertObjects.size();
+
+					JSONObject wrapperObject = new JSONObject();
+
+					wrapperObject = new JSONObject();
+					wrapperObject.put("QueryType", "batch_insert");
+					wrapperObject.put("Database", DB);
+					wrapperObject.put("Datatable", "original_month");
+					wrapperObject.put("InsertObjects", InsertObjects);
+					agent.Query(wrapperObject);
+					wrapperObject = new JSONObject();
+					wrapperObject.put("QueryType", "batch_put");
+					wrapperObject.put("Database", DB);
+					wrapperObject.put("Datatable", "original_present");
+					wrapperObject.put("InsertObjects", InsertObjects);
+					agent.Query(wrapperObject);
+					// LogUtil.info("insert into " + DB + "." +
+					// "original_month&" + "original_present "
+					// + InsertObjects.toFormatString());
+					LogUtil.info(
+							"insert into " + DB + "." + "original_month&" + "original_present " + InsertObjects.size());
+				}
+			}
+
+		} catch (Exception e) {
+			LogUtil.error("HBaseUtil.BatchInsert.Exception: " + e.toString());
+			Constant.DBConn = false;
+		}
+	}
+
+	public static void BatchInsert_Set1(ZillionAgent agent, String DB, PointSet ps) throws Exception {
+		JSONArray InsertObjects = new JSONArray();
+		try {
+			if (DB != null) {
+
+				JSONObject InsertObject = new JSONObject();
+				// InsertObject.put("building", ps.buildingSign);
+				InsertObject.put("building", ps.buildingSignUP);
+				InsertObject.put("meter", ps.meterSign);
+				InsertObject.put("funcid", (long) ps.funcID);
+				InsertObject.put("receivetime", Constant.format(new Date((long) ps.sendTime)));
+				InsertObject.put("data", ps.dataSet);
+				InsertObject.put("status", "processing:sent");
+
+				// LogUtil.info(InsertObject.toFormatString());
+
+				InsertObjects.add(InsertObject);
+
+				if (InsertObjects.size() > 0) {
+
+					JSONObject wrapperObject = new JSONObject();
+
+					wrapperObject = new JSONObject();
+					wrapperObject.put("QueryType", "batch_insert");
+					wrapperObject.put("Database", DB);
+					wrapperObject.put("Datatable", "originalset");
+					wrapperObject.put("InsertObjects", InsertObjects);
+					agent.Query(wrapperObject);
+					wrapperObject = new JSONObject();
+					wrapperObject.put("QueryType", "batch_put");
+					wrapperObject.put("Database", DB);
+					wrapperObject.put("Datatable", "originalset_present");
+					wrapperObject.put("InsertObjects", InsertObjects);
+					agent.Query(wrapperObject);
+					// LogUtil.info("insert into " + DB + "." + "originalset&" +
+					// "originalset_present "
+					// + InsertObject.toFormatString());
+				}
+			}
+
+		} catch (Exception e) {
+			LogUtil.error("HBaseUtil.BatchInsert_Set1.Exception: " + e.toString());
+		}
+	}
+
+	public static void BatchInsert_Set2(ZillionAgent agent, String DB, PointSet ps) throws Exception {
+		JSONArray InsertObjects = new JSONArray();
+		try {
+			if (DB != null) {
+
+				JSONObject InsertObject = new JSONObject();
+				// InsertObject.put("building", ps.buildingSign);
+				InsertObject.put("building", ps.buildingSignUP);
+				InsertObject.put("meter", ps.meterSign);
+				InsertObject.put("funcid", (long) ps.funcID);
+				InsertObject.put("receivetime", Constant.format(new Date((long) ps.sendTime)));
+				InsertObject.put("data", ps.dataSet);
+				InsertObject.put("status", "finish:finish:" + ps.status);
+				InsertObject.put("endtime", Constant.format(new Date()));
+
+				// LogUtil.info(InsertObject.toFormatString());
+
+				InsertObjects.add(InsertObject);
+
+				if (InsertObjects.size() > 0) {
+
+					JSONObject wrapperObject = new JSONObject();
+
+					wrapperObject = new JSONObject();
+					wrapperObject.put("QueryType", "batch_put");
+					wrapperObject.put("Database", DB);
+					wrapperObject.put("Datatable", "originalset");
+					wrapperObject.put("InsertObjects", InsertObjects);
+					agent.Query(wrapperObject);
+					wrapperObject = new JSONObject();
+					wrapperObject.put("QueryType", "batch_put");
+					wrapperObject.put("Database", DB);
+					wrapperObject.put("Datatable", "originalset_present");
+					wrapperObject.put("InsertObjects", InsertObjects);
+					agent.Query(wrapperObject);
+					// LogUtil.info("insert into " + DB + "." + "originalset&" +
+					// "originalset_present "
+					// + InsertObject.toFormatString());
+				}
+			}
+
+		} catch (Exception e) {
+			LogUtil.error("HBaseUtil.BatchInsert_Set2.Exception: " + e.toString());
+		}
+	}
+
+	public static void BatchInsert_Set3(ZillionAgent agent, String DB, PointSet ps) throws Exception {
+		JSONArray InsertObjects = new JSONArray();
+		try {
+			if (DB != null) {
+
+				JSONObject InsertObject = new JSONObject();
+				// InsertObject.put("building", ps.buildingSign);
+				InsertObject.put("building", ps.buildingSignUP);
+				InsertObject.put("meter", ps.meterSign);
+				InsertObject.put("funcid", (long) ps.funcID);
+				InsertObject.put("receivetime", Constant.format(new Date((long) ps.sendTime)));
+				InsertObject.put("data", ps.dataSet);
+				InsertObject.put("status", "finish:finish:" + "fail:timeout");
+				InsertObject.put("endtime", Constant.format(new Date()));
+
+				// LogUtil.info(InsertObject.toFormatString());
+
+				InsertObjects.add(InsertObject);
+
+				if (InsertObjects.size() > 0) {
+					JSONObject wrapperObject = new JSONObject();
+
+					wrapperObject = new JSONObject();
+					wrapperObject.put("QueryType", "batch_put");
+					wrapperObject.put("Database", DB);
+					wrapperObject.put("Datatable", "originalset");
+					wrapperObject.put("InsertObjects", InsertObjects);
+					agent.Query(wrapperObject);
+					wrapperObject = new JSONObject();
+					wrapperObject.put("QueryType", "batch_put");
+					wrapperObject.put("Database", DB);
+					wrapperObject.put("Datatable", "originalset_present");
+					wrapperObject.put("InsertObjects", InsertObjects);
+					agent.Query(wrapperObject);
+					// LogUtil.info("insert into " + DB + "." + "originalset&" +
+					// "originalset_present "
+					// + InsertObject.toFormatString());
+				}
+			}
+
+		} catch (Exception e) {
+			LogUtil.error("HBaseUtil.BatchInsert_Set3.Exception: " + e.toString());
+		}
+	}
+
+}

+ 5 - 0
collect/src/main/java/com/saga/util/MySQLUtil.java

@@ -0,0 +1,5 @@
+package com.saga.util;
+
+public class MySQLUtil {
+
+}

+ 34 - 0
collect/src/main/resources/hbase-site.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+<configuration>
+	<!-- hbase-site.xml -->
+	<property>
+		<name>dfs.replication</name>
+		<value>1</value>
+	</property>
+
+	<property>
+		<name>hbase.rootdir</name>
+		<value>hdfs://namenode:8020/hbase</value>
+	</property>
+	<property>
+		<name>hbase.cluster.distributed</name>
+		<value>true</value>
+	</property>
+	<property>
+		<name>hbase.zookeeper.quorum</name>
+		<value>zookeeper1,zookeeper2,zookeeper3</value>
+	</property>
+	<property>
+		<name>hbase.zookeeper.property.dataDir</name>
+		<value>/var/zookeeper/data</value>
+	</property>
+
+	<!--
+	<property>
+		<name>hbase.security.authentication</name>
+		<value>simple</value>
+	</property>
+	-->
+
+</configuration>

+ 17 - 0
collect/src/main/resources/log4j.properties

@@ -0,0 +1,17 @@
+log4j.rootLogger=INFO,ConsoleAppender,RollingLogFileAppender
+
+log4j.appender.RollingLogFileAppender=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.RollingLogFileAppender.Threshold=INFO
+log4j.appender.RollingLogFileAppender.ImmediateFlush=true
+log4j.appender.RollingLogFileAppender.File=log.log
+log4j.appender.RollingLogFileAppender.DatePattern=yyyy-MM-dd'.log'  
+log4j.appender.RollingLogFileAppender.Append=true
+log4j.appender.RollingLogFileAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.RollingLogFileAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %t %m%n
+
+log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender
+log4j.appender.ConsoleAppender.Threshold=INFO
+log4j.appender.ConsoleAppender.ImmediateFlush=true
+log4j.appender.ConsoleAppender.Target=System.out
+log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.ConsoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} %t %m%n

BIN
collect/zillion-util-1.5.jar