|
|
@@ -11,6 +11,7 @@ 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.WarnInfoDto;
|
|
|
@@ -50,62 +51,27 @@ public class WarnService {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 统一处理上报数据
|
|
|
+ * 【主】统一处理上报离线数据
|
|
|
*
|
|
|
* @param data 上报的数据对象
|
|
|
* param ext 上报的原始数据
|
|
|
*/
|
|
|
public void processWarningOfflineData(IotDevice iotDevice, JSONObject data) {
|
|
|
//转异步处理
|
|
|
- processWarningReportDataSyn(iotDevice, data);
|
|
|
+ processWarningOfflineDataSyn(iotDevice, data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 处理离线数据:针对主动上报的的离线消息
|
|
|
+ * 【主】处理离线数据:针对定时检查的离线
|
|
|
*
|
|
|
* @param iotDevice
|
|
|
- * @param data
|
|
|
*/
|
|
|
- public void processWarningOfflineDataSyn(IotDevice iotDevice, JSONObject data) {
|
|
|
- CompletableFuture.runAsync(() -> {
|
|
|
- // 获取该设备有哪些告警配置
|
|
|
- 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());
|
|
|
- warnResult.setDevtypeBid(iotDevice.getDevtypeBid());
|
|
|
- warnResult.setConfig(warnConfigInfo);
|
|
|
- warnResult.setOffline(true);
|
|
|
- warnResult.setTriggered(true);
|
|
|
- warnResult.setMessage(WarnMessageBuilderUtil.buildWarningOfflineMessage(iotDevice.getDevtypeBid(), iotDevice.getDevCode(), iotDevice.getDevName(),iotDevice.getDevUpdateddate()));
|
|
|
- handleWarnRecord(warnResult);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.error("[设备告警] tid{},没有离线告警配置或者已经关闭:{}", iotDevice.getTid(), warnConfigInfo);
|
|
|
- }
|
|
|
-
|
|
|
- }, threadPoolTaskExecutor);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理离线数据:针对定时检查的离线
|
|
|
- *
|
|
|
- * @param iotDevice
|
|
|
- */
|
|
|
- public void processWarningOfflineDataSyn(IotDevice iotDevice) {
|
|
|
+ public void processWarningOfflineData(IotDevice iotDevice) {
|
|
|
processWarningOfflineDataSyn(iotDevice, JSONObject.from(iotDevice));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 统一处理上报数据
|
|
|
+ * 【主】统一处理上报数据
|
|
|
*
|
|
|
* @param data 上报的数据对象
|
|
|
* param ext 上报的原始数据
|
|
|
@@ -115,6 +81,52 @@ public class WarnService {
|
|
|
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(() -> {
|
|
|
+ // 获取该设备有哪些告警配置
|
|
|
+ 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());
|
|
|
+ warnResult.setDevtypeBid(iotDevice.getDevtypeBid());
|
|
|
+ warnResult.setConfig(warnConfigInfo);
|
|
|
+ warnResult.setOffline(true);
|
|
|
+ warnResult.setTriggered(true);
|
|
|
+ warnResult.setMessage(WarnMessageBuilderUtil.buildWarningOfflineMessage(iotDevice.getDevtypeBid(), iotDevice.getDevCode(), iotDevice.getDevName(), iotDevice.getDevUpdateddate()));
|
|
|
+ // 处理警告记录前的日志
|
|
|
+ log.info("[设备告警] 正在为设备{}处理警告记录:{}", iotDevice.getDevBid(),warnResult);
|
|
|
+ handleWarnRecord(warnResult);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 日志记录没有离线告警配置或者已经关闭的情况
|
|
|
+ log.error("[设备告警] tid{},没有离线告警配置或者已经关闭:{}", iotDevice.getDevBid(), warnConfigInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ }, threadPoolTaskExecutor);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 异常捕获时的日志记录
|
|
|
+ log.error("[设备告警] 在处理设备{}时发生异常:{}", iotDevice.getDevBid(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 统一处理上报数据:异步处理
|