|
@@ -4,13 +4,18 @@ package com.huimv.environ.eco.timer;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.json.JSONObject;
|
|
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.EggData;
|
|
import com.huimv.environ.eco.entity.EggHouse;
|
|
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.HistoryEntity;
|
|
import com.huimv.environ.eco.entity.eggvo.HistroyOne;
|
|
import com.huimv.environ.eco.entity.eggvo.HistroyOne;
|
|
import com.huimv.environ.eco.entity.eggvo.HistroyTwo;
|
|
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.IEggDataService;
|
|
import com.huimv.environ.eco.service.IEggHouseService;
|
|
import com.huimv.environ.eco.service.IEggHouseService;
|
|
|
|
+import com.huimv.environ.eco.service.ISysThresholdService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpEntity;
|
|
import org.springframework.http.HttpEntity;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
@@ -36,6 +41,11 @@ public class EggTimer {
|
|
@Autowired
|
|
@Autowired
|
|
private IEggHouseService eggHouseService;
|
|
private IEggHouseService eggHouseService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysThresholdService sysThresholdService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBaseWarningInfoService baseWarningInfoService;
|
|
|
|
+
|
|
|
|
|
|
@Scheduled(cron = "0 0/10 * * * ? ")
|
|
@Scheduled(cron = "0 0/10 * * * ? ")
|
|
public void saveEggData (){
|
|
public void saveEggData (){
|
|
@@ -50,7 +60,7 @@ public class EggTimer {
|
|
long end = date.getTime();
|
|
long end = date.getTime();
|
|
DateTime dateTime = DateUtil.offsetMinute(date, -10);
|
|
DateTime dateTime = DateUtil.offsetMinute(date, -10);
|
|
long start = dateTime.getTime();
|
|
long start = dateTime.getTime();
|
|
-
|
|
|
|
|
|
+ SysThreshold byId = sysThresholdService.getById(1);
|
|
for (EggHouse eggHouse : list) {
|
|
for (EggHouse eggHouse : list) {
|
|
Integer i = eggHouse.getI();
|
|
Integer i = eggHouse.getI();
|
|
ResponseEntity<HistoryEntity> forEntity = restTemplate.exchange(BASE_URL + HISTORY_LIST+FARM_CODE+"&i="+i+"&start="+start+"&end="+end, HttpMethod.GET, httpEntity,HistoryEntity.class );
|
|
ResponseEntity<HistoryEntity> forEntity = restTemplate.exchange(BASE_URL + HISTORY_LIST+FARM_CODE+"&i="+i+"&start="+start+"&end="+end, HttpMethod.GET, httpEntity,HistoryEntity.class );
|
|
@@ -69,7 +79,6 @@ public class EggTimer {
|
|
eggData.setWtrTdy(data1.getWtr_tdy());
|
|
eggData.setWtrTdy(data1.getWtr_tdy());
|
|
eggData.setUploadTime( new Date(uploadTime));
|
|
eggData.setUploadTime( new Date(uploadTime));
|
|
|
|
|
|
-
|
|
|
|
eggData.setFN( data1.getF_n());
|
|
eggData.setFN( data1.getF_n());
|
|
eggData.setFLv( data1.getF_lv());
|
|
eggData.setFLv( data1.getF_lv());
|
|
eggData.setFV(data1.getF_v() );
|
|
eggData.setFV(data1.getF_v() );
|
|
@@ -77,13 +86,55 @@ public class EggTimer {
|
|
eggData.setTT( data1.getT_t());
|
|
eggData.setTT( data1.getT_t());
|
|
eggData.setHT( data1.getH_t());
|
|
eggData.setHT( data1.getH_t());
|
|
eggData.setHtL( data1.getHt_l());
|
|
eggData.setHtL( data1.getHt_l());
|
|
-
|
|
|
|
-
|
|
|
|
eggDataService.save(eggData);
|
|
eggDataService.save(eggData);
|
|
|
|
+ saveWarning(eggData,byId);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|