|
@@ -1,194 +1,194 @@
|
|
-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.dao.PigDao;
|
|
|
|
-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;
|
|
|
|
-
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
-import java.util.*;
|
|
|
|
-
|
|
|
|
-@SpringBootTest
|
|
|
|
-class HuimvSmartApiserviceApplicationTests {
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private IndoorEnvironmentDao indoorEnvironmentDao;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private OutdoorEnvironmentDao outdoorEnvironmentDao;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private PigDao pigDao;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- @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() * 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.setAirQuality(gas.get(random.nextInt(5)));
|
|
|
|
- entity.setCollectTime(collectTime);
|
|
|
|
- collectTime = DateUtil.offsetMinute(collectTime,5);
|
|
|
|
-// System.out.println(entity);
|
|
|
|
- list.add(entity);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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.setAirQuality(gas.get(random.nextInt(4)));
|
|
|
|
- entity.setCollectTime(collectTime);
|
|
|
|
- collectTime = DateUtil.offsetMinute(collectTime,5);
|
|
|
|
- list.add(entity);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- outdoorEnvironmentDao.batchInsertData(list);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+//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.dao.PigDao;
|
|
|
|
+//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;
|
|
|
|
+//
|
|
|
|
+//import java.math.BigDecimal;
|
|
|
|
+//import java.util.*;
|
|
|
|
+//
|
|
|
|
+//@SpringBootTest
|
|
|
|
+//class HuimvSmartApiserviceApplicationTests {
|
|
|
|
+//
|
|
|
|
+// @Autowired
|
|
|
|
+// private IndoorEnvironmentDao indoorEnvironmentDao;
|
|
|
|
+//
|
|
|
|
+// @Autowired
|
|
|
|
+// private OutdoorEnvironmentDao outdoorEnvironmentDao;
|
|
|
|
+//
|
|
|
|
+// @Autowired
|
|
|
|
+// private PigDao pigDao;
|
|
|
|
+//
|
|
|
|
+//
|
|
// @Test
|
|
// @Test
|
|
-// void createPigData() {
|
|
|
|
|
|
+// void contextLoads() {
|
|
//
|
|
//
|
|
-// String[] breeds = {"黑猪","金华两头乌","杜巴嘉","巴嘉","杜洛克","嘉兴黑猪","大白猪"};
|
|
|
|
-// String[] originPlace = {"金华","杭州"};
|
|
|
|
|
|
+// }
|
|
//
|
|
//
|
|
-// List<YearPigBaseEntity> all = new ArrayList<>();
|
|
|
|
-// List<YearPigBaseEntity> mothers = new ArrayList<>();
|
|
|
|
-// List<YearPigBaseEntity> fathers = new ArrayList<>();
|
|
|
|
|
|
+//
|
|
|
|
+// @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();
|
|
// Random random = new Random();
|
|
-// for (int i = 5; i < 2001; i++) {
|
|
|
|
-// YearPigBaseEntity entity = new YearPigBaseEntity();
|
|
|
|
-// String number = String.valueOf(i);
|
|
|
|
-// String earTag = "N00000".substring(0, 6 - number.length()) + number;
|
|
|
|
-// entity.setEartag(earTag);
|
|
|
|
-// int dayAge = random.nextInt(200) + 50;
|
|
|
|
-// entity.setDayAge(dayAge);
|
|
|
|
-// entity.setUnitId(random.nextInt(4) + 1);
|
|
|
|
-// BigDecimal bigDecimal = new BigDecimal(dayAge);
|
|
|
|
-// BigDecimal weight = bigDecimal.multiply(new BigDecimal(0.8)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
-// entity.setWeight(weight.doubleValue());
|
|
|
|
-// entity.setBreed(breeds[random.nextInt(breeds.length)]);
|
|
|
|
-// String sex = i % 2 == 0 ? "公" : "母";
|
|
|
|
-// entity.setSex(sex);
|
|
|
|
-// if (dayAge >= 150 && "母".equals(sex)) {
|
|
|
|
-// mothers.add(entity);
|
|
|
|
-// }
|
|
|
|
-// if (dayAge >= 150 && "公".equals(sex)) {
|
|
|
|
-// fathers.add(entity);
|
|
|
|
-// }
|
|
|
|
-// entity.setBirthday(DateUtil.offsetDay(DateUtil.date(),i % 200));
|
|
|
|
-// entity.setOriginPlace(originPlace[random.nextInt(2)]);
|
|
|
|
-// //System.out.println(entity.getDayAge() + " " + " " + entity.getUnitId() + " " + entity.getWeight());
|
|
|
|
-// entity.setPigstyId(random.nextInt(4) + 1);
|
|
|
|
-// entity.setPeriodId(1);
|
|
|
|
-// entity.setInFenceTime(DateUtil.offsetDay(DateUtil.parseDate("2021-01-01"),random.nextInt(91) - 30));
|
|
|
|
-// all.add(entity);
|
|
|
|
|
|
+// 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() * 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.setAirQuality(gas.get(random.nextInt(5)));
|
|
|
|
+// entity.setCollectTime(collectTime);
|
|
|
|
+// collectTime = DateUtil.offsetMinute(collectTime,5);
|
|
|
|
+//// System.out.println(entity);
|
|
|
|
+// list.add(entity);
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
-// for (YearPigBaseEntity yearPigBaseEntity : all) {
|
|
|
|
-// if (yearPigBaseEntity.getDayAge() < 150) {
|
|
|
|
-// yearPigBaseEntity.setMotherEartag(mothers.get(random.nextInt(mothers.size())).getEartag());
|
|
|
|
-// yearPigBaseEntity.setFatherEartag(fathers.get(random.nextInt(fathers.size())).getEartag());
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// pigDao.batchInsertData(all);
|
|
|
|
-//
|
|
|
|
-// List<SowChildbirthEntity> sowChildbirthEntityList = new ArrayList<>();
|
|
|
|
-// for (YearPigBaseEntity mother : mothers) {
|
|
|
|
-// SowChildbirthEntity entity = new SowChildbirthEntity();
|
|
|
|
-// entity.setEartag(mother.getEartag());
|
|
|
|
-// entity.setChildbirthWeight(mother.getWeight());
|
|
|
|
-// entity.setPregnancyDate(DateUtil.offsetMonth(mother.getInFenceTime(),3));
|
|
|
|
-// entity.setChildbirthCount(random.nextInt(10) + 5);
|
|
|
|
-// sowChildbirthEntityList.add(entity);
|
|
|
|
-// }
|
|
|
|
-// sowChildbirthDao.batchInsertData(sowChildbirthEntityList);
|
|
|
|
|
|
+// 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.setAirQuality(gas.get(random.nextInt(4)));
|
|
|
|
+// entity.setCollectTime(collectTime);
|
|
|
|
+// collectTime = DateUtil.offsetMinute(collectTime,5);
|
|
|
|
+// list.add(entity);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// outdoorEnvironmentDao.batchInsertData(list);
|
|
// }
|
|
// }
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//// @Test
|
|
|
|
+//// void createPigData() {
|
|
|
|
+////
|
|
|
|
+//// String[] breeds = {"黑猪","金华两头乌","杜巴嘉","巴嘉","杜洛克","嘉兴黑猪","大白猪"};
|
|
|
|
+//// String[] originPlace = {"金华","杭州"};
|
|
|
|
+////
|
|
|
|
+//// List<YearPigBaseEntity> all = new ArrayList<>();
|
|
|
|
+//// List<YearPigBaseEntity> mothers = new ArrayList<>();
|
|
|
|
+//// List<YearPigBaseEntity> fathers = new ArrayList<>();
|
|
|
|
+////
|
|
|
|
+//// Random random = new Random();
|
|
|
|
+//// for (int i = 5; i < 2001; i++) {
|
|
|
|
+//// YearPigBaseEntity entity = new YearPigBaseEntity();
|
|
|
|
+//// String number = String.valueOf(i);
|
|
|
|
+//// String earTag = "N00000".substring(0, 6 - number.length()) + number;
|
|
|
|
+//// entity.setEartag(earTag);
|
|
|
|
+//// int dayAge = random.nextInt(200) + 50;
|
|
|
|
+//// entity.setDayAge(dayAge);
|
|
|
|
+//// entity.setUnitId(random.nextInt(4) + 1);
|
|
|
|
+//// BigDecimal bigDecimal = new BigDecimal(dayAge);
|
|
|
|
+//// BigDecimal weight = bigDecimal.multiply(new BigDecimal(0.8)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+//// entity.setWeight(weight.doubleValue());
|
|
|
|
+//// entity.setBreed(breeds[random.nextInt(breeds.length)]);
|
|
|
|
+//// String sex = i % 2 == 0 ? "公" : "母";
|
|
|
|
+//// entity.setSex(sex);
|
|
|
|
+//// if (dayAge >= 150 && "母".equals(sex)) {
|
|
|
|
+//// mothers.add(entity);
|
|
|
|
+//// }
|
|
|
|
+//// if (dayAge >= 150 && "公".equals(sex)) {
|
|
|
|
+//// fathers.add(entity);
|
|
|
|
+//// }
|
|
|
|
+//// entity.setBirthday(DateUtil.offsetDay(DateUtil.date(),i % 200));
|
|
|
|
+//// entity.setOriginPlace(originPlace[random.nextInt(2)]);
|
|
|
|
+//// //System.out.println(entity.getDayAge() + " " + " " + entity.getUnitId() + " " + entity.getWeight());
|
|
|
|
+//// entity.setPigstyId(random.nextInt(4) + 1);
|
|
|
|
+//// entity.setPeriodId(1);
|
|
|
|
+//// entity.setInFenceTime(DateUtil.offsetDay(DateUtil.parseDate("2021-01-01"),random.nextInt(91) - 30));
|
|
|
|
+//// all.add(entity);
|
|
|
|
+//// }
|
|
|
|
+////
|
|
|
|
+//// for (YearPigBaseEntity yearPigBaseEntity : all) {
|
|
|
|
+//// if (yearPigBaseEntity.getDayAge() < 150) {
|
|
|
|
+//// yearPigBaseEntity.setMotherEartag(mothers.get(random.nextInt(mothers.size())).getEartag());
|
|
|
|
+//// yearPigBaseEntity.setFatherEartag(fathers.get(random.nextInt(fathers.size())).getEartag());
|
|
|
|
+//// }
|
|
|
|
+//// }
|
|
|
|
+//// pigDao.batchInsertData(all);
|
|
|
|
+////
|
|
|
|
+//// List<SowChildbirthEntity> sowChildbirthEntityList = new ArrayList<>();
|
|
|
|
+//// for (YearPigBaseEntity mother : mothers) {
|
|
|
|
+//// SowChildbirthEntity entity = new SowChildbirthEntity();
|
|
|
|
+//// entity.setEartag(mother.getEartag());
|
|
|
|
+//// entity.setChildbirthWeight(mother.getWeight());
|
|
|
|
+//// entity.setPregnancyDate(DateUtil.offsetMonth(mother.getInFenceTime(),3));
|
|
|
|
+//// entity.setChildbirthCount(random.nextInt(10) + 5);
|
|
|
|
+//// sowChildbirthEntityList.add(entity);
|
|
|
|
+//// }
|
|
|
|
+//// sowChildbirthDao.batchInsertData(sowChildbirthEntityList);
|
|
|
|
+////
|
|
|
|
+////
|
|
|
|
+////
|
|
|
|
+////
|
|
|
|
+//// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//}
|