HuimvSmartApiserviceApplicationTests.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package com.huimv.apiservice;
  2. import cn.hutool.core.date.DateTime;
  3. import cn.hutool.core.date.DateUtil;
  4. import com.huimv.apiservice.dao.IndoorEnvironmentDao;
  5. import com.huimv.apiservice.dao.OutdoorEnvironmentDao;
  6. import com.huimv.apiservice.dao.PigDao;
  7. import com.huimv.apiservice.dao.SowChildbirthDao;
  8. import com.huimv.apiservice.entity.IndoorEnvironmentEntity;
  9. import com.huimv.apiservice.entity.OutdoorEnvironmentEntity;
  10. import com.huimv.apiservice.entity.SowChildbirthEntity;
  11. import com.huimv.apiservice.entity.YearPigBaseEntity;
  12. import org.junit.jupiter.api.Test;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.boot.test.context.SpringBootTest;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import java.math.BigDecimal;
  17. import java.math.RoundingMode;
  18. import java.util.*;
  19. @SpringBootTest
  20. class HuimvSmartApiserviceApplicationTests {
  21. @Autowired
  22. private IndoorEnvironmentDao indoorEnvironmentDao;
  23. @Autowired
  24. private OutdoorEnvironmentDao outdoorEnvironmentDao;
  25. @Autowired
  26. private PigDao pigDao;
  27. @Autowired
  28. private SowChildbirthDao sowChildbirthDao;
  29. @Test
  30. void contextLoads() {
  31. }
  32. @Test
  33. void createIndoorEnv() {
  34. DateTime today = DateUtil.beginOfDay(new Date());
  35. System.out.println(today);
  36. // BigDecimal bigDecimal = new BigDecimal(Math.random() * 8 + 25).setScale(1, BigDecimal.ROUND_HALF_UP);
  37. // double temperature = bigDecimal.doubleValue();
  38. // BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
  39. // double humidity = bigDecimal2.doubleValue();
  40. // System.out.println(temperature + " " + humidity);
  41. Date collectTime = today;
  42. List<String> gas = new ArrayList<>();
  43. gas.add("优");
  44. gas.add("良");
  45. gas.add("轻度");
  46. gas.add("中度");
  47. gas.add("重度");
  48. gas.add("严重");
  49. Random random = new Random();
  50. List<IndoorEnvironmentEntity> list = new ArrayList<>();
  51. for (int i = 0; i < 288; i++) {
  52. IndoorEnvironmentEntity entity = new IndoorEnvironmentEntity();
  53. entity.setDate(today);
  54. entity.setPigstyId(1);
  55. BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).setScale(1, BigDecimal.ROUND_HALF_UP);
  56. double temperature = bigDecimal.doubleValue();
  57. entity.setTemperature(temperature);
  58. BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
  59. double humidity = bigDecimal2.doubleValue();
  60. entity.setHumidity(humidity);
  61. entity.setGas(gas.get(random.nextInt(5)));
  62. entity.setCollectTime(collectTime);
  63. collectTime = DateUtil.offsetMinute(collectTime,5);
  64. // System.out.println(entity);
  65. list.add(entity);
  66. }
  67. indoorEnvironmentDao.batchInsertData(list);
  68. }
  69. @Test
  70. void createOutdoorEnv() {
  71. DateTime today = DateUtil.beginOfDay(new Date());
  72. System.out.println(today);
  73. // BigDecimal bigDecimal = new BigDecimal(Math.random() * 8 + 25).setScale(1, BigDecimal.ROUND_HALF_UP);
  74. // double temperature = bigDecimal.doubleValue();
  75. // BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
  76. // double humidity = bigDecimal2.doubleValue();
  77. // System.out.println(temperature + " " + humidity);
  78. Date collectTime = today;
  79. List<String> gas = new ArrayList<>();
  80. gas.add("优");
  81. gas.add("良");
  82. gas.add("轻度");
  83. gas.add("中度");
  84. gas.add("重度");
  85. gas.add("严重");
  86. Random random = new Random();
  87. List<OutdoorEnvironmentEntity> list = new ArrayList<>();
  88. for (int i = 0; i < 288; i++) {
  89. OutdoorEnvironmentEntity entity = new OutdoorEnvironmentEntity();
  90. entity.setDate(today);
  91. BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).setScale(1, BigDecimal.ROUND_HALF_UP);
  92. double temperature = bigDecimal.doubleValue();
  93. entity.setTemperature(temperature);
  94. BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
  95. double humidity = bigDecimal2.doubleValue();
  96. entity.setHumidity(humidity);
  97. entity.setGas(gas.get(random.nextInt(4)));
  98. entity.setCollectTime(collectTime);
  99. collectTime = DateUtil.offsetMinute(collectTime,5);
  100. list.add(entity);
  101. }
  102. outdoorEnvironmentDao.batchInsertData(list);
  103. }
  104. // @Test
  105. // void createPigData() {
  106. //
  107. // String[] breeds = {"黑猪","金华两头乌","杜巴嘉","巴嘉","杜洛克","嘉兴黑猪","大白猪"};
  108. // String[] originPlace = {"金华","杭州"};
  109. //
  110. // List<YearPigBaseEntity> all = new ArrayList<>();
  111. // List<YearPigBaseEntity> mothers = new ArrayList<>();
  112. // List<YearPigBaseEntity> fathers = new ArrayList<>();
  113. //
  114. // Random random = new Random();
  115. // for (int i = 5; i < 2001; i++) {
  116. // YearPigBaseEntity entity = new YearPigBaseEntity();
  117. // String number = String.valueOf(i);
  118. // String earTag = "N00000".substring(0, 6 - number.length()) + number;
  119. // entity.setEartag(earTag);
  120. // int dayAge = random.nextInt(200) + 50;
  121. // entity.setDayAge(dayAge);
  122. // entity.setUnitId(random.nextInt(4) + 1);
  123. // BigDecimal bigDecimal = new BigDecimal(dayAge);
  124. // BigDecimal weight = bigDecimal.multiply(new BigDecimal(0.8)).setScale(2, BigDecimal.ROUND_HALF_UP);
  125. // entity.setWeight(weight.doubleValue());
  126. // entity.setBreed(breeds[random.nextInt(breeds.length)]);
  127. // String sex = i % 2 == 0 ? "公" : "母";
  128. // entity.setSex(sex);
  129. // if (dayAge >= 150 && "母".equals(sex)) {
  130. // mothers.add(entity);
  131. // }
  132. // if (dayAge >= 150 && "公".equals(sex)) {
  133. // fathers.add(entity);
  134. // }
  135. // entity.setBirthday(DateUtil.offsetDay(DateUtil.date(),i % 200));
  136. // entity.setOriginPlace(originPlace[random.nextInt(2)]);
  137. // //System.out.println(entity.getDayAge() + " " + " " + entity.getUnitId() + " " + entity.getWeight());
  138. // entity.setPigstyId(random.nextInt(4) + 1);
  139. // entity.setPeriodId(1);
  140. // entity.setInFenceTime(DateUtil.offsetDay(DateUtil.parseDate("2021-01-01"),random.nextInt(91) - 30));
  141. // all.add(entity);
  142. // }
  143. //
  144. // for (YearPigBaseEntity yearPigBaseEntity : all) {
  145. // if (yearPigBaseEntity.getDayAge() < 150) {
  146. // yearPigBaseEntity.setMotherEartag(mothers.get(random.nextInt(mothers.size())).getEartag());
  147. // yearPigBaseEntity.setFatherEartag(fathers.get(random.nextInt(fathers.size())).getEartag());
  148. // }
  149. // }
  150. // pigDao.batchInsertData(all);
  151. //
  152. // List<SowChildbirthEntity> sowChildbirthEntityList = new ArrayList<>();
  153. // for (YearPigBaseEntity mother : mothers) {
  154. // SowChildbirthEntity entity = new SowChildbirthEntity();
  155. // entity.setEartag(mother.getEartag());
  156. // entity.setChildbirthWeight(mother.getWeight());
  157. // entity.setPregnancyDate(DateUtil.offsetMonth(mother.getInFenceTime(),3));
  158. // entity.setChildbirthCount(random.nextInt(10) + 5);
  159. // sowChildbirthEntityList.add(entity);
  160. // }
  161. // sowChildbirthDao.batchInsertData(sowChildbirthEntityList);
  162. //
  163. //
  164. //
  165. //
  166. // }
  167. }