|
|
@@ -1,15 +1,19 @@
|
|
|
package com.sckw.slope.detection.consumer;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.sckw.core.model.constant.NumberConstant;
|
|
|
+import com.sckw.core.model.enums.AlarmTitleEnum;
|
|
|
+import com.sckw.core.model.enums.AlarmTypeEnum;
|
|
|
import com.sckw.core.model.enums.DictEnum;
|
|
|
import com.sckw.core.model.enums.DictItemEnum;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
|
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.tdengine.DevicesMapper;
|
|
|
import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
|
import com.sckw.slope.detection.model.dos.mysql.*;
|
|
|
import com.sckw.slope.detection.model.dos.tdengine.Devices;
|
|
|
@@ -26,23 +30,21 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneOffset;
|
|
|
+import java.time.*;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author lfdc
|
|
|
* @description
|
|
|
- * @date 2023-11-18 16:11:36
|
|
|
+ * @date 2023-10-26 08:10:45
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-@Service
|
|
|
-public class MqttCallbackHandler {
|
|
|
+@Service("system/iot/deviceDataSlopeDemo")
|
|
|
+public class MqttCallbackHandler extends AbstractHandler {
|
|
|
|
|
|
@Value("${sms.url}")
|
|
|
private String messageUrl;
|
|
|
@@ -65,17 +67,26 @@ public class MqttCallbackHandler {
|
|
|
@Autowired
|
|
|
HandlerFactory handlerFactory;
|
|
|
|
|
|
- @Transactional
|
|
|
+ @TraceLog(description = "处理system/iot/device_data_slope")
|
|
|
+ @DSTransactional
|
|
|
public HttpResult handle(String topic, String payload) {
|
|
|
// 根据topic分别进行消息处理。
|
|
|
log.info("MqttDeviceCallbackHandler:" + topic + "|" + payload);
|
|
|
- System.out.println("处理sharjeck/ai/test/out");
|
|
|
+ System.out.println("system/iot/device_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 {
|
|
|
- Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
|
|
|
- DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
|
|
|
+// DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
|
|
|
String deviceCode = devicesAlarm.getGuid();
|
|
|
List<KwsDevice> deviceList = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
|
|
|
- .eq(KwsDevice::getSnCode, deviceCode)
|
|
|
+ .eq(KwsDevice::getSnCodeFullName, deviceCode)
|
|
|
.eq(KwsDevice::getDelFlag, NumberConstant.ZERO)
|
|
|
);
|
|
|
KwsDevice device = null;
|
|
|
@@ -84,7 +95,7 @@ public class MqttCallbackHandler {
|
|
|
}
|
|
|
if (device == null) {
|
|
|
log.error("接收处理数据:{}", payload);
|
|
|
- log.error("设备数据并未维护,不做处理");
|
|
|
+ log.error("设备数据并未维护+[" + devicesAlarm.getGuid() + "],不做处理");
|
|
|
return null;
|
|
|
}
|
|
|
List<DevicesItem> devicesItemList = devicesAlarm.getDevicesItemList();
|
|
|
@@ -101,6 +112,10 @@ public class MqttCallbackHandler {
|
|
|
continue;
|
|
|
}
|
|
|
Long ts = devicesAlarm.getTs();
|
|
|
+// //获取到是 十位 1700970600
|
|
|
+// if (Objects.nonNull(ts)) {
|
|
|
+// ts = ts * 1000;
|
|
|
+// }
|
|
|
//判断是否满足设备超时离线报警
|
|
|
checkDeviceAlarm(deviceCode, device, itemValue, ts);
|
|
|
//判断是否满足数值超阈值报警
|
|
|
@@ -109,7 +124,22 @@ public class MqttCallbackHandler {
|
|
|
Long level = Long.valueOf(map.get("level"));
|
|
|
Long thresholdId = Long.valueOf(map.get("thresholdId"));
|
|
|
//阈值表以及明细表存储
|
|
|
- insertAlarmAndDetail(level, device, thresholdId, itemValue, ts);
|
|
|
+ long id = insertAlarmAndDetail(level, device, thresholdId, itemValue, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
+ //todo 不适用redis存统计 使用新字段处理
|
|
|
+ /**阈值次数存redis*/
|
|
|
+// String key = Global.REDIS_SYS_ALARM_PREFIX + Global.POUND + String.valueOf(id) + Global.POUND + AlarmTypeEnum.ALARM_ONE.getStatus()
|
|
|
+// + Global.POUND + AlarmTitleEnum.ALARM_TITLE_TWO.getStatus();
|
|
|
+// String number = RedissonUtils.getString(key);
|
|
|
+// Long count = alarmDetailMapper.selectCount(new LambdaQueryWrapper<KwsAlarmDetail>()
|
|
|
+// .eq(KwsAlarmDetail::getAlarmId, id)
|
|
|
+// .eq(KwsAlarmDetail::getStatus, 0)
|
|
|
+// );
|
|
|
+// if (StringUtils.isBlank(number)) {
|
|
|
+// RedissonUtils.putString(key, "1", Global.COMMON_EXPIRE);
|
|
|
+// } else {
|
|
|
+// RedissonUtils.putString(key, count.toString(), Global.COMMON_EXPIRE);
|
|
|
+// }
|
|
|
+
|
|
|
/*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
|
|
|
设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
|
|
|
Map<String, Object> messageMap = new HashMap<>();
|
|
|
@@ -164,25 +194,26 @@ public class MqttCallbackHandler {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
- DevicesMapper devicesMapper;
|
|
|
-
|
|
|
private void checkDeviceAlarm(String deviceCode, KwsDevice device, String itemValue, Long ts) {
|
|
|
- Devices devices = tdengineService.selectLastData(deviceCode);
|
|
|
- if (devices != null) {
|
|
|
- Date deviceTime = devices.getTs();
|
|
|
- Date date = new Date();
|
|
|
- long diff = Math.abs(date.getTime() - deviceTime.getTime());
|
|
|
- long diffHours = diff / (60 * 60 * 1000) % 24;
|
|
|
- if (diffHours > 24) {
|
|
|
- insertAlarmAndDetail(1L, device, device.getId(), itemValue, ts);
|
|
|
- // todo 暂未设备告警电话,设备告警不推送短信
|
|
|
- device.setOnline(1);
|
|
|
- deviceMapper.updateById(device);
|
|
|
- } else {
|
|
|
- device.setOnline(0);
|
|
|
- deviceMapper.updateById(device);
|
|
|
+ try {
|
|
|
+ Devices devices = tdengineService.selectLastData(device.getSnCode());
|
|
|
+ if (devices != null) {
|
|
|
+ Date deviceTime = devices.getTs();
|
|
|
+ Date date = new Date();
|
|
|
+ long diff = Math.abs(date.getTime() - deviceTime.getTime());
|
|
|
+ long diffHours = diff / (60 * 60 * 1000) % 24;
|
|
|
+ if (diffHours > 24) {
|
|
|
+ long id = insertAlarmAndDetail(1L, device, device.getId(), itemValue, ts, AlarmTitleEnum.ALARM_TITLE_ONE.getStatus(), AlarmTypeEnum.ALARM_TWO.getCode());
|
|
|
+ // todo 暂未设备告警电话,设备告警不推送短信
|
|
|
+ device.setOnline(1);
|
|
|
+ deviceMapper.updateById(device);
|
|
|
+ } else {
|
|
|
+ device.setOnline(0);
|
|
|
+ deviceMapper.updateById(device);
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("判断是否满足设备超时离线报警 error ", e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -227,6 +258,17 @@ public class MqttCallbackHandler {
|
|
|
Map<String, Long> minMap = new HashMap<>();
|
|
|
List<BigDecimal> maxList = new ArrayList<>();
|
|
|
List<BigDecimal> minList = new ArrayList<>();
|
|
|
+ //添加阈值map
|
|
|
+ for (KwsThreshold kwsThreshold : kwsThresholds) {
|
|
|
+ String max = kwsThreshold.getMax();
|
|
|
+ Long thresholdId = kwsThreshold.getId();
|
|
|
+ String min = kwsThreshold.getMin();
|
|
|
+ Integer level = kwsThreshold.getLevel();
|
|
|
+ maxMap.put(max, level.longValue());
|
|
|
+ maxMap.put(level.toString(), thresholdId.longValue());
|
|
|
+ minMap.put(min, level.longValue());
|
|
|
+ minMap.put(level.toString(), thresholdId.longValue());
|
|
|
+ }
|
|
|
for (KwsThreshold kwsThreshold : kwsThresholds) {
|
|
|
maxList.add(new BigDecimal(kwsThreshold.getMax()));
|
|
|
minList.add(new BigDecimal(kwsThreshold.getMin()));
|
|
|
@@ -261,9 +303,9 @@ public class MqttCallbackHandler {
|
|
|
map.put("level", "1");
|
|
|
map.put("thresholdId", "1");
|
|
|
map.put("flag", "1");
|
|
|
- if (min != null && max != null) {
|
|
|
+ if (min != null || max != null) {
|
|
|
if (max != null) {
|
|
|
- Long level = maxMap.get(max);
|
|
|
+ Long level = maxMap.get(max.toString());
|
|
|
Long thresholdId = maxMap.get(level.toString());
|
|
|
map.put("level", level.toString());
|
|
|
map.put("thresholdId", thresholdId.toString());
|
|
|
@@ -271,7 +313,7 @@ public class MqttCallbackHandler {
|
|
|
// insertAlarmAndDetail(level, device, thresholdId, itemValue, ts);
|
|
|
}
|
|
|
if (min != null) {
|
|
|
- Long level = minMap.get(min);
|
|
|
+ Long level = minMap.get(min.toString());
|
|
|
Long thresholdId = minMap.get(level.toString());
|
|
|
map.put("level", level.toString());
|
|
|
map.put("thresholdId", thresholdId.toString());
|
|
|
@@ -285,6 +327,16 @@ public class MqttCallbackHandler {
|
|
|
Map<String, Long> minMap = new HashMap<>();
|
|
|
List<BigDecimal> maxList = new ArrayList<>();
|
|
|
List<BigDecimal> minList = new ArrayList<>();
|
|
|
+ for (KwsThreshold kwsThreshold : kwsThresholds) {
|
|
|
+ String max = kwsThreshold.getMax();
|
|
|
+ Long thresholdId = kwsThreshold.getId();
|
|
|
+ String min = kwsThreshold.getMin();
|
|
|
+ Integer level = kwsThreshold.getLevel();
|
|
|
+ maxMap.put(max, level.longValue());
|
|
|
+ maxMap.put(level.toString(), thresholdId.longValue());
|
|
|
+ minMap.put(min, level.longValue());
|
|
|
+ minMap.put(level.toString(), thresholdId.longValue());
|
|
|
+ }
|
|
|
for (KwsThreshold kwsThreshold : kwsThresholds) {
|
|
|
maxList.add(new BigDecimal(kwsThreshold.getMax()));
|
|
|
minList.add(new BigDecimal(kwsThreshold.getMin()));
|
|
|
@@ -348,20 +400,78 @@ public class MqttCallbackHandler {
|
|
|
* @param thresholdId 阈值id/设备id
|
|
|
* @param itemValue td数据当时检测值
|
|
|
* @param ts td时间
|
|
|
+ * @param alarmTitle 设备类型明细
|
|
|
+ * @param type 设备类型
|
|
|
*/
|
|
|
- private void insertAlarmAndDetail(Long level, KwsDevice device, Long thresholdId, String itemValue, Long ts) {
|
|
|
+ private long insertAlarmAndDetail(Long level, KwsDevice device, Long thresholdId,
|
|
|
+ String itemValue, Long ts,
|
|
|
+ String alarmTitle, Integer type
|
|
|
+ ) {
|
|
|
Long deviceId = device.getId();
|
|
|
KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
|
|
|
.eq(KwsProjectDevice::getDeviceId, deviceId)
|
|
|
.eq(KwsProjectDevice::getDelFlag, 0)
|
|
|
- .eq(KwsProjectDevice::getStatus, 0)
|
|
|
.orderByDesc(KwsProjectDevice::getCreateTime)
|
|
|
.last(" limit 1")
|
|
|
);
|
|
|
+ //新增未读数据
|
|
|
+ long alarmId = insertUnread(level, device, thresholdId, itemValue, ts, alarmTitle, type, deviceId, projectDevice);
|
|
|
+ //新增历史数据
|
|
|
+ insertHistoryRead(level, device, thresholdId, itemValue, ts, alarmTitle, type, deviceId, projectDevice);
|
|
|
+
|
|
|
+ return alarmId;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void insertHistoryRead(Long level, KwsDevice device, Long thresholdId, String itemValue, Long ts, String alarmTitle, Integer type, Long deviceId, KwsProjectDevice projectDevice) {
|
|
|
LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
|
|
|
.eq(KwsAlarm::getLevel, level.intValue())
|
|
|
.eq(KwsAlarm::getDeviceId, deviceId)
|
|
|
- .eq(KwsAlarm::getType, NumberConstant.ONE)
|
|
|
+ .eq(KwsAlarm::getStatus, NumberConstant.ONE)
|
|
|
+ .eq(KwsAlarm::getType, type)
|
|
|
+ .orderByDesc(KwsAlarm::getCreateTime);
|
|
|
+ if (projectDevice != null) {
|
|
|
+ wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
|
|
|
+ .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
|
|
|
+ if (projectDevice.getProjectId() != null) {
|
|
|
+ wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ long alarmId = new IdWorker(NumberConstant.ONE).nextId();
|
|
|
+ List<KwsAlarm> alarms = alarmMapper.selectList(wrapper);
|
|
|
+ if (CollectionUtils.isEmpty(alarms)) {
|
|
|
+ KwsAlarm alarm = new KwsAlarm();
|
|
|
+ String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
|
|
|
+ String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
|
|
|
+ String projectId = projectDevice == null ? null :
|
|
|
+ (projectDevice.getProjectId() == null ? null : projectDevice.getProjectId().toString());
|
|
|
+ alarm.setId(alarmId);
|
|
|
+ alarm.setCompanyId(companyId);
|
|
|
+ alarm.setMountainId(mountainId);
|
|
|
+ alarm.setProjectId(projectId);
|
|
|
+ alarm.setDeviceId(deviceId);
|
|
|
+ alarm.setTitle(alarmTitle);
|
|
|
+ alarm.setLevel(level.intValue());
|
|
|
+ alarm.setType(type);
|
|
|
+ LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ alarm.setCreateTime(localDateTime);
|
|
|
+ alarm.setUpdateTime(localDateTime);
|
|
|
+ alarm.setStatus(1);
|
|
|
+ alarm.setTriggerTimes(0);
|
|
|
+ alarm.setIsHistory(1);
|
|
|
+ alarmMapper.insert(alarm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private long insertUnread(Long level, KwsDevice device, Long thresholdId,
|
|
|
+ String itemValue, Long ts,
|
|
|
+ String alarmTitle, Integer type, Long deviceId, KwsProjectDevice projectDevice) {
|
|
|
+ LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
|
|
|
+ .eq(KwsAlarm::getLevel, level.intValue())
|
|
|
+ .eq(KwsAlarm::getDeviceId, deviceId)
|
|
|
+ .eq(KwsAlarm::getStatus, NumberConstant.ZERO)
|
|
|
+ .eq(KwsAlarm::getType, type)
|
|
|
+ .eq(KwsAlarm::getIsHistory, NumberConstant.ZERO)
|
|
|
+ .eq(KwsAlarm::getDelFlag, NumberConstant.ZERO)
|
|
|
.orderByDesc(KwsAlarm::getCreateTime);
|
|
|
if (projectDevice != null) {
|
|
|
wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
|
|
|
@@ -370,10 +480,10 @@ public class MqttCallbackHandler {
|
|
|
wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
|
|
|
}
|
|
|
}
|
|
|
+ long alarmId = new IdWorker(NumberConstant.ONE).nextId();
|
|
|
List<KwsAlarm> alarms = alarmMapper.selectList(wrapper);
|
|
|
if (CollectionUtils.isEmpty(alarms)) {
|
|
|
KwsAlarm alarm = new KwsAlarm();
|
|
|
- long alarmId = new IdWorker(NumberConstant.ONE).nextId();
|
|
|
String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
|
|
|
String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
|
|
|
String projectId = projectDevice == null ? null :
|
|
|
@@ -383,13 +493,15 @@ public class MqttCallbackHandler {
|
|
|
alarm.setMountainId(mountainId);
|
|
|
alarm.setProjectId(projectId);
|
|
|
alarm.setDeviceId(deviceId);
|
|
|
- alarm.setTitle("2");
|
|
|
+ alarm.setTitle(alarmTitle);
|
|
|
alarm.setLevel(level.intValue());
|
|
|
- alarm.setType(2);
|
|
|
- LocalDateTime localDateTime = new Date(ts).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
|
|
|
+ alarm.setType(type);
|
|
|
+ LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+// LocalDateTime localDateTime = new Date(ts).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
|
|
|
alarm.setCreateTime(localDateTime);
|
|
|
alarm.setUpdateTime(localDateTime);
|
|
|
alarm.setStatus(0);
|
|
|
+ alarm.setTriggerTimes(1);
|
|
|
alarmMapper.insert(alarm);
|
|
|
KwsAlarmDetail alarmDetail = new KwsAlarmDetail();
|
|
|
alarmDetail.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
@@ -399,18 +511,51 @@ public class MqttCallbackHandler {
|
|
|
alarmDetail.setPid(thresholdId);
|
|
|
alarmDetail.setVal(itemValue);
|
|
|
alarmDetail.setLat(device.getLogicLat());
|
|
|
- alarmDetail.setLng(device.getLogicAlt());
|
|
|
+ alarmDetail.setLng(device.getLogicLng());
|
|
|
alarmDetail.setAlt(device.getLogicAlt());
|
|
|
alarmDetail.setCreateTime(localDateTime);
|
|
|
alarmDetail.setUpdateTime(localDateTime);
|
|
|
alarmDetail.setStatus(0);
|
|
|
+ alarmDetail.setDelFlag(NumberConstant.ZERO);
|
|
|
+ alarmDetail.setIsHistory(NumberConstant.ZERO);
|
|
|
alarmDetailMapper.insert(alarmDetail);
|
|
|
} else {
|
|
|
+ alarmId = alarms.get(0).getId();
|
|
|
KwsAlarm alarm = alarms.get(0);
|
|
|
- LocalDateTime localDateTime = new Date(ts).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
|
|
|
+ LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+// LocalDateTime localDateTime = new Date(ts).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
|
|
|
alarm.setUpdateTime(localDateTime);
|
|
|
+ alarm.setStatus(0);
|
|
|
+ Long aLong = alarmDetailMapper.selectCount(new LambdaQueryWrapper<KwsAlarmDetail>()
|
|
|
+ .eq(KwsAlarmDetail::getAlarmId, alarmId)
|
|
|
+ .eq(KwsAlarmDetail::getStatus, 0)
|
|
|
+ .eq(KwsAlarmDetail::getIsHistory, 0)
|
|
|
+ .eq(KwsAlarmDetail::getDelFlag, 0)
|
|
|
+ );
|
|
|
+ alarm.setTriggerTimes(aLong.intValue() + 1);
|
|
|
alarmMapper.updateById(alarm);
|
|
|
+ String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
|
|
|
+ String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
|
|
|
+ String projectId = projectDevice == null ? null :
|
|
|
+ (projectDevice.getProjectId() == null ? null : projectDevice.getProjectId().toString());
|
|
|
+ KwsAlarmDetail alarmDetail = new KwsAlarmDetail();
|
|
|
+ alarmDetail.setId(new IdWorker(NumberConstant.TWO).nextId());
|
|
|
+ alarmDetail.setMountainId(mountainId);
|
|
|
+ alarmDetail.setCompanyId(companyId);
|
|
|
+ alarmDetail.setAlarmId(alarm.getId());
|
|
|
+ alarmDetail.setPid(thresholdId);
|
|
|
+ alarmDetail.setVal(itemValue);
|
|
|
+ alarmDetail.setLat(device.getLogicLat());
|
|
|
+ alarmDetail.setLng(device.getLogicLng());
|
|
|
+ alarmDetail.setAlt(device.getLogicAlt());
|
|
|
+ alarmDetail.setCreateTime(localDateTime);
|
|
|
+ alarmDetail.setUpdateTime(localDateTime);
|
|
|
+ alarmDetail.setStatus(0);
|
|
|
+ alarmDetail.setDelFlag(NumberConstant.ZERO);
|
|
|
+ alarmDetail.setIsHistory(NumberConstant.ZERO);
|
|
|
+ alarmDetailMapper.insert(alarmDetail);
|
|
|
}
|
|
|
+ return alarmId;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -439,21 +584,30 @@ public class MqttCallbackHandler {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
+
|
|
|
+ Long ts = 1700969880l;
|
|
|
+ Instant timestamp = Instant.ofEpochSecond(ts);
|
|
|
+
|
|
|
+ ts = ts * 1000;
|
|
|
+ Instant instant = new Date(ts).toInstant();
|
|
|
+ OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.of("+8"));
|
|
|
+ LocalDateTime timeLocalDateTime = offsetDateTime.toLocalDateTime();
|
|
|
+
|
|
|
+ instant = Instant.ofEpochMilli(ts);
|
|
|
+ ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
|
|
|
+ LocalDateTime localDateTimes = zonedDateTime.toLocalDateTime();
|
|
|
+ System.out.println(localDateTimes);
|
|
|
+
|
|
|
+ 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();
|
|
|
- alarm.setGuid("s8");
|
|
|
List<DevicesItem> list = new ArrayList<>();
|
|
|
DevicesItem item = new DevicesItem();
|
|
|
item.setItemName("alt");
|
|
|
item.setItemValue("20.12646584");
|
|
|
long time = new Date().getTime();
|
|
|
-// item.setTs(new Date().getTime());
|
|
|
String md5 = new MD5Utils().getMd5(String.valueOf(time));
|
|
|
-// item.setGuid(md5);
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
String format = simpleDateFormat.format(new Date());
|
|
|
-// item.setTslverId(format);
|
|
|
-// item.setMsgId(format);
|
|
|
-// item.setRawTs(format);
|
|
|
list.add(item);
|
|
|
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\"}]}";
|
|
|
@@ -474,3 +628,4 @@ public class MqttCallbackHandler {
|
|
|
System.out.println(min);
|
|
|
}
|
|
|
}
|
|
|
+
|