|
@@ -1,5 +1,6 @@
|
|
|
package com.sckw.slope.detection.consumer;
|
|
package com.sckw.slope.detection.consumer;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -9,6 +10,7 @@ import com.sckw.core.model.enums.DictItemEnum;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
import com.sckw.core.utils.IdWorker;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
|
|
+import com.sckw.log.TraceLog.TraceLog;
|
|
|
import com.sckw.slope.detection.dao.mysql.*;
|
|
import com.sckw.slope.detection.dao.mysql.*;
|
|
|
import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
|
import com.sckw.slope.detection.model.dos.mysql.*;
|
|
import com.sckw.slope.detection.model.dos.mysql.*;
|
|
@@ -40,7 +42,7 @@ import java.util.stream.Collectors;
|
|
|
* @date 2023-10-26 08:10:45
|
|
* @date 2023-10-26 08:10:45
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
-@Service("sharjeck/ai/test/out")
|
|
|
|
|
|
|
+@Service("system/iot/device_data_slope")
|
|
|
public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
|
|
|
|
|
@Value("${sms.url}")
|
|
@Value("${sms.url}")
|
|
@@ -64,18 +66,27 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
HandlerFactory handlerFactory;
|
|
HandlerFactory handlerFactory;
|
|
|
|
|
|
|
|
|
|
+ @TraceLog(description = "处理system/iot/device_data/")
|
|
|
// @Transactional
|
|
// @Transactional
|
|
|
@DSTransactional
|
|
@DSTransactional
|
|
|
public HttpResult handle(String topic, String payload) {
|
|
public HttpResult handle(String topic, String payload) {
|
|
|
// 根据topic分别进行消息处理。
|
|
// 根据topic分别进行消息处理。
|
|
|
log.info("MqttDeviceCallbackHandler:" + topic + "|" + payload);
|
|
log.info("MqttDeviceCallbackHandler:" + topic + "|" + payload);
|
|
|
- System.out.println("处理sharjeck/ai/test/out");
|
|
|
|
|
|
|
+ System.out.println("system/iot/original_data_slope");
|
|
|
|
|
+ DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
|
|
|
|
|
+ Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
|
|
|
|
|
+ JSONObject objects = JSONObject.parseObject(payload);
|
|
|
|
|
+ String deviceTs = objects.getString("ts");
|
|
|
|
|
+ String deviceGuid = objects.getString("guid");
|
|
|
|
|
+ String deviceTslverId = objects.getString("tslver_id");
|
|
|
|
|
+ String deviceMsgId = objects.getString("msg_id");
|
|
|
|
|
+ String deviceRawTs = objects.getString("raw_ts");
|
|
|
|
|
+ JSONArray checkArr = objects.getJSONArray("check_arr");
|
|
|
try {
|
|
try {
|
|
|
- Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
|
|
|
|
|
- DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
|
|
|
|
|
- String deviceCode = devicesAlarm.getDeviceCode();
|
|
|
|
|
|
|
+// DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
|
|
|
|
|
+ String deviceCode = devicesAlarm.getGuid();
|
|
|
List<KwsDevice> deviceList = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
|
|
List<KwsDevice> deviceList = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
|
|
|
- .eq(KwsDevice::getSnCode, deviceCode)
|
|
|
|
|
|
|
+ .eq(KwsDevice::getSnCodeFullName, deviceCode)
|
|
|
.eq(KwsDevice::getDelFlag, NumberConstant.ZERO)
|
|
.eq(KwsDevice::getDelFlag, NumberConstant.ZERO)
|
|
|
);
|
|
);
|
|
|
KwsDevice device = null;
|
|
KwsDevice device = null;
|
|
@@ -84,7 +95,7 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
}
|
|
}
|
|
|
if (device == null) {
|
|
if (device == null) {
|
|
|
log.error("接收处理数据:{}", payload);
|
|
log.error("接收处理数据:{}", payload);
|
|
|
- log.error("设备数据并未维护,不做处理");
|
|
|
|
|
|
|
+ log.error("设备数据并未维护+["+devicesAlarm.getGuid()+"],不做处理");
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
List<DevicesItem> devicesItemList = devicesAlarm.getDevicesItemList();
|
|
List<DevicesItem> devicesItemList = devicesAlarm.getDevicesItemList();
|
|
@@ -100,7 +111,7 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
if (org.springframework.util.CollectionUtils.isEmpty(kwsThresholds)) {
|
|
if (org.springframework.util.CollectionUtils.isEmpty(kwsThresholds)) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- Long ts = devicesItem.getTs();
|
|
|
|
|
|
|
+ Long ts = devicesAlarm.getTs();
|
|
|
//判断是否满足设备超时离线报警
|
|
//判断是否满足设备超时离线报警
|
|
|
checkDeviceAlarm(deviceCode, device, itemValue, ts);
|
|
checkDeviceAlarm(deviceCode, device, itemValue, ts);
|
|
|
//判断是否满足数值超阈值报警
|
|
//判断是否满足数值超阈值报警
|
|
@@ -166,7 +177,7 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
|
|
|
|
|
private void checkDeviceAlarm(String deviceCode, KwsDevice device, String itemValue, Long ts) {
|
|
private void checkDeviceAlarm(String deviceCode, KwsDevice device, String itemValue, Long ts) {
|
|
|
try {
|
|
try {
|
|
|
- Devices devices = tdengineService.selectLastData(deviceCode);
|
|
|
|
|
|
|
+ Devices devices = tdengineService.selectLastData(device.getSnCode());
|
|
|
if (devices != null) {
|
|
if (devices != null) {
|
|
|
Date deviceTime = devices.getTs();
|
|
Date deviceTime = devices.getTs();
|
|
|
Date date = new Date();
|
|
Date date = new Date();
|
|
@@ -203,7 +214,7 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
KwsDeviceReferenceMapper deviceReferenceMapper;
|
|
KwsDeviceReferenceMapper deviceReferenceMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private TdengineService tdengineService;
|
|
|
|
|
|
|
+ private TdengineService tdengineService;
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> checkThresholdAlarm(DevicesItem devicesItem, List<KwsThreshold> kwsThresholds, KwsDevice device) {
|
|
private Map<String, String> checkThresholdAlarm(DevicesItem devicesItem, List<KwsThreshold> kwsThresholds, KwsDevice device) {
|
|
@@ -275,7 +286,7 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
map.put("flag", "1");
|
|
map.put("flag", "1");
|
|
|
if (min != null || max != null) {
|
|
if (min != null || max != null) {
|
|
|
if (max != null) {
|
|
if (max != null) {
|
|
|
- Long level = maxMap.get(max);
|
|
|
|
|
|
|
+ Long level = maxMap.get(max.toString());
|
|
|
Long thresholdId = maxMap.get(level.toString());
|
|
Long thresholdId = maxMap.get(level.toString());
|
|
|
map.put("level", level.toString());
|
|
map.put("level", level.toString());
|
|
|
map.put("thresholdId", thresholdId.toString());
|
|
map.put("thresholdId", thresholdId.toString());
|
|
@@ -283,7 +294,7 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
// insertAlarmAndDetail(level, device, thresholdId, itemValue, ts);
|
|
// insertAlarmAndDetail(level, device, thresholdId, itemValue, ts);
|
|
|
}
|
|
}
|
|
|
if (min != null) {
|
|
if (min != null) {
|
|
|
- Long level = minMap.get(min);
|
|
|
|
|
|
|
+ Long level = minMap.get(min.toString());
|
|
|
Long thresholdId = minMap.get(level.toString());
|
|
Long thresholdId = minMap.get(level.toString());
|
|
|
map.put("level", level.toString());
|
|
map.put("level", level.toString());
|
|
|
map.put("thresholdId", thresholdId.toString());
|
|
map.put("thresholdId", thresholdId.toString());
|
|
@@ -376,7 +387,6 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
|
|
KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
|
|
|
.eq(KwsProjectDevice::getDeviceId, deviceId)
|
|
.eq(KwsProjectDevice::getDeviceId, deviceId)
|
|
|
.eq(KwsProjectDevice::getDelFlag, 0)
|
|
.eq(KwsProjectDevice::getDelFlag, 0)
|
|
|
- .eq(KwsProjectDevice::getStatus, 0)
|
|
|
|
|
.orderByDesc(KwsProjectDevice::getCreateTime)
|
|
.orderByDesc(KwsProjectDevice::getCreateTime)
|
|
|
.last(" limit 1")
|
|
.last(" limit 1")
|
|
|
);
|
|
);
|
|
@@ -461,21 +471,17 @@ public class MqttDeviceCallbackHandler extends AbstractHandler {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
|
|
+
|
|
|
|
|
+ String aaa = "{\"ts\":1700808976,\"guid\":\"0838161D-4C64-EC3E-A3A8-C736C47D93D4\",\"tslver_id\":\"3\",\"msg_id\":\"586569123094614016\",\"raw_ts\":\"\",\"check_arr\":[{\"itemName\":\"lng\",\"itemValue\":\"103.51826198069217\"},{\"itemName\":\"lat\",\"itemValue\":\"29.46725728245242\"},{\"itemName\":\"high\",\"itemValue\":\"710.1730218537282\"},{\"itemName\":\"fix\",\"itemValue\":4015},{\"itemName\":\"e\",\"itemValue\":\"302.7644742928626\"},{\"itemName\":\"n\",\"itemValue\":\"711.0632664506148\"},{\"itemName\":\"u\",\"itemValue\":\"-271.97856155098333\"},{\"itemName\":\"num\",\"itemValue\":7200},{\"itemName\":\"time\",\"itemValue\":\"2023-11-0818:00:00\"}]}";
|
|
|
DevicesAlarm alarm = new DevicesAlarm();
|
|
DevicesAlarm alarm = new DevicesAlarm();
|
|
|
- alarm.setDeviceCode("s8");
|
|
|
|
|
List<DevicesItem> list = new ArrayList<>();
|
|
List<DevicesItem> list = new ArrayList<>();
|
|
|
DevicesItem item = new DevicesItem();
|
|
DevicesItem item = new DevicesItem();
|
|
|
item.setItemName("alt");
|
|
item.setItemName("alt");
|
|
|
item.setItemValue("20.12646584");
|
|
item.setItemValue("20.12646584");
|
|
|
long time = new Date().getTime();
|
|
long time = new Date().getTime();
|
|
|
- item.setTs(new Date().getTime());
|
|
|
|
|
String md5 = new MD5Utils().getMd5(String.valueOf(time));
|
|
String md5 = new MD5Utils().getMd5(String.valueOf(time));
|
|
|
- item.setGuid(md5);
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
String format = simpleDateFormat.format(new Date());
|
|
String format = simpleDateFormat.format(new Date());
|
|
|
- item.setTslverId(format);
|
|
|
|
|
- item.setMsgId(format);
|
|
|
|
|
- item.setRawTs(format);
|
|
|
|
|
list.add(item);
|
|
list.add(item);
|
|
|
alarm.setDevicesItemList(list);
|
|
alarm.setDevicesItemList(list);
|
|
|
String demoTest = "{\"deviceCode\":\"s8\",\"devicesItemList\":[{\"guid\":\"c7653b298bec06eb78be3140b5c2ea9b\",\"itemName\":\"alt\",\"itemValue\":\"20.12646584\",\"msg_id\":\"2023-11-18 14:49:06\",\"raw_ts\":\"2023-11-18 14:49:06\",\"ts\":1700290146508,\"tslver_Id\":\"2023-11-18 14:49:06\"}]}";
|
|
String demoTest = "{\"deviceCode\":\"s8\",\"devicesItemList\":[{\"guid\":\"c7653b298bec06eb78be3140b5c2ea9b\",\"itemName\":\"alt\",\"itemValue\":\"20.12646584\",\"msg_id\":\"2023-11-18 14:49:06\",\"raw_ts\":\"2023-11-18 14:49:06\",\"ts\":1700290146508,\"tslver_Id\":\"2023-11-18 14:49:06\"}]}";
|