|
@@ -5,6 +5,7 @@ import cn.hutool.core.codec.Base64;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -12,6 +13,8 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.huimv.admin.common.utils.HttpClientSSLUtils;
|
|
|
import com.huimv.admin.common.utils.NumberUtils;
|
|
|
import com.huimv.admin.entity.*;
|
|
|
+import com.huimv.admin.entity.dto.WeatherDto;
|
|
|
+import com.huimv.admin.entity.dto.WeatherLives;
|
|
|
import com.huimv.admin.entity.zengxindto.LoginOnlyDto;
|
|
|
import com.huimv.admin.entity.zengxindto.LonginOnlyDtoToken;
|
|
|
import com.huimv.admin.entity.zengxindto.ShackDatasDto;
|
|
@@ -62,7 +65,7 @@ public class EnvTimer {
|
|
|
String username = "华统";
|
|
|
String password = "888888";
|
|
|
String passwordMD5 = "21218cca77804d2ba1922c33e0151105";
|
|
|
- String baseurl ="https://yzwlw.loongk.com/";
|
|
|
+ String baseurl = "https://yzwlw.loongk.com/";
|
|
|
|
|
|
@Scheduled(cron = "0 0/11 * * * ? ")
|
|
|
@Transactional
|
|
@@ -70,50 +73,50 @@ public class EnvTimer {
|
|
|
//目前是这家
|
|
|
Integer farmId = 21;
|
|
|
String encode = loginOnly();
|
|
|
- System.out.println("encode"+encode);
|
|
|
+ System.out.println("encode" + encode);
|
|
|
//获取阈值
|
|
|
EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.add("Authorization",encode);
|
|
|
+ headers.add("Authorization", encode);
|
|
|
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
|
|
|
//TODO 只有一家,先拿全部
|
|
|
List<EnvDevice> list = envDeviceService.list();
|
|
|
for (EnvDevice envDevice : list) {
|
|
|
- if (ObjectUtil.isNotEmpty(envDevice) && StringUtils.isNotBlank(envDevice.getDeviceCode())){
|
|
|
+ if (ObjectUtil.isNotEmpty(envDevice) && StringUtils.isNotBlank(envDevice.getDeviceCode())) {
|
|
|
System.out.println(envDevice.getDeviceCode());
|
|
|
String shishiBody = "";
|
|
|
try {
|
|
|
ResponseEntity<String> exchange = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackDatas/" + envDevice.getDeviceCode(), HttpMethod.GET, requestEntity, String.class);
|
|
|
- shishiBody = exchange.getBody();
|
|
|
- }catch (Exception e){
|
|
|
+ shishiBody = exchange.getBody();
|
|
|
+ } catch (Exception e) {
|
|
|
System.out.println(e);
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isBlank(shishiBody)){
|
|
|
- System.out.println(new Date() +"实时数据"+ shishiBody);
|
|
|
+ if (StringUtils.isBlank(shishiBody)) {
|
|
|
+ System.out.println(new Date() + "实时数据" + shishiBody);
|
|
|
return;
|
|
|
}
|
|
|
ShackDatasDto shackDatasDto = JSONUtil.toBean(shishiBody, ShackDatasDto.class);
|
|
|
String onLine = shackDatasDto.getData().getOnLine();
|
|
|
- if ("N".equals(onLine)){
|
|
|
+ if ("N".equals(onLine)) {
|
|
|
envDevice.setDeviceStatus(0);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
envDevice.setDeviceStatus(1);
|
|
|
}
|
|
|
envDeviceService.updateById(envDevice);
|
|
|
List<ShackDatasSensor> sensorDatas = shackDatasDto.getData().getSensorDatas();
|
|
|
EnvData envData = new EnvData();
|
|
|
for (ShackDatasSensor sensorData : sensorDatas) {
|
|
|
- if (sensorData.getId().equals(envDevice.getOhter1())){
|
|
|
+ if (sensorData.getId().equals(envDevice.getOhter1())) {
|
|
|
String val = sensorData.getVal();
|
|
|
//TODO 预警
|
|
|
- saveTemWarning(val,envWarningThreshold,envDevice,farmId);
|
|
|
+ saveTemWarning(val, envWarningThreshold, envDevice, farmId);
|
|
|
envData.setEnvTemp(val);
|
|
|
}
|
|
|
- if (sensorData.getId().equals(envDevice.getOhter2())){
|
|
|
+ if (sensorData.getId().equals(envDevice.getOhter2())) {
|
|
|
String val = sensorData.getVal();
|
|
|
//TODO 预警
|
|
|
- saveHumWarning(val,envWarningThreshold,envDevice,farmId);
|
|
|
+ saveHumWarning(val, envWarningThreshold, envDevice, farmId);
|
|
|
envData.setEnvHum(val);
|
|
|
}
|
|
|
}
|
|
@@ -125,50 +128,58 @@ public class EnvTimer {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
@Scheduled(cron = "0 0/12 * * * ? ")
|
|
|
@Transactional
|
|
|
- public void getHuanKongs() throws Exception {
|
|
|
+ public void getHuanKongs() {
|
|
|
Integer farmId = 21;
|
|
|
EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
|
|
|
|
|
|
- List<BasePigpen> list = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId).eq("f_type", 3).ne("id",178).ne("id",181));
|
|
|
+ List<BasePigpen> list = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId).eq("f_type", 3).ne("id", 178).ne("id", 181));
|
|
|
+ String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
|
|
|
+ String result = HttpUtil.get(url);
|
|
|
+ WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
|
|
|
+ List<WeatherLives> lives = weatherDto.getLives();
|
|
|
+ WeatherLives weatherLives = lives.get(0);
|
|
|
+ int humidity = Integer.parseInt(weatherLives.getHumidity());
|
|
|
+ int temperature = Integer.parseInt(weatherLives.getTemperature());
|
|
|
+
|
|
|
for (BasePigpen basePigpen : list) {
|
|
|
EnvData envData = new EnvData();
|
|
|
envData.setCreateTime(new Date());
|
|
|
envData.setFarmId(farmId);
|
|
|
envData.setUnitId(basePigpen.getId());
|
|
|
- EnvDevice envDevice = new EnvDevice();
|
|
|
+ EnvDevice envDevice = new EnvDevice();
|
|
|
envDevice.setUnitName(basePigpen.getBuildName());
|
|
|
envDevice.setUnitId(basePigpen.getId());
|
|
|
envDevice.setFarmId(farmId);
|
|
|
|
|
|
- String tem = NumberUtils.getNum(28, 31, 1);
|
|
|
- String hum = NumberUtils.getNum(50, 60, 0);
|
|
|
- saveTemWarning(tem,envWarningThreshold,envDevice,farmId);
|
|
|
+ String tem = NumberUtils.getNum(temperature-3, temperature+3, 1);
|
|
|
+ String hum = NumberUtils.getNum(humidity-3, humidity+3, 0);
|
|
|
+ saveTemWarning(tem, envWarningThreshold, envDevice, farmId);
|
|
|
envData.setEnvTemp(tem);
|
|
|
- saveHumWarning(hum,envWarningThreshold,envDevice,farmId);
|
|
|
+ saveHumWarning(hum, envWarningThreshold, envDevice, farmId);
|
|
|
envData.setEnvHum(hum);
|
|
|
|
|
|
-
|
|
|
envDataService.save(envData);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void saveHumWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
|
|
|
- if (StringUtils.isNotBlank(val)){
|
|
|
- String maxHum ;
|
|
|
- String minHum ;
|
|
|
- if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxHum())){
|
|
|
- maxHum ="90";
|
|
|
- }else {
|
|
|
+ if (StringUtils.isNotBlank(val)) {
|
|
|
+ String maxHum;
|
|
|
+ String minHum;
|
|
|
+ if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxHum())) {
|
|
|
+ maxHum = "90";
|
|
|
+ } else {
|
|
|
maxHum = envWarningThreshold.getMaxHum();
|
|
|
}
|
|
|
- if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinHum())){
|
|
|
- minHum ="0";
|
|
|
- }else {
|
|
|
- minHum =envWarningThreshold.getMinHum();
|
|
|
+ if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinHum())) {
|
|
|
+ minHum = "0";
|
|
|
+ } else {
|
|
|
+ minHum = envWarningThreshold.getMinHum();
|
|
|
}
|
|
|
- if (Double.parseDouble(maxHum) < Double.parseDouble(val)){
|
|
|
+ if (Double.parseDouble(maxHum) < Double.parseDouble(val)) {
|
|
|
EnvWarningInfo envWarningInfo = new EnvWarningInfo();
|
|
|
envWarningInfo.setBuildLocation(envDevice.getUnitName());
|
|
|
envWarningInfo.setDate(new Date());
|
|
@@ -177,11 +188,11 @@ public class EnvTimer {
|
|
|
envWarningInfo.setUnitId(envDevice.getUnitId());
|
|
|
envWarningInfo.setUnitName(envDevice.getUnitName());
|
|
|
envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
|
|
|
- envWarningInfo.setWarningContent("当前湿度为"+val+"%超过阈值,请及时检查");
|
|
|
+ envWarningInfo.setWarningContent("当前湿度为" + val + "%超过阈值,请及时检查");
|
|
|
envWarningInfo.setWarningType(2);
|
|
|
envWarningInfoService.save(envWarningInfo);
|
|
|
}
|
|
|
- if (Double.parseDouble(minHum) >Double.parseDouble(val)){
|
|
|
+ if (Double.parseDouble(minHum) > Double.parseDouble(val)) {
|
|
|
EnvWarningInfo envWarningInfo = new EnvWarningInfo();
|
|
|
envWarningInfo.setBuildLocation(envDevice.getUnitName());
|
|
|
envWarningInfo.setDate(new Date());
|
|
@@ -190,29 +201,29 @@ public class EnvTimer {
|
|
|
envWarningInfo.setUnitId(envDevice.getUnitId());
|
|
|
envWarningInfo.setUnitName(envDevice.getUnitName());
|
|
|
envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
|
|
|
- envWarningInfo.setWarningContent("当前湿度为"+val+"%低于阈值,请及时检查");
|
|
|
+ envWarningInfo.setWarningContent("当前湿度为" + val + "%低于阈值,请及时检查");
|
|
|
envWarningInfo.setWarningType(2);
|
|
|
envWarningInfoService.save(envWarningInfo);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void saveTemWarning(String val, EnvWarningThreshold envWarningThreshold,EnvDevice envDevice,Integer farmId) {
|
|
|
- if (StringUtils.isNotBlank(val)){
|
|
|
- String maxTem ;
|
|
|
- String minTem ;
|
|
|
- if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxTem())){
|
|
|
- maxTem ="40";
|
|
|
- }else {
|
|
|
+ private void saveTemWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
|
|
|
+ if (StringUtils.isNotBlank(val)) {
|
|
|
+ String maxTem;
|
|
|
+ String minTem;
|
|
|
+ if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxTem())) {
|
|
|
+ maxTem = "40";
|
|
|
+ } else {
|
|
|
maxTem = envWarningThreshold.getMaxTem();
|
|
|
}
|
|
|
- if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinTem())){
|
|
|
- minTem ="0";
|
|
|
- }else {
|
|
|
- minTem =envWarningThreshold.getMinTem();
|
|
|
+ if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinTem())) {
|
|
|
+ minTem = "0";
|
|
|
+ } else {
|
|
|
+ minTem = envWarningThreshold.getMinTem();
|
|
|
}
|
|
|
- System.out.println("maxTem:"+Double.parseDouble(maxTem)+" minTem:"+Double.parseDouble(minTem)+" val:"+Double.parseDouble(val));
|
|
|
- if (Double.parseDouble(maxTem) < Double.parseDouble(val)){
|
|
|
+ System.out.println("maxTem:" + Double.parseDouble(maxTem) + " minTem:" + Double.parseDouble(minTem) + " val:" + Double.parseDouble(val));
|
|
|
+ if (Double.parseDouble(maxTem) < Double.parseDouble(val)) {
|
|
|
EnvWarningInfo envWarningInfo = new EnvWarningInfo();
|
|
|
envWarningInfo.setBuildLocation(envDevice.getUnitName());
|
|
|
envWarningInfo.setDate(new Date());
|
|
@@ -221,11 +232,11 @@ public class EnvTimer {
|
|
|
envWarningInfo.setUnitId(envDevice.getUnitId());
|
|
|
envWarningInfo.setUnitName(envDevice.getUnitName());
|
|
|
envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
|
|
|
- envWarningInfo.setWarningContent("当前温度为"+val+"°超过阈值,请及时检查");
|
|
|
+ envWarningInfo.setWarningContent("当前温度为" + val + "°超过阈值,请及时检查");
|
|
|
envWarningInfo.setWarningType(1);
|
|
|
envWarningInfoService.save(envWarningInfo);
|
|
|
}
|
|
|
- if (Double.parseDouble(minTem)>Double.parseDouble(val)){
|
|
|
+ if (Double.parseDouble(minTem) > Double.parseDouble(val)) {
|
|
|
EnvWarningInfo envWarningInfo = new EnvWarningInfo();
|
|
|
envWarningInfo.setBuildLocation(envDevice.getUnitName());
|
|
|
envWarningInfo.setDate(new Date());
|
|
@@ -234,7 +245,7 @@ public class EnvTimer {
|
|
|
envWarningInfo.setUnitId(envDevice.getUnitId());
|
|
|
envWarningInfo.setUnitName(envDevice.getUnitName());
|
|
|
envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
|
|
|
- envWarningInfo.setWarningContent("当前温度为"+val+"°低于阈值,请及时检查");
|
|
|
+ envWarningInfo.setWarningContent("当前温度为" + val + "°低于阈值,请及时检查");
|
|
|
envWarningInfo.setWarningType(1);
|
|
|
envWarningInfoService.save(envWarningInfo);
|
|
|
}
|
|
@@ -262,30 +273,30 @@ public class EnvTimer {
|
|
|
QueryWrapper<EnvDevice> queryWrapper1 = new QueryWrapper<>();
|
|
|
queryWrapper1.eq("device_status", 1);
|
|
|
Integer count1 = envDeviceService.count(queryWrapper1);
|
|
|
- Integer OffDeviceCount = count- count1;
|
|
|
+ Integer OffDeviceCount = count - count1;
|
|
|
//创建一个数值格式化对象
|
|
|
NumberFormat numberFormat = NumberFormat.getInstance();
|
|
|
//设置精确到小数点后两位
|
|
|
numberFormat.setMaximumFractionDigits(2);
|
|
|
- String onDeviceRate = numberFormat.format((float)count1 / (float) count* 100);
|
|
|
+ String onDeviceRate = numberFormat.format((float) count1 / (float) count * 100);
|
|
|
|
|
|
EnvDeviceOnline envDeviceOnline = envDeviceOnlineService.getOne(new QueryWrapper<EnvDeviceOnline>().eq("farm_id", farmId).ge("creat_time", beginOfMonth));
|
|
|
- if (ObjectUtil.isEmpty(envDeviceOnline)){
|
|
|
+ if (ObjectUtil.isEmpty(envDeviceOnline)) {
|
|
|
envDeviceOnline = new EnvDeviceOnline();
|
|
|
envDeviceOnline.setCreatTime(date);
|
|
|
envDeviceOnline.setDeviceOff(OffDeviceCount);
|
|
|
envDeviceOnline.setDeviceOn(count1);
|
|
|
- envDeviceOnline.setFarmId(farmId+"");
|
|
|
+ envDeviceOnline.setFarmId(farmId + "");
|
|
|
envDeviceOnline.setOnlineRate(onDeviceRate);
|
|
|
envDeviceOnline.setNowMonth(beginOfMonth.month());
|
|
|
envDeviceOnline.setNowYear(beginOfMonth.year());
|
|
|
envDeviceOnlineService.save(envDeviceOnline);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
envDeviceOnline = new EnvDeviceOnline();
|
|
|
envDeviceOnline.setCreatTime(date);
|
|
|
envDeviceOnline.setDeviceOff(OffDeviceCount);
|
|
|
envDeviceOnline.setDeviceOn(count1);
|
|
|
- envDeviceOnline.setFarmId(farmId+"");
|
|
|
+ envDeviceOnline.setFarmId(farmId + "");
|
|
|
envDeviceOnline.setOnlineRate(onDeviceRate);
|
|
|
envDeviceOnline.setNowMonth(beginOfMonth.month());
|
|
|
envDeviceOnline.setNowYear(beginOfMonth.year());
|
|
@@ -296,4 +307,4 @@ public class EnvTimer {
|
|
|
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+}
|