|
@@ -3,7 +3,9 @@ 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.dao.OutdoorEnvironmentDao;
|
|
|
import com.huimv.apiservice.entity.IndoorEnvironmentEntity;
|
|
|
+import com.huimv.apiservice.entity.OutdoorEnvironmentEntity;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
@@ -18,6 +20,9 @@ class HuimvSmartApiserviceApplicationTests {
|
|
|
@Autowired
|
|
|
private IndoorEnvironmentDao indoorEnvironmentDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OutdoorEnvironmentDao outdoorEnvironmentDao;
|
|
|
+
|
|
|
@Test
|
|
|
void contextLoads() {
|
|
|
|
|
@@ -52,7 +57,7 @@ class HuimvSmartApiserviceApplicationTests {
|
|
|
IndoorEnvironmentEntity entity = new IndoorEnvironmentEntity();
|
|
|
entity.setDate(today);
|
|
|
entity.setPigstyId(1);
|
|
|
- BigDecimal bigDecimal = new BigDecimal(Math.random() * 8 + 25).setScale(1, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).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);
|
|
@@ -65,13 +70,53 @@ class HuimvSmartApiserviceApplicationTests {
|
|
|
list.add(entity);
|
|
|
}
|
|
|
|
|
|
-// indoorEnvironmentDao.batchInsertData(list)
|
|
|
+ indoorEnvironmentDao.batchInsertData(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void createOutdoorEnv() {
|
|
|
|
|
|
+ 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<OutdoorEnvironmentEntity> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 288; i++) {
|
|
|
+ OutdoorEnvironmentEntity entity = new OutdoorEnvironmentEntity();
|
|
|
+ entity.setDate(today);
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).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(4)));
|
|
|
+ entity.setCollectTime(collectTime);
|
|
|
+ collectTime = DateUtil.offsetMinute(collectTime,5);
|
|
|
+ list.add(entity);
|
|
|
+ }
|
|
|
|
|
|
+ outdoorEnvironmentDao.batchInsertData(list);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|