|
@@ -1,13 +1,77 @@
|
|
|
package com.huimv.apiservice;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.huimv.apiservice.dao.IndoorEnvironmentDao;
|
|
|
+import com.huimv.apiservice.entity.IndoorEnvironmentEntity;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
@SpringBootTest
|
|
|
class HuimvSmartApiserviceApplicationTests {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IndoorEnvironmentDao indoorEnvironmentDao;
|
|
|
+
|
|
|
@Test
|
|
|
void contextLoads() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void createIndoorEnv() {
|
|
|
+
|
|
|
+ DateTime today = DateUtil.beginOfDay(new Date());
|
|
|
+ System.out.println(today);
|
|
|
+// BigDecimal bigDecimal = new BigDecimal(Math.random() * 8 + 25).setScale(1, BigDecimal.ROUND_HALF_UP);
|
|
|
+// double temperature = bigDecimal.doubleValue();
|
|
|
+
|
|
|
+// BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+// double humidity = bigDecimal2.doubleValue();
|
|
|
+
|
|
|
+// System.out.println(temperature + " " + humidity);
|
|
|
+ Date collectTime = today;
|
|
|
+
|
|
|
+ List<String> gas = new ArrayList<>();
|
|
|
+ gas.add("优");
|
|
|
+ gas.add("良");
|
|
|
+ gas.add("轻度");
|
|
|
+ gas.add("中度");
|
|
|
+ gas.add("重度");
|
|
|
+ gas.add("严重");
|
|
|
+
|
|
|
+ Random random = new Random();
|
|
|
+ List<IndoorEnvironmentEntity> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 288; i++) {
|
|
|
+ IndoorEnvironmentEntity entity = new IndoorEnvironmentEntity();
|
|
|
+ entity.setDate(today);
|
|
|
+ entity.setPigstyId(1);
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(Math.random() * 8 + 25).setScale(1, BigDecimal.ROUND_HALF_UP);
|
|
|
+ double temperature = bigDecimal.doubleValue();
|
|
|
+ entity.setTemperature(temperature);
|
|
|
+ BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ double humidity = bigDecimal2.doubleValue();
|
|
|
+ entity.setHumidity(humidity);
|
|
|
+ entity.setGas(gas.get(random.nextInt(5)));
|
|
|
+ entity.setCollectTime(collectTime);
|
|
|
+ collectTime = DateUtil.offsetMinute(collectTime,5);
|
|
|
+ System.out.println(entity);
|
|
|
+ list.add(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+// indoorEnvironmentDao.batchInsertData(list)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|