|
@@ -1,5 +1,6 @@
|
|
|
package com.huimv.environment.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
@@ -10,6 +11,7 @@ import com.huimv.environment.entity.*;
|
|
|
import com.huimv.environment.repo.*;
|
|
|
import com.huimv.environment.service.IEnvironmentControlService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.ParseException;
|
|
@@ -38,6 +40,11 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
|
|
|
@Autowired
|
|
|
private FarmSmRepository farmSmRepository;
|
|
|
|
|
|
+ @Value("${minTemp}")
|
|
|
+ private Double minTemp ; //低温报警值
|
|
|
+ @Value("${maxTemp}")
|
|
|
+ private Double maxTemp ;//高温报警值
|
|
|
+
|
|
|
@Override
|
|
|
public Result getPigpenByFarm(Integer farmId) {
|
|
|
//--读取所有猪舍
|
|
@@ -82,7 +89,6 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
-// @DS("master")
|
|
|
public Result getLastEnvData(Integer lqid) {
|
|
|
String todayDate = new DateUtil().formatDate(new Date());
|
|
|
System.out.println(" todayDate>>"+todayDate);
|
|
@@ -114,70 +120,83 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
|
|
|
return new Result(ResultCode.SUCCESS, envJo);
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public Result getAllFarm() {
|
|
|
-//
|
|
|
-//
|
|
|
-// List<FarmSm> all = farmSmRepository.findAll();
|
|
|
-//
|
|
|
-// String dateStr = "2021-03-14 00:00:00";
|
|
|
-// Date date = null;
|
|
|
-// try {
|
|
|
-// date = DateUtil.parseDateTime(dateStr);
|
|
|
-// } catch (ParseException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-//
|
|
|
-// List endList = new ArrayList();
|
|
|
-//
|
|
|
-// for (FarmSm farmSm : all) {
|
|
|
-// Map endMap = new HashMap();
|
|
|
-// endMap.put("name",farmSm.getName());
|
|
|
-//
|
|
|
-// String lqid = farmSm.getLqid();
|
|
|
-// endMap.put("lqid",farmSm.getLqid());
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// List<SjHkAq> allByLqidAndScsjBetween = aqRepo.findAllByLqidAndScsjBetween(lqid, date, new Date());
|
|
|
-//
|
|
|
-// List aqList = new ArrayList();
|
|
|
-// for (SjHkAq sjHkAq : allByLqidAndScsjBetween) {
|
|
|
-// Map map1 = new HashMap();
|
|
|
-// map1.put("time",(sjHkAq.getScsj()+"").substring(11,19));
|
|
|
-// map1.put("data",sjHkAq.getDqaq());
|
|
|
-// aqList.add(map1);
|
|
|
-// }
|
|
|
-//
|
|
|
-// endMap.put("aq",aqList);
|
|
|
-//
|
|
|
-// List<SjHkSd> allByLqidAndScsjBetween1 = sdRepo.findAllByLqidAndScsjBetween(lqid, date, new Date());
|
|
|
-// List sdList = new ArrayList();
|
|
|
-// for (SjHkSd sjHkAq : allByLqidAndScsjBetween1) {
|
|
|
-// Map map1 = new HashMap();
|
|
|
-// map1.put("time",(sjHkAq.getScsj()+"").substring(11,19));
|
|
|
-// map1.put("data",sjHkAq.getDqsd());
|
|
|
-// sdList.add(map1);
|
|
|
-// }
|
|
|
-// endMap.put("sd",sdList);
|
|
|
-//
|
|
|
-//
|
|
|
-// List<SjHkWd> allByLqidAndScsjBetween2 = wdRepo.findAllByLqidAndScsjBetween(lqid, date, new Date());
|
|
|
-// List wdList = new ArrayList();
|
|
|
-// for (SjHkWd sjHkAq : allByLqidAndScsjBetween2) {
|
|
|
-// Map map1 = new HashMap();
|
|
|
-// map1.put("time",(sjHkAq.getScsj()+"").substring(11,19));
|
|
|
-// map1.put("data",sjHkAq.getDqwd());
|
|
|
-// wdList.add(map1);
|
|
|
-// }
|
|
|
-// endMap.put("wd",wdList);
|
|
|
-// endList.add(endMap);
|
|
|
-//
|
|
|
-// }
|
|
|
-// return new Result(ResultCode.SUCCESS,endList);
|
|
|
-// }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceUpDataEntityRepo deviceUpDataEntityRepo;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getAllFarm(){
|
|
|
+ List endList = new ArrayList();
|
|
|
+ List<FarmSm> all = farmSmRepository.findAll();
|
|
|
+
|
|
|
+
|
|
|
+ for (FarmSm farmSm : all) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ String lqid = farmSm.getLqid();
|
|
|
+ DeviceUpDataEntity byDeviceId = deviceUpDataEntityRepo.findByDeviceId(lqid);
|
|
|
+ map.put("aq",0);
|
|
|
+ map.put("name",farmSm.getName());
|
|
|
+ map.put("lqid",byDeviceId.getDeviceId());
|
|
|
+ map.put("sd",byDeviceId.getDataHumiConvert());
|
|
|
+ map.put("wd",byDeviceId.getDataTempConvert());
|
|
|
+ endList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return new Result(ResultCode.SUCCESS,endList);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
+ public Result getAllBylqid(String lqid) {
|
|
|
+ List endList = new ArrayList();
|
|
|
+
|
|
|
+
|
|
|
+ String today= cn.hutool.core.date.DateUtil.today();
|
|
|
+// List<DeviceUpDataEntity> allByTimestampBetweenAndDeviceId = deviceUpDataEntityRepo.findAllByTimestampBetweenAndDeviceId(starTime, endTime, lqid);
|
|
|
+ List<DeviceUpDataEntity> allByDeviceIdOrderByIdDesc = deviceUpDataEntityRepo.findAllByDeviceIdOrderByIdDesc(today,lqid);
|
|
|
+ for (DeviceUpDataEntity deviceUpDataEntity : allByDeviceIdOrderByIdDesc) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("time",deviceUpDataEntity.getTimestamp().substring(11));
|
|
|
+ map.put("wd",deviceUpDataEntity.getDataTempConvert());
|
|
|
+ map.put("sd",deviceUpDataEntity.getDataHumiConvert());
|
|
|
+ map.put("aq",0);
|
|
|
+ endList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return new Result(ResultCode.SUCCESS,endList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result warningInfor() {
|
|
|
+ List endList = new ArrayList();
|
|
|
+ List<DeviceUpDataEntity> allByTimestampBetween = deviceUpDataEntityRepo.findAllByTimestampBetween(minTemp, maxTemp, cn.hutool.core.date.DateUtil.today());
|
|
|
+ for (DeviceUpDataEntity deviceUpDataEntity : allByTimestampBetween) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("farmName",farmSmRepository.findByLqid(deviceUpDataEntity.getDeviceId()).getName());
|
|
|
+ map.put("time",deviceUpDataEntity.getTimestamp());
|
|
|
+ String str = "";
|
|
|
+ if (deviceUpDataEntity.getDataTempConvert() < minTemp){
|
|
|
+ str = str +"温度过低,温度:"+ deviceUpDataEntity.getDataTempConvert();
|
|
|
+ }
|
|
|
+ if (deviceUpDataEntity.getDataTempConvert() > maxTemp){
|
|
|
+ str = str +"温度过高,温度:"+ deviceUpDataEntity.getDataTempConvert();
|
|
|
+ }
|
|
|
+ map.put("msg",str);
|
|
|
+ endList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new Result(ResultCode.SUCCESS,endList) ;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result findByZSID() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* @Override
|
|
|
public Result getAllFarm() {
|
|
|
|
|
|
|
|
@@ -228,9 +247,9 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
|
|
|
|
|
|
}
|
|
|
return new Result(ResultCode.SUCCESS,endList);
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
- @Override
|
|
|
+ /* @Override
|
|
|
public Result getAllBylqid(String lqid) {
|
|
|
|
|
|
String dateStr = "2021-03-14 00:00:00";
|
|
@@ -282,6 +301,6 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
|
|
|
|
|
|
return new Result(ResultCode.SUCCESS,map);
|
|
|
}
|
|
|
-
|
|
|
+*/
|
|
|
|
|
|
}
|