|
@@ -1,146 +1,146 @@
|
|
-package com.huimv.environ.eco.timer;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-import cn.hutool.core.date.DateTime;
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
-import com.huimv.environ.eco.entity.BaseWarningInfo;
|
|
|
|
-import com.huimv.environ.eco.entity.EggData;
|
|
|
|
-import com.huimv.environ.eco.entity.EggHouse;
|
|
|
|
-import com.huimv.environ.eco.entity.SysThreshold;
|
|
|
|
-import com.huimv.environ.eco.entity.eggvo.HistoryEntity;
|
|
|
|
-import com.huimv.environ.eco.entity.eggvo.HistroyOne;
|
|
|
|
-import com.huimv.environ.eco.entity.eggvo.HistroyTwo;
|
|
|
|
-import com.huimv.environ.eco.service.IBaseWarningInfoService;
|
|
|
|
-import com.huimv.environ.eco.service.IEggDataService;
|
|
|
|
-import com.huimv.environ.eco.service.IEggHouseService;
|
|
|
|
-import com.huimv.environ.eco.service.ISysThresholdService;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.http.HttpEntity;
|
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
|
-import org.springframework.http.HttpMethod;
|
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
|
-
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-
|
|
|
|
-@Component
|
|
|
|
-public class EggTimer {
|
|
|
|
- private static final String BASE_URL= "https://iot1.bigherdsman.com/api/v2/";
|
|
|
|
- private static final String TOKEN= "72438b180e9168fe90db126e3310cd0b20a7196d";
|
|
|
|
-
|
|
|
|
- private static final String HISTORY_LIST= "history/list/?code=";
|
|
|
|
- private static final String FARM_CODE = "2022011710";
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private IEggDataService eggDataService;
|
|
|
|
- @Autowired
|
|
|
|
- private IEggHouseService eggHouseService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ISysThresholdService sysThresholdService;
|
|
|
|
- @Autowired
|
|
|
|
- private IBaseWarningInfoService baseWarningInfoService;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- @Scheduled(cron = "0 0/10 * * * ? ")
|
|
|
|
-// @Scheduled(cron = "0 * * * * ? ")
|
|
|
|
- public void saveEggData(){
|
|
|
|
- System.out.println("test");
|
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
|
- headers.set("Authorization","Token "+TOKEN);
|
|
|
|
- HttpEntity<JSONObject> httpEntity = new HttpEntity<>(headers);
|
|
|
|
-
|
|
|
|
- List<EggHouse> list = eggHouseService.list();
|
|
|
|
- Date date= new Date();
|
|
|
|
- long end = date.getTime();
|
|
|
|
- DateTime dateTime = DateUtil.offsetMinute(date, -10);
|
|
|
|
- long start = dateTime.getTime();
|
|
|
|
- SysThreshold byId = sysThresholdService.getById(1);
|
|
|
|
- for (EggHouse eggHouse : list) {
|
|
|
|
- Integer i = eggHouse.getI();
|
|
|
|
- try {
|
|
|
|
- ResponseEntity<HistoryEntity> forEntity = restTemplate.exchange(BASE_URL + HISTORY_LIST+FARM_CODE+"&i="+i+"&start="+start+"&end="+end, HttpMethod.GET, httpEntity,HistoryEntity.class );
|
|
|
|
- List<HistroyOne> data = forEntity.getBody().getData();
|
|
|
|
- for (HistroyOne datum : data) {
|
|
|
|
- Long uploadTime = datum.getUpload_time();
|
|
|
|
- HistroyTwo data1 = datum.getData();
|
|
|
|
-
|
|
|
|
- EggData eggData = new EggData();
|
|
|
|
- eggData.setCo2(data1.getCo2());
|
|
|
|
- eggData.setFtDoTalTdy(data1.getFt_do_tal_tdy());
|
|
|
|
- eggData.setHR(data1.getH_r());
|
|
|
|
- eggData.setI(i);
|
|
|
|
- eggData.setTCur(data1.getT_cur());
|
|
|
|
- eggData.setWtrTdy(data1.getWtr_tdy());
|
|
|
|
- eggData.setUploadTime( new Date(uploadTime));
|
|
|
|
-
|
|
|
|
- eggData.setFN( data1.getF_n());
|
|
|
|
- eggData.setFLv( data1.getF_lv());
|
|
|
|
- eggData.setFV(data1.getF_v() );
|
|
|
|
- eggData.setTS(data1.getT_s());
|
|
|
|
- eggData.setTT( data1.getT_t());
|
|
|
|
- eggData.setHT( data1.getH_t());
|
|
|
|
- eggData.setHtL( data1.getHt_l());
|
|
|
|
- eggDataService.save(eggData);
|
|
|
|
- saveWarning(eggData,byId);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }catch (Exception e){
|
|
|
|
- System.out.println("数据未取到");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void saveWarning(EggData eggData, SysThreshold byId) {
|
|
|
|
- String minTem = byId.getMinTem();
|
|
|
|
- String maxTem = byId.getMaxTem();
|
|
|
|
- String minHum = byId.getMinHum();
|
|
|
|
- String maxHum = byId.getMaxHum();
|
|
|
|
- Double tCur = eggData.getTCur();
|
|
|
|
- Integer hr = eggData.getHR();
|
|
|
|
- Integer i = eggData.getI();
|
|
|
|
-
|
|
|
|
- BaseWarningInfo baseWarningInfo = new BaseWarningInfo();
|
|
|
|
- baseWarningInfo.setFarmId(1);
|
|
|
|
- baseWarningInfo.setLevel(1);
|
|
|
|
- baseWarningInfo.setLevelName("一级报警");
|
|
|
|
- baseWarningInfo.setUploadTime(new Date());
|
|
|
|
- baseWarningInfo.setWarningTime(eggData.getUploadTime());
|
|
|
|
- //高温
|
|
|
|
- if (tCur>Double.parseDouble(maxTem)){
|
|
|
|
- baseWarningInfo.setMsg(i+"号舍高温预警:温度为"+tCur+"℃,超过高温阈值"+maxTem+"℃");
|
|
|
|
- baseWarningInfo.setAlarmType(7);
|
|
|
|
- baseWarningInfo.setWarningName("高温报警");
|
|
|
|
- baseWarningInfoService.save(baseWarningInfo);
|
|
|
|
- }
|
|
|
|
- //低温
|
|
|
|
- if (tCur<Double.parseDouble(minTem)){
|
|
|
|
- baseWarningInfo.setMsg(i+"号舍低温预警:温度为"+tCur+"℃,低于低温阈值"+minTem+"℃");
|
|
|
|
- baseWarningInfo.setAlarmType(7);
|
|
|
|
- baseWarningInfo.setWarningName("低温报警");
|
|
|
|
- baseWarningInfoService.save(baseWarningInfo);
|
|
|
|
- }
|
|
|
|
- //高湿
|
|
|
|
- if (hr>Integer.parseInt(maxHum)){
|
|
|
|
- baseWarningInfo.setMsg(i+"号舍高湿度预警:温度为"+hr+",高于阈值"+maxHum);
|
|
|
|
- baseWarningInfo.setAlarmType(7);
|
|
|
|
- baseWarningInfo.setWarningName("高湿度报警");
|
|
|
|
- baseWarningInfoService.save(baseWarningInfo);
|
|
|
|
- }
|
|
|
|
- //低湿
|
|
|
|
- if (hr<Integer.parseInt(minHum)){
|
|
|
|
- baseWarningInfo.setMsg(i+"号舍低湿度预警:温度为"+hr+",低于阈值"+minHum);
|
|
|
|
- baseWarningInfo.setAlarmType(7);
|
|
|
|
- baseWarningInfo.setWarningName("低湿度报警");
|
|
|
|
- baseWarningInfoService.save(baseWarningInfo);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+//package com.huimv.environ.eco.timer;
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//import cn.hutool.core.date.DateTime;
|
|
|
|
+//import cn.hutool.core.date.DateUtil;
|
|
|
|
+//import cn.hutool.json.JSONObject;
|
|
|
|
+//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
+//import com.huimv.environ.eco.entity.BaseWarningInfo;
|
|
|
|
+//import com.huimv.environ.eco.entity.EggData;
|
|
|
|
+//import com.huimv.environ.eco.entity.EggHouse;
|
|
|
|
+//import com.huimv.environ.eco.entity.SysThreshold;
|
|
|
|
+//import com.huimv.environ.eco.entity.eggvo.HistoryEntity;
|
|
|
|
+//import com.huimv.environ.eco.entity.eggvo.HistroyOne;
|
|
|
|
+//import com.huimv.environ.eco.entity.eggvo.HistroyTwo;
|
|
|
|
+//import com.huimv.environ.eco.service.IBaseWarningInfoService;
|
|
|
|
+//import com.huimv.environ.eco.service.IEggDataService;
|
|
|
|
+//import com.huimv.environ.eco.service.IEggHouseService;
|
|
|
|
+//import com.huimv.environ.eco.service.ISysThresholdService;
|
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+//import org.springframework.http.HttpEntity;
|
|
|
|
+//import org.springframework.http.HttpHeaders;
|
|
|
|
+//import org.springframework.http.HttpMethod;
|
|
|
|
+//import org.springframework.http.ResponseEntity;
|
|
|
|
+//import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
|
+//import org.springframework.web.client.RestTemplate;
|
|
|
|
+//
|
|
|
|
+//import java.util.Date;
|
|
|
|
+//import java.util.List;
|
|
|
|
+//
|
|
|
|
+//@Component
|
|
|
|
+//public class EggTimer {
|
|
|
|
+// private static final String BASE_URL= "https://iot1.bigherdsman.com/api/v2/";
|
|
|
|
+// private static final String TOKEN= "72438b180e9168fe90db126e3310cd0b20a7196d";
|
|
|
|
+//
|
|
|
|
+// private static final String HISTORY_LIST= "history/list/?code=";
|
|
|
|
+// private static final String FARM_CODE = "2022011710";
|
|
|
|
+//
|
|
|
|
+// @Autowired
|
|
|
|
+// private IEggDataService eggDataService;
|
|
|
|
+// @Autowired
|
|
|
|
+// private IEggHouseService eggHouseService;
|
|
|
|
+//
|
|
|
|
+// @Autowired
|
|
|
|
+// private ISysThresholdService sysThresholdService;
|
|
|
|
+// @Autowired
|
|
|
|
+// private IBaseWarningInfoService baseWarningInfoService;
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// @Scheduled(cron = "0 0/10 * * * ? ")
|
|
|
|
+//// @Scheduled(cron = "0 * * * * ? ")
|
|
|
|
+// public void saveEggData(){
|
|
|
|
+// System.out.println("test");
|
|
|
|
+// RestTemplate restTemplate = new RestTemplate();
|
|
|
|
+// HttpHeaders headers = new HttpHeaders();
|
|
|
|
+// headers.set("Authorization","Token "+TOKEN);
|
|
|
|
+// HttpEntity<JSONObject> httpEntity = new HttpEntity<>(headers);
|
|
|
|
+//
|
|
|
|
+// List<EggHouse> list = eggHouseService.list();
|
|
|
|
+// Date date= new Date();
|
|
|
|
+// long end = date.getTime();
|
|
|
|
+// DateTime dateTime = DateUtil.offsetMinute(date, -10);
|
|
|
|
+// long start = dateTime.getTime();
|
|
|
|
+// SysThreshold byId = sysThresholdService.getById(1);
|
|
|
|
+// for (EggHouse eggHouse : list) {
|
|
|
|
+// Integer i = eggHouse.getI();
|
|
|
|
+// try {
|
|
|
|
+// ResponseEntity<HistoryEntity> forEntity = restTemplate.exchange(BASE_URL + HISTORY_LIST+FARM_CODE+"&i="+i+"&start="+start+"&end="+end, HttpMethod.GET, httpEntity,HistoryEntity.class );
|
|
|
|
+// List<HistroyOne> data = forEntity.getBody().getData();
|
|
|
|
+// for (HistroyOne datum : data) {
|
|
|
|
+// Long uploadTime = datum.getUpload_time();
|
|
|
|
+// HistroyTwo data1 = datum.getData();
|
|
|
|
+//
|
|
|
|
+// EggData eggData = new EggData();
|
|
|
|
+// eggData.setCo2(data1.getCo2());
|
|
|
|
+// eggData.setFtDoTalTdy(data1.getFt_do_tal_tdy());
|
|
|
|
+// eggData.setHR(data1.getH_r());
|
|
|
|
+// eggData.setI(i);
|
|
|
|
+// eggData.setTCur(data1.getT_cur());
|
|
|
|
+// eggData.setWtrTdy(data1.getWtr_tdy());
|
|
|
|
+// eggData.setUploadTime( new Date(uploadTime));
|
|
|
|
+//
|
|
|
|
+// eggData.setFN( data1.getF_n());
|
|
|
|
+// eggData.setFLv( data1.getF_lv());
|
|
|
|
+// eggData.setFV(data1.getF_v() );
|
|
|
|
+// eggData.setTS(data1.getT_s());
|
|
|
|
+// eggData.setTT( data1.getT_t());
|
|
|
|
+// eggData.setHT( data1.getH_t());
|
|
|
|
+// eggData.setHtL( data1.getHt_l());
|
|
|
|
+// eggDataService.save(eggData);
|
|
|
|
+// saveWarning(eggData,byId);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }catch (Exception e){
|
|
|
|
+// System.out.println("数据未取到");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private void saveWarning(EggData eggData, SysThreshold byId) {
|
|
|
|
+// String minTem = byId.getMinTem();
|
|
|
|
+// String maxTem = byId.getMaxTem();
|
|
|
|
+// String minHum = byId.getMinHum();
|
|
|
|
+// String maxHum = byId.getMaxHum();
|
|
|
|
+// Double tCur = eggData.getTCur();
|
|
|
|
+// Integer hr = eggData.getHR();
|
|
|
|
+// Integer i = eggData.getI();
|
|
|
|
+//
|
|
|
|
+// BaseWarningInfo baseWarningInfo = new BaseWarningInfo();
|
|
|
|
+// baseWarningInfo.setFarmId(1);
|
|
|
|
+// baseWarningInfo.setLevel(1);
|
|
|
|
+// baseWarningInfo.setLevelName("一级报警");
|
|
|
|
+// baseWarningInfo.setUploadTime(new Date());
|
|
|
|
+// baseWarningInfo.setWarningTime(eggData.getUploadTime());
|
|
|
|
+// //高温
|
|
|
|
+// if (tCur>Double.parseDouble(maxTem)){
|
|
|
|
+// baseWarningInfo.setMsg(i+"号舍高温预警:温度为"+tCur+"℃,超过高温阈值"+maxTem+"℃");
|
|
|
|
+// baseWarningInfo.setAlarmType(7);
|
|
|
|
+// baseWarningInfo.setWarningName("高温报警");
|
|
|
|
+// baseWarningInfoService.save(baseWarningInfo);
|
|
|
|
+// }
|
|
|
|
+// //低温
|
|
|
|
+// if (tCur<Double.parseDouble(minTem)){
|
|
|
|
+// baseWarningInfo.setMsg(i+"号舍低温预警:温度为"+tCur+"℃,低于低温阈值"+minTem+"℃");
|
|
|
|
+// baseWarningInfo.setAlarmType(7);
|
|
|
|
+// baseWarningInfo.setWarningName("低温报警");
|
|
|
|
+// baseWarningInfoService.save(baseWarningInfo);
|
|
|
|
+// }
|
|
|
|
+// //高湿
|
|
|
|
+// if (hr>Integer.parseInt(maxHum)){
|
|
|
|
+// baseWarningInfo.setMsg(i+"号舍高湿度预警:温度为"+hr+",高于阈值"+maxHum);
|
|
|
|
+// baseWarningInfo.setAlarmType(7);
|
|
|
|
+// baseWarningInfo.setWarningName("高湿度报警");
|
|
|
|
+// baseWarningInfoService.save(baseWarningInfo);
|
|
|
|
+// }
|
|
|
|
+// //低湿
|
|
|
|
+// if (hr<Integer.parseInt(minHum)){
|
|
|
|
+// baseWarningInfo.setMsg(i+"号舍低湿度预警:温度为"+hr+",低于阈值"+minHum);
|
|
|
|
+// baseWarningInfo.setAlarmType(7);
|
|
|
|
+// baseWarningInfo.setWarningName("低湿度报警");
|
|
|
|
+// baseWarningInfoService.save(baseWarningInfo);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//}
|