|
@@ -1,6 +1,9 @@
|
|
|
package com.yunfeiyun.agmp.iots.warn.service;
|
|
package com.yunfeiyun.agmp.iots.warn.service;
|
|
|
|
|
|
|
|
|
|
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.exception.BizException;
|
|
|
import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotWarnindicator;
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotWarnindicator;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.EnumWarnRuleOp;
|
|
import com.yunfeiyun.agmp.iot.common.enums.EnumWarnRuleOp;
|
|
@@ -29,23 +32,40 @@ public class WarnPestService {
|
|
|
|
|
|
|
|
//需要的参数,devId
|
|
//需要的参数,devId
|
|
|
String devId = "";
|
|
String devId = "";
|
|
|
-
|
|
|
|
|
//需要的参数,iotWarnindicator的:默认全部,外加+devCode,devTypeBid
|
|
//需要的参数,iotWarnindicator的:默认全部,外加+devCode,devTypeBid
|
|
|
- IotWarnindicator iotWarnindicator = new IotWarnindicator();
|
|
|
|
|
|
|
+ IotWarnindicator pestByTypeWarnindicator = new IotWarnindicator();
|
|
|
|
|
+ IotWarnindicator pestByCountWarnindicator = new IotWarnindicator();
|
|
|
|
|
+ IotWarnindicator designatePestWarnindicator = new IotWarnindicator();
|
|
|
|
|
|
|
|
//需要的参数,iotWarnconfig的:全部
|
|
//需要的参数,iotWarnconfig的:全部
|
|
|
IotWarnconfig iotWarnconfig = new IotWarnconfig();
|
|
IotWarnconfig iotWarnconfig = new IotWarnconfig();
|
|
|
|
|
|
|
|
- WarnStatusDto pestByType = processPestByType(iotWarnindicator);
|
|
|
|
|
- WarnStatusDto pestByCount = processPestByCount(iotWarnindicator);
|
|
|
|
|
- WarnStatusDto designatePest = processPestByDesignatePest(iotWarnindicator);
|
|
|
|
|
|
|
+ //底层调用:统一处理一个虫情设备的三个要素
|
|
|
|
|
+ processPestIotWarnindicators(devId, iotWarnconfig, pestByTypeWarnindicator, pestByCountWarnindicator, designatePestWarnindicator);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理一个虫情设备的三个要素
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param devId
|
|
|
|
|
+ * @param iotWarnconfig
|
|
|
|
|
+ * @param pestByTypeWarnindicator
|
|
|
|
|
+ * @param pestByCountWarnindicator
|
|
|
|
|
+ * @param designatePestWarnindicator
|
|
|
|
|
+ */
|
|
|
|
|
+ private void processPestIotWarnindicators(String devId, IotWarnconfig iotWarnconfig, IotWarnindicator pestByTypeWarnindicator, IotWarnindicator pestByCountWarnindicator, IotWarnindicator designatePestWarnindicator) {
|
|
|
|
|
+ WarnStatusDto pestByType = processPestByType(pestByTypeWarnindicator);
|
|
|
|
|
+ WarnStatusDto pestByCount = processPestByCount(pestByCountWarnindicator);
|
|
|
|
|
+ WarnStatusDto designatePest = processPestByDesignatePest(designatePestWarnindicator);
|
|
|
|
|
+ //合并结果
|
|
|
handlerAllWarnLog(devId, iotWarnconfig, pestByType, pestByCount, designatePest);
|
|
handlerAllWarnLog(devId, iotWarnconfig, pestByType, pestByCount, designatePest);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据虫害类型处理
|
|
* 根据虫害类型处理
|
|
|
*/
|
|
*/
|
|
|
- public WarnStatusDto processPestByType(IotWarnindicator iotWarnindicator) {
|
|
|
|
|
|
|
+ private WarnStatusDto processPestByType(IotWarnindicator iotWarnindicator) {
|
|
|
|
|
+ validateParam(iotWarnindicator);
|
|
|
String startTime = DateUtils.getDate() + " 00:00:00";
|
|
String startTime = DateUtils.getDate() + " 00:00:00";
|
|
|
String endTime = DateUtils.getDate() + " 23:59:59";
|
|
String endTime = DateUtils.getDate() + " 23:59:59";
|
|
|
String wdBid = iotWarnindicator.getWdBid();
|
|
String wdBid = iotWarnindicator.getWdBid();
|
|
@@ -56,7 +76,8 @@ public class WarnPestService {
|
|
|
/**
|
|
/**
|
|
|
* 根据虫害总数处理
|
|
* 根据虫害总数处理
|
|
|
*/
|
|
*/
|
|
|
- public WarnStatusDto processPestByCount(IotWarnindicator iotWarnindicator) {
|
|
|
|
|
|
|
+ private WarnStatusDto processPestByCount(IotWarnindicator iotWarnindicator) {
|
|
|
|
|
+ validateParam(iotWarnindicator);
|
|
|
String startTime = DateUtils.getDate() + " 00:00:00";
|
|
String startTime = DateUtils.getDate() + " 00:00:00";
|
|
|
String endTime = DateUtils.getDate() + " 23:59:59";
|
|
String endTime = DateUtils.getDate() + " 23:59:59";
|
|
|
String wdBid = iotWarnindicator.getWdBid();
|
|
String wdBid = iotWarnindicator.getWdBid();
|
|
@@ -69,7 +90,7 @@ public class WarnPestService {
|
|
|
* @param iotWarnindicator
|
|
* @param iotWarnindicator
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- WarnStatusDto buildWarnStatusDto(int currentValue, IotWarnindicator iotWarnindicator) {
|
|
|
|
|
|
|
+ private WarnStatusDto buildWarnStatusDto(int currentValue, IotWarnindicator iotWarnindicator) {
|
|
|
String expression = iotWarnindicator.getWiExpression();
|
|
String expression = iotWarnindicator.getWiExpression();
|
|
|
String targetValue = iotWarnindicator.getWiValue();
|
|
String targetValue = iotWarnindicator.getWiValue();
|
|
|
String statue = iotWarnindicator.getWiStatus();
|
|
String statue = iotWarnindicator.getWiStatus();
|
|
@@ -94,7 +115,8 @@ public class WarnPestService {
|
|
|
/**
|
|
/**
|
|
|
* 根据指定虫害处理
|
|
* 根据指定虫害处理
|
|
|
*/
|
|
*/
|
|
|
- public WarnStatusDto processPestByDesignatePest(IotWarnindicator iotWarnindicator) {
|
|
|
|
|
|
|
+ private WarnStatusDto processPestByDesignatePest(IotWarnindicator iotWarnindicator) {
|
|
|
|
|
+ validateParam(iotWarnindicator);
|
|
|
//根据自己需要的父子结构单独再写一个方法
|
|
//根据自己需要的父子结构单独再写一个方法
|
|
|
//iotWarnBussinessService.selectIotWarnPestConfigInfoList("pestDetail");
|
|
//iotWarnBussinessService.selectIotWarnPestConfigInfoList("pestDetail");
|
|
|
return null;
|
|
return null;
|
|
@@ -109,7 +131,11 @@ public class WarnPestService {
|
|
|
* @param pestByCount
|
|
* @param pestByCount
|
|
|
* @param designatePest
|
|
* @param designatePest
|
|
|
*/
|
|
*/
|
|
|
- void handlerAllWarnLog(String devBid, IotWarnconfig iotWarnconfig, WarnStatusDto pestByType, WarnStatusDto pestByCount, WarnStatusDto designatePest) {
|
|
|
|
|
|
|
+ private void handlerAllWarnLog(String devBid, IotWarnconfig iotWarnconfig, WarnStatusDto pestByType, WarnStatusDto pestByCount, WarnStatusDto designatePest) {
|
|
|
|
|
+ if (StringUtils.isEmpty(devBid)) {
|
|
|
|
|
+ log.error("【设备预警】病虫害:设备id 不可为空");
|
|
|
|
|
+ throw new BizException(ErrorCode.FAILURE.getCode(), "病虫害:设备id 不可为空");
|
|
|
|
|
+ }
|
|
|
String pestByTypeMessage = null;
|
|
String pestByTypeMessage = null;
|
|
|
String pestByCountMessage = null;
|
|
String pestByCountMessage = null;
|
|
|
String designatePestMessage = null;
|
|
String designatePestMessage = null;
|
|
@@ -130,14 +156,13 @@ public class WarnPestService {
|
|
|
//构建消息
|
|
//构建消息
|
|
|
if (pestByCount != null && pestByCount.isWarn()) {
|
|
if (pestByCount != null && pestByCount.isWarn()) {
|
|
|
pestByCountMessage = WarnMessageBuilderUtil.buildWarningMessage(
|
|
pestByCountMessage = WarnMessageBuilderUtil.buildWarningMessage(
|
|
|
- pestByType.getDevType(),
|
|
|
|
|
- pestByType.getDevCode(),
|
|
|
|
|
- pestByType.getName(),
|
|
|
|
|
- pestByType.getValue(),
|
|
|
|
|
- pestByType.getUnit(),
|
|
|
|
|
- pestByType.getOpt(),
|
|
|
|
|
-
|
|
|
|
|
- pestByType.getIndicatorValue()
|
|
|
|
|
|
|
+ pestByCount.getDevType(),
|
|
|
|
|
+ pestByCount.getDevCode(),
|
|
|
|
|
+ pestByCount.getName(),
|
|
|
|
|
+ pestByCount.getValue(),
|
|
|
|
|
+ pestByCount.getUnit(),
|
|
|
|
|
+ pestByCount.getOpt(),
|
|
|
|
|
+ pestByCount.getIndicatorValue()
|
|
|
);
|
|
);
|
|
|
isWarn = true;
|
|
isWarn = true;
|
|
|
}
|
|
}
|
|
@@ -180,4 +205,17 @@ public class WarnPestService {
|
|
|
//发送告警
|
|
//发送告警
|
|
|
reCountService.handlerMessage(warnResult);
|
|
reCountService.handlerMessage(warnResult);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public void validateParam(IotWarnindicator warnStatusDto) {
|
|
|
|
|
+ if (StringUtils.isEmpty(warnStatusDto.getDevCode())) {
|
|
|
|
|
+ log.error("【设备预警】病虫害:设备code 不可为空");
|
|
|
|
|
+ throw new BizException(ErrorCode.FAILURE.getCode(), "设备code不可为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ String devTypeBid = warnStatusDto.getDevTypeBid();
|
|
|
|
|
+ if (StringUtils.isEmpty(devTypeBid)) {
|
|
|
|
|
+ log.error("【设备预警】病虫害:设备类型 不可为空");
|
|
|
|
|
+ throw new BizException(ErrorCode.FAILURE.getCode(), "病虫害:设备类型 不可为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|