|
@@ -1,143 +1,143 @@
|
|
|
-package com.huimv.apiservice.task;
|
|
|
-
|
|
|
-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.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
-import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
-import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Random;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * 定时任务
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @author yinhao
|
|
|
- * @date 2021/5/26 15:16
|
|
|
- */
|
|
|
-@Configuration
|
|
|
-@EnableScheduling
|
|
|
-@EnableAsync
|
|
|
-public class CreateEverydayDataTask {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IndoorEnvironmentDao indoorEnvironmentDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private OutdoorEnvironmentDao outdoorEnvironmentDao;
|
|
|
-
|
|
|
- @Async
|
|
|
- //@Scheduled(cron = "1 0 0 * * ?")
|
|
|
- @Scheduled(cron = "30 15 14 * * ?")
|
|
|
- void createTodayIndoorEnvData() {
|
|
|
-
|
|
|
- System.out.println("createTodayIndoorEnvData begin------->");
|
|
|
- DateTime today = DateUtil.beginOfDay(new Date());
|
|
|
- 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();
|
|
|
-
|
|
|
- //当前日期
|
|
|
+//package com.huimv.apiservice.task;
|
|
|
+//
|
|
|
+//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.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.context.annotation.Configuration;
|
|
|
+//import org.springframework.scheduling.annotation.Async;
|
|
|
+//import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
+//import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+//import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+//
|
|
|
+//import java.math.BigDecimal;
|
|
|
+//import java.util.ArrayList;
|
|
|
+//import java.util.Date;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Random;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * <p>
|
|
|
+// * 定时任务
|
|
|
+// * </p>
|
|
|
+// *
|
|
|
+// * @author yinhao
|
|
|
+// * @date 2021/5/26 15:16
|
|
|
+// */
|
|
|
+//@Configuration
|
|
|
+//@EnableScheduling
|
|
|
+//@EnableAsync
|
|
|
+//public class CreateEverydayDataTask {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private IndoorEnvironmentDao indoorEnvironmentDao;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private OutdoorEnvironmentDao outdoorEnvironmentDao;
|
|
|
+//
|
|
|
+// @Async
|
|
|
+// //@Scheduled(cron = "1 0 0 * * ?")
|
|
|
+//// @Scheduled(cron = "30 15 14 * * ?")
|
|
|
+// void createTodayIndoorEnvData() {
|
|
|
+//
|
|
|
+// System.out.println("createTodayIndoorEnvData begin------->");
|
|
|
+// DateTime today = DateUtil.beginOfDay(new Date());
|
|
|
+// 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);
|
|
|
+//// //牧场id
|
|
|
+//// entity.setFarmId(144);
|
|
|
+//// //猪舍id
|
|
|
+//// entity.setPigstyId(56);
|
|
|
+//// //温度
|
|
|
+//// entity.setTemperature(getTemperature());
|
|
|
+//// //湿度
|
|
|
+//// entity.setHumidity(getHumidity());
|
|
|
+//// //空气质量
|
|
|
+//// entity.setAirQuality(gas.get(random.nextInt(5)));
|
|
|
+//// //采集时间
|
|
|
+// entity.setCollectTime(collectTime);
|
|
|
+// collectTime = DateUtil.offsetMinute(collectTime, 5);
|
|
|
+// list.add(entity);
|
|
|
+// }
|
|
|
+//
|
|
|
+// indoorEnvironmentDao.batchInsertData(list);
|
|
|
+// System.out.println("createTodayIndoorEnvData end------->");
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Async
|
|
|
+// //@Scheduled(cron = "1 0 0 * * ?")
|
|
|
+//// @Scheduled(cron = "30 15 14 * * ?")
|
|
|
+// void createTodayOutdoorEnvData() {
|
|
|
+//
|
|
|
+// System.out.println("createTodayOutdoorEnvData begin------->");
|
|
|
+// DateTime today = DateUtil.beginOfDay(new Date());
|
|
|
+// 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);
|
|
|
-// //牧场id
|
|
|
// entity.setFarmId(144);
|
|
|
-// //猪舍id
|
|
|
-// entity.setPigstyId(56);
|
|
|
-// //温度
|
|
|
// entity.setTemperature(getTemperature());
|
|
|
-// //湿度
|
|
|
// entity.setHumidity(getHumidity());
|
|
|
-// //空气质量
|
|
|
-// entity.setAirQuality(gas.get(random.nextInt(5)));
|
|
|
-// //采集时间
|
|
|
- entity.setCollectTime(collectTime);
|
|
|
- collectTime = DateUtil.offsetMinute(collectTime, 5);
|
|
|
- list.add(entity);
|
|
|
- }
|
|
|
-
|
|
|
- indoorEnvironmentDao.batchInsertData(list);
|
|
|
- System.out.println("createTodayIndoorEnvData end------->");
|
|
|
- }
|
|
|
-
|
|
|
- @Async
|
|
|
- //@Scheduled(cron = "1 0 0 * * ?")
|
|
|
- @Scheduled(cron = "30 15 14 * * ?")
|
|
|
- void createTodayOutdoorEnvData() {
|
|
|
-
|
|
|
- System.out.println("createTodayOutdoorEnvData begin------->");
|
|
|
- DateTime today = DateUtil.beginOfDay(new Date());
|
|
|
- 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);
|
|
|
- entity.setFarmId(144);
|
|
|
- entity.setTemperature(getTemperature());
|
|
|
- entity.setHumidity(getHumidity());
|
|
|
- entity.setAirQuality(gas.get(random.nextInt(4)));
|
|
|
- entity.setCollectTime(collectTime);
|
|
|
- collectTime = DateUtil.offsetMinute(collectTime, 5);
|
|
|
- list.add(entity);
|
|
|
- }
|
|
|
-
|
|
|
- outdoorEnvironmentDao.batchInsertData(list);
|
|
|
- System.out.println("createTodayOutdoorEnvData end------->");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Async
|
|
|
- @Scheduled(cron = "1 0 0 * * ?")
|
|
|
- //@Scheduled(cron = "1 52 18 * * ?")
|
|
|
- void callPigHealthData() {
|
|
|
- System.out.println("callPigHealthData begin------->");
|
|
|
- indoorEnvironmentDao.callPigHealthData();
|
|
|
- System.out.println("callPigHealthData end------->");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private double getTemperature() {
|
|
|
- BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).setScale(1, BigDecimal.ROUND_HALF_UP);
|
|
|
- return bigDecimal.doubleValue();
|
|
|
- }
|
|
|
-
|
|
|
- private double getHumidity(){
|
|
|
- BigDecimal bigDecimal = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
- return bigDecimal.doubleValue();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+// entity.setAirQuality(gas.get(random.nextInt(4)));
|
|
|
+// entity.setCollectTime(collectTime);
|
|
|
+// collectTime = DateUtil.offsetMinute(collectTime, 5);
|
|
|
+// list.add(entity);
|
|
|
+// }
|
|
|
+//
|
|
|
+// outdoorEnvironmentDao.batchInsertData(list);
|
|
|
+// System.out.println("createTodayOutdoorEnvData end------->");
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+//// @Async
|
|
|
+//// @Scheduled(cron = "1 0 0 * * ?")
|
|
|
+//// //@Scheduled(cron = "1 52 18 * * ?")
|
|
|
+//// void callPigHealthData() {
|
|
|
+//// System.out.println("callPigHealthData begin------->");
|
|
|
+//// indoorEnvironmentDao.callPigHealthData();
|
|
|
+//// System.out.println("callPigHealthData end------->");
|
|
|
+////
|
|
|
+//// }
|
|
|
+//
|
|
|
+//// private double getTemperature() {
|
|
|
+//// BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).setScale(1, BigDecimal.ROUND_HALF_UP);
|
|
|
+//// return bigDecimal.doubleValue();
|
|
|
+//// }
|
|
|
+////
|
|
|
+//// private double getHumidity(){
|
|
|
+//// BigDecimal bigDecimal = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+//// return bigDecimal.doubleValue();
|
|
|
+//// }
|
|
|
+//
|
|
|
+//
|
|
|
+//}
|