|
|
@@ -1,10 +1,15 @@
|
|
|
package com.yunfeiyun.agmp.iots.warn.service;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceTypeLv1Enum;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.EnumWarnRuleOp;
|
|
|
+import com.yunfeiyun.agmp.iots.warn.model.WarnConfigInfo;
|
|
|
import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
|
|
|
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.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -12,11 +17,13 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
/**
|
|
|
* 预警核心服务类
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class WarnService {
|
|
|
|
|
|
@@ -26,15 +33,18 @@ public class WarnService {
|
|
|
@Autowired
|
|
|
private ReCountService reCountService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IotWarnBussinessService iotWarnBussinessService;
|
|
|
+
|
|
|
/**
|
|
|
* 统一处理上报数据
|
|
|
*
|
|
|
* @param devId 设备id
|
|
|
* @param data 上报的数据对象
|
|
|
*/
|
|
|
- public void processWarningReportData(String devId, JSONObject data) {
|
|
|
+ public void processWarningReportData(IotDevice iotDevice, JSONObject data) {
|
|
|
//转异步处理
|
|
|
- processWarningReportDataSyn(devId, data);
|
|
|
+ processWarningReportDataSyn(iotDevice, data);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -44,27 +54,41 @@ public class WarnService {
|
|
|
* @param devId 设备id
|
|
|
* @param data 上报的数据对象
|
|
|
*/
|
|
|
- private void processWarningReportDataSyn(String devId, JSONObject data) {
|
|
|
+ private void processWarningReportDataSyn(IotDevice iotDevice, JSONObject data) {
|
|
|
+ String devId = iotDevice.getDevBid();
|
|
|
+ String devtypeBid = iotDevice.getDevtypeBid();
|
|
|
+ String devClass = IotDeviceDictEnum.getLv1CodeByCode(devtypeBid);
|
|
|
+ IotDeviceTypeLv1Enum iotDeviceTypeLv1Enum = IotDeviceTypeLv1Enum.findEnumByCode(devClass);
|
|
|
+ if (iotDeviceTypeLv1Enum == null) {
|
|
|
+ log.error("[设备告警] 设备大类不存在,devId:{}, devtypeBid:{}", devId, devtypeBid);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
- String devClass = "设备大类"; // todo
|
|
|
// 获取该设备有哪些告警配置
|
|
|
- List<Object> objects = getConfigByDevId(devId);
|
|
|
+ WarnConfigInfo warnConfigInfo = new WarnConfigInfo();
|
|
|
+ warnConfigInfo.setTid(iotDevice.getTid());
|
|
|
+ warnConfigInfo.setWoObjid(devId);
|
|
|
+ warnConfigInfo.setWoType("1");
|
|
|
+
|
|
|
+ Map<String, List<WarnConfigInfo>> configMap = iotWarnBussinessService.selectIotWarnConfigInfoMap(warnConfigInfo);
|
|
|
//配置一个个检查
|
|
|
- for (Object config : objects) {
|
|
|
+ for(Map.Entry<String, List<WarnConfigInfo>> entry : configMap.entrySet()) {
|
|
|
+ List<WarnConfigInfo> configList = entry.getValue();
|
|
|
WarnResult warnResult = null;
|
|
|
- switch (devClass) {
|
|
|
- case "气象站": {
|
|
|
- warnResult = comparableQxzReportData(devId, config, data);
|
|
|
- break;
|
|
|
- }
|
|
|
- case "墒情站": {
|
|
|
- warnResult = comparableSqzReportData(devId, config, data);
|
|
|
- break;
|
|
|
- }
|
|
|
- case "病虫害": {
|
|
|
- warnResult = comparableBchReportData(devId, config, data);
|
|
|
+ switch (iotDeviceTypeLv1Enum) {
|
|
|
+ case QXZ: {
|
|
|
+ warnResult = comparableQxzReportData(devId, configList, data);
|
|
|
break;
|
|
|
}
|
|
|
+// case SQZ: {
|
|
|
+// warnResult = comparableSqzReportData(devId, config, data);
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// case "病虫害": {
|
|
|
+// warnResult = comparableBchReportData(devId, config, data);
|
|
|
+// break;
|
|
|
+// }
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -72,6 +96,28 @@ public class WarnService {
|
|
|
handleWarnRecord(warnResult);
|
|
|
}
|
|
|
}
|
|
|
+// for (Object config : objects) {
|
|
|
+// WarnResult warnResult = null;
|
|
|
+// switch (iotDeviceTypeLv1Enum) {
|
|
|
+// case QXZ: {
|
|
|
+// warnResult = comparableQxzReportData(devId, config, data);
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// case SQZ: {
|
|
|
+// warnResult = comparableSqzReportData(devId, config, data);
|
|
|
+// break;
|
|
|
+// }
|
|
|
+//// case "病虫害": {
|
|
|
+//// warnResult = comparableBchReportData(devId, config, data);
|
|
|
+//// break;
|
|
|
+//// }
|
|
|
+// default:
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// if (warnResult != null) {
|
|
|
+// handleWarnRecord(warnResult);
|
|
|
+// }
|
|
|
+// }
|
|
|
}, threadPoolTaskExecutor);
|
|
|
}
|
|
|
|
|
|
@@ -103,13 +149,13 @@ public class WarnService {
|
|
|
* @param config 对应的配置
|
|
|
* @param jsonObject 上报的数据
|
|
|
*/
|
|
|
- WarnResult comparableQxzReportData(String devId, Object config, JSONObject jsonObject) {
|
|
|
+ WarnResult comparableQxzReportData(String devId, List<WarnConfigInfo> configList, JSONObject jsonObject) {
|
|
|
WarnResult warnResult = null;
|
|
|
- if ("指标类型" == "多指标满足") {
|
|
|
- warnResult = comparableQxzMultipleIndicators(devId, config, jsonObject);
|
|
|
- } else {
|
|
|
- warnResult = comparableQxzSingleIndicator(devId, config, jsonObject);
|
|
|
- }
|
|
|
+// if ("指标类型" == "多指标满足") {
|
|
|
+// warnResult = comparableQxzMultipleIndicators(devId, config, jsonObject);
|
|
|
+// } else {
|
|
|
+// warnResult = comparableQxzSingleIndicator(devId, config, jsonObject);
|
|
|
+// }
|
|
|
return warnResult;
|
|
|
}
|
|
|
|