feat: 增加低电压告警

dev
huangfeng 9 months ago
parent 91f8134686
commit bb19b442ab

@ -11,8 +11,10 @@ import java.util.HashMap;
@Service @Service
public class ClearCacheTask { public class ClearCacheTask {
public static HashMap<Integer, Long> warnMap = new HashMap<>(); public static HashMap<Integer, Long> reportCountMap = new HashMap<>();
public static HashMap<Integer, Long> activityMap = new HashMap<>();
public static HashMap<String, Long> heartbeatMap = new HashMap<>(); public static HashMap<String, Long> heartbeatMap = new HashMap<>();
public static HashMap<Integer, Long> lowVoltMap = new HashMap<>();
@Resource @Resource
NewCacheService newCacheService; NewCacheService newCacheService;
@ -24,13 +26,15 @@ public class ClearCacheTask {
@Scheduled(cron = "0 0 9 * * MON-FRI") @Scheduled(cron = "0 0 9 * * MON-FRI")
private void clearWarnMap() { private void clearWarnMap() {
warnMap.clear(); reportCountMap.clear();
activityMap.clear();
heartbeatMap.clear(); heartbeatMap.clear();
} }
@Scheduled(cron = "0 0 10 * * ?") @Scheduled(cron = "0 0 10 * * ?")
private void clearFubin() { private void clearFubin() {
PulliceModel.fubinDoneMap.clear(); PulliceModel.fubinDoneMap.clear();
lowVoltMap.clear();
} }
} }

@ -28,6 +28,7 @@ public class MntnCheckTask {
private int maxCount = 50; private int maxCount = 50;
private int maxDay = 3; private int maxDay = 3;
private int lostPer = 10; private int lostPer = 10;
private float lowVolt = 15;
public HashMap<Integer, Long> lostingMap = new HashMap<>(); public HashMap<Integer, Long> lostingMap = new HashMap<>();
private HashMap<Integer, Long> _lostMap; private HashMap<Integer, Long> _lostMap;
@ -97,38 +98,57 @@ public class MntnCheckTask {
MntnRawReportsExample.Criteria criteria = example.createCriteria(); MntnRawReportsExample.Criteria criteria = example.createCriteria();
criteria.andTermIdEqualTo(termId); criteria.andTermIdEqualTo(termId);
criteria.andCreateTimeGreaterThan(time); criteria.andCreateTimeGreaterThan(time);
if (shutdown == 0) { if (shutdown == 1) {
long count = rawReportsMapper.countByExample(example); return;
if (count > maxCount) { }
this.sendWarningCount(term, count); long count = rawReportsMapper.countByExample(example);
} else if (count <= 0) { if (count > maxCount) {
example = new MntnRawReportsExample(); this.sendWarningCount(term, count);
criteria = example.createCriteria(); }
criteria.andTermIdEqualTo(termId);
example.setOrderByClause("create_time desc"); example = new MntnRawReportsExample();
PageHelper.startPage(1, 1); criteria = example.createCriteria();
List<MntnRawReports> list = rawReportsMapper.selectByExample(example); criteria.andTermIdEqualTo(termId);
if (!CollectionUtils.isEmpty(list)) { example.setOrderByClause("create_time desc");
Long lasttime = list.get(0).getCreateTime(); PageHelper.startPage(1, 1);
long days = (System.currentTimeMillis() / 1000 - lasttime) / 60 / 60 / 24; List<MntnRawReports> list = rawReportsMapper.selectByExample(example);
if (days >= maxDay) { if (!CollectionUtils.isEmpty(list)) {
_lostMap.put(termId, days); MntnRawReports last = list.get(0);
Long lasttime = last.getCreateTime();
long days = (System.currentTimeMillis() / 1000 - lasttime) / 60 / 60 / 24;
if (days >= maxDay) {
_lostMap.put(termId, days);
} else {
last.makeRawReport();
try {
Object chargeVolt = last.getReportMap().get("batteryChargingVoltage");
float volt = Float.parseFloat(chargeVolt.toString());
if (volt < lowVolt) {
// this.sendWarningLowVolt(term, chargeVolt);
} }
} catch (Exception ignore) {
} }
} }
} }
} }
private void sendWarningLowVolt(Terminals term, Object chargeVolt) {
String str = "装置" + term.getCmdid() + "最新充电电压" + chargeVolt
+ "V, 低于设定的阈值" + lowVolt + "V;";
if (!ClearCacheTask.lowVoltMap.containsKey(term.getId())) {
ClearCacheTask.lowVoltMap.put(term.getId(), 1L);
log.warn(str);
DingTalkPushUtil.alertYW.add(str);
}
}
private void sendWarningCount(Terminals term, long count) { private void sendWarningCount(Terminals term, long count) {
String str = "装置" + term.getCmdid() + "最近" + minutes + "分钟内,运维报送次数:" + count String str = "装置" + term.getCmdid() + "最近" + minutes + "分钟内,运维报送次数:" + count
+ "次, 超过设定的阈值" + maxCount + "次;"; + "次, 超过设定的阈值" + maxCount + "次;";
if (ClearCacheTask.warnMap.containsKey(term.getId())) { if (!ClearCacheTask.reportCountMap.containsKey(term.getId())) {
Long cnt = ClearCacheTask.warnMap.get(term.getId()); ClearCacheTask.reportCountMap.put(term.getId(), 1L);
cnt++;
ClearCacheTask.warnMap.put(term.getId(), cnt);
} else {
ClearCacheTask.warnMap.put(term.getId(), 1L);
log.warn(str); log.warn(str);
DingTalkPushUtil.alertYW.add(str); DingTalkPushUtil.alertYW.add(str);
} }
@ -139,8 +159,8 @@ public class MntnCheckTask {
+ maxDay + "天的有" + lostCount + "台,超过设定的阈值" + lostPer + "%;"; + maxDay + "天的有" + lostCount + "台,超过设定的阈值" + lostPer + "%;";
int id = activity.getId() - 100000; int id = activity.getId() - 100000;
if (!ClearCacheTask.warnMap.containsKey(id)) { if (!ClearCacheTask.activityMap.containsKey(id)) {
ClearCacheTask.warnMap.put(id, 1L); ClearCacheTask.activityMap.put(id, 1L);
log.warn(str); log.warn(str);
DingTalkPushUtil.alertYW.add(str); DingTalkPushUtil.alertYW.add(str);
} }

Loading…
Cancel
Save