|
|
@ -1,12 +1,14 @@
|
|
|
|
package com.shxy.xymanager_framework.timeTask;
|
|
|
|
package com.shxy.xymanager_framework.timeTask;
|
|
|
|
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
|
|
|
import com.shxy.xymanager_common.entity.MntnActivities;
|
|
|
|
import com.shxy.xymanager_common.entity.MntnRawReports;
|
|
|
|
import com.shxy.xymanager_common.entity.MntnRawReports;
|
|
|
|
import com.shxy.xymanager_common.entity.MntnRawReportsExample;
|
|
|
|
import com.shxy.xymanager_common.entity.MntnRawReportsExample;
|
|
|
|
import com.shxy.xymanager_common.entity.Terminals;
|
|
|
|
import com.shxy.xymanager_common.entity.Terminals;
|
|
|
|
import com.shxy.xymanager_common.util.DateUtil;
|
|
|
|
|
|
|
|
import com.shxy.xymanager_common.util.DingTalkPushUtil;
|
|
|
|
import com.shxy.xymanager_common.util.DingTalkPushUtil;
|
|
|
|
|
|
|
|
import com.shxy.xymanager_dao.dao.MntnActivitiesMapper;
|
|
|
|
import com.shxy.xymanager_dao.dao.MntnRawReportsMapper;
|
|
|
|
import com.shxy.xymanager_dao.dao.MntnRawReportsMapper;
|
|
|
|
|
|
|
|
import com.shxy.xymanager_service.service.ActivitiesService;
|
|
|
|
import com.shxy.xymanager_service.service.NewCacheService;
|
|
|
|
import com.shxy.xymanager_service.service.NewCacheService;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
@ -25,7 +27,9 @@ public class MntnCheckTask {
|
|
|
|
private int minutes = 60;
|
|
|
|
private int minutes = 60;
|
|
|
|
private int maxCount = 50;
|
|
|
|
private int maxCount = 50;
|
|
|
|
private int maxDay = 3;
|
|
|
|
private int maxDay = 3;
|
|
|
|
private HashMap<Integer, Long> doneMap = new HashMap<>();
|
|
|
|
private int lostPer = 10;
|
|
|
|
|
|
|
|
private HashMap<Integer, Long> warnMap = new HashMap<>();
|
|
|
|
|
|
|
|
private HashMap<Integer, Long> lostMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${maintain.check}")
|
|
|
|
@Value("${maintain.check}")
|
|
|
|
private boolean needCheck;
|
|
|
|
private boolean needCheck;
|
|
|
@ -34,6 +38,10 @@ public class MntnCheckTask {
|
|
|
|
MntnRawReportsMapper rawReportsMapper;
|
|
|
|
MntnRawReportsMapper rawReportsMapper;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
NewCacheService newCacheService;
|
|
|
|
NewCacheService newCacheService;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
ActivitiesService activitiesService;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
MntnActivitiesMapper activitiesMapper;
|
|
|
|
|
|
|
|
|
|
|
|
private int shutdown = 0;
|
|
|
|
private int shutdown = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -44,13 +52,14 @@ public class MntnCheckTask {
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 0 9,13 * * MON-FRI")
|
|
|
|
@Scheduled(cron = "0 0 9,13 * * MON-FRI")
|
|
|
|
private void clear() {
|
|
|
|
private void clear() {
|
|
|
|
doneMap.clear();
|
|
|
|
warnMap.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(initialDelay = 60000, fixedDelay = 60 * 5 * 1000)
|
|
|
|
@Scheduled(initialDelay = 60000, fixedDelay = 60 * 5 * 1000)
|
|
|
|
private void checkAll() {
|
|
|
|
private void checkAll() {
|
|
|
|
if (needCheck) {
|
|
|
|
if (needCheck) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
lostMap.clear();
|
|
|
|
log.info("MntnCheckTask.checkAll 开始.");
|
|
|
|
log.info("MntnCheckTask.checkAll 开始.");
|
|
|
|
Map<Integer, Terminals> terminalMap = newCacheService.getTerminalMap();
|
|
|
|
Map<Integer, Terminals> terminalMap = newCacheService.getTerminalMap();
|
|
|
|
Iterator<Integer> it = terminalMap.keySet().iterator();
|
|
|
|
Iterator<Integer> it = terminalMap.keySet().iterator();
|
|
|
@ -58,6 +67,23 @@ public class MntnCheckTask {
|
|
|
|
Integer termId = it.next();
|
|
|
|
Integer termId = it.next();
|
|
|
|
this.checkOne(termId);
|
|
|
|
this.checkOne(termId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<MntnActivities> activityList = activitiesService.listAll();
|
|
|
|
|
|
|
|
for (MntnActivities activity : activityList) {
|
|
|
|
|
|
|
|
int lostCount = 0;
|
|
|
|
|
|
|
|
for (Terminals term : activity.getTerms()) {
|
|
|
|
|
|
|
|
if (lostMap.containsKey(term.getId())) {
|
|
|
|
|
|
|
|
lostCount++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
activity.setLostCount(lostCount);
|
|
|
|
|
|
|
|
activitiesMapper.updateByPrimaryKeySelective(activity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int lost = lostCount * 100 / activity.getTermCount();
|
|
|
|
|
|
|
|
if (lost >= lostPer) {
|
|
|
|
|
|
|
|
this.sendWarningLost(activity, lostCount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
log.info("MntnCheckTask.checkAll 结束.");
|
|
|
|
log.info("MntnCheckTask.checkAll 结束.");
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("MntnCheckTask.checkAll error.", e);
|
|
|
|
log.error("MntnCheckTask.checkAll error.", e);
|
|
|
@ -79,7 +105,7 @@ public class MntnCheckTask {
|
|
|
|
long count = rawReportsMapper.countByExample(example);
|
|
|
|
long count = rawReportsMapper.countByExample(example);
|
|
|
|
if (count > maxCount) {
|
|
|
|
if (count > maxCount) {
|
|
|
|
this.sendWarningCount(term, count);
|
|
|
|
this.sendWarningCount(term, count);
|
|
|
|
} else if (count <= 0 && term.getIsfavor() != null && term.getIsfavor().intValue() == 1) {
|
|
|
|
} else if (count <= 0) {
|
|
|
|
example = new MntnRawReportsExample();
|
|
|
|
example = new MntnRawReportsExample();
|
|
|
|
criteria = example.createCriteria();
|
|
|
|
criteria = example.createCriteria();
|
|
|
|
criteria.andTermIdEqualTo(termId);
|
|
|
|
criteria.andTermIdEqualTo(termId);
|
|
|
@ -89,9 +115,8 @@ public class MntnCheckTask {
|
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
Long lasttime = list.get(0).getCreateTime();
|
|
|
|
Long lasttime = list.get(0).getCreateTime();
|
|
|
|
long days = (System.currentTimeMillis() / 1000 - lasttime) / 60 / 60 / 24;
|
|
|
|
long days = (System.currentTimeMillis() / 1000 - lasttime) / 60 / 60 / 24;
|
|
|
|
if (days > maxDay) {
|
|
|
|
if (days >= maxDay) {
|
|
|
|
Date date = new Date(lasttime * 1000);
|
|
|
|
lostMap.put(termId, days);
|
|
|
|
this.sendWarningDay(term, date, days);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -102,29 +127,27 @@ public class MntnCheckTask {
|
|
|
|
String str = "装置" + term.getCmdid() + "最近" + minutes + "分钟内,运维报送次数:" + count
|
|
|
|
String str = "装置" + term.getCmdid() + "最近" + minutes + "分钟内,运维报送次数:" + count
|
|
|
|
+ "次, 超过设定的阈值" + maxCount + "次;";
|
|
|
|
+ "次, 超过设定的阈值" + maxCount + "次;";
|
|
|
|
|
|
|
|
|
|
|
|
if (doneMap.containsKey(term.getId())) {
|
|
|
|
if (warnMap.containsKey(term.getId())) {
|
|
|
|
Long cnt = doneMap.get(term.getId());
|
|
|
|
Long cnt = warnMap.get(term.getId());
|
|
|
|
cnt++;
|
|
|
|
cnt++;
|
|
|
|
doneMap.put(term.getId(), cnt);
|
|
|
|
warnMap.put(term.getId(), cnt);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
doneMap.put(term.getId(), 1L);
|
|
|
|
warnMap.put(term.getId(), 1L);
|
|
|
|
log.warn(str);
|
|
|
|
log.warn(str);
|
|
|
|
DingTalkPushUtil.alertYW.add(str);
|
|
|
|
DingTalkPushUtil.alertYW.add(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendWarningDay(Terminals term, Date date, long days) {
|
|
|
|
private void sendWarningLost(MntnActivities activity, int lostCount) {
|
|
|
|
String str = "装置" + term.getCmdid() + "距离最后一次报送时间" + DateUtil.format(date)
|
|
|
|
String str = "活动--" + activity.getTitle() + "里的装置掉线超过" + maxDay + "天的有"
|
|
|
|
+ "已过" + days + "天,超过设定的阈值" + maxDay + "天;";
|
|
|
|
+ lostCount + "台,超过设定的阈值" + lostPer + "%;";
|
|
|
|
|
|
|
|
|
|
|
|
if (doneMap.containsKey(term.getId())) {
|
|
|
|
int id = activity.getId() - 100000;
|
|
|
|
Long cnt = doneMap.get(term.getId());
|
|
|
|
if (!warnMap.containsKey(id)) {
|
|
|
|
cnt++;
|
|
|
|
warnMap.put(id, 1L);
|
|
|
|
doneMap.put(term.getId(), cnt);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
doneMap.put(term.getId(), 1L);
|
|
|
|
|
|
|
|
log.warn(str);
|
|
|
|
log.warn(str);
|
|
|
|
DingTalkPushUtil.alertYW.add(str);
|
|
|
|
DingTalkPushUtil.alertYW.add(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|