|
@@ -0,0 +1,52 @@
|
|
|
+package com.huimv.environ.eco.timer;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.huimv.environ.eco.entity.BaseRoom;
|
|
|
+import com.huimv.environ.eco.entity.SysHumidity;
|
|
|
+import com.huimv.environ.eco.entity.SysTemperature;
|
|
|
+import com.huimv.environ.eco.mapper.BaseRoomMapper;
|
|
|
+import com.huimv.environ.eco.mapper.SysHumidityMapper;
|
|
|
+import com.huimv.environ.eco.mapper.SysTemperatureMapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Configuration
|
|
|
+@EnableScheduling
|
|
|
+public class WaterData {
|
|
|
+ @Autowired
|
|
|
+ private SysHumidityMapper humidityMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysTemperatureMapper temperatureMapper;
|
|
|
+ @Autowired
|
|
|
+ private BaseRoomMapper roomMapper;
|
|
|
+
|
|
|
+ @Scheduled(cron = "* 0/30 * * * ? ")
|
|
|
+ private void action() {
|
|
|
+ QueryWrapper<BaseRoom> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("farm_id", 1);
|
|
|
+ List<BaseRoom> baseRooms = roomMapper.selectList(queryWrapper);
|
|
|
+ for (BaseRoom baseRoom : baseRooms) {
|
|
|
+ SysHumidity sysHumidity = new SysHumidity();
|
|
|
+ sysHumidity.setCreateTime(new Date());
|
|
|
+ sysHumidity.setFarmId(1);
|
|
|
+ sysHumidity.setRoomId(baseRoom.getId());
|
|
|
+ String hum = NumberUtils.getNumFloat(50.0, 80.0);
|
|
|
+ sysHumidity.setValue(Double.valueOf(hum));
|
|
|
+ humidityMapper.insert(sysHumidity);
|
|
|
+
|
|
|
+ SysTemperature sysTemperature = new SysTemperature();
|
|
|
+ sysTemperature.setCreateTime(new Date());
|
|
|
+ sysTemperature.setFarmId(1);
|
|
|
+ sysTemperature.setRoomId(baseRoom.getId());
|
|
|
+ String temp = NumberUtils.getNumFloat(18.0, 25.0);
|
|
|
+ sysTemperature.setValue(Double.valueOf(temp));
|
|
|
+ temperatureMapper.insert(sysTemperature);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|