feat: 增加活动装置掉线告警

dev
huangfeng 10 months ago
parent 85bb2a472f
commit 85218039ae

@ -31,6 +31,15 @@ public class MntnActivities {
*/ */
private Integer termCount; private Integer termCount;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column mntn_activities.lost_count
*
* @mbg.generated
*/
private Integer lostCount;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
@ -130,6 +139,30 @@ public class MntnActivities {
this.termCount = termCount; this.termCount = termCount;
} }
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column mntn_activities.lost_count
*
* @return the value of mntn_activities.lost_count
*
* @mbg.generated
*/
public Integer getLostCount() {
return lostCount;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column mntn_activities.lost_count
*
* @param lostCount the value for mntn_activities.lost_count
*
* @mbg.generated
*/
public void setLostCount(Integer lostCount) {
this.lostCount = lostCount;
}
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column mntn_activities.status * This method returns the value of the database column mntn_activities.status

@ -385,6 +385,66 @@ public class MntnActivitiesExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andLostCountIsNull() {
addCriterion("lost_count is null");
return (Criteria) this;
}
public Criteria andLostCountIsNotNull() {
addCriterion("lost_count is not null");
return (Criteria) this;
}
public Criteria andLostCountEqualTo(Integer value) {
addCriterion("lost_count =", value, "lostCount");
return (Criteria) this;
}
public Criteria andLostCountNotEqualTo(Integer value) {
addCriterion("lost_count <>", value, "lostCount");
return (Criteria) this;
}
public Criteria andLostCountGreaterThan(Integer value) {
addCriterion("lost_count >", value, "lostCount");
return (Criteria) this;
}
public Criteria andLostCountGreaterThanOrEqualTo(Integer value) {
addCriterion("lost_count >=", value, "lostCount");
return (Criteria) this;
}
public Criteria andLostCountLessThan(Integer value) {
addCriterion("lost_count <", value, "lostCount");
return (Criteria) this;
}
public Criteria andLostCountLessThanOrEqualTo(Integer value) {
addCriterion("lost_count <=", value, "lostCount");
return (Criteria) this;
}
public Criteria andLostCountIn(List<Integer> values) {
addCriterion("lost_count in", values, "lostCount");
return (Criteria) this;
}
public Criteria andLostCountNotIn(List<Integer> values) {
addCriterion("lost_count not in", values, "lostCount");
return (Criteria) this;
}
public Criteria andLostCountBetween(Integer value1, Integer value2) {
addCriterion("lost_count between", value1, value2, "lostCount");
return (Criteria) this;
}
public Criteria andLostCountNotBetween(Integer value1, Integer value2) {
addCriterion("lost_count not between", value1, value2, "lostCount");
return (Criteria) this;
}
public Criteria andStatusIsNull() { public Criteria andStatusIsNull() {
addCriterion("`status` is null"); addCriterion("`status` is null");
return (Criteria) this; return (Criteria) this;

@ -9,6 +9,7 @@
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id" />
<result column="title" jdbcType="VARCHAR" property="title" /> <result column="title" jdbcType="VARCHAR" property="title" />
<result column="term_count" jdbcType="INTEGER" property="termCount" /> <result column="term_count" jdbcType="INTEGER" property="termCount" />
<result column="lost_count" jdbcType="INTEGER" property="lostCount" />
<result column="status" jdbcType="TINYINT" property="status" /> <result column="status" jdbcType="TINYINT" property="status" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
@ -84,7 +85,7 @@
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
id, title, term_count, `status`, create_time, update_time id, title, term_count, lost_count, `status`, create_time, update_time
</sql> </sql>
<select id="selectByExample" parameterType="com.shxy.xymanager_common.entity.MntnActivitiesExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.shxy.xymanager_common.entity.MntnActivitiesExample" resultMap="BaseResultMap">
<!-- <!--
@ -140,10 +141,12 @@
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer"> <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID() SELECT LAST_INSERT_ID()
</selectKey> </selectKey>
insert into mntn_activities (title, term_count, `status`, insert into mntn_activities (title, term_count, lost_count,
create_time, update_time) `status`, create_time, update_time
values (#{title,jdbcType=VARCHAR}, #{termCount,jdbcType=INTEGER}, #{status,jdbcType=TINYINT}, )
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}) values (#{title,jdbcType=VARCHAR}, #{termCount,jdbcType=INTEGER}, #{lostCount,jdbcType=INTEGER},
#{status,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
)
</insert> </insert>
<insert id="insertSelective" parameterType="com.shxy.xymanager_common.entity.MntnActivities"> <insert id="insertSelective" parameterType="com.shxy.xymanager_common.entity.MntnActivities">
<!-- <!--
@ -161,6 +164,9 @@
<if test="termCount != null"> <if test="termCount != null">
term_count, term_count,
</if> </if>
<if test="lostCount != null">
lost_count,
</if>
<if test="status != null"> <if test="status != null">
`status`, `status`,
</if> </if>
@ -178,6 +184,9 @@
<if test="termCount != null"> <if test="termCount != null">
#{termCount,jdbcType=INTEGER}, #{termCount,jdbcType=INTEGER},
</if> </if>
<if test="lostCount != null">
#{lostCount,jdbcType=INTEGER},
</if>
<if test="status != null"> <if test="status != null">
#{status,jdbcType=TINYINT}, #{status,jdbcType=TINYINT},
</if> </if>
@ -215,6 +224,9 @@
<if test="row.termCount != null"> <if test="row.termCount != null">
term_count = #{row.termCount,jdbcType=INTEGER}, term_count = #{row.termCount,jdbcType=INTEGER},
</if> </if>
<if test="row.lostCount != null">
lost_count = #{row.lostCount,jdbcType=INTEGER},
</if>
<if test="row.status != null"> <if test="row.status != null">
`status` = #{row.status,jdbcType=TINYINT}, `status` = #{row.status,jdbcType=TINYINT},
</if> </if>
@ -238,6 +250,7 @@
set id = #{row.id,jdbcType=INTEGER}, set id = #{row.id,jdbcType=INTEGER},
title = #{row.title,jdbcType=VARCHAR}, title = #{row.title,jdbcType=VARCHAR},
term_count = #{row.termCount,jdbcType=INTEGER}, term_count = #{row.termCount,jdbcType=INTEGER},
lost_count = #{row.lostCount,jdbcType=INTEGER},
`status` = #{row.status,jdbcType=TINYINT}, `status` = #{row.status,jdbcType=TINYINT},
create_time = #{row.createTime,jdbcType=TIMESTAMP}, create_time = #{row.createTime,jdbcType=TIMESTAMP},
update_time = #{row.updateTime,jdbcType=TIMESTAMP} update_time = #{row.updateTime,jdbcType=TIMESTAMP}
@ -258,6 +271,9 @@
<if test="termCount != null"> <if test="termCount != null">
term_count = #{termCount,jdbcType=INTEGER}, term_count = #{termCount,jdbcType=INTEGER},
</if> </if>
<if test="lostCount != null">
lost_count = #{lostCount,jdbcType=INTEGER},
</if>
<if test="status != null"> <if test="status != null">
`status` = #{status,jdbcType=TINYINT}, `status` = #{status,jdbcType=TINYINT},
</if> </if>
@ -278,6 +294,7 @@
update mntn_activities update mntn_activities
set title = #{title,jdbcType=VARCHAR}, set title = #{title,jdbcType=VARCHAR},
term_count = #{termCount,jdbcType=INTEGER}, term_count = #{termCount,jdbcType=INTEGER},
lost_count = #{lostCount,jdbcType=INTEGER},
`status` = #{status,jdbcType=TINYINT}, `status` = #{status,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=TIMESTAMP}, create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP} update_time = #{updateTime,jdbcType=TIMESTAMP}

@ -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);
} }
} }
} }

Loading…
Cancel
Save