|
|
@@ -3,6 +3,7 @@ package com.sckw.slope.detection.consumer;
|
|
|
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.Global;
|
|
|
import com.sckw.core.model.constant.NumberConstant;
|
|
|
import com.sckw.core.model.enums.AlarmTitleEnum;
|
|
|
import com.sckw.core.model.enums.AlarmTypeEnum;
|
|
|
@@ -12,11 +13,13 @@ import com.sckw.core.utils.DateUtils;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.log.TraceLog.TraceLog;
|
|
|
+import com.sckw.redis.utils.RedissonUtils;
|
|
|
import com.sckw.slope.detection.dao.mysql.*;
|
|
|
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;
|
|
|
import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
|
|
|
+import com.sckw.slope.detection.model.dto.AlarmList;
|
|
|
import com.sckw.slope.detection.model.dto.DevicesAlarm;
|
|
|
import com.sckw.slope.detection.model.dto.DevicesItem;
|
|
|
import com.sckw.slope.detection.model.param.SmsMessageParam;
|
|
|
@@ -25,11 +28,13 @@ import com.sckw.slope.detection.service.CommonService;
|
|
|
import com.sckw.slope.detection.service.TdengineService;
|
|
|
import com.sckw.slope.detection.service.api.DetectionApiService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.dubbo.common.utils.MD5Utils;
|
|
|
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;
|
|
|
@@ -134,7 +139,7 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
// ts = ts * 1000;
|
|
|
// }
|
|
|
//判断是否满足设备超时离线报警
|
|
|
- checkDeviceAlarm(deviceCode, device, itemValue, ts);
|
|
|
+// checkDeviceAlarm(deviceCode, device, itemValue, ts);
|
|
|
//判断是否满足数值超阈值报警
|
|
|
Map<String, String> map = checkThresholdAlarm(devicesItem, kwsThresholds, device);
|
|
|
if ("2".equals(map.get("flag"))) {
|
|
|
@@ -144,26 +149,14 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
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);
|
|
|
-// }
|
|
|
-
|
|
|
+// redisPutAlarmCount(id);
|
|
|
/*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
|
|
|
设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
|
|
|
Map<String, Object> messageMap = new HashMap<>();
|
|
|
pushSmsMessage(messageUrl, device, level, thresholdId, messageMap);
|
|
|
}
|
|
|
//集成要素阈值告警
|
|
|
-// deviceIntegrationsAlarm(device);
|
|
|
+ deviceIntegrationsAlarm(device,ts);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -172,7 +165,22 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
return HttpResult.ok();
|
|
|
}
|
|
|
|
|
|
- private void deviceIntegrationsAlarm(KwsDevice device) {
|
|
|
+ private void redisPutAlarmCount(long id) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deviceIntegrationsAlarm(KwsDevice device,Long ts) {
|
|
|
List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(
|
|
|
new LambdaQueryWrapper<KwsDeviceIntegration>()
|
|
|
.eq(KwsDeviceIntegration::getDeviceId, device.getId())
|
|
|
@@ -196,13 +204,25 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
String snCode = device.getSnCode();
|
|
|
intergData = deviceIntegrationMapper.selectListParamsAndInterNameByDeviceId(device.getId());
|
|
|
if (!Objects.isNull(intergData)) {
|
|
|
- for (DeviceIntegrationVo inter : intergData) {
|
|
|
+ for (DeviceIntegrationVo deviceIntegration : intergData) {
|
|
|
//获取到当前测量值--现在只有单一值
|
|
|
- List<SlopeData> slopeData = slopeDataMapper.selectListByTwoLine(snCode, inter.getPartNames());
|
|
|
+ List<SlopeData> slopeData = slopeDataMapper.selectListByTwoLine(snCode, deviceIntegration.getPartNames());
|
|
|
if (!Objects.isNull(slopeData)) {
|
|
|
- double offset = commonService.returnIntegrationData(snCode,slopeData,inter);
|
|
|
+ List<KwsThreshold> thresholdList = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
|
|
|
+ .eq(KwsThreshold::getDeviceId, device.getId())
|
|
|
+ .eq(KwsThreshold::getItemName, deviceIntegration.getPartNames())
|
|
|
+ );
|
|
|
+ double offset = commonService.returnIntegrationData(snCode, slopeData, deviceIntegration);
|
|
|
+ Map<String, String> map = newAlarmCompute(new BigDecimal(offset), thresholdList);
|
|
|
+ if ("2".equals(map.get("flag"))) {
|
|
|
+ Long level = Long.valueOf(map.get("level"));
|
|
|
+ Long thresholdId = Long.valueOf(map.get("thresholdId"));
|
|
|
+ //阈值表以及明细表存储
|
|
|
+ long id = insertAlarmAndDetail(level, device, thresholdId, deviceIntegration.getPartNames(), ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
+ Map<String, Object> messageMap = new HashMap<>();
|
|
|
+ pushSmsMessage(messageUrl, device, level, thresholdId, messageMap);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -304,6 +324,23 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
checkItemName.add(DictItemEnum.ALTITUDE_Z.getValue());
|
|
|
checkItemName.add(DictItemEnum.LONGITUDE_X.getValue());
|
|
|
checkItemName.add(DictItemEnum.LATITUDE_Y.getValue());
|
|
|
+ //放入告警数值-告警等级
|
|
|
+ //放入告警等级-告警主键id
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ if (checkItemName.contains(itemName)) {
|
|
|
+ BigDecimal offset = commonService.computeOffset(itemValue, itemName, deviceRelation);
|
|
|
+ map = newAlarmCompute(offset, kwsThresholds);
|
|
|
+ } else {
|
|
|
+ map = newAlarmCompute(new BigDecimal(itemValue), kwsThresholds);
|
|
|
+ }
|
|
|
+// map = oldAlarmCompute(checkItemName, itemName, itemValue, deviceRelation, kwsThresholds);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 之前的阈值告警计算方式
|
|
|
+ */
|
|
|
+ private Map<String, String> oldAlarmCompute(List<String> checkItemName, String itemName, String itemValue, KwsDeviceReference deviceRelation, List<KwsThreshold> kwsThresholds) {
|
|
|
//需要计算的阈值
|
|
|
if (checkItemName.contains(itemName)) {
|
|
|
BigDecimal offset = commonService.computeOffset(itemValue, itemName, deviceRelation);
|
|
|
@@ -445,6 +482,65 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private Map<String, String> newAlarmCompute(BigDecimal offset, List<KwsThreshold> kwsThresholds) {
|
|
|
+ //最大值从大到小计算 告警阈值
|
|
|
+ List<AlarmList> maxAlarmList = new ArrayList<>();
|
|
|
+ for (KwsThreshold kwsThreshold : kwsThresholds) {
|
|
|
+ if (kwsThreshold.getMax() != null) {
|
|
|
+ AlarmList alarmList = new AlarmList();
|
|
|
+ alarmList.setLevel(kwsThreshold.getLevel().toString());
|
|
|
+ alarmList.setId(kwsThreshold.getId());
|
|
|
+ alarmList.setValue(new BigDecimal(kwsThreshold.getMax()));
|
|
|
+ maxAlarmList.add(alarmList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //最小值从小到大计算 告警阈值
|
|
|
+ List<AlarmList> minAlarmList = new ArrayList<>();
|
|
|
+ for (KwsThreshold kwsThreshold : kwsThresholds) {
|
|
|
+ if (kwsThreshold.getMin() != null) {
|
|
|
+ AlarmList alarmList = new AlarmList();
|
|
|
+ alarmList.setLevel(kwsThreshold.getLevel().toString());
|
|
|
+ alarmList.setId(kwsThreshold.getId());
|
|
|
+ alarmList.setValue(new BigDecimal(kwsThreshold.getMin()));
|
|
|
+ minAlarmList.add(alarmList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ maxAlarmList = maxAlarmList.stream().sorted(Comparator.comparing(AlarmList::getValue).reversed()).collect(Collectors.toList());
|
|
|
+// HashMap<Object, Object> maxAlarmMap = kwsThresholds.stream().collect(HashMap::new,
|
|
|
+// (m, v) -> m.put(v.getMax(), v.getId()), HashMap::putAll);
|
|
|
+ minAlarmList = minAlarmList.stream().sorted(Comparator.comparing(AlarmList::getValue)).collect(Collectors.toList());
|
|
|
+// HashMap<Object, Object> mixAlarmMap = kwsThresholds.stream().collect(HashMap::new,
|
|
|
+// (m, v) -> m.put(v.getMax(), v.getId()), HashMap::putAll);
|
|
|
+ String maxLevel = getListMaxNumber(offset, maxAlarmList);
|
|
|
+ String minLevel = getListMinNumber(offset, minAlarmList);
|
|
|
+ /**存在阈值触发*/
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("level", "1");
|
|
|
+ map.put("thresholdId", "1");
|
|
|
+ map.put("flag", "1");
|
|
|
+ if (maxLevel != null || minLevel != null) {
|
|
|
+ if (maxLevel != null) {
|
|
|
+ for (AlarmList alarmList : maxAlarmList) {
|
|
|
+ if (maxLevel.equals(alarmList.getLevel())) {
|
|
|
+ map.put("level", maxLevel);
|
|
|
+ map.put("thresholdId", alarmList.getId().toString());
|
|
|
+ map.put("flag", "2");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (minLevel != null) {
|
|
|
+ for (AlarmList alarmList : maxAlarmList) {
|
|
|
+ if (minLevel.equals(alarmList.getLevel())) {
|
|
|
+ map.put("level", minLevel);
|
|
|
+ map.put("thresholdId", alarmList.getId().toString());
|
|
|
+ map.put("flag", "2");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存阈值主表以及明细表
|
|
|
*
|
|
|
@@ -456,9 +552,10 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
* @param alarmTitle 设备类型明细
|
|
|
* @param type 设备类型
|
|
|
*/
|
|
|
- private long insertAlarmAndDetail(Long level, KwsDevice device, Long thresholdId,
|
|
|
- String itemValue, Long ts,
|
|
|
- String alarmTitle, Integer type
|
|
|
+ @Transactional
|
|
|
+ public 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>()
|
|
|
@@ -475,12 +572,15 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
return alarmId;
|
|
|
}
|
|
|
|
|
|
- private void insertHistoryRead(Long level, KwsDevice device, Long thresholdId, String itemValue, Long ts, String alarmTitle, Integer type, Long deviceId, KwsProjectDevice projectDevice) {
|
|
|
+ public 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::getStatus, NumberConstant.ONE)
|
|
|
.eq(KwsAlarm::getType, type)
|
|
|
+ .eq(KwsAlarm::getLevel, level.intValue())
|
|
|
+ .eq(KwsAlarm::getDeviceId, deviceId)
|
|
|
+ .eq(KwsAlarm::getIsHistory, 1)
|
|
|
+ .eq(KwsAlarm::getTitle, alarmTitle)
|
|
|
+ .eq(KwsAlarm::getDelFlag, 0)
|
|
|
.orderByDesc(KwsAlarm::getCreateTime);
|
|
|
if (projectDevice != null) {
|
|
|
wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
|
|
|
@@ -490,8 +590,8 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
}
|
|
|
}
|
|
|
long alarmId = new IdWorker(NumberConstant.ONE).nextId();
|
|
|
- List<KwsAlarm> alarms = alarmMapper.selectList(wrapper);
|
|
|
- if (CollectionUtils.isEmpty(alarms)) {
|
|
|
+ KwsAlarm alarms = alarmMapper.selectOne(wrapper);
|
|
|
+ if (alarms == null) {
|
|
|
KwsAlarm alarm = new KwsAlarm();
|
|
|
String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
|
|
|
String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
|
|
|
@@ -515,27 +615,18 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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())
|
|
|
- .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
|
|
|
- if (projectDevice.getProjectId() != null) {
|
|
|
- wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
|
|
|
- }
|
|
|
- }
|
|
|
+ public long insertUnread(Long level, KwsDevice device, Long thresholdId,
|
|
|
+ String itemValue, Long ts,
|
|
|
+ String alarmTitle, Integer type, Long deviceId, KwsProjectDevice projectDevice) {
|
|
|
+
|
|
|
long alarmId = new IdWorker(NumberConstant.ONE).nextId();
|
|
|
- List<KwsAlarm> alarms = alarmMapper.selectList(wrapper);
|
|
|
- if (CollectionUtils.isEmpty(alarms)) {
|
|
|
+ KwsAlarm alarms = selectAlarmData(level, deviceId, type, alarmTitle, projectDevice);
|
|
|
+// if (!CollectionUtils.isEmpty() && alarms.size() > 1) {
|
|
|
+// //去重
|
|
|
+// checkAlarmData(alarms, level, deviceId, type, alarmTitle, projectDevice);
|
|
|
+// }
|
|
|
+// alarms = selectAlarmData(level, deviceId, type, alarmTitle, projectDevice);
|
|
|
+ if (alarms == null) {
|
|
|
KwsAlarm alarm = new KwsAlarm();
|
|
|
String mountainId = projectDevice == null ? null : projectDevice.getMountainId();
|
|
|
String companyId = projectDevice == null ? null : projectDevice.getCompanyId();
|
|
|
@@ -573,8 +664,8 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
alarmDetail.setIsHistory(NumberConstant.ZERO);
|
|
|
alarmDetailMapper.insert(alarmDetail);
|
|
|
} else {
|
|
|
- alarmId = alarms.get(0).getId();
|
|
|
- KwsAlarm alarm = alarms.get(0);
|
|
|
+ alarmId = alarms.getId();
|
|
|
+ KwsAlarm alarm = alarms;
|
|
|
LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
// LocalDateTime localDateTime = new Date(ts).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
|
|
|
alarm.setUpdateTime(localDateTime);
|
|
|
@@ -611,6 +702,53 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
return alarmId;
|
|
|
}
|
|
|
|
|
|
+ private KwsAlarm selectAlarmData(Long level, Long deviceId, Integer type, String alarmTitle, 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::getTitle, alarmTitle)
|
|
|
+ .eq(KwsAlarm::getIsHistory, NumberConstant.ZERO)
|
|
|
+ .eq(KwsAlarm::getDelFlag, NumberConstant.ZERO)
|
|
|
+ .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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ KwsAlarm alarms = alarmMapper.selectOne(wrapper);
|
|
|
+ return alarms;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkAlarmData(List<KwsAlarm> alarms, Long level, Long deviceId, Integer type, String alarmTitle, KwsProjectDevice projectDevice) {
|
|
|
+ for (KwsAlarm alarm : alarms) {
|
|
|
+ List<KwsAlarmDetail> details = alarmDetailMapper.selectList(new LambdaQueryWrapper<KwsAlarmDetail>().eq(KwsAlarmDetail::getAlarmId, alarm.getDeviceId()));
|
|
|
+ if (org.springframework.util.CollectionUtils.isEmpty(details) && details.size() == 0) {
|
|
|
+ alarm.setDelFlag(1);
|
|
|
+ alarmMapper.updateById(alarm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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::getTitle, alarmTitle)
|
|
|
+ .eq(KwsAlarm::getIsHistory, NumberConstant.ZERO)
|
|
|
+ .eq(KwsAlarm::getDelFlag, NumberConstant.ZERO)
|
|
|
+ .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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 计算最小值
|
|
|
*
|
|
|
@@ -636,6 +774,31 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private static String getListMaxNumber(BigDecimal number, List<AlarmList> alarmLists) {
|
|
|
+ for (AlarmList list : alarmLists) {
|
|
|
+ if (number.compareTo(list.getValue()) > 0) {
|
|
|
+ return list.getLevel();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算最小值
|
|
|
+ *
|
|
|
+ * @param number
|
|
|
+ * @param alarmLists
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String getListMinNumber(BigDecimal number, List<AlarmList> alarmLists) {
|
|
|
+ for (AlarmList list : alarmLists) {
|
|
|
+ if (number.compareTo(list.getValue()) < 0) {
|
|
|
+ return list.getLevel();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
String s = "2023-11-30 22:00:00";
|
|
|
Date date = DateUtils.formatDate(s);
|