|
@@ -1,43 +1,183 @@
|
|
|
package com.yunfeiyun.agmp.iots.warn.service;
|
|
package com.yunfeiyun.agmp.iots.warn.service;
|
|
|
|
|
|
|
|
|
|
+import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotWarnindicator;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.enums.EnumWarnRuleOp;
|
|
|
|
|
+import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
|
|
|
|
|
+import com.yunfeiyun.agmp.iots.warn.model.WarnStatusDto;
|
|
|
|
|
+import com.yunfeiyun.agmp.iots.warn.util.CompareUtil;
|
|
|
|
|
+import com.yunfeiyun.agmp.iots.warn.util.WarnMessageBuilderUtil;
|
|
|
|
|
+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;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@Service
|
|
@Service
|
|
|
|
|
+@Slf4j
|
|
|
public class WarnPestService {
|
|
public class WarnPestService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IotWarnBussinessService iotWarnBussinessService;
|
|
private IotWarnBussinessService iotWarnBussinessService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ReCountService reCountService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 虫害处理入口
|
|
* 虫害处理入口
|
|
|
*/
|
|
*/
|
|
|
public void process() {
|
|
public void process() {
|
|
|
- processPestByType();
|
|
|
|
|
- processPestByCount();
|
|
|
|
|
- processPestByDesignatePest();
|
|
|
|
|
|
|
+ //单个配置单个设备的处理逻辑,外层需要遍历
|
|
|
|
|
+
|
|
|
|
|
+ //需要的参数,devId
|
|
|
|
|
+ String devId = "";
|
|
|
|
|
+
|
|
|
|
|
+ //需要的参数,iotWarnindicator的:默认全部,外加+devCode,devTypeBid
|
|
|
|
|
+ IotWarnindicator iotWarnindicator = new IotWarnindicator();
|
|
|
|
|
+
|
|
|
|
|
+ //需要的参数,iotWarnconfig的:全部
|
|
|
|
|
+ IotWarnconfig iotWarnconfig = new IotWarnconfig();
|
|
|
|
|
+
|
|
|
|
|
+ WarnStatusDto pestByType = processPestByType(iotWarnindicator);
|
|
|
|
|
+ WarnStatusDto pestByCount = processPestByCount(iotWarnindicator);
|
|
|
|
|
+ WarnStatusDto designatePest = processPestByDesignatePest(iotWarnindicator);
|
|
|
|
|
+ handlerAllWarnLog(devId, iotWarnconfig, pestByType, pestByCount, designatePest);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据虫害类型处理
|
|
* 根据虫害类型处理
|
|
|
*/
|
|
*/
|
|
|
- public void processPestByType() {
|
|
|
|
|
- iotWarnBussinessService.selectIotWarnPestConfigInfoList("pestType");
|
|
|
|
|
|
|
+ public WarnStatusDto processPestByType(IotWarnindicator iotWarnindicator) {
|
|
|
|
|
+ String startTime = DateUtils.getDate() + " 00:00:00";
|
|
|
|
|
+ String endTime = DateUtils.getDate() + " 23:59:59";
|
|
|
|
|
+ String wdBid = iotWarnindicator.getWdBid();
|
|
|
|
|
+ int currentValue = iotWarnBussinessService.statPestTypeCountByDevId(wdBid, startTime, endTime);
|
|
|
|
|
+ return buildWarnStatusDto(currentValue, iotWarnindicator);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据虫害总数处理
|
|
* 根据虫害总数处理
|
|
|
*/
|
|
*/
|
|
|
- public void processPestByCount() {
|
|
|
|
|
- iotWarnBussinessService.selectIotWarnPestConfigInfoList("pestNum");
|
|
|
|
|
|
|
+ public WarnStatusDto processPestByCount(IotWarnindicator iotWarnindicator) {
|
|
|
|
|
+ String startTime = DateUtils.getDate() + " 00:00:00";
|
|
|
|
|
+ String endTime = DateUtils.getDate() + " 23:59:59";
|
|
|
|
|
+ String wdBid = iotWarnindicator.getWdBid();
|
|
|
|
|
+ int currentValue = iotWarnBussinessService.statPestCountByDevId(wdBid, startTime, endTime);
|
|
|
|
|
+ return buildWarnStatusDto(currentValue, iotWarnindicator);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param currentValue
|
|
|
|
|
+ * @param iotWarnindicator
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ WarnStatusDto buildWarnStatusDto(int currentValue, IotWarnindicator iotWarnindicator) {
|
|
|
|
|
+ String expression = iotWarnindicator.getWiExpression();
|
|
|
|
|
+ String targetValue = iotWarnindicator.getWiValue();
|
|
|
|
|
+ String statue = iotWarnindicator.getWiStatus();
|
|
|
|
|
+ //开启的处理
|
|
|
|
|
+ if ("0".equals(statue)) {
|
|
|
|
|
+ EnumWarnRuleOp warnRuleOp = EnumWarnRuleOp.findEnumByCode(expression);
|
|
|
|
|
+ boolean tempSuccess = CompareUtil.comp(currentValue + "", expression, targetValue);
|
|
|
|
|
+ WarnStatusDto warnStatusDto = new WarnStatusDto();
|
|
|
|
|
+ warnStatusDto.setDevType(iotWarnindicator.getDevTypeBid());
|
|
|
|
|
+ warnStatusDto.setDevCode(iotWarnindicator.getDevCode());
|
|
|
|
|
+ warnStatusDto.setName(iotWarnindicator.getWiName());
|
|
|
|
|
+ warnStatusDto.setValue(currentValue + "");
|
|
|
|
|
+ warnStatusDto.setUnit(iotWarnindicator.getWiUnit());
|
|
|
|
|
+ warnStatusDto.setOpt(warnRuleOp.getName());
|
|
|
|
|
+ warnStatusDto.setIndicatorValue(targetValue);
|
|
|
|
|
+ warnStatusDto.setWarn(tempSuccess);
|
|
|
|
|
+ return warnStatusDto;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据指定虫害处理
|
|
* 根据指定虫害处理
|
|
|
*/
|
|
*/
|
|
|
- public void processPestByDesignatePest() {
|
|
|
|
|
|
|
+ public WarnStatusDto processPestByDesignatePest(IotWarnindicator iotWarnindicator) {
|
|
|
//根据自己需要的父子结构单独再写一个方法
|
|
//根据自己需要的父子结构单独再写一个方法
|
|
|
- iotWarnBussinessService.selectIotWarnPestConfigInfoList("pestDetail");
|
|
|
|
|
|
|
+ //iotWarnBussinessService.selectIotWarnPestConfigInfoList("pestDetail");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将三个的告警处理结果合并
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param devBid
|
|
|
|
|
+ * @param iotWarnconfig
|
|
|
|
|
+ * @param pestByType
|
|
|
|
|
+ * @param pestByCount
|
|
|
|
|
+ * @param designatePest
|
|
|
|
|
+ */
|
|
|
|
|
+ void handlerAllWarnLog(String devBid, IotWarnconfig iotWarnconfig, WarnStatusDto pestByType, WarnStatusDto pestByCount, WarnStatusDto designatePest) {
|
|
|
|
|
+ String pestByTypeMessage = null;
|
|
|
|
|
+ String pestByCountMessage = null;
|
|
|
|
|
+ String designatePestMessage = null;
|
|
|
|
|
+ boolean isWarn = false;
|
|
|
|
|
+ //构建消息
|
|
|
|
|
+ if (pestByType != null && pestByType.isWarn()) {
|
|
|
|
|
+ pestByTypeMessage = WarnMessageBuilderUtil.buildWarningMessage(
|
|
|
|
|
+ pestByType.getDevType(),
|
|
|
|
|
+ pestByType.getDevCode(),
|
|
|
|
|
+ pestByType.getName(),
|
|
|
|
|
+ pestByType.getValue(),
|
|
|
|
|
+ pestByType.getUnit(),
|
|
|
|
|
+ pestByType.getOpt(),
|
|
|
|
|
+ pestByType.getIndicatorValue()
|
|
|
|
|
+ );
|
|
|
|
|
+ isWarn = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ //构建消息
|
|
|
|
|
+ if (pestByCount != null && pestByCount.isWarn()) {
|
|
|
|
|
+ pestByCountMessage = WarnMessageBuilderUtil.buildWarningMessage(
|
|
|
|
|
+ pestByType.getDevType(),
|
|
|
|
|
+ pestByType.getDevCode(),
|
|
|
|
|
+ pestByType.getName(),
|
|
|
|
|
+ pestByType.getValue(),
|
|
|
|
|
+ pestByType.getUnit(),
|
|
|
|
|
+ pestByType.getOpt(),
|
|
|
|
|
+
|
|
|
|
|
+ pestByType.getIndicatorValue()
|
|
|
|
|
+ );
|
|
|
|
|
+ isWarn = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ //构建消息
|
|
|
|
|
+ if (designatePest != null && designatePest.isWarn()) {
|
|
|
|
|
+ designatePestMessage = WarnMessageBuilderUtil.buildWarningMessage(
|
|
|
|
|
+ pestByType.getDevType(),
|
|
|
|
|
+ pestByType.getDevCode(),
|
|
|
|
|
+ pestByType.getName(),
|
|
|
|
|
+ pestByType.getValue(),
|
|
|
|
|
+ pestByType.getUnit(),
|
|
|
|
|
+ pestByType.getOpt(),
|
|
|
|
|
+ pestByType.getIndicatorValue()
|
|
|
|
|
+ );
|
|
|
|
|
+ isWarn = true;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
|
|
+ if (pestByTypeMessage != null) {
|
|
|
|
|
+ buffer.append(buffer);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (pestByCountMessage != null) {
|
|
|
|
|
+ buffer.append(pestByCountMessage);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (designatePestMessage != null) {
|
|
|
|
|
+ buffer.append(designatePestMessage);
|
|
|
|
|
+ }
|
|
|
|
|
+ //构建发送消息的参数
|
|
|
|
|
+ WarnResult warnResult = new WarnResult();
|
|
|
|
|
+ warnResult.setMessageId(warnResult.getUUId());
|
|
|
|
|
+ warnResult.setDevId(devBid);
|
|
|
|
|
+ warnResult.setTid(iotWarnconfig.getTid());
|
|
|
|
|
+ warnResult.setConfigId(iotWarnconfig.getWcBid());
|
|
|
|
|
+ warnResult.setReportData("-");
|
|
|
|
|
+ warnResult.setTargetReCount(iotWarnconfig.getWcRepeatnum());
|
|
|
|
|
+ warnResult.setDevtypeBid(iotWarnconfig.getDevtypeBid());
|
|
|
|
|
+ warnResult.setConfig(iotWarnconfig);
|
|
|
|
|
+ warnResult.setTriggered(isWarn);
|
|
|
|
|
+ warnResult.setMessage(buffer.toString());
|
|
|
|
|
+ //发送告警
|
|
|
|
|
+ reCountService.handlerMessage(warnResult);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|