|
|
|
@ -1,16 +1,18 @@
|
|
|
|
|
package com.shxy.xymanager_framework.timeTask;
|
|
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.shxy.xymanager_common.entity.MntnRawReports;
|
|
|
|
|
import com.shxy.xymanager_common.entity.MntnRawReportsExample;
|
|
|
|
|
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_dao.dao.MntnRawReportsMapper;
|
|
|
|
|
import com.shxy.xymanager_service.service.CacheService;
|
|
|
|
|
import com.shxy.xymanager_service.service.NewCacheService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
@ -21,7 +23,8 @@ import java.util.*;
|
|
|
|
|
public class MntnCheckTask {
|
|
|
|
|
|
|
|
|
|
private int minutes = 60;
|
|
|
|
|
private int max = 50;
|
|
|
|
|
private int maxCount = 50;
|
|
|
|
|
private int maxDay = 3;
|
|
|
|
|
private HashMap<Integer, Long> doneMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
@Value("${maintain.check}")
|
|
|
|
@ -74,15 +77,45 @@ public class MntnCheckTask {
|
|
|
|
|
criteria.andCreateTimeGreaterThan(time);
|
|
|
|
|
if (shutdown == 0) {
|
|
|
|
|
long count = rawReportsMapper.countByExample(example);
|
|
|
|
|
if (count > max) {
|
|
|
|
|
this.sendWarning(term, count);
|
|
|
|
|
if (count > maxCount) {
|
|
|
|
|
this.sendWarningCount(term, count);
|
|
|
|
|
} else if (count <= 0) {
|
|
|
|
|
example = new MntnRawReportsExample();
|
|
|
|
|
criteria = example.createCriteria();
|
|
|
|
|
criteria.andTermIdEqualTo(termId);
|
|
|
|
|
example.setOrderByClause("create_time desc");
|
|
|
|
|
PageHelper.startPage(1, 1);
|
|
|
|
|
List<MntnRawReports> list = rawReportsMapper.selectByExample(example);
|
|
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
|
Long lasttime = list.get(0).getCreateTime();
|
|
|
|
|
long days = (System.currentTimeMillis() / 1000 - lasttime) / 60 / 60 / 24;
|
|
|
|
|
if (days > maxDay) {
|
|
|
|
|
Date date = new Date(lasttime * 1000);
|
|
|
|
|
// this.sendWarningDay(term, date, days);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendWarning(Terminals term, long count) {
|
|
|
|
|
private void sendWarningCount(Terminals term, long count) {
|
|
|
|
|
String str = "装置" + term.getCmdid() + "最近" + minutes + "分钟内,运维报送次数:" + count
|
|
|
|
|
+ "次, 超过设定的阈值" + max + "次;";
|
|
|
|
|
+ "次, 超过设定的阈值" + maxCount + "次;";
|
|
|
|
|
|
|
|
|
|
if (doneMap.containsKey(term.getId())) {
|
|
|
|
|
Long cnt = doneMap.get(term.getId());
|
|
|
|
|
cnt++;
|
|
|
|
|
doneMap.put(term.getId(), cnt);
|
|
|
|
|
} else {
|
|
|
|
|
doneMap.put(term.getId(), 1L);
|
|
|
|
|
log.warn(str);
|
|
|
|
|
DingTalkPushUtil.alertYW.add(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendWarningDay(Terminals term, Date date, long days) {
|
|
|
|
|
String str = "装置" + term.getCmdid() + "距离最后一次报送时间" + DateUtil.format(date)
|
|
|
|
|
+ "已过" + days + "天,超过设定的阈值" + maxDay + "天;";
|
|
|
|
|
|
|
|
|
|
if (doneMap.containsKey(term.getId())) {
|
|
|
|
|
Long cnt = doneMap.get(term.getId());
|
|
|
|
@ -90,6 +123,7 @@ public class MntnCheckTask {
|
|
|
|
|
doneMap.put(term.getId(), cnt);
|
|
|
|
|
} else {
|
|
|
|
|
doneMap.put(term.getId(), 1L);
|
|
|
|
|
log.warn(str);
|
|
|
|
|
DingTalkPushUtil.alertYW.add(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|