Browse Source

MongoDB测试类

shilin 4 years ago
parent
commit
0cc5341894
2 changed files with 94 additions and 0 deletions
  1. 49 0
      pom.xml
  2. 45 0
      src/test/java/test/MongoDBTest.java

+ 49 - 0
pom.xml

@@ -259,6 +259,16 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-redis</artifactId>
         </dependency>
+		<dependency>
+			<groupId>org.mongodb</groupId>
+			<artifactId>mongo-java-driver</artifactId>
+			<version>3.10.2</version>
+		</dependency>
+		<dependency>
+			<groupId>redis.clients</groupId>
+			<artifactId>jedis</artifactId>
+			<version>2.9.0</version>
+		</dependency>
 	</dependencies>
 
 
@@ -308,6 +318,45 @@
 	<build>
 		<plugins>
 
+
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<!--忽略测试启动类 -->
+				<configuration>
+					<skip>true</skip>
+				</configuration>
+			</plugin>
+			<!-- generator 配置-->
+			<plugin>
+				<groupId>org.mybatis.generator</groupId>
+				<artifactId>mybatis-generator-maven-plugin</artifactId>
+				<version>1.3.7</version>
+				<configuration>
+					<!--允许移动生成的文件 -->
+					<verbose>false</verbose>
+					<!--允许覆盖生成的文件 -->
+					<overwrite>false</overwrite>
+					<!--配置文件的路径 -->
+					<configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
+				</configuration>
+				<dependencies>
+					<dependency>
+						<groupId>mysql</groupId>
+						<artifactId>mysql-connector-java</artifactId>
+						<version>${mysql.version}</version>
+					</dependency>
+				</dependencies>
+			</plugin>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+				<configuration>
+					<fork>true</fork>
+				</configuration>
+			</plugin>
+
+
 			<plugin>
 				<groupId>org.springframework.boot</groupId>
 				<artifactId>spring-boot-maven-plugin</artifactId>

+ 45 - 0
src/test/java/test/MongoDBTest.java

@@ -0,0 +1,45 @@
+package test;
+
+import com.gyee.SpringbootStart;
+import com.gyee.frame.model.custom.PointData;
+import com.gyee.frame.util.mongodb.IMongodbUtil;
+import com.gyee.frame.util.mongodb.MongodbUtilImpl;
+import lombok.SneakyThrows;
+import org.springframework.boot.SpringApplication;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+public class MongoDBTest {
+
+    @SneakyThrows
+    public static void main(String[] args) {
+
+        SpringApplication.run(SpringbootStart.class, args);
+        IMongodbUtil mongodb = new MongodbUtilImpl();
+        Calendar c = Calendar.getInstance();
+        c.set(Calendar.MONTH, 3);
+        c.set(Calendar.DAY_OF_MONTH, 25);
+        c.set(Calendar.HOUR_OF_DAY, 0);
+        c.set(Calendar.MINUTE, 0);
+        c.set(Calendar.SECOND, 0);
+
+        Date beginDate = c.getTime();
+        c.add(Calendar.DAY_OF_MONTH, 1);
+        Date endDate = c.getTime();
+
+//查看历史快照数据
+        List<PointData> ls = mongodb.getHistoryDatasSnap("HB_GD_KBF_JS_P4_L19_220_CI0136",
+                beginDate.getTime() / 1000, endDate.getTime() / 1000,
+                (long) 24, 3600L);
+        if (!ls.isEmpty()) {
+            ls.forEach(obj -> System.out.println(obj.getEdnaId() + "___" +obj.getPointTime() + "___" + obj.getPointValueInDouble()));
+        }
+//查看实时数据
+        PointData real=mongodb.getRealData("HB_GD_KBF_JS_P4_L19_220_CI0136");
+        System.out.println(real.getPointValueInDouble());
+    }
+
+
+}