|
@@ -5,11 +5,16 @@ import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.huimv.receiver.cloud.dao.entity.EnvDayEntity;
|
|
import com.huimv.receiver.cloud.dao.entity.EnvDayEntity;
|
|
import com.huimv.receiver.cloud.dao.entity.EnvHourEntity;
|
|
import com.huimv.receiver.cloud.dao.entity.EnvHourEntity;
|
|
|
|
+import com.huimv.receiver.cloud.dao.entity.SysThresholdEntity;
|
|
import com.huimv.receiver.cloud.dao.repo.EnvDayRepo;
|
|
import com.huimv.receiver.cloud.dao.repo.EnvDayRepo;
|
|
import com.huimv.receiver.cloud.dao.repo.EnvHourRepo;
|
|
import com.huimv.receiver.cloud.dao.repo.EnvHourRepo;
|
|
|
|
+import com.huimv.receiver.cloud.dao.repo.SysThresholdEntityRepo;
|
|
import com.huimv.receiver.cloud.service.IEnviron;
|
|
import com.huimv.receiver.cloud.service.IEnviron;
|
|
import com.huimv.receiver.cloud.service.IWarningInfo;
|
|
import com.huimv.receiver.cloud.service.IWarningInfo;
|
|
|
|
+import com.huimv.receiver.farm.service.IAlarm;
|
|
|
|
+import com.huimv.receiver.utils.Const;
|
|
import com.huimv.receiver.utils.DateUtil;
|
|
import com.huimv.receiver.utils.DateUtil;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -29,6 +34,7 @@ import java.util.Optional;
|
|
* @Create : 2020-12-25
|
|
* @Create : 2020-12-25
|
|
**/
|
|
**/
|
|
@Service
|
|
@Service
|
|
|
|
+@Slf4j
|
|
public class EnvironImpl implements IEnviron {
|
|
public class EnvironImpl implements IEnviron {
|
|
@Autowired
|
|
@Autowired
|
|
private EnvHourRepo envHourRepo;
|
|
private EnvHourRepo envHourRepo;
|
|
@@ -38,6 +44,10 @@ public class EnvironImpl implements IEnviron {
|
|
private IWarningInfo warningInfo;
|
|
private IWarningInfo warningInfo;
|
|
@Autowired
|
|
@Autowired
|
|
private DateUtil dateUtil;
|
|
private DateUtil dateUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ private com.huimv.receiver.cloud.dao.repo.SysThresholdEntityRepo thresholdRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAlarm iAlarm;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void handleEnvironJSONArray(String data) {
|
|
public void handleEnvironJSONArray(String data) {
|
|
@@ -200,9 +210,47 @@ public class EnvironImpl implements IEnviron {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void handleMinuteJSONObject(String data) {
|
|
|
|
|
|
+ public void handleMinuteJSONObject(String data) throws ParseException {
|
|
System.out.println("data>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+data);
|
|
System.out.println("data>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+data);
|
|
-// JSONObject deviceJo = JSON.parseObject(data);
|
|
|
|
|
|
+ JSONObject environJo = JSON.parseObject(data);
|
|
|
|
+ System.out.println("environJo="+environJo);
|
|
|
|
+ String farmId = environJo.getString("farmId");
|
|
|
|
+ System.out.println("farmId="+farmId);
|
|
|
|
+ //读取阈值
|
|
|
|
+ String thresholdData = getThreshold(farmId);
|
|
|
|
+ if(thresholdData == null) {
|
|
|
|
+ log.info("阈值记录为空.");
|
|
|
|
+ }else{
|
|
|
|
+ JSONObject thresholdJo = JSON.parseObject(thresholdData);
|
|
|
|
+ System.out.println("阈值="+thresholdJo);
|
|
|
|
+ //环保氨氮数据>=阈值氨氮数据
|
|
|
|
+ if(new BigDecimal(environJo.getString("adPj")).compareTo(new BigDecimal(thresholdJo.getString("ammonia"))) > -1){
|
|
|
|
+ String alarmInfo = "当前氨氮数据为"+environJo.getString("adPj")+"高于或等于阈值"+thresholdJo.getString("ammonia")+".";
|
|
|
|
+ //报警数据直接入库
|
|
|
|
+ iAlarm.handleEnvironAlarm(alarmInfo,Const.TYPE_ALARM_AD,farmId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //环保COD数据>=阈值COD数据
|
|
|
|
+ if(new BigDecimal(environJo.getString("hxxylPj")).compareTo(new BigDecimal(thresholdJo.getString("cOD"))) > -1){
|
|
|
|
+ String alarmInfo = "当前化学需氧量数据为"+environJo.getString("hxxylPj")+"高于或等于阈值"+thresholdJo.getString("cOD")+".";
|
|
|
|
+ //报警数据直接入库
|
|
|
|
+ iAlarm.handleEnvironAlarm(alarmInfo,Const.TYPE_ALARM_COD,farmId);
|
|
|
|
+ }
|
|
|
|
+ //环保PH数据>=阈值PH数据
|
|
|
|
+ if(new BigDecimal(environJo.getString("phPj")).compareTo(new BigDecimal(thresholdJo.getString("ph"))) > -1){
|
|
|
|
+ String alarmInfo = "当前PH值数据为"+environJo.getString("phPj")+"高于或等于阈值"+thresholdJo.getString("ph")+".";
|
|
|
|
+ //报警数据直接入库
|
|
|
|
+ iAlarm.handleEnvironAlarm(alarmInfo,Const.TYPE_ALARM_PH,farmId);
|
|
|
|
+ }
|
|
|
|
+ //环保污水浓度数据>=阈值污水浓度数据
|
|
|
|
+ if(new BigDecimal(environJo.getString("wsPj")).compareTo(new BigDecimal(thresholdJo.getString("flow"))) > -1){
|
|
|
|
+ String alarmInfo = "当前污水浓度数据为"+environJo.getString("wsPj")+"高于或等于阈值"+thresholdJo.getString("flow")+".";
|
|
|
|
+ //报警数据直接入库
|
|
|
|
+ iAlarm.handleEnvironAlarm(alarmInfo,Const.TYPE_ALARM_WS,farmId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
// EnvHourEntity envHourEntity = JSON.parseObject(data, EnvHourEntity.class);
|
|
// EnvHourEntity envHourEntity = JSON.parseObject(data, EnvHourEntity.class);
|
|
// envHourRepo.save(envHourEntity);
|
|
// envHourRepo.save(envHourEntity);
|
|
|
|
|
|
@@ -214,6 +262,17 @@ public class EnvironImpl implements IEnviron {
|
|
// countDayAvgEnviron2(farmId, todayDateText);
|
|
// countDayAvgEnviron2(farmId, todayDateText);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //读取阈值
|
|
|
|
+ private String getThreshold(String farmId) {
|
|
|
|
+ //
|
|
|
|
+ Optional<SysThresholdEntity> option = thresholdRepo.findByFarmId(farmId);
|
|
|
|
+ if(option.isPresent()){
|
|
|
|
+ return JSON.toJSON(option.get()).toString();
|
|
|
|
+ }else{
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void countDayAvgEnviron_old1(Integer farmId, String todayDateText) {
|
|
public void countDayAvgEnviron_old1(Integer farmId, String todayDateText) {
|
|
System.out.println("farmId=" + farmId);
|
|
System.out.println("farmId=" + farmId);
|
|
System.out.println("todayDateText=" + todayDateText);
|
|
System.out.println("todayDateText=" + todayDateText);
|