|
|
@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.iots.warn.service;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.IotEnumOnlineStatus;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.device.ElementFormatUtil;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceTypeLv1Enum;
|
|
|
@@ -10,9 +11,10 @@ import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDevicefactor;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.EnumWarnRuleOp;
|
|
|
+import com.yunfeiyun.agmp.iot.common.enums.IotDeviceStatusTypeEnum;
|
|
|
import com.yunfeiyun.agmp.iots.service.IIotDevicefactorService;
|
|
|
import com.yunfeiyun.agmp.iots.warn.model.WarnConfigInfo;
|
|
|
-import com.yunfeiyun.agmp.iots.warn.model.WarnQxSqInfoDto;
|
|
|
+import com.yunfeiyun.agmp.iots.warn.model.WarnInfoDto;
|
|
|
import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
|
|
|
import com.yunfeiyun.agmp.iots.warn.model.WarnStatusDto;
|
|
|
import com.yunfeiyun.agmp.iots.warn.util.CompareUtil;
|
|
|
@@ -46,42 +48,101 @@ public class WarnService {
|
|
|
|
|
|
@Autowired
|
|
|
private IIotDevicefactorService iotDevicefactorService;
|
|
|
+ @Autowired
|
|
|
+ private WarnPestService warnPestService;
|
|
|
|
|
|
- private Map<String, IotDevicefactor> getDevicefactorMap(String devBid){
|
|
|
- IotDevicefactor param = new IotDevicefactor();
|
|
|
- param.setDevBid(devBid);
|
|
|
- List<IotDevicefactor> factorList = iotDevicefactorService.selectIotDevicefactorList(param);
|
|
|
- Map<String, IotDevicefactor> factorMap = new HashMap<>();
|
|
|
- for(IotDevicefactor factor : factorList){
|
|
|
- String dfCode = factor.getDfCode();
|
|
|
- String dfAddress = factor.getDfAddress();
|
|
|
- String key = dfAddress + dfCode;
|
|
|
- factorMap.put(key, factor);
|
|
|
- }
|
|
|
- return factorMap;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 【主】统一处理上报离线数据
|
|
|
+ *
|
|
|
+ * @param data 上报的数据对象
|
|
|
+ * param ext 上报的原始数据
|
|
|
+ */
|
|
|
+ public void processWarningOfflineData(IotDevice iotDevice, JSONObject data) {
|
|
|
+ //转异步处理
|
|
|
+ processWarningOfflineDataSyn(iotDevice, data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 统一处理上报数据
|
|
|
+ * 【主】处理离线数据:针对定时检查的离线
|
|
|
*
|
|
|
- * @param data 上报的数据对象
|
|
|
- * param ext 上报的原始数据
|
|
|
+ * @param iotDevice
|
|
|
+ */
|
|
|
+ public void processWarningOfflineData(IotDevice iotDevice) {
|
|
|
+ processWarningOfflineDataSyn(iotDevice, JSONObject.from(iotDevice));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 【主】统一处理上报数据
|
|
|
+ *
|
|
|
+ * @param data 上报的数据对象
|
|
|
+ * param ext 上报的原始数据
|
|
|
*/
|
|
|
public void processWarningReportData(IotDevice iotDevice, JSONObject data) {
|
|
|
//转异步处理
|
|
|
processWarningReportDataSyn(iotDevice, data);
|
|
|
}
|
|
|
|
|
|
+ private void processWarningOfflineDataSyn(IotDevice iotDevice, JSONObject data) {
|
|
|
+ try {
|
|
|
+ // 记录开始处理离线数据的日志
|
|
|
+ log.info("[设备告警] 开始处理设备{}的离线数据{}", iotDevice.getDevBid(), data);
|
|
|
+ // 不是离线的不处理
|
|
|
+ if (!IotDeviceStatusTypeEnum.OFFLINE.getCode().equals(iotDevice.getDevStatus())) {
|
|
|
+ log.info("[设备告警] 设备{}当前不是离线状态,跳过处理", iotDevice.getDevBid());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ // 获取该设备有哪些告警配置
|
|
|
+ IotWarnconfig warnConfigInfo = iotWarnBussinessService.selectIotWarnOfflineConfigInfo(iotDevice.getTid());
|
|
|
+
|
|
|
+ // 存在离线配置,且开启
|
|
|
+ if (warnConfigInfo != null && "0".equals(warnConfigInfo.getWcStatus())) {
|
|
|
+ // 离线
|
|
|
+ if (IotEnumOnlineStatus.OFFLINE.getStatus().equals(iotDevice.getDevStatus())) {
|
|
|
+ WarnResult warnResult = new WarnResult();
|
|
|
+ warnResult.setMessageId(warnResult.getUUId());
|
|
|
+ warnResult.setDevId(iotDevice.getDevBid());
|
|
|
+ warnResult.setTid(iotDevice.getTid());
|
|
|
+ warnResult.setConfigId(warnConfigInfo.getWcBid());
|
|
|
+ warnResult.setReportData(data.toJSONString());
|
|
|
+ warnResult.setTargetReCount(warnConfigInfo.getWcRepeatnum() == null ? 0 : warnConfigInfo.getWcRepeatnum());
|
|
|
+ warnResult.setDevtypeBid(iotDevice.getDevtypeBid());
|
|
|
+ warnResult.setConfig(warnConfigInfo);
|
|
|
+ warnResult.setOffline(true);
|
|
|
+ warnResult.setTriggered(true);
|
|
|
+ warnResult.setMessage(WarnMessageBuilderUtil.buildWarningOfflineMessage(iotDevice.getDevtypeBid(), iotDevice.getDevCode(), StringUtils.isEmpty(iotDevice.getDevUpdateddate()) ? iotDevice.getDevCreateddate() : iotDevice.getDevUpdateddate()));
|
|
|
+ // 处理警告记录前的日志
|
|
|
+ log.info("[设备告警] 正在为设备{}处理警告记录:{}", iotDevice.getDevBid(), warnResult);
|
|
|
+ handleWarnRecord(warnResult);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 日志记录没有离线告警配置或者已经关闭的情况
|
|
|
+ log.error("[设备告警] devId:{} , tid{},没有离线告警配置或者已经关闭:{}", iotDevice.getDevBid(), iotDevice.getTid(), warnConfigInfo);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("{}", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }, threadPoolTaskExecutor);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 异常捕获时的日志记录
|
|
|
+ log.error("[设备告警] 在处理设备{}时发生异常:{}", iotDevice.getDevBid(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 统一处理上报数据:异步处理
|
|
|
*
|
|
|
- * @param data 上报的数据对象
|
|
|
+ * @param data 上报的数据对象
|
|
|
*/
|
|
|
private void processWarningReportDataSyn(IotDevice iotDevice, JSONObject data) {
|
|
|
String devBid = iotDevice.getDevBid();
|
|
|
String devtypeBid = iotDevice.getDevtypeBid();
|
|
|
- String devClass = IotDeviceDictEnum.getLv1CodeByCode(devtypeBid);
|
|
|
+ String devClass = IotDeviceDictEnum.getLv1CodeByCode(devtypeBid);
|
|
|
IotDeviceTypeLv1Enum iotDeviceTypeLv1Enum = IotDeviceTypeLv1Enum.findEnumByCode(devClass);
|
|
|
if (iotDeviceTypeLv1Enum == null) {
|
|
|
log.error("[设备告警] 设备大类不存在,devBid:{}, devtypeBid:{}", devBid, devtypeBid);
|
|
|
@@ -103,31 +164,31 @@ public class WarnService {
|
|
|
Map<String, IotDevicefactor> factorMap = getDevicefactorMap(devBid);
|
|
|
|
|
|
//配置一个个检查
|
|
|
- for(Map.Entry<String, List<WarnConfigInfo>> entry : configMap.entrySet()) {
|
|
|
+ for (Map.Entry<String, List<WarnConfigInfo>> entry : configMap.entrySet()) {
|
|
|
List<WarnConfigInfo> configList = entry.getValue();
|
|
|
WarnResult warnResult = null;
|
|
|
|
|
|
- WarnQxSqInfoDto warnQxSqInfoDto = new WarnQxSqInfoDto();
|
|
|
- warnQxSqInfoDto.setIotDevice(iotDevice);
|
|
|
- warnQxSqInfoDto.setConfigList(configList);
|
|
|
- warnQxSqInfoDto.setJsonObject(data);
|
|
|
- warnQxSqInfoDto.setFactorMap(factorMap);
|
|
|
- warnQxSqInfoDto.setIotDeviceTypeLv1Enum(iotDeviceTypeLv1Enum);
|
|
|
+ WarnInfoDto warnInfoDto = new WarnInfoDto();
|
|
|
+ warnInfoDto.setIotDevice(iotDevice);
|
|
|
+ warnInfoDto.setConfigList(configList);
|
|
|
+ warnInfoDto.setJsonObject(data);
|
|
|
+ warnInfoDto.setFactorMap(factorMap);
|
|
|
+ warnInfoDto.setIotDeviceTypeLv1Enum(iotDeviceTypeLv1Enum);
|
|
|
|
|
|
- try{
|
|
|
+ try {
|
|
|
switch (iotDeviceTypeLv1Enum) {
|
|
|
case QXZ: {
|
|
|
- warnResult = comparableQxzReportData(warnQxSqInfoDto);
|
|
|
+ warnResult = comparableQxzReportData(warnInfoDto);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case SQZ: {
|
|
|
+ warnResult = comparableSqzReportData(warnInfoDto);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case GSSQ: {
|
|
|
+ warnResult = comparableGssqReportData(warnInfoDto);
|
|
|
break;
|
|
|
}
|
|
|
-// case SQZ: {
|
|
|
-// warnResult = comparableSqzReportData(warnQxSqInfoDto);
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// case GSSQ: {
|
|
|
-// warnResult = comparableGssqReportData(warnQxSqInfoDto);
|
|
|
-// break;
|
|
|
-// }
|
|
|
// case "病虫害": {
|
|
|
// warnResult = comparableBchReportData(devBid, config, data);
|
|
|
// break;
|
|
|
@@ -135,7 +196,7 @@ public class WarnService {
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("[设备告警] 设备上报数据 异常,devBid:{}, config:{}, data:{}", devBid, configList, data, e);
|
|
|
}
|
|
|
|
|
|
@@ -157,6 +218,40 @@ public class WarnService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 检查租户是否有默认的离线告警信息
|
|
|
+ */
|
|
|
+ public void checkTenantOfflineConfig() {
|
|
|
+ List<String> tids = iotWarnBussinessService.selectAllTid();
|
|
|
+ for (String tid : tids) {
|
|
|
+ log.info("【告警】检查租户 tid:{}离线配置 {}", tid);
|
|
|
+ try {
|
|
|
+ IotWarnconfig iotWarnconfig = iotWarnBussinessService.selectIotWarnOfflineConfigInfo(tid);
|
|
|
+ if (iotWarnconfig == null) {
|
|
|
+ log.info("【告警】检查租户 tid:{}离线配置不存在,自动添加", tid);
|
|
|
+ iotWarnBussinessService.insertIotOfflineWarnConfig(tid);
|
|
|
+ log.info("【告警】检查租户 tid:{}离线配置不存在,自动添加完毕", tid);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【告警】检查租户 tid:{}离线配置 {}", tid, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, IotDevicefactor> getDevicefactorMap(String devBid) {
|
|
|
+ IotDevicefactor param = new IotDevicefactor();
|
|
|
+ param.setDevBid(devBid);
|
|
|
+ List<IotDevicefactor> factorList = iotDevicefactorService.selectIotDevicefactorList(param);
|
|
|
+ Map<String, IotDevicefactor> factorMap = new HashMap<>();
|
|
|
+ for (IotDevicefactor factor : factorList) {
|
|
|
+ String dfCode = factor.getDfCode();
|
|
|
+ String dfAddress = factor.getDfAddress();
|
|
|
+ String key = dfAddress + dfCode;
|
|
|
+ factorMap.put(key, factor);
|
|
|
+ }
|
|
|
+ return factorMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 根据设备id获取策略,可能有多个
|
|
|
*
|
|
|
* @param devBid
|
|
|
@@ -171,7 +266,7 @@ public class WarnService {
|
|
|
String devCode = iotDevice.getDevCode();
|
|
|
BigDecimal errorValue = new BigDecimal("-99");
|
|
|
Map<String, String> currentValueMap = new HashMap<>();
|
|
|
- for(Object obj : jsonArray) {
|
|
|
+ for (Object obj : jsonArray) {
|
|
|
JSONObject ob;
|
|
|
try {
|
|
|
ob = JSONObject.from(obj);
|
|
|
@@ -201,16 +296,16 @@ public class WarnService {
|
|
|
return currentValueMap;
|
|
|
}
|
|
|
|
|
|
- private String getDisplayName(String key, Map<String, IotDevicefactor> factorMap){
|
|
|
+ private String getDisplayName(String key, Map<String, IotDevicefactor> factorMap) {
|
|
|
String wiName = "";
|
|
|
- if(factorMap.containsKey(key)){
|
|
|
+ if (factorMap.containsKey(key)) {
|
|
|
IotDevicefactor iotDevicefactor = factorMap.get(key);
|
|
|
// 如果禁用,直接返回null,不进行预警判断
|
|
|
- if(Objects.equals(iotDevicefactor.getDfDisable(), "1")){
|
|
|
+ if (Objects.equals(iotDevicefactor.getDfDisable(), "1")) {
|
|
|
return null;
|
|
|
}
|
|
|
String displayname = iotDevicefactor.getDfDisplayname();
|
|
|
- if(StringUtils.isNotEmpty(displayname)){
|
|
|
+ if (StringUtils.isNotEmpty(displayname)) {
|
|
|
wiName = displayname;
|
|
|
}
|
|
|
}
|
|
|
@@ -218,12 +313,12 @@ public class WarnService {
|
|
|
return wiName;
|
|
|
}
|
|
|
|
|
|
- private WarnStatusDto getQxzWarnStatusDto(WarnConfigInfo config, WarnQxSqInfoDto warnQxSqInfoDto) {
|
|
|
- IotDevice iotDevice = warnQxSqInfoDto.getIotDevice();
|
|
|
+ private WarnStatusDto getQxzWarnStatusDto(WarnConfigInfo config, WarnInfoDto warnInfoDto) {
|
|
|
+ IotDevice iotDevice = warnInfoDto.getIotDevice();
|
|
|
String devCode = iotDevice.getDevCode();
|
|
|
- Map<String, String> currentValueMap = warnQxSqInfoDto.getCurrentValueMap();
|
|
|
- Map<String, IotDevicefactor> factorMap = warnQxSqInfoDto.getFactorMap();
|
|
|
- IotDeviceTypeLv1Enum iotDeviceTypeLv1Enum = warnQxSqInfoDto.getIotDeviceTypeLv1Enum();
|
|
|
+ Map<String, String> currentValueMap = warnInfoDto.getCurrentValueMap();
|
|
|
+ Map<String, IotDevicefactor> factorMap = warnInfoDto.getFactorMap();
|
|
|
+ IotDeviceTypeLv1Enum iotDeviceTypeLv1Enum = warnInfoDto.getIotDeviceTypeLv1Enum();
|
|
|
|
|
|
String targetValue = config.getWiValue();
|
|
|
String wiAddress = config.getWiAddress();
|
|
|
@@ -235,7 +330,7 @@ public class WarnService {
|
|
|
|
|
|
// 如果配置禁用,或者要素禁用,直接返回null,不进行预警判断
|
|
|
boolean status = "0".equals(wcStatus) && "0".equals(wiStatus);
|
|
|
- if(!status){
|
|
|
+ if (!status) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -245,25 +340,25 @@ public class WarnService {
|
|
|
}
|
|
|
|
|
|
// 如果没有配置预警条件和值,直接返回null,不进行预警判断
|
|
|
- if(StringUtils.isEmpty(expression) || StringUtils.isEmpty(targetValue)){
|
|
|
+ if (StringUtils.isEmpty(expression) || StringUtils.isEmpty(targetValue)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
String wiName = config.getWiName();
|
|
|
// 如果禁用,直接返回null,不进行预警判断
|
|
|
String displayname = getDisplayName(key, factorMap);
|
|
|
- if(displayname == null){
|
|
|
+ if (displayname == null) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- if(StringUtils.isNotEmpty(displayname)){
|
|
|
+ if (StringUtils.isNotEmpty(displayname)) {
|
|
|
wiName = displayname;
|
|
|
}
|
|
|
String wiUnit = config.getWiUnit();
|
|
|
String currentValue = currentValueMap.get(key);
|
|
|
|
|
|
EnumWarnRuleOp warnRuleOp = EnumWarnRuleOp.findEnumByCode(expression);
|
|
|
- if(warnRuleOp == null){
|
|
|
+ if (warnRuleOp == null) {
|
|
|
log.error("[设备告警] 表达式不正确,devCode:{}, wiAddress:{}, config:{}", devCode, wiAddress, config);
|
|
|
return null;
|
|
|
}
|
|
|
@@ -285,28 +380,26 @@ public class WarnService {
|
|
|
|
|
|
/**
|
|
|
* 【气象站】比较该设备上报的任一要素否达到预警条件
|
|
|
+ *
|
|
|
* @param warnResult
|
|
|
- * @param configList
|
|
|
- * @param factorMap
|
|
|
- * @param currentValueMap
|
|
|
- * @param devCode
|
|
|
+ * @param warnInfoDto
|
|
|
* @return
|
|
|
*/
|
|
|
- public WarnResult comparableQxzSingleIndicator(WarnResult warnResult, WarnQxSqInfoDto warnQxSqInfoDto) {
|
|
|
- List<WarnConfigInfo> configList = warnQxSqInfoDto.getConfigList();
|
|
|
+ public WarnResult comparableQxzSingleIndicator(WarnResult warnResult, WarnInfoDto warnInfoDto) {
|
|
|
+ List<WarnConfigInfo> configList = warnInfoDto.getConfigList();
|
|
|
WarnStatusDto warnStatusDto = null;
|
|
|
for (WarnConfigInfo config : configList) {
|
|
|
- warnStatusDto = getQxzWarnStatusDto(config, warnQxSqInfoDto);
|
|
|
+ warnStatusDto = getQxzWarnStatusDto(config, warnInfoDto);
|
|
|
// 如果没有预警配置,直接返回null,不进行预警判断
|
|
|
- if(warnStatusDto == null){
|
|
|
+ if (warnStatusDto == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- if(warnStatusDto.isWarn()){
|
|
|
+ if (warnStatusDto.isWarn()) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if(warnStatusDto != null && warnStatusDto.isWarn()){
|
|
|
- String message = WarnMessageBuilderUtil.buildQxzWarningMessage(
|
|
|
+ if (warnStatusDto != null && warnStatusDto.isWarn()) {
|
|
|
+ String message = WarnMessageBuilderUtil.buildWarningMessage(
|
|
|
warnStatusDto.getDevType(),
|
|
|
warnStatusDto.getDevCode(),
|
|
|
warnStatusDto.getName(),
|
|
|
@@ -325,40 +418,39 @@ public class WarnService {
|
|
|
/**
|
|
|
* 处理多个指标是否同时满足预警条件。
|
|
|
*
|
|
|
- * @param devId 设备ID
|
|
|
- * @param config 告警规则
|
|
|
- * @param jsonObject 上报的数据
|
|
|
+ * @param warnResult
|
|
|
+ * @param warnInfoDto
|
|
|
* @return WarnResult 包含是否触发告警的信息
|
|
|
*/
|
|
|
- public WarnResult comparableQxzMultipleIndicators(WarnResult warnResult, WarnQxSqInfoDto warnQxSqInfoDto) {
|
|
|
- List<WarnConfigInfo> configList = warnQxSqInfoDto.getConfigList();
|
|
|
+ public WarnResult comparableQxzMultipleIndicators(WarnResult warnResult, WarnInfoDto warnInfoDto) {
|
|
|
+ List<WarnConfigInfo> configList = warnInfoDto.getConfigList();
|
|
|
WarnStatusDto warnStatusDto = null;
|
|
|
List<WarnStatusDto> warnStatusDtos = new ArrayList<>();
|
|
|
for (WarnConfigInfo config : configList) {
|
|
|
- warnStatusDto = getQxzWarnStatusDto(config, warnQxSqInfoDto);
|
|
|
+ warnStatusDto = getQxzWarnStatusDto(config, warnInfoDto);
|
|
|
// 如果没有预警配置,直接返回null,不进行预警判断
|
|
|
- if(warnStatusDto == null){
|
|
|
+ if (warnStatusDto == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- if(!warnStatusDto.isWarn()){
|
|
|
+ if (!warnStatusDto.isWarn()) {
|
|
|
return warnResult;
|
|
|
}
|
|
|
warnStatusDtos.add(warnStatusDto);
|
|
|
}
|
|
|
- if(warnStatusDtos.isEmpty()){
|
|
|
+ if (warnStatusDtos.isEmpty()) {
|
|
|
return warnResult;
|
|
|
}
|
|
|
|
|
|
StringBuilder messageBuilder = new StringBuilder();
|
|
|
- for(int i = 0; i < warnStatusDtos.size(); i++){
|
|
|
+ for (int i = 0; i < warnStatusDtos.size(); i++) {
|
|
|
warnStatusDto = warnStatusDtos.get(i);
|
|
|
String devType = null;
|
|
|
String dCode = null;
|
|
|
- if(i == 0){
|
|
|
+ if (i == 0) {
|
|
|
devType = warnStatusDto.getDevType();
|
|
|
dCode = warnStatusDto.getDevCode();
|
|
|
}
|
|
|
- String message = WarnMessageBuilderUtil.buildQxzWarningMessage(
|
|
|
+ String message = WarnMessageBuilderUtil.buildWarningMessage(
|
|
|
devType,
|
|
|
dCode,
|
|
|
warnStatusDto.getName(),
|
|
|
@@ -378,18 +470,17 @@ public class WarnService {
|
|
|
/**
|
|
|
* 【气象站】比较该设备上报的要素和配置是否达到预警条件
|
|
|
*
|
|
|
- * @param devBid 设备id
|
|
|
- * @param config 对应的配置
|
|
|
- * @param jsonObject 上报的数据
|
|
|
+ * @param warnInfoDto
|
|
|
+ * @return
|
|
|
*/
|
|
|
- private WarnResult comparableQxzReportData(WarnQxSqInfoDto warnQxSqInfoDto) {
|
|
|
- IotDevice iotDevice = warnQxSqInfoDto.getIotDevice();
|
|
|
- List<WarnConfigInfo> configList = warnQxSqInfoDto.getConfigList();
|
|
|
- JSONObject jsonObject = warnQxSqInfoDto.getJsonObject();
|
|
|
+ private WarnResult comparableQxzReportData(WarnInfoDto warnInfoDto) {
|
|
|
+ IotDevice iotDevice = warnInfoDto.getIotDevice();
|
|
|
+ List<WarnConfigInfo> configList = warnInfoDto.getConfigList();
|
|
|
+ JSONObject jsonObject = warnInfoDto.getJsonObject();
|
|
|
JSONArray jsonArray = jsonObject.getJSONArray("data");
|
|
|
Map<String, String> currentValueMap = getQxzCurrentValueMap(iotDevice, jsonArray);
|
|
|
|
|
|
- warnQxSqInfoDto.setCurrentValueMap(currentValueMap);
|
|
|
+ warnInfoDto.setCurrentValueMap(currentValueMap);
|
|
|
|
|
|
String devBid = iotDevice.getDevBid();
|
|
|
WarnConfigInfo configInfo = configList.get(0);
|
|
|
@@ -409,10 +500,10 @@ public class WarnService {
|
|
|
warnResult.setConfig(iotWarnconfig);
|
|
|
warnResult.setTriggered(false);
|
|
|
|
|
|
- if("0".equals(wcCondition)){
|
|
|
- warnResult = comparableQxzSingleIndicator(warnResult, warnQxSqInfoDto);
|
|
|
+ if ("0".equals(wcCondition)) {
|
|
|
+ warnResult = comparableQxzSingleIndicator(warnResult, warnInfoDto);
|
|
|
} else {
|
|
|
- warnResult = comparableQxzMultipleIndicators(warnResult, warnQxSqInfoDto);
|
|
|
+ warnResult = comparableQxzMultipleIndicators(warnResult, warnInfoDto);
|
|
|
}
|
|
|
return warnResult;
|
|
|
}
|
|
|
@@ -420,19 +511,17 @@ public class WarnService {
|
|
|
|
|
|
/**
|
|
|
* 【墒情站】比较该设备上报的要素和配置是否达到预警条件
|
|
|
- *
|
|
|
*/
|
|
|
- WarnResult comparableSqzReportData(WarnQxSqInfoDto warnQxSqInfoDto) {
|
|
|
- return comparableQxzReportData(warnQxSqInfoDto);
|
|
|
+ WarnResult comparableSqzReportData(WarnInfoDto warnInfoDto) {
|
|
|
+ return comparableQxzReportData(warnInfoDto);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 【管式墒情】比较该设备上报的要素和配置是否达到预警条件
|
|
|
- *
|
|
|
*/
|
|
|
- WarnResult comparableGssqReportData(WarnQxSqInfoDto warnQxSqInfoDto) {
|
|
|
- return comparableQxzReportData(warnQxSqInfoDto);
|
|
|
+ WarnResult comparableGssqReportData(WarnInfoDto warnInfoDto) {
|
|
|
+ return comparableQxzReportData(warnInfoDto);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -448,4 +537,50 @@ public class WarnService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 拦截处理设备变更:如果离线转离线进行预警处理
|
|
|
+ *
|
|
|
+ * @param iotDeviceList
|
|
|
+ */
|
|
|
+ public void processWarningOfflineToOnlineDeviceData(List<IotDevice> iotDeviceList) {
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ for (IotDevice iotDevice : iotDeviceList) {
|
|
|
+
|
|
|
+ //离线转在线
|
|
|
+ if (IotDeviceStatusTypeEnum.OFFLINE.getCode().equals(iotDevice.getDevOriginalStatus())
|
|
|
+ && IotDeviceStatusTypeEnum.ONLINE.getCode().equals(iotDevice.getDevStatus()
|
|
|
+ )) {
|
|
|
+ log.info("[离线告警]自动处理离线告警消息:设备号: {} ,bid:{}", iotDevice.getDevCode(), iotDevice.getDevBid());
|
|
|
+ autoDealWarnOfflineLog(iotDevice.getDevBid());
|
|
|
+ } else {
|
|
|
+ log.info("[离线告警]自动处理离线告警消息:设备号: {} ,bid:{} ,原始状态:", iotDevice.getDevCode(), iotDevice.getDevBid(), iotDevice.getDevOriginalStatus());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("[离线告警]自动处理离线告警消息:失败 {}", e);
|
|
|
+ }
|
|
|
+ }, threadPoolTaskExecutor);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void autoDealWarnOfflineLog(String devId) {
|
|
|
+ iotWarnBussinessService.autoDealWarnOfflineLog(devId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 虫害
|
|
|
+ */
|
|
|
+ public void processWarningPestData() {
|
|
|
+ warnPestService.process();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 病害
|
|
|
+ */
|
|
|
+ public void processWarningDiseaseData() {
|
|
|
+
|
|
|
+ }
|
|
|
}
|